diff options
author | Robert Griesemer <gri@golang.org> | 2021-02-10 17:21:23 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-02-12 22:16:58 +0000 |
commit | bab3461123060804628744a82e8ba03c51c27564 (patch) | |
tree | a04943812a119b574757c5a103637ab2ad87dee0 /src/cmd/compile/internal/types2/infer.go | |
parent | 9168590977fca7a8d86b27b6c39fff0cd5efb8a4 (diff) | |
download | go-bab3461123060804628744a82e8ba03c51c27564.tar.gz go-bab3461123060804628744a82e8ba03c51c27564.zip |
[dev.typeparams] cmd/compile/internal/types: review of infer.go
The changes between (equivalent, and reviewed) go/types/infer.go
and infer.go can be seen by comparing patchset 1 and 2. The actual
change is just removing the "// UNREVIEWED" marker and fixing a
few comments.
Change-Id: Ieb0c07c325a2e446550f85b159f99d4dfe5f1d5a
Reviewed-on: https://go-review.googlesource.com/c/go/+/291171
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/types2/infer.go')
-rw-r--r-- | src/cmd/compile/internal/types2/infer.go | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/types2/infer.go b/src/cmd/compile/internal/types2/infer.go index 125d3f31b9..09d099e625 100644 --- a/src/cmd/compile/internal/types2/infer.go +++ b/src/cmd/compile/internal/types2/infer.go @@ -1,4 +1,3 @@ -// UNREVIEWED // Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -15,7 +14,7 @@ import "bytes" // is impossible because unification fails, an error is reported and the resulting types list is // nil, and index is 0. Otherwise, types is the list of inferred type arguments, and index is // the index of the first type argument in that list that couldn't be inferred (and thus is nil). -// If all type arguments where inferred successfully, index is < 0. +// If all type arguments were inferred successfully, index is < 0. func (check *Checker) infer(tparams []*TypeName, params *Tuple, args []*operand) (types []Type, index int) { assert(params.Len() == len(args)) @@ -70,7 +69,7 @@ func (check *Checker) infer(tparams []*TypeName, params *Tuple, args []*operand) if targ := arg.typ; isTyped(targ) { // If we permit bidirectional unification, and targ is // a generic function, we need to initialize u.y with - // the respectice type parameters of targ. + // the respective type parameters of targ. if !u.unify(par.typ, targ) { errorf("type", par.typ, targ, arg) return nil, 0 @@ -292,19 +291,17 @@ func (check *Checker) inferB(tparams []*TypeName, targs []Type) (types []Type, i typ := tpar.typ.(*TypeParam) sbound := check.structuralType(typ.bound.Under()) if sbound != nil { - //check.dump(">>> unify(%s, %s)", tpar, sbound) if !u.unify(typ, sbound) { check.errorf(tpar.pos, "%s does not match %s", tpar, sbound) return nil, 0 } - //check.dump(">>> => indices = %v, types = %s", u.x.indices, u.types) } } // u.x.types() now contains the incoming type arguments plus any additional type // arguments for which there were structural constraints. The newly inferred non- // nil entries may still contain references to other type parameters. For instance, - // for [type A interface{}, B interface{type []C}, C interface{type *A}], if A == int + // for [A any, B interface{type []C}, C interface{type *A}], if A == int // was given, unification produced the type list [int, []C, *A]. We eliminate the // remaining type parameters by substituting the type parameters in this type list // until nothing changes anymore. @@ -316,7 +313,7 @@ func (check *Checker) inferB(tparams []*TypeName, targs []Type) (types []Type, i } // dirty tracks the indices of all types that may still contain type parameters. - // We know that nil types entries and entries corresponding to provided (non-nil) + // We know that nil type entries and entries corresponding to provided (non-nil) // type arguments are clean, so exclude them from the start. var dirty []int for i, typ := range types { @@ -326,8 +323,8 @@ func (check *Checker) inferB(tparams []*TypeName, targs []Type) (types []Type, i } for len(dirty) > 0 { - // TODO(gri) Instead of creating a new smap for each iteration, - // provide an update operation for smaps and only change when + // TODO(gri) Instead of creating a new substMap for each iteration, + // provide an update operation for substMaps and only change when // needed. Optimization. smap := makeSubstMap(tparams, types) n := 0 @@ -341,7 +338,6 @@ func (check *Checker) inferB(tparams []*TypeName, targs []Type) (types []Type, i } dirty = dirty[:n] } - //check.dump(">>> inferred types = %s", types) return } |