aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/noder.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-01-12 15:56:54 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-12 15:56:55 -0800
commitf065ff221b546c9ac550d947f89eb3b44b11fc2f (patch)
tree2957e97b914933fc2d68196539ed2c66998a12ff /src/cmd/compile/internal/noder/noder.go
parent099599662d15598fc2690e60bd36bc087a3bdec5 (diff)
parentd9acf6f3a3758c3096ee5ef5a24c2bc5df9d9c8b (diff)
downloadgo-f065ff221b546c9ac550d947f89eb3b44b11fc2f.tar.gz
go-f065ff221b546c9ac550d947f89eb3b44b11fc2f.zip
[dev.typeparams] all: merge dev.regabi (d9acf6f) into dev.typeparams
Conflicts: - src/cmd/compile/fmtmap_test.go Merge List: + 2021-01-12 d9acf6f3a3 [dev.regabi] cmd/compile: remove Func.ClosureType + 2021-01-12 41352fd401 [dev.regabi] cmd/compile: transform closures during walk + 2021-01-12 d6ad88b4db [dev.regabi] cmd/compile: compile functions before closures + 2021-01-12 432f9ffb11 [dev.regabi] cmd/compile: unindent compileFunctions + 2021-01-12 cc90e7a51e [dev.regabi] cmd/compile: always use the compile queue + 2021-01-12 cd5b74d2df [dev.regabi] cmd/compile: call NeedFuncSym in InitLSym + 2021-01-12 95acd8121b [dev.regabi] cmd/compile: remove Name.Typegen + 2021-01-12 12ee55ba7b [dev.regabi] cmd/compile: stop using Vargen for import/export + 2021-01-12 b4d2a0445b [dev.regabi] cmd/compile: refactor closure var setup/teardown + 2021-01-12 f57f484053 [dev.regabi] cmd/compile: decouple escape analysis from Name.Vargen + 2021-01-10 7fd84c6e46 [dev.regabi] cmd/compile: remove OCLOSUREREAD + 2021-01-10 c9c26d7ffb [dev.regabi] cmd/compile: use ClosureVars for method value wrappers + 2021-01-10 950cf4d46c [dev.regabi] cmd/compile: bind closure vars during SSA constructions + 2021-01-10 8b2efa990b [dev.regabi] cmd/compile: deref PAUTOHEAPs during SSA construction + 2021-01-08 6ee9b118a2 [dev.regabi] cmd/compile: remove fmt_test code; it has outlived its usefulness + 2021-01-08 b241938e04 [dev.regabi] cmd/compile: fix some methods error text Change-Id: I9a530f9a78b16e2bb14ea0a4ecbd9a75f9350342
Diffstat (limited to 'src/cmd/compile/internal/noder/noder.go')
-rw-r--r--src/cmd/compile/internal/noder/noder.go66
1 files changed, 3 insertions, 63 deletions
diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go
index 5a9e37af7d..6a0ee831d7 100644
--- a/src/cmd/compile/internal/noder/noder.go
+++ b/src/cmd/compile/internal/noder/noder.go
@@ -1888,7 +1888,6 @@ func fakeRecv() *ir.Field {
func (p *noder) funcLit(expr *syntax.FuncLit) ir.Node {
xtype := p.typeExpr(expr.Type)
- ntype := p.typeExpr(expr.Type)
fn := ir.NewFunc(p.pos(expr))
fn.SetIsHiddenClosure(ir.CurFunc != nil)
@@ -1899,50 +1898,11 @@ func (p *noder) funcLit(expr *syntax.FuncLit) ir.Node {
fn.Nname.Defn = fn
clo := ir.NewClosureExpr(p.pos(expr), fn)
- fn.ClosureType = ntype
fn.OClosure = clo
p.funcBody(fn, expr.Body)
- // closure-specific variables are hanging off the
- // ordinary ones in the symbol table; see oldname.
- // unhook them.
- // make the list of pointers for the closure call.
- for _, v := range fn.ClosureVars {
- // Unlink from v1; see comment in syntax.go type Param for these fields.
- v1 := v.Defn
- v1.Name().Innermost = v.Outer
-
- // If the closure usage of v is not dense,
- // we need to make it dense; now that we're out
- // of the function in which v appeared,
- // look up v.Sym in the enclosing function
- // and keep it around for use in the compiled code.
- //
- // That is, suppose we just finished parsing the innermost
- // closure f4 in this code:
- //
- // func f() {
- // v := 1
- // func() { // f2
- // use(v)
- // func() { // f3
- // func() { // f4
- // use(v)
- // }()
- // }()
- // }()
- // }
- //
- // At this point v.Outer is f2's v; there is no f3's v.
- // To construct the closure f4 from within f3,
- // we need to use f3's v and in this case we need to create f3's v.
- // We are now in the context of f3, so calling oldname(v.Sym)
- // obtains f3's v, creating it if necessary (as it is in the example).
- //
- // capturevars will decide whether to use v directly or &v.
- v.Outer = oldname(v.Sym()).(*ir.Name)
- }
+ ir.FinishCaptureNames(base.Pos, ir.CurFunc, fn)
return clo
}
@@ -1976,32 +1936,12 @@ func oldname(s *types.Sym) ir.Node {
return ir.NewIdent(base.Pos, s)
}
- if ir.CurFunc != nil && n.Op() == ir.ONAME && n.Name().Curfn != nil && n.Name().Curfn != ir.CurFunc {
- // Inner func is referring to var in outer func.
- //
+ if n, ok := n.(*ir.Name); ok {
// TODO(rsc): If there is an outer variable x and we
// are parsing x := 5 inside the closure, until we get to
// the := it looks like a reference to the outer x so we'll
// make x a closure variable unnecessarily.
- n := n.(*ir.Name)
- c := n.Innermost
- if c == nil || c.Curfn != ir.CurFunc {
- // Do not have a closure var for the active closure yet; make one.
- c = typecheck.NewName(s)
- c.Class = ir.PAUTOHEAP
- c.SetIsClosureVar(true)
- c.Defn = n
-
- // Link into list of active closure variables.
- // Popped from list in func funcLit.
- c.Outer = n.Innermost
- n.Innermost = c
-
- ir.CurFunc.ClosureVars = append(ir.CurFunc.ClosureVars, c)
- }
-
- // return ref to closure var, not original
- return c
+ return ir.CaptureName(base.Pos, ir.CurFunc, n)
}
return n