From 589e32dbdf89484d620c635a966c736085cae5c4 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 25 May 2021 17:49:32 -0700 Subject: [dev.typeparams] cmd/compile/internal/types2: replace Sum type with Union type - We still mostly ignore the tilde information. - More consistent naming: A Union term is the pair (type, tilde). Rename Union.terms to Union.types; the Union.types and Union.tilde slices make up the Union terms. - Replace Sum.is with Union.underIs: underIs iterates through all union terms and calls its argument function with the underlying type of the term (and thus can ignore the tilde information). This also eliminates the need to call under in the argument function. - Added Union.is for situations where we need to consider the tilde information for each Union term. Change-Id: I70fcf1813e072651dc0f61d52d5555642ee762fd Reviewed-on: https://go-review.googlesource.com/c/go/+/323274 Trust: Robert Griesemer Reviewed-by: Robert Findley --- src/cmd/compile/internal/types2/subst.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 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 a2b81ba0cc..bfec61a065 100644 --- a/src/cmd/compile/internal/types2/subst.go +++ b/src/cmd/compile/internal/types2/subst.go @@ -298,21 +298,13 @@ func (subst *subster) typ(typ Type) Type { } } - case *Sum: - types, copied := subst.typeList(t.types) - if copied { - // Don't do it manually, with a Sum literal: the new - // types list may not be unique and NewSum may remove - // duplicates. - return NewSum(types) - } - case *Union: - terms, copied := subst.typeList(t.terms) + types, copied := subst.typeList(t.types) if copied { - // TODO(gri) Do we need to remove duplicates that may have - // crept in after substitution? It may not matter. - return newUnion(terms, t.tilde) + // 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) } case *Interface: -- cgit v1.2.3-54-g00ecf