aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/subst.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-07-27 19:13:26 -0700
committerRobert Griesemer <gri@golang.org>2021-07-29 19:45:02 +0000
commitff0c0dbca6a7a3a3d6528481829679be4c9d7e94 (patch)
treef1a8f548ddcfdbb13d0af7811f0efca53709f8f3 /src/cmd/compile/internal/types2/subst.go
parent2fa8f00915893670964e05e14be7202f6f97760b (diff)
downloadgo-ff0c0dbca6a7a3a3d6528481829679be4c9d7e94.tar.gz
go-ff0c0dbca6a7a3a3d6528481829679be4c9d7e94.zip
[dev.typeparams] cmd/compile/internal/types2: use type terms to represent unions
This is just an internal representation change for now. Change-Id: I7e0126e9b17850ec020c2a60db13582761557bea Reviewed-on: https://go-review.googlesource.com/c/go/+/338092 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/subst.go')
-rw-r--r--src/cmd/compile/internal/types2/subst.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/types2/subst.go b/src/cmd/compile/internal/types2/subst.go
index 87e3e3018e..fc71343431 100644
--- a/src/cmd/compile/internal/types2/subst.go
+++ b/src/cmd/compile/internal/types2/subst.go
@@ -145,12 +145,12 @@ func (subst *subster) typ(typ Type) Type {
}
case *Union:
- types, copied := subst.typeList(t.types)
+ terms, copied := subst.termList(t.terms)
if copied {
// TODO(gri) Remove duplicates that may have crept in after substitution
// (unlikely but possible). This matters for the Identical
// predicate on unions.
- return newUnion(types, t.tilde)
+ return &Union{terms}
}
case *Interface:
@@ -386,3 +386,21 @@ func (subst *subster) typeList(in []Type) (out []Type, copied bool) {
}
return
}
+
+func (subst *subster) termList(in []*term) (out []*term, copied bool) {
+ out = in
+ for i, t := range in {
+ if u := subst.typ(t.typ); u != t.typ {
+ if !copied {
+ // first function that got substituted => allocate new out slice
+ // and copy all functions
+ new := make([]*term, len(in))
+ copy(new, out)
+ out = new
+ copied = true
+ }
+ out[i] = &term{t.tilde, u}
+ }
+ }
+ return
+}