Skip to content

cmd/compile: eliminate base.Pos and ir.CurFunc #19683

Open

Description

@mdempsky

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:

  1. Identify a function Bar that uses lineno.
  2. Split it into two functions Bar and Barl; Barl takes an additional pos src.XPos parameter, and Bar just calls Barl with lineno.
  3. 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).

Activity

  1. added this to the Go1.9Maybe milestone on Mar 23, 2017
  2. josharian commented on Mar 23, 2017

    @josharian
    Contributor

    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. :)

  3. griesemer commented on Mar 23, 2017

    @griesemer
    Contributor

    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?

  4. mdempsky commented on Mar 23, 2017

    @mdempsky
    ContributorAuthor

    @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.

  5. mdempsky commented on Mar 23, 2017

    @mdempsky
    ContributorAuthor

    @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?).

  6. josharian commented on Mar 23, 2017

    @josharian
    Contributor

    I think we can push the Curfn logic into callers. ...

    SGTM. Do you want to tackle this set of things, or shall I?

  7. mdempsky commented on Mar 23, 2017

    @mdempsky
    ContributorAuthor

    @josharian I can look into it.

  8. gopherbot commented on Mar 24, 2017

    @gopherbot
    Contributor

    CL https://golang.org/cl/38592 mentions this issue.

  9. gopherbot commented on Mar 24, 2017

    @gopherbot
    Contributor

    CL https://golang.org/cl/38597 mentions this issue.

  10. josharian commented on Mar 24, 2017

    @josharian
    Contributor

    @mdempsky nod/Curfn is top of my queue now. Looks like the remaining item there is:

    I think ONAME can be handled by refactoring all the n := nod(ONAME, nil, nil); n.Sym = s instances to n := newname(s).

    Are you actively working on this? If not, I will start on it.

  11. mdempsky commented on Mar 24, 2017

    @mdempsky
    ContributorAuthor

    @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.

  12. gopherbot commented on Mar 28, 2017

    @gopherbot
    Contributor

    CL https://golang.org/cl/38770 mentions this issue.

  13. 116 remaining items

  14. gopherbot commented on Oct 6, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/835166 mentions this issue: cmd/compile/internal/ir: stop setting CurFunc in WithFunc

  15. gopherbot commented on Oct 6, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846045 mentions this issue: cmd/compile: remove underscores introduced in curfunc refactoring

  16. gopherbot commented on Oct 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846671 mentions this issue: cmd/compile: inject base.Pos across compiler and remove it

  17. gopherbot commented on Oct 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846667 mentions this issue: cmd/compile: pass explicit positions in leaf helpers

  18. gopherbot commented on Oct 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846670 mentions this issue: cmd/compile: replace ir.SetPos and ir.WithPos with ir.NodePos

  19. gopherbot commented on Oct 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846669 mentions this issue: cmd/compile: pass base.Pos or local pos to base.FatalfAt where tracked

  20. gopherbot commented on Oct 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846668 mentions this issue: cmd/compile: save and restore base.Pos in functions that set it

  21. gopherbot commented on Oct 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846665 mentions this issue: cmd/compile: add Diagf to use for base.Ctxt.DiagFunc

  22. gopherbot commented on Oct 7, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/846666 mentions this issue: cmd/compile/internal/types: add CheckSizeAt and pass pos in CalcSize

  23. gopherbot commented on Oct 14, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/849288 mentions this issue: cmd/compile: save and restore base.Pos in remaining places

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.help wanted

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions