1
0
mirror of https://github.com/golang/go synced 2024-11-22 20:24:47 -07:00

cmd/compile/internal/types2: remove concept of finals

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>
This commit is contained in:
Robert Griesemer 2021-03-09 17:14:15 -08:00
parent acd7cb5887
commit 41245ab283
2 changed files with 6 additions and 27 deletions

View 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

View 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)