]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: remove concept of finals
authorRobert Griesemer <gri@golang.org>
Wed, 10 Mar 2021 01:14:15 +0000 (17:14 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 10 Mar 2021 01:46:25 +0000 (01:46 +0000)
This is a 1:1 port of the respective change in go/types
in https://golang.org/cl/299590.

Change-Id: I65ad723f2e21e3d95fc0b94665e0121e31871a48
Reviewed-on: https://go-review.googlesource.com/c/go/+/300250
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/check.go
src/cmd/compile/internal/types2/typexpr.go

index 95fb4e1076cf8a01009b2a96cc5760781bacfd31..c853925a2af56ded23a2354d80dba3ceae6ace23 100644 (file)
@@ -107,7 +107,6 @@ type Checker struct {
        methods  map[*TypeName][]*Func    // maps package scope type names to associated non-blank (non-interface) methods
        untyped  map[syntax.Expr]exprInfo // map of expressions without final type
        delayed  []func()                 // stack of delayed action segments; segments are processed in FIFO order
-       finals   []func()                 // list of final actions; processed at the end of type-checking the current set of files
        objPath  []Object                 // path of object dependencies during type inference (for cycle reporting)
 
        // context within which the current object is type-checked
@@ -147,14 +146,6 @@ func (check *Checker) later(f func()) {
        check.delayed = append(check.delayed, f)
 }
 
-// atEnd adds f to the list of actions processed at the end
-// of type-checking, before initialization order computation.
-// Actions added by atEnd are processed after any actions
-// added by later.
-func (check *Checker) atEnd(f func()) {
-       check.finals = append(check.finals, f)
-}
-
 // push pushes obj onto the object path and returns its index in the path.
 func (check *Checker) push(obj Object) int {
        check.objPath = append(check.objPath, obj)
@@ -214,7 +205,6 @@ func (check *Checker) initFiles(files []*syntax.File) {
        check.methods = nil
        check.untyped = nil
        check.delayed = nil
-       check.finals = nil
 
        // determine package name and collect valid files
        pkg := check.pkg
@@ -281,7 +271,6 @@ func (check *Checker) checkFiles(files []*syntax.File) (err error) {
 
        print("== processDelayed ==")
        check.processDelayed(0) // incl. all functions
-       check.processFinals()
 
        print("== initOrder ==")
        check.initOrder()
@@ -324,16 +313,6 @@ func (check *Checker) processDelayed(top int) {
        check.delayed = check.delayed[:top]
 }
 
-func (check *Checker) processFinals() {
-       n := len(check.finals)
-       for _, f := range check.finals {
-               f() // must not append to check.finals
-       }
-       if len(check.finals) != n {
-               panic("internal error: final action list grew")
-       }
-}
-
 func (check *Checker) recordUntyped() {
        if !debug && check.Types == nil {
                return // nothing to do
index 177fcf4215baf84bac45fa13d61a1061276e244a..14bc91785ef217ddd672f5fb6651607ca340cad1 100644 (file)
@@ -141,7 +141,7 @@ func (check *Checker) ordinaryType(pos syntax.Pos, typ Type) {
        // We don't want to call under() (via Interface) or complete interfaces while we
        // are in the middle of type-checking parameter declarations that might belong to
        // interface methods. Delay this check to the end of type-checking.
-       check.atEnd(func() {
+       check.later(func() {
                if t := asInterface(typ); t != nil {
                        check.completeInterface(pos, t) // TODO(gri) is this the correct position?
                        if t.allTypes != nil {
@@ -574,7 +574,7 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) {
                //
                // Delay this check because it requires fully setup types;
                // it is safe to continue in any case (was issue 6667).
-               check.atEnd(func() {
+               check.later(func() {
                        if !Comparable(typ.key) {
                                var why string
                                if asTypeParam(typ.key) != nil {
@@ -676,7 +676,7 @@ func (check *Checker) instantiatedType(x syntax.Expr, targs []syntax.Expr, def *
 
        // make sure we check instantiation works at least once
        // and that the resulting type is valid
-       check.atEnd(func() {
+       check.later(func() {
                t := typ.expand()
                check.validType(t, nil)
        })
@@ -954,7 +954,7 @@ func (check *Checker) completeInterface(pos syntax.Pos, ityp *Interface) {
                        // If we're pre-go1.14 (overlapping embeddings are not permitted), report that
                        // error here as well (even though we could do it eagerly) because it's the same
                        // error message.
-                       check.atEnd(func() {
+                       check.later(func() {
                                if !check.allowVersion(m.pkg, 1, 14) || !check.identical(m.typ, other.Type()) {
                                        var err error_
                                        err.errorf(pos, "duplicate method %s", m.name)
@@ -1170,7 +1170,7 @@ func (check *Checker) structType(styp *Struct, e *syntax.StructType) {
                        // (via under(t)) a possibly incomplete type.
                        embeddedTyp := typ // for closure below
                        embeddedPos := pos
-                       check.atEnd(func() {
+                       check.later(func() {
                                t, isPtr := deref(embeddedTyp)
                                switch t := optype(t).(type) {
                                case *Basic:
@@ -1230,7 +1230,7 @@ func (check *Checker) collectTypeConstraints(pos syntax.Pos, types []syntax.Expr
        // interfaces, which may not be complete yet. It's ok to do this check at the
        // end because it's not a requirement for correctness of the code.
        // Note: This is a quadratic algorithm, but type lists tend to be short.
-       check.atEnd(func() {
+       check.later(func() {
                for i, t := range list {
                        if t := asInterface(t); t != nil {
                                check.completeInterface(types[i].Pos(), t)