mirror of
https://github.com/golang/go
synced 2024-09-04 15:34:21 +00:00
[dev.typeparams] cmd/compile: allow embedding Type.Vargen into Sym.Name
Unified IR currently works by hoisting local type definitions to package scope, which requires giving them a unique name. Its current solution is to directly embed the ·N suffix in Sym.Name, rather than set Type.Vargen. This CL extends types/fmt.go to support trimming this suffix again when appropriate. Longer term, I want to revisit this hack, but this seemed like the least invasive solution while also handling generics and local types. Change-Id: If99fcdcc1e19e37d5887de3b021c256a3fe46b98 Reviewed-on: https://go-review.googlesource.com/c/go/+/327052 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
62e32dd386
commit
61888d47c4
|
@ -324,7 +324,21 @@ func tconv2(b *bytes.Buffer, t *Type, verb rune, mode fmtMode, visited map[*Type
|
||||||
verb = 'v'
|
verb = 'v'
|
||||||
}
|
}
|
||||||
|
|
||||||
sconv2(b, t.Sym(), verb, mode)
|
// In unified IR, function-scope defined types will have a ·N
|
||||||
|
// suffix embedded directly in their Name. Trim this off for
|
||||||
|
// non-fmtTypeID modes.
|
||||||
|
sym := t.Sym()
|
||||||
|
if mode != fmtTypeID {
|
||||||
|
i := len(sym.Name)
|
||||||
|
for i > 0 && sym.Name[i-1] >= '0' && sym.Name[i-1] <= '9' {
|
||||||
|
i--
|
||||||
|
}
|
||||||
|
const dot = "·"
|
||||||
|
if i >= len(dot) && sym.Name[i-len(dot):i] == dot {
|
||||||
|
sym = &Sym{Pkg: sym.Pkg, Name: sym.Name[:i-len(dot)]}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sconv2(b, sym, verb, mode)
|
||||||
|
|
||||||
// TODO(mdempsky): Investigate including Vargen in fmtTypeIDName
|
// TODO(mdempsky): Investigate including Vargen in fmtTypeIDName
|
||||||
// output too. It seems like it should, but that mode is currently
|
// output too. It seems like it should, but that mode is currently
|
||||||
|
|
Loading…
Reference in a new issue