-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
In go/ast, we use ast.Expr and ast.Stmt to represent when an ast.Node is known to be an expression or statement, respectively.
Within cmd/compile, we have analogous ir.Expr and ir.Stmt interface types, but for historical reasons most code still uses ir.Node. This issue lays out a plan for how to migrate the compiler to use them. (Having started a few attempts at this, it's clearly not something that can gracefully land in a single CL.)
- Introduce new
ir.ExprNodeandir.StmtNodetypes. Normally, these will be type aliases toir.Node; but if thestrict-irbuild tag is set, then they'll be aliases toir.Exprandir.Stmt, respectively, instead. - Add a unit test (e.g., cmd/compile/internal/ir.TestStrictIR) that simply uses go/types to check that a (initially empty) list of packages all still type check successfully with the
strict-irbuild tag set. - One package at a time, replace as many uses of
ir.Nodewithir.ExprNodeorir.StmtNodeas possible (and refactoring code as needed), and then add the package to the unit test from step 2 to prevent backsliding. - Once all cmd/compile packages have been transitioned, we change
ir.ExprNodeandir.StmtNodeto be aliases toir.Exprandir.Stmtunconditionally (i.e., makestrict-irthe default/only mode), and removeTestStrictIRtoo. - Global rewrite CL removing
ir.ExprNodeandir.StmtNodeand replacing all uses withir.Exprandir.Stmt. (This could be split into 2 or more steps if we're concerned about conflicts with in-flight CLs; but I think as long as we give heads up before landing the CL, it should be fine.)
I don't think this is pressing work, but wanted to lay out a plan and start getting buy-in from the rest of the compiler team before embarking upon it.
Two possible cons to this plan to note:
- Interface-to-interface type conversions (e.g., Expr->Node or Stmt->Node) require a runtime conversion to compute the itab, so it's possible this ends up slowing down some code paths. This is something worth measuring between steps 3 and 4. (Any ideas on how to measure the possible impact here before doing all the work would be welcome.)
- Because we can't use generics in the compiler, we'll probably have to duplicate some
[]ir.Nodecode paths to also operate on[]ir.Exprand[]ir.Stmt.
It's worth noting though that both of these cons apply to go/ast already, and I've not heard them raised before. But then Go 1 compatibility also precludes any work that could address these issues.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status