]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: print recursive types correctly
authorKeith Randall <khr@golang.org>
Thu, 9 Jan 2020 22:58:18 +0000 (14:58 -0800)
committerKeith Randall <khr@golang.org>
Mon, 13 Jan 2020 18:52:18 +0000 (18:52 +0000)
commit5d8a61a43eea306b4426adf8b903135517b019c9
treef5e2c8e01c67334125cadcf8a17763e09658b38a
parent52c4488471ed52085a29e173226b3cbd2bf22b20
cmd/compile: print recursive types correctly

Change the type printer to take a map of types that we're currently
printing. When we happen upon a type that we're already in the middle
of printing, print a reference to it instead.

A reference to another type is built using the offset of the first
byte of that type's string representation in the result. To facilitate
that computation (and it's probably more efficient, regardless), we
print the type to a buffer as we go, and build the string at the end.

It would be nice to use string.Builder instead of bytes.Buffer, but
string.Builder wasn't around in Go 1.4, and we'd like to bootstrap
from that version.

Fixes #29312

Change-Id: I49d788c1fa20f770df7b2bae3b9979d990d54803
Reviewed-on: https://go-review.googlesource.com/c/go/+/214239
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/main.go
src/cmd/compile/internal/ssa/export_test.go
src/cmd/compile/internal/types/utils.go