assert(len(targs) == typ.TypeParams().Len())
if check.conf.Trace {
- check.trace(pos, "-- instantiating %s with %s", typ, targs)
+ check.trace(pos, "-- instantiating signature %s with %s", typ, targs)
check.indent++
defer func() {
check.indent--
} else {
check.mono.recordInstance(check.pkg, pos, tparams, targs, xlist)
}
- })
+ }).describef(pos, "verify instantiation")
return inst
}
// this is a sufficiently bounded process.
for i := top; i < len(check.delayed); i++ {
a := &check.delayed[i]
- if check.conf.Trace && a.desc != nil {
- fmt.Println()
- check.trace(a.desc.pos.Pos(), "-- "+a.desc.format, a.desc.args...)
+ if check.conf.Trace {
+ if a.desc != nil {
+ check.trace(a.desc.pos.Pos(), "-- "+a.desc.format, a.desc.args...)
+ } else {
+ check.trace(nopos, "-- delayed %p", a.f)
+ }
}
a.f() // may append to check.delayed
+ if check.conf.Trace {
+ fmt.Println()
+ }
}
assert(top <= len(check.delayed)) // stack must not have shrunk
check.delayed = check.delayed[:top]
if !check.conf.IgnoreFuncBodies && fdecl.Body != nil {
check.later(func() {
check.funcBody(decl, obj.name, sig, fdecl.Body, nil)
- })
+ }).describef(obj, "func %s", obj.name)
}
}
//
func (check *Checker) rawExpr(x *operand, e syntax.Expr, hint Type, allowGeneric bool) exprKind {
if check.conf.Trace {
- check.trace(e.Pos(), "expr %s", e)
+ check.trace(e.Pos(), "-- expr %s", e)
check.indent++
defer func() {
check.indent--
// but before the enclosing scope contents changes (#22992).
check.later(func() {
check.funcBody(decl, "<function literal>", sig, e.Body, iota)
- })
+ }).describef(e, "func literal")
}
x.mode = value
x.typ = sig
// instance creates a type or function instance using the given original type
// typ and arguments targs. For Named types the resulting instance will be
-// unexpanded.
+// unexpanded. check may be nil.
func (check *Checker) instance(pos syntax.Pos, orig Type, targs []Type, ctxt *Context) (res Type) {
var h string
if ctxt != nil {
// anymore; we need to set tparams to nil.
sig.tparams = nil
res = sig
+
default:
// only types and functions can be generic
panic(fmt.Sprintf("%v: cannot instantiate %v", pos, orig))
// expandNamed ensures that the underlying type of n is instantiated.
// The underlying type will be Typ[Invalid] if there was an error.
func expandNamed(ctxt *Context, n *Named, instPos syntax.Pos) (tparams *TypeParamList, underlying Type, methods *methodList) {
+ check := n.check
+ if check != nil && check.conf.Trace {
+ check.trace(instPos, "-- expandNamed %s", n)
+ check.indent++
+ defer func() {
+ check.indent--
+ check.trace(instPos, "=> %s (tparams = %s, under = %s)", n, tparams.list(), underlying)
+ }()
+ }
+
n.orig.resolve(ctxt)
assert(n.orig.underlying != nil)
- check := n.check
-
if _, unexpanded := n.orig.underlying.(*Named); unexpanded {
// We should only get an unexpanded underlying here during type checking
// (for example, in recursive type declarations).
}
if check.conf.Trace {
- check.trace(body.Pos(), "--- %s: %s", name, sig)
- defer func() {
- check.trace(syntax.EndPos(body), "--- <end>")
- }()
+ check.trace(body.Pos(), "-- %s: %s", name, sig)
}
// set function scope extent
pos = ityp.methods[0].pos
}
- check.trace(pos, "type set for %s", ityp)
+ check.trace(pos, "-- type set for %s", ityp)
check.indent++
defer func() {
check.indent--
err.errorf(mpos[other.(*Func)], "other declaration of %s", m.name)
check.report(&err)
}
- })
+ }).describef(pos, "duplicate method check for %s", m.name)
}
}
}
}
}
- })
+ }).describef(e, "check var type %s", typ)
}
// definedType is like typ but also accepts a type name def.
}
check.errorf(e.Key, "invalid map key type %s%s", typ.key, why)
}
- })
+ }).describef(e.Key, "check map key %s", typ.key)
return typ
func (check *Checker) instantiatedType(x syntax.Expr, xlist []syntax.Expr, def *Named) (res Type) {
if check.conf.Trace {
- check.trace(x.Pos(), "-- instantiating %s with %s", x, xlist)
+ check.trace(x.Pos(), "-- instantiating type %s with %s", x, xlist)
check.indent++
defer func() {
check.indent--
}
check.validType(inst)
- })
+ }).describef(x, "resolve instance %s", inst)
return inst
}
check.softErrorf(tlist[i], "overlapping terms %s and %s", t, terms[j])
}
}
- })
+ }).describef(uexpr, "check term validity %s", uexpr)
return u
}
assert(len(targs) == typ.TypeParams().Len())
if trace {
- check.trace(pos, "-- instantiating %s with %s", typ, targs)
+ check.trace(pos, "-- instantiating signature %s with %s", typ, targs)
check.indent++
defer func() {
check.indent--
} else {
check.mono.recordInstance(check.pkg, pos, tparams, targs, xlist)
}
- })
+ }).describef(atPos(pos), "verify instantiation")
return inst
}
// this is a sufficiently bounded process.
for i := top; i < len(check.delayed); i++ {
a := &check.delayed[i]
- if trace && a.desc != nil {
- fmt.Println()
- check.trace(a.desc.pos.Pos(), "-- "+a.desc.format, a.desc.args...)
+ if trace {
+ if a.desc != nil {
+ check.trace(a.desc.pos.Pos(), "-- "+a.desc.format, a.desc.args...)
+ } else {
+ check.trace(token.NoPos, "-- delayed %p", a.f)
+ }
}
a.f() // may append to check.delayed
+ if trace {
+ fmt.Println()
+ }
}
assert(top <= len(check.delayed)) // stack must not have shrunk
check.delayed = check.delayed[:top]
if !check.conf.IgnoreFuncBodies && fdecl.Body != nil {
check.later(func() {
check.funcBody(decl, obj.name, sig, fdecl.Body, nil)
- })
+ }).describef(obj, "func %s", obj.name)
}
}
//
func (check *Checker) rawExpr(x *operand, e ast.Expr, hint Type, allowGeneric bool) exprKind {
if trace {
- check.trace(e.Pos(), "expr %s", e)
+ check.trace(e.Pos(), "-- expr %s", e)
check.indent++
defer func() {
check.indent--
// but before the enclosing scope contents changes (#22992).
check.later(func() {
check.funcBody(decl, "<function literal>", sig, e.Body, iota)
- })
+ }).describef(e, "func literal")
}
x.mode = value
x.typ = sig
// instance creates a type or function instance using the given original type
// typ and arguments targs. For Named types the resulting instance will be
-// unexpanded.
+// unexpanded. check may be nil.
func (check *Checker) instance(pos token.Pos, orig Type, targs []Type, ctxt *Context) (res Type) {
var h string
if ctxt != nil {
// anymore; we need to set tparams to nil.
sig.tparams = nil
res = sig
+
default:
// only types and functions can be generic
panic(fmt.Sprintf("%v: cannot instantiate %v", pos, orig))
// expandNamed ensures that the underlying type of n is instantiated.
// The underlying type will be Typ[Invalid] if there was an error.
func expandNamed(ctxt *Context, n *Named, instPos token.Pos) (tparams *TypeParamList, underlying Type, methods *methodList) {
+ check := n.check
+ if check != nil && trace {
+ check.trace(instPos, "-- expandNamed %s", n)
+ check.indent++
+ defer func() {
+ check.indent--
+ check.trace(instPos, "=> %s (tparams = %s, under = %s)", n, tparams.list(), underlying)
+ }()
+ }
+
n.orig.resolve(ctxt)
assert(n.orig.underlying != nil)
- check := n.check
-
if _, unexpanded := n.orig.underlying.(*Named); unexpanded {
// We should only get an unexpanded underlying here during type checking
// (for example, in recursive type declarations).
}
if trace {
- check.trace(body.Pos(), "--- %s: %s", name, sig)
- defer func() {
- check.trace(body.End(), "--- <end>")
- }()
+ check.trace(body.Pos(), "-- %s: %s", name, sig)
}
// set function scope extent
pos = ityp.methods[0].pos
}
- check.trace(pos, "type set for %s", ityp)
+ check.trace(pos, "-- type set for %s", ityp)
check.indent++
defer func() {
check.indent--
check.errorf(atPos(pos), _DuplicateDecl, "duplicate method %s", m.name)
check.errorf(atPos(mpos[other.(*Func)]), _DuplicateDecl, "\tother declaration of %s", m.name) // secondary error, \t indented
}
- })
+ }).describef(atPos(pos), "duplicate method check for %s", m.name)
}
}
}
}
}
- })
+ }).describef(e, "check var type %s", typ)
}
// definedType is like typ but also accepts a type name def.
}
check.errorf(e.Key, _IncomparableMapKey, "incomparable map key type %s%s", typ.key, why)
}
- })
+ }).describef(e.Key, "check map key %s", typ.key)
return typ
func (check *Checker) instantiatedType(ix *typeparams.IndexExpr, def *Named) (res Type) {
pos := ix.X.Pos()
if trace {
- check.trace(pos, "-- instantiating %s with %s", ix.X, ix.Indices)
+ check.trace(pos, "-- instantiating type %s with %s", ix.X, ix.Indices)
check.indent++
defer func() {
check.indent--
}
check.validType(inst)
- })
+ }).describef(ix, "resolve instance %s", inst)
return inst
}
check.softErrorf(tlist[i], _InvalidUnion, "overlapping terms %s and %s", t, terms[j])
}
}
- })
+ }).describef(uexpr, "check term validity %s", uexpr)
return u
}