Skip to content

cmd/compile: replace ir.Node with *ir.Name or *ir.Func where appropriate #42982

@mdempsky

Description

@mdempsky

On the dev.regabi branch, there's now a lot of code that uses ir.Node when really *ir.Name or *ir.Func would be sufficient, clearer, and more efficient. We should change those where possible.

For example, both of these fields only ever store *ir.Name:

vars []ir.Node
idx map[ir.Node]int32

As basic steps, I'd recommend:

  1. Pick a slice or map that appears to only be used for variables (or functions) and change it from ir.Node to *ir.Name (or *ir.Func).

  2. Add type assertions and type conversions as necessary to get it to compile.

  3. Check that it still works correctly.

  4. Rewrite function signatures to push the type assertions as far out as possible.

Beware: Sometimes code may mostly store Names, but still occasionally store other Nodes. For example, state.vars says it's only used for ONAMEs, but then OANDAND/OOROR nodes end up getting stuffed in there too.

I'd recommend for contributors to start small. Maybe a few variables. Ideally sticking to just one file at a time. Also, coordinate here to avoid redundant work, or to ask questions if you're unsure.

/cc @cuonglm @zephyrtronium @rsc

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.SuggestedIssues that may be good for new contributors looking for work to do.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions