aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/dcl.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-07-01 15:23:41 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-07-02 14:56:37 +0000
commita18726a648df48917e0ed1404cf6cdbc81acd495 (patch)
tree3523ed696e16507d1d37bb9e8d542b05d0233945 /src/cmd/compile/internal/typecheck/dcl.go
parent2aea44204ef8e3467bd2d21865e3d2b8045f3d12 (diff)
downloadgo-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/typecheck/dcl.go')
-rw-r--r--src/cmd/compile/internal/typecheck/dcl.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/typecheck/dcl.go b/src/cmd/compile/internal/typecheck/dcl.go
index f3ccbb4ac0..66d755089a 100644
--- a/src/cmd/compile/internal/typecheck/dcl.go
+++ b/src/cmd/compile/internal/typecheck/dcl.go
@@ -450,7 +450,16 @@ func autotmpname(n int) string {
if s == "" {
// Give each tmp a different name so that they can be registerized.
// Add a preceding . to avoid clashing with legal names.
- s = fmt.Sprintf(".autotmp_%d", n)
+ prefix := ".autotmp_%d"
+
+ // In quirks mode, pad out the number to stabilize variable
+ // sorting. This ensures autotmps 8 and 9 sort the same way even
+ // if they get renumbered to 9 and 10, respectively.
+ if base.Debug.UnifiedQuirks != 0 {
+ prefix = ".autotmp_%06d"
+ }
+
+ s = fmt.Sprintf(prefix, n)
autotmpnames[n] = s
}
return s