From ff0c0dbca6a7a3a3d6528481829679be4c9d7e94 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 27 Jul 2021 19:13:26 -0700 Subject: [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 Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/subst.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/cmd/compile/internal/types2/subst.go') 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 +} -- cgit v1.2.3-54-g00ecf