You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/compile: eliminate base.Pos and ir.CurFunc #19683
This is an umbrella issue for eliminating the global lineno variable from package gc. Filing as a HelpWanted issue because I think it's a relatively low-barrier-to-entry issue that people can usefully contribute to the compiler with small incremental improvements.
Here's the general algorithm:
Identify a function Bar that uses lineno.
Split it into two functions Bar and Barl; Barl takes an additional pos src.XPos parameter, and Bar just calls Barl with lineno.
Change callers of Bar to use Barl. Ideally, the caller can supply the position information directly (e.g., via n.Pos or something); but if necessary, just use lineno and later we'll recursively apply this procedure on the caller function.
An example of this is yyerror and Warn now have yyerrorl and `Warnl' functions that we're trying to use instead.
Note: sometimes uses of lineno should just go away entirely (e.g., CL 38393 / 80c4b53). I suggest pinging here to discuss instances and/or express interest in working on this to avoid duplicating work (e.g., @josharian and I are looking at this in the backend for #15756).
One caveat. If the function in question calls nod, then it might need to accept both pos srx.XPos and curfn *Node, since both those globals are used in nod. Just as lineno can be the default value of the pos arg, the global Curfn can be the default value of the curfn arg.
I'll send an example CL of this soon, which also introduces nodl.
Unless, @mdempsky, you dislike this, in which case we need another strategy. :)
@josharian I was thinking about that, and I think we can push the Curfn logic into callers. We don't actually need Curfn for OPACK or OLABEL, just ONAME and for setting IsHiddenClosure.
I think ONAME can be handled by refactoring all the n := nod(ONAME, nil, nil); n.Sym = s instances to n := newname(s).
The IsHiddenClosure logic can probably just be set as appropriate in closure.go instead.
@griesemer Yeah, if the position information can be obtained using existing parameters, that's preferable. But there are a lot of helper functions in dcl.go that construct Nodes, though none of their parameters include position information currently. Some of those will probably need to be extended (e.g., newname?), and others can probably just use src.NoPos (e.g., typenod?).
Activity
josharian commentedon Mar 23, 2017
One caveat. If the function in question calls nod, then it might need to accept both
pos srx.XPosandcurfn *Node, since both those globals are used in nod. Just aslinenocan be the default value of theposarg, the globalCurfncan be the default value of thecurfnarg.I'll send an example CL of this soon, which also introduces
nodl.Unless, @mdempsky, you dislike this, in which case we need another strategy. :)
griesemer commentedon Mar 23, 2017
Presumably many functions don't need an extra src.XPos because they can get the info from any of the nodes they are working with?
mdempsky commentedon Mar 23, 2017
@josharian I was thinking about that, and I think we can push the Curfn logic into callers. We don't actually need Curfn for OPACK or OLABEL, just ONAME and for setting IsHiddenClosure.
I think ONAME can be handled by refactoring all the
n := nod(ONAME, nil, nil); n.Sym = sinstances ton := newname(s).The IsHiddenClosure logic can probably just be set as appropriate in closure.go instead.
mdempsky commentedon Mar 23, 2017
@griesemer Yeah, if the position information can be obtained using existing parameters, that's preferable. But there are a lot of helper functions in dcl.go that construct Nodes, though none of their parameters include position information currently. Some of those will probably need to be extended (e.g., newname?), and others can probably just use src.NoPos (e.g., typenod?).
josharian commentedon Mar 23, 2017
SGTM. Do you want to tackle this set of things, or shall I?
mdempsky commentedon Mar 23, 2017
@josharian I can look into it.
gopherbot commentedon Mar 24, 2017
CL https://golang.org/cl/38592 mentions this issue.
gopherbot commentedon Mar 24, 2017
CL https://golang.org/cl/38597 mentions this issue.
josharian commentedon Mar 24, 2017
@mdempsky nod/Curfn is top of my queue now. Looks like the remaining item there is:
Are you actively working on this? If not, I will start on it.
mdempsky commentedon Mar 24, 2017
@josharian I've got a CL for it, then got side tracked pondering what Node.Addable signifies and whether we could get rid of it.
I'll finish up the CL and mail it in just a sec.
cmd/compile: provide pos and curfn to temp
gopherbot commentedon Mar 28, 2017
CL https://golang.org/cl/38770 mentions this issue.
cmd/compile: fix two instances of { lineno = ...; yyerror }
116 remaining items
cmd/compile/internal/ir: stop setting CurFunc in WithFunc
cmd/compile: remove ir.CurFunc and typecheck funcStack
cmd/compile: rename ir.WithFunc to ir.WithPos
gopherbot commentedon Oct 6, 2026
Change https://go.dev/cl/835166 mentions this issue:
cmd/compile/internal/ir: stop setting CurFunc in WithFuncgopherbot commentedon Oct 6, 2026
Change https://go.dev/cl/846045 mentions this issue:
cmd/compile: remove underscores introduced in curfunc refactoringcmd/compile: remove underscores introduced in curfunc refactoring
gopherbot commentedon Oct 7, 2026
Change https://go.dev/cl/846671 mentions this issue:
cmd/compile: inject base.Pos across compiler and remove itgopherbot commentedon Oct 7, 2026
Change https://go.dev/cl/846667 mentions this issue:
cmd/compile: pass explicit positions in leaf helpersgopherbot commentedon Oct 7, 2026
Change https://go.dev/cl/846670 mentions this issue:
cmd/compile: replace ir.SetPos and ir.WithPos with ir.NodePosgopherbot commentedon Oct 7, 2026
Change https://go.dev/cl/846669 mentions this issue:
cmd/compile: pass base.Pos or local pos to base.FatalfAt where trackedgopherbot commentedon Oct 7, 2026
Change https://go.dev/cl/846668 mentions this issue:
cmd/compile: save and restore base.Pos in functions that set itgopherbot commentedon Oct 7, 2026
Change https://go.dev/cl/846665 mentions this issue:
cmd/compile: add Diagf to use for base.Ctxt.DiagFuncgopherbot commentedon Oct 7, 2026
Change https://go.dev/cl/846666 mentions this issue:
cmd/compile/internal/types: add CheckSizeAt and pass pos in CalcSizecmd/compile: call a new Diagf function without positions from ctxt.Diag
gopherbot commentedon Oct 14, 2026
Change https://go.dev/cl/849288 mentions this issue:
cmd/compile: save and restore base.Pos in remaining places