Skip to content

Commit

Permalink
go/types: make Interface.Complete a no-op
Browse files Browse the repository at this point in the history
This is a partial port of CL 340255 to go/types. Of course we can't
delete Interface.Complete, but make it a no-op.

Completing interfaces is no longer necessary.

Change-Id: Ida3c84cc94713f14a646c7682f5d4ae5339a0faa
Reviewed-on: https://go-review.googlesource.com/c/go/+/342489
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
  • Loading branch information
findleyr committed Aug 16, 2021
1 parent e61d144 commit fda8ee8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
4 changes: 0 additions & 4 deletions src/go/internal/gcimporter/iimport.go
Expand Up @@ -174,10 +174,6 @@ func iImportData(fset *token.FileSet, imports map[string]*types.Package, dataRea
p.doDecl(localpkg, name)
}

for _, typ := range p.interfaceList {
typ.Complete()
}

// record all referenced packages as imports
list := append(([]*types.Package)(nil), pkgList[1:]...)
sort.Sort(byPath(list))
Expand Down
18 changes: 4 additions & 14 deletions src/go/types/interface.go
Expand Up @@ -104,22 +104,12 @@ func (t *Interface) IsComparable() bool { return t.typeSet().IsComparable() }
// IsConstraint reports whether interface t is not just a method set.
func (t *Interface) IsConstraint() bool { return !t.typeSet().IsMethodSet() }

// Complete computes the interface's type set. It must be called by users of
// NewInterfaceType and NewInterface after the interface's embedded types are
// fully defined and before using the interface type in any way other than to
// form other types. The interface must not contain duplicate methods or a
// panic occurs. Complete returns the receiver.
// Complete just returns its receiver. There's no other effect.
//
// Deprecated: Type sets are now computed lazily, on demand; this function
// is only here for backward-compatibility. It does not have to
// be called explicitly anymore.
// Deprecated: Interfaces are now completed on demand; this function is only
// here for backward-compatibility. It does not have to be called explicitly
// anymore.
func (t *Interface) Complete() *Interface {
// Some tests are still depending on the state change
// (string representation of an Interface not containing an
// /* incomplete */ marker) caused by the explicit Complete
// call, so we compute the type set eagerly here.
t.complete = true
t.typeSet()
return t
}

Expand Down
3 changes: 2 additions & 1 deletion src/go/types/issues_test.go
Expand Up @@ -405,8 +405,9 @@ func TestIssue28282(t *testing.T) {
// create type interface { error }
et := Universe.Lookup("error").Type()
it := NewInterfaceType(nil, []Type{et})
it.Complete()
// verify that after completing the interface, the embedded method remains unchanged
// (interfaces are "completed" lazily now, so the completion happens implicitly when
// accessing Method(0))
want := et.Underlying().(*Interface).Method(0)
got := it.Method(0)
if got != want {
Expand Down

0 comments on commit fda8ee8

Please sign in to comment.