]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: rename types.context to types.environment
authorRobert Griesemer <gri@golang.org>
Tue, 16 Nov 2021 19:27:56 +0000 (11:27 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 17 Nov 2021 04:31:55 +0000 (04:31 +0000)
This CL is a clean port of CL 363176 from go/types to types2.

It also includes a minor adjustment to a field access in go/types
to match types2 in that respect.

Change-Id: If33fc7e68372b12d61d06b75dd9f7c0715b57bc1
Reviewed-on: https://go-review.googlesource.com/c/go/+/364474
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/stmt.go
src/go/types/decl.go

index faf4ccac0b0e2eb457ace5bfba15a6820df975c9..38fc25c74db83e9cc90314cd0a47fac5d31e8402 100644 (file)
@@ -39,8 +39,9 @@ type exprInfo struct {
        val   constant.Value // constant value; or nil (if not a constant)
 }
 
-// A context represents the context within which an object is type-checked.
-type context struct {
+// An environment represents the environment within which an object is
+// type-checked.
+type environment struct {
        decl          *declInfo                 // package-level declaration whose init expression/function body is checked
        scope         *Scope                    // top-most scope for lookups
        pos           syntax.Pos                // if valid, identifiers are looked up as if at position pos (used by Eval)
@@ -53,9 +54,9 @@ type context struct {
        hasCallOrRecv bool                      // set if an expression contains a function call or channel receive operation
 }
 
-// lookup looks up name in the current context and returns the matching object, or nil.
-func (ctxt *context) lookup(name string) Object {
-       _, obj := ctxt.scope.LookupParent(name, ctxt.pos)
+// lookup looks up name in the current environment and returns the matching object, or nil.
+func (env *environment) lookup(name string) Object {
+       _, obj := env.scope.LookupParent(name, env.pos)
        return obj
 }
 
@@ -137,9 +138,9 @@ type Checker struct {
        objPath  []Object                 // path of object dependencies during type inference (for cycle reporting)
        defTypes []*Named                 // defined types created during type checking, for final validation.
 
-       // context within which the current object is type-checked
-       // (valid only for the duration of type-checking a specific object)
-       context
+       // environment within which the current object is type-checked (valid only
+       // for the duration of type-checking a specific object)
+       environment
 
        // debugging
        indent int // indentation for tracing
index e85abbb82faeeddea860b52603f3b567d030b7e9..4b79c59af31f6938658aaa279af2dad16d29150b 100644 (file)
@@ -51,7 +51,7 @@ func pathString(path []Object) string {
        return s
 }
 
-// objDecl type-checks the declaration of obj in its respective (file) context.
+// objDecl type-checks the declaration of obj in its respective (file) environment.
 // For the meaning of def, see Checker.definedType, in typexpr.go.
 func (check *Checker) objDecl(obj Object, def *Named) {
        if check.conf.Trace && obj.Type() == nil {
@@ -178,11 +178,11 @@ func (check *Checker) objDecl(obj Object, def *Named) {
                unreachable()
        }
 
-       // save/restore current context and setup object context
-       defer func(ctxt context) {
-               check.context = ctxt
-       }(check.context)
-       check.context = context{
+       // save/restore current environment and set up object environment
+       defer func(env environment) {
+               check.environment = env
+       }(check.environment)
+       check.environment = environment{
                scope: d.file,
        }
 
@@ -646,7 +646,7 @@ func (check *Checker) collectTypeParams(dst **TypeParamList, list []*syntax.Fiel
        // function closures may appear inside a type parameter list but they
        // cannot be generic, and their bodies are processed in delayed and
        // sequential fashion. Note that with each new declaration, we save
-       // the existing context and restore it when done; thus inTParamList
+       // the existing environment and restore it when done; thus inTParamList
        // is true exactly only when we are in a specific type parameter list.
        assert(!check.inTParamList)
        check.inTParamList = true
index 6869c87929505c8e0f3029c813140b3aec5cd580..44d9256c50f1ac231ebe6a6c57f0c35eaa104c7e 100644 (file)
@@ -28,13 +28,13 @@ func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body
        sig.scope.pos = body.Pos()
        sig.scope.end = syntax.EndPos(body)
 
-       // save/restore current context and setup function context
+       // save/restore current environment and set up function environment
        // (and use 0 indentation at function start)
-       defer func(ctxt context, indent int) {
-               check.context = ctxt
+       defer func(env environment, indent int) {
+               check.environment = env
                check.indent = indent
-       }(check.context, check.indent)
-       check.context = context{
+       }(check.environment, check.indent)
+       check.environment = environment{
                decl:  decl,
                scope: sig.scope,
                iota:  iota,
index 2108cf6b0551ff0e52cf0b9463eef7fa8da689f1..4f28553aa6af08b0916897d98f598662c757f5a5 100644 (file)
@@ -239,7 +239,7 @@ loop:
                        // If we reach a generic type that is part of a cycle
                        // and we are in a type parameter list, we have a cycle
                        // through a type parameter list, which is invalid.
-                       if check.environment.inTParamList && isGeneric(obj.typ) {
+                       if check.inTParamList && isGeneric(obj.typ) {
                                tparCycle = true
                                break loop
                        }