cmd/compile: support reading union type for compiler backend in unified IR

Fixes #52124

Change-Id: I5749822d41d8e51f476bceb277b1d2cf7350dcc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/397874
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cuong Manh Le 2022-04-04 14:07:36 +07:00
parent c8110c3df6
commit efbe17d6f1
2 changed files with 21 additions and 0 deletions

View file

@ -442,9 +442,21 @@ func (r *reader) doTyp() *types.Type {
return r.structType()
case pkgbits.TypeInterface:
return r.interfaceType()
case pkgbits.TypeUnion:
return r.unionType()
}
}
func (r *reader) unionType() *types.Type {
terms := make([]*types.Type, r.Len())
tildes := make([]bool, len(terms))
for i := range terms {
tildes[i] = r.Bool()
terms[i] = r.typ()
}
return types.NewUnion(terms, tildes)
}
func (r *reader) interfaceType() *types.Type {
tpkg := types.LocalPkg // TODO(mdempsky): Remove after iexport is gone.

View file

@ -0,0 +1,9 @@
// compile
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package p
type I interface{ any | int }