diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-07-01 15:23:41 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-07-02 14:56:37 +0000 |
commit | a18726a648df48917e0ed1404cf6cdbc81acd495 (patch) | |
tree | 3523ed696e16507d1d37bb9e8d542b05d0233945 /src/cmd/compile/internal/gc | |
parent | 2aea44204ef8e3467bd2d21865e3d2b8045f3d12 (diff) | |
download | go-a18726a648df48917e0ed1404cf6cdbc81acd495.tar.gz go-a18726a648df48917e0ed1404cf6cdbc81acd495.zip |
[dev.typeparams] cmd/compile: incremental typecheck during unified IR
This CL changes unified IR to incrementally typecheck the IR as it's
constructed. This is significant, because it means reader can now use
typecheck.Expr to typecheck sub-expressions when it's needed. This
should be helpful for construction and insertion of dictionaries.
This CL does introduce two quirks outside of unified IR itself,
which simplify preserving binary output:
1. Top-level declarations are sorted after they're constructed, to
avoid worrying about the order that closures are added.
2. Zero-padding autotmp_N variable names. Interleaving typechecking
means autotmp variables are sometimes named differently (since their
naming depends on the number of variables declared so far), and this
ensures that code that sorts variables by names doesn't suddenly sort
autotmp_8/autotmp_9 differently than it would have sorted
autotmp_9/autotmp_10.
While at it, this CL also updated reader to use ir.WithFunc instead of
manually setting and restoring ir.CurFunc. There's now only one
remaining direct use of ir.CurFunc.
Change-Id: I6233b4c059596e471c53166f94750917d710462f
Reviewed-on: https://go-review.googlesource.com/c/go/+/332469
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/gc')
-rw-r--r-- | src/cmd/compile/internal/gc/main.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index c94f19fd47..68017516df 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -32,6 +32,7 @@ import ( "log" "os" "runtime" + "sort" ) func hidePanic() { @@ -202,6 +203,20 @@ func Main(archInit func(*ssagen.ArchInfo)) { typecheck.Export(initTask) } + // Stability quirk: sort top-level declarations, so we're not + // sensitive to the order that functions are added. In particular, + // the order that noder+typecheck add function closures is very + // subtle, and not important to reproduce. + // + // Note: This needs to happen after pkginit.Task, otherwise it risks + // changing the order in which top-level variables are initialized. + if base.Debug.UnifiedQuirks != 0 { + s := typecheck.Target.Decls + sort.SliceStable(s, func(i, j int) bool { + return s[i].Pos().Before(s[j].Pos()) + }) + } + // Eliminate some obviously dead code. // Must happen after typechecking. for _, n := range typecheck.Target.Decls { |