diff --git a/src/cmd/compile/internal/types2/context.go b/src/cmd/compile/internal/types2/context.go index 2d790fe5dd..ae39c7b830 100644 --- a/src/cmd/compile/internal/types2/context.go +++ b/src/cmd/compile/internal/types2/context.go @@ -12,6 +12,26 @@ import ( "sync" ) +// This file contains a definition of the type-checking context; an opaque type +// that may be supplied by users during instantiation. +// +// Contexts serve two purposes: +// - reduce the duplication of identical instances +// - short-circuit instantiation cycles +// +// For the latter purpose, we must always have a context during instantiation, +// whether or not it is supplied by the user. For both purposes, it must be the +// case that hashing a pointer-identical type produces consistent results +// (somewhat obviously). +// +// However, neither of these purposes require that our hash is perfect, and so +// this was not an explicit design goal of the context type. In fact, due to +// concurrent use it is convenient not to guarantee de-duplication. +// +// Nevertheless, in the future it could be helpful to allow users to leverage +// contexts to canonicalize instances, and it would probably be possible to +// achieve such a guarantee. + // A Context is an opaque type checking context. It may be used to share // identical type instances across type-checked packages or calls to // Instantiate. Contexts are safe for concurrent use. diff --git a/src/go/types/context.go b/src/go/types/context.go index 692b3a6682..15756b062d 100644 --- a/src/go/types/context.go +++ b/src/go/types/context.go @@ -12,6 +12,26 @@ import ( "sync" ) +// This file contains a definition of the type-checking context; an opaque type +// that may be supplied by users during instantiation. +// +// Contexts serve two purposes: +// - reduce the duplication of identical instances +// - short-circuit instantiation cycles +// +// For the latter purpose, we must always have a context during instantiation, +// whether or not it is supplied by the user. For both purposes, it must be the +// case that hashing a pointer-identical type produces consistent results +// (somewhat obviously). +// +// However, neither of these purposes require that our hash is perfect, and so +// this was not an explicit design goal of the context type. In fact, due to +// concurrent use it is convenient not to guarantee de-duplication. +// +// Nevertheless, in the future it could be helpful to allow users to leverage +// contexts to canonicalize instances, and it would probably be possible to +// achieve such a guarantee. + // A Context is an opaque type checking context. It may be used to share // identical type instances across type-checked packages or calls to // Instantiate. Contexts are safe for concurrent use.