aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2021-06-26 18:18:16 -0700
committerKeith Randall <khr@golang.org>2021-06-29 20:39:05 +0000
commit5fa6bbc669c22f05deb421c324b90b30ae3caa08 (patch)
tree78ce2c34869ee254f7ca69a52d085e3c75b6d425 /src/cmd/compile/internal/typecheck
parentdfa8fd861ca99614f03ce409584c4f9ea3e6a3da (diff)
downloadgo-5fa6bbc669c22f05deb421c324b90b30ae3caa08.tar.gz
go-5fa6bbc669c22f05deb421c324b90b30ae3caa08.zip
[dev.typeparams] cmd/compile: clean up instantiation and dictionary naming
Separate generation of instantiation and dictionary name generation. Add code to add subdictionaries to a dictionary. Not quite working yet, as we need to trigger generation of the subdictionaries for methods. Change-Id: I0d46053eba695b217630b06ef2f990f6a0b52d83 Reviewed-on: https://go-review.googlesource.com/c/go/+/331209 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck')
-rw-r--r--src/cmd/compile/internal/typecheck/subr.go51
1 files changed, 36 insertions, 15 deletions
diff --git a/src/cmd/compile/internal/typecheck/subr.go b/src/cmd/compile/internal/typecheck/subr.go
index fb6d660db5..db1faaf6f7 100644
--- a/src/cmd/compile/internal/typecheck/subr.go
+++ b/src/cmd/compile/internal/typecheck/subr.go
@@ -888,19 +888,10 @@ func TypesOf(x []ir.Node) []*types.Type {
return r
}
-// MakeInstName makes the unique name for a stenciled generic function or method,
-// based on the name of the function fnsym and the targs. It replaces any
-// existing bracket type list in the name. makeInstName asserts that fnsym has
-// brackets in its name if and only if hasBrackets is true.
-//
-// Names of declared generic functions have no brackets originally, so hasBrackets
-// should be false. Names of generic methods already have brackets, since the new
-// type parameter is specified in the generic type of the receiver (e.g. func
-// (func (v *value[T]).set(...) { ... } has the original name (*value[T]).set.
-//
-// The standard naming is something like: 'genFn[int,bool]' for functions and
-// '(*genType[int,bool]).methodName' for methods
-func MakeInstName(fnsym *types.Sym, targs []*types.Type, hasBrackets bool) *types.Sym {
+// makeGenericName returns the name of the generic function instantiated
+// with the given types.
+// name is the name of the generic function or method.
+func makeGenericName(name string, targs []*types.Type, hasBrackets bool) string {
b := bytes.NewBufferString("")
// Determine if the type args are concrete types or new typeparams.
@@ -922,7 +913,6 @@ func MakeInstName(fnsym *types.Sym, targs []*types.Type, hasBrackets bool) *type
b.WriteString(".inst.")
}
- name := fnsym.Name
i := strings.Index(name, "[")
assert(hasBrackets == (i >= 0))
if i >= 0 {
@@ -952,7 +942,38 @@ func MakeInstName(fnsym *types.Sym, targs []*types.Type, hasBrackets bool) *type
if strings.HasPrefix(b.String(), ".inst..inst.") {
panic(fmt.Sprintf("multiple .inst. prefix in %s", b.String()))
}
- return fnsym.Pkg.Lookup(b.String())
+ return b.String()
+}
+
+// MakeInstName makes the unique name for a stenciled generic function or method,
+// based on the name of the function fnsym and the targs. It replaces any
+// existing bracket type list in the name. makeInstName asserts that fnsym has
+// brackets in its name if and only if hasBrackets is true.
+//
+// Names of declared generic functions have no brackets originally, so hasBrackets
+// should be false. Names of generic methods already have brackets, since the new
+// type parameter is specified in the generic type of the receiver (e.g. func
+// (func (v *value[T]).set(...) { ... } has the original name (*value[T]).set.
+//
+// The standard naming is something like: 'genFn[int,bool]' for functions and
+// '(*genType[int,bool]).methodName' for methods
+func MakeInstName(gf *types.Sym, targs []*types.Type, hasBrackets bool) *types.Sym {
+ return gf.Pkg.Lookup(makeGenericName(gf.Name, targs, hasBrackets))
+}
+
+func MakeDictName(gf *types.Sym, targs []*types.Type, hasBrackets bool) *types.Sym {
+ for _, targ := range targs {
+ if targ.HasTParam() {
+ fmt.Printf("FUNCTION %s\n", gf.Name)
+ for _, targ := range targs {
+ fmt.Printf(" PARAM %+v\n", targ)
+ }
+ panic("dictionary should always have concrete type args")
+ }
+ }
+ name := makeGenericName(gf.Name, targs, hasBrackets)
+ name = ".dict." + name[6:]
+ return gf.Pkg.Lookup(name)
}
func assert(p bool) {