diff options
| author | Matthew Dempsky <mdempsky@google.com> | 2023-08-16 18:56:41 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-08-17 19:36:26 +0000 |
| commit | 5c6fbd2c3ee4a71493d3a7aa6f09a70ddcf0b230 (patch) | |
| tree | 223fe819041df81f3a631f83ad1500d9825613cf /src/cmd/compile/internal/noder/reader.go | |
| parent | e45397100584e0ca55901f203d16c2acadbb4447 (diff) | |
| download | go-5c6fbd2c3ee4a71493d3a7aa6f09a70ddcf0b230.tar.xz | |
cmd/compile: always construct typechecked closures
This CL extends ir.NewClosureFunc to take the signature type argument,
and to handle naming the closure and adding it to typecheck.Target.
It also removes the code for typechecking OCLOSURE and ODCLFUNC nodes,
by having them always constructed as typechecked. ODCLFUNC node
construction will be further simplified in the followup CL.
Change-Id: Iabde4557d33051ee470a3bc4fd49599490024cba
Reviewed-on: https://go-review.googlesource.com/c/go/+/520337
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/noder/reader.go')
| -rw-r--r-- | src/cmd/compile/internal/noder/reader.go | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index c51963e1c2..d71a1fc5fa 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -755,6 +755,7 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index, implicits, explicits []*types.Typ name.Func = ir.NewFunc(r.pos()) name.Func.Nname = name + name.Func.SetTypecheck(1) if r.hasTypeParams() { name.Func.SetDupok(true) @@ -999,6 +1000,7 @@ func (r *reader) method(rext *reader) *types.Field { name.Func = ir.NewFunc(r.pos()) name.Func.Nname = name + name.Func.SetTypecheck(1) if r.hasTypeParams() { name.Func.SetDupok(true) @@ -1096,8 +1098,6 @@ func (r *reader) funcExt(name *ir.Name, method *types.Sym) { } } - typecheck.Func(fn) - if r.Bool() { assert(name.Defn == nil) @@ -2722,15 +2722,9 @@ func (r *reader) syntheticClosure(origPos src.XPos, typ *types.Type, ifaceHack b // position instead. See also the explanation in reader.funcLit. inlPos := r.inlPos(origPos) - fn := ir.NewClosureFunc(origPos, r.curfn != nil) + // TODO(mdempsky): Remove hard-coding of typecheck.Target. + fn := ir.NewClosureFunc(origPos, inlPos, typ, r.curfn, typecheck.Target) fn.SetWrapper(true) - clo := fn.OClosure - clo.SetPos(inlPos) - ir.NameClosure(clo, r.curfn) - - setType(fn.Nname, typ) - typecheck.Func(fn) - setType(clo, fn.Type()) var init ir.Nodes for i, n := range captures { @@ -2767,8 +2761,7 @@ func (r *reader) syntheticClosure(origPos src.XPos, typ *types.Type, ifaceHack b bodyReader[fn] = pri pri.funcBody(fn) - // TODO(mdempsky): Remove hard-coding of typecheck.Target. - return ir.InitExpr(init, ir.UseClosure(clo, typecheck.Target)) + return ir.InitExpr(init, fn.OClosure) } // syntheticSig duplicates and returns the params and results lists @@ -3120,14 +3113,8 @@ func (r *reader) funcLit() ir.Node { xtype2 := r.signature(nil) r.suppressInlPos-- - fn := ir.NewClosureFunc(pos, r.curfn != nil) - clo := fn.OClosure - clo.SetPos(r.inlPos(pos)) // see comment above - ir.NameClosure(clo, r.curfn) - - setType(fn.Nname, xtype2) - typecheck.Func(fn) - setType(clo, fn.Type()) + // TODO(mdempsky): Remove hard-coding of typecheck.Target. + fn := ir.NewClosureFunc(pos, r.inlPos(pos), xtype2, r.curfn, typecheck.Target) fn.ClosureVars = make([]*ir.Name, 0, r.Len()) for len(fn.ClosureVars) < cap(fn.ClosureVars) { @@ -3141,8 +3128,7 @@ func (r *reader) funcLit() ir.Node { r.addBody(fn, nil) - // TODO(mdempsky): Remove hard-coding of typecheck.Target. - return ir.UseClosure(clo, typecheck.Target) + return fn.OClosure } func (r *reader) exprList() []ir.Node { @@ -3463,6 +3449,7 @@ func unifiedInlineCall(call *ir.CallExpr, fn *ir.Func, inlIndex int) *ir.Inlined // TODO(mdempsky): This still feels clumsy. Can we do better? tmpfn := ir.NewFunc(fn.Pos()) tmpfn.Nname = ir.NewNameAt(fn.Nname.Pos(), callerfn.Sym(), fn.Type()) + tmpfn.SetTypecheck(1) tmpfn.Closgen = callerfn.Closgen defer func() { callerfn.Closgen = tmpfn.Closgen }() @@ -3638,6 +3625,7 @@ func expandInline(fn *ir.Func, pri pkgReaderIndex) { tmpfn := ir.NewFunc(fn.Pos()) tmpfn.Nname = ir.NewNameAt(fn.Nname.Pos(), fn.Sym(), fn.Type()) + tmpfn.SetTypecheck(1) tmpfn.ClosureVars = fn.ClosureVars { @@ -3861,7 +3849,6 @@ func wrapMethodValue(recvType *types.Type, method *types.Field, target *ir.Packa recv := ir.NewHiddenParam(pos, fn, typecheck.Lookup(".this"), recvType) if !needed { - typecheck.Func(fn) return } @@ -3883,6 +3870,7 @@ func newWrapperFunc(pos src.XPos, sym *types.Sym, wrapper *types.Type, method *t fn.Nname = name setType(name, sig) + fn.SetTypecheck(1) // TODO(mdempsky): De-duplicate with similar logic in funcargs. defParams := func(class ir.Class, params *types.Type) { @@ -3899,8 +3887,6 @@ func newWrapperFunc(pos src.XPos, sym *types.Sym, wrapper *types.Type, method *t } func finishWrapperFunc(fn *ir.Func, target *ir.Package) { - typecheck.Func(fn) - ir.WithFunc(fn, func() { typecheck.Stmts(fn.Body) }) |
