diff options
author | Keith Randall <khr@golang.org> | 2020-03-19 16:25:08 -0700 |
---|---|---|
committer | Keith Randall <khr@golang.org> | 2020-04-09 21:18:55 +0000 |
commit | 28157b3292a9da90a7ceea89e9b01d9dd03b4979 (patch) | |
tree | 984d536a28817d99157d768bc397a02995816207 /src/cmd/compile/internal/ssa/check.go | |
parent | a1550d3ca3a6a90b8bbb610950d1b30649411243 (diff) | |
download | go-28157b3292a9da90a7ceea89e9b01d9dd03b4979.tar.gz go-28157b3292a9da90a7ceea89e9b01d9dd03b4979.zip |
cmd/compile: start implementing strongly typed aux and auxint fields
Right now the Aux and AuxInt fields of ssa.Values are typed as
interface{} and int64, respectively. Each rule that uses these values
must cast them to the type they actually are (*obj.LSym, or int32, or
ValAndOff, etc.), use them, and then cast them back to interface{} or
int64.
We know for each opcode what the types of the Aux and AuxInt fields
should be. So let's modify the rule generator to declare the types to
be what we know they should be, autoconverting to and from the generic
types for us. That way we can make the rules more type safe.
It's difficult to make a single CL for this, so I've coopted the "=>"
token to indicate a rule that is strongly typed. "->" rules are
processed as before. That will let us migrate a few rules at a time in
separate CLs. Hopefully we can reach a state where all rules are
strongly typed and we can drop the distinction.
This CL changes just a few rules to get a feel for what this
transition would look like.
I've decided not to put explicit types in the rules. I think it
makes the rules somewhat clearer, but definitely more verbose.
In particular, the passthrough rules that don't modify the fields
in question are verbose for no real reason.
Change-Id: I63a1b789ac5702e7caf7934cd49f784235d1d73d
Reviewed-on: https://go-review.googlesource.com/c/go/+/190197
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/check.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/check.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/ssa/check.go b/src/cmd/compile/internal/ssa/check.go index 4c694a03ac..b246bd9c7d 100644 --- a/src/cmd/compile/internal/ssa/check.go +++ b/src/cmd/compile/internal/ssa/check.go @@ -119,6 +119,7 @@ func checkFunc(f *Func) { // Check to make sure aux values make sense. canHaveAux := false canHaveAuxInt := false + // TODO: enforce types of Aux in this switch (like auxString does below) switch opcodeTable[v.Op].auxType { case auxNone: case auxBool: @@ -158,7 +159,12 @@ func checkFunc(f *Func) { if math.IsNaN(v.AuxFloat()) { f.Fatalf("value %v has an AuxInt that encodes a NaN", v) } - case auxString, auxSym, auxTyp, auxArchSpecific: + case auxString: + if _, ok := v.Aux.(string); !ok { + f.Fatalf("value %v has Aux type %T, want string", v, v.Aux) + } + canHaveAux = true + case auxSym, auxTyp, auxArchSpecific: canHaveAux = true case auxSymOff, auxSymValAndOff, auxTypSize: canHaveAuxInt = true |