diff options
author | Matthew Dempsky <mdempsky@google.com> | 2021-06-25 10:15:40 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2021-06-25 23:10:23 +0000 |
commit | ed647b16d02da4571c22baac23c302f2d888b88b (patch) | |
tree | b5834ec36a08a15adaed65a5eefbb8efbb8a03bc /src/cmd/compile/internal/typecheck/stmt.go | |
parent | 942edc750292060450fda38835c452f6125447c3 (diff) | |
download | go-ed647b16d02da4571c22baac23c302f2d888b88b.tar.gz go-ed647b16d02da4571c22baac23c302f2d888b88b.zip |
[dev.typeparams] cmd/compile: use Type.LinkString for map keys
This CL changes typecheck and order to use Type.LinkString for
computing map keys instead of Type.NameString. As mentioned in the
LinkString docs (added by the previous CL), LinkString reliably maps
type identity to string equality as long as the LinkString calls all
happen within the same compilation unit (which they do here).
This eliminates the need for subsequent types.Identical checks.
Change-Id: I32ff591e69d6f23f2dc6ebd5af343618ebe89013
Reviewed-on: https://go-review.googlesource.com/c/go/+/330911
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/stmt.go')
-rw-r--r-- | src/cmd/compile/internal/typecheck/stmt.go | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/src/cmd/compile/internal/typecheck/stmt.go b/src/cmd/compile/internal/typecheck/stmt.go index 313491ba0b..54cf508acc 100644 --- a/src/cmd/compile/internal/typecheck/stmt.go +++ b/src/cmd/compile/internal/typecheck/stmt.go @@ -662,29 +662,18 @@ func tcSwitchType(n *ir.SwitchStmt) { } type typeSet struct { - m map[string][]typeSetEntry -} - -type typeSetEntry struct { - pos src.XPos - typ *types.Type + m map[string]src.XPos } func (s *typeSet) add(pos src.XPos, typ *types.Type) { if s.m == nil { - s.m = make(map[string][]typeSetEntry) + s.m = make(map[string]src.XPos) } - // LongString does not uniquely identify types, so we need to - // disambiguate collisions with types.Identical. - // TODO(mdempsky): Add a method that *is* unique. - ls := typ.NameString() - prevs := s.m[ls] - for _, prev := range prevs { - if types.Identical(typ, prev.typ) { - base.ErrorfAt(pos, "duplicate case %v in type switch\n\tprevious case at %s", typ, base.FmtPos(prev.pos)) - return - } + ls := typ.LinkString() + if prev, ok := s.m[ls]; ok { + base.ErrorfAt(pos, "duplicate case %v in type switch\n\tprevious case at %s", typ, base.FmtPos(prev)) + return } - s.m[ls] = append(prevs, typeSetEntry{pos, typ}) + s.m[ls] = pos } |