aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2022-08-29 17:25:32 +0700
committerGopher Robot <gobot@golang.org>2022-08-30 17:23:27 +0000
commitddc93a536faf4576d182cd3197b116d61d05c484 (patch)
tree15b430fa0e677db158fe01574c95b5b29dd57187 /src/cmd/compile/internal/noder
parentc22865fcfa1ec434e5655c652c6376fa2d0eb821 (diff)
downloadgo-ddc93a536faf4576d182cd3197b116d61d05c484.tar.xz
cmd/compile: fix unified IR shapifying recursive instantiated types
Shape-based stenciling in unified IR is done by converting type argument to its underlying type. So it agressively check that type argument is not a TFORW. However, for recursive instantiated type argument, it may still be a TFORW when shapifying happens. Thus the assertion failed, causing the compiler crashing. To fix it, just allow fully instantiated type when shapifying. Fixes #54512 Fixes #54722 Change-Id: I527e3fd696388c8a37454e738f0324f0c2ec16cb Reviewed-on: https://go-review.googlesource.com/c/go/+/426335 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Heschi Kreinick <heschi@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder')
-rw-r--r--src/cmd/compile/internal/noder/reader.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go
index d1a8843138..a34d5c924a 100644
--- a/src/cmd/compile/internal/noder/reader.go
+++ b/src/cmd/compile/internal/noder/reader.go
@@ -817,7 +817,22 @@ func (dict *readerDict) mangle(sym *types.Sym) *types.Sym {
// If basic is true, then the type argument is used to instantiate a
// type parameter whose constraint is a basic interface.
func shapify(targ *types.Type, basic bool) *types.Type {
- base.Assertf(targ.Kind() != types.TFORW, "%v is missing its underlying type", targ)
+ if targ.Kind() == types.TFORW {
+ if targ.IsFullyInstantiated() {
+ // For recursive instantiated type argument, it may still be a TFORW
+ // when shapifying happens. If we don't have targ's underlying type,
+ // shapify won't work. The worst case is we end up not reusing code
+ // optimally in some tricky cases.
+ if base.Debug.Shapify != 0 {
+ base.Warn("skipping shaping of recursive type %v", targ)
+ }
+ if targ.HasShape() {
+ return targ
+ }
+ } else {
+ base.Fatalf("%v is missing its underlying type", targ)
+ }
+ }
// When a pointer type is used to instantiate a type parameter
// constrained by a basic interface, we know the pointer's element