Skip to content

Commit 59a9a03

Browse files
committed
cmd/compile: switch to computing dict format on instantiated functions
Change to computing the dictionary form on each shape-instantiated function, rather than once on the underlying generic function/method. The problem with computing the dictionary format on the generic function is that we had to force early transformations to create all the needed/implicit CONVIFACE nodes, since many of these nodes cause the need for a dictionary entry. Also, the dictionary entries needed can different with different instantiations of the same generic function, especially depending on whether a type argument is a non-interface or interface type, or a instantiated type vs. a non-instantiated type. By computing the dictionary format on the instantiated function, we are scanning a function where all the transformations have been done to create implicit CONVFIFACE nodes, and we know the above relevant information about the type params (which are shapes). Much of the change is more mechanical changes from typeparams to shapes, and generic functions/info to instantiated functions/info. Some of the most important non-mechanical changes are: - Separated out the dictionary transformations to nodes into a separate dictPass, since we need to analyze instantiated functions after stenciling, but before the dictionary transformations. - Added type param index to shape types, since we need to be able distinguish type params of an instantiation which are different but happen to have the same shape. - Allow the type substituter to work with shapes again (since for the dictionary entries we need to substitute shape params to the concrete type args). - Support types.IdentityStrict() that does strict type comparison (no special case for shapes). This needed for type substitution, formatting and creating dictionaries, etc. We can maybe create better names for this function. - Add new information to instInfo to contain a mapping from the shape type params to their instantiated type bound. This is needed when doing the dictionary transformations related to type bounds. Change-Id: I1c3ca312c5384f318c4dd7d0858dba9766396ff6 Reviewed-on: https://go-review.googlesource.com/c/go/+/349613 Trust: Dan Scales <[email protected]> Run-TryBot: Dan Scales <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 0edc6c4 commit 59a9a03

File tree

5 files changed

+375
-308
lines changed

5 files changed

+375
-308
lines changed

src/cmd/compile/internal/noder/irgen.go

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -97,39 +97,42 @@ func check2(noders []*noder) {
9797
}
9898
}
9999

100-
// gfInfo is information gathered on a generic function.
101-
type gfInfo struct {
102-
tparams []*types.Type
100+
// dictInfo is the dictionary format for an instantiation of a generic function with
101+
// particular shapes. shapeParams, derivedTypes, subDictCalls, and itabConvs describe
102+
// the actual dictionary entries in order, and the remaining fields are other info
103+
// needed in doing dictionary processing during compilation.
104+
type dictInfo struct {
105+
// Types substituted for the type parameters, which are shape types.
106+
shapeParams []*types.Type
107+
// All types derived from those typeparams used in the instantiation.
103108
derivedTypes []*types.Type
104-
// Nodes in generic function that requires a subdictionary. Includes
109+
// Nodes in the instantiation that requires a subdictionary. Includes
105110
// method and function calls (OCALL), function values (OFUNCINST), method
106111
// values/expressions (OXDOT).
107112
subDictCalls []ir.Node
108-
// Nodes in generic functions that are a conversion from a typeparam/derived
113+
// Nodes in the instantiation that are a conversion from a typeparam/derived
109114
// type to a specific interface.
110115
itabConvs []ir.Node
116+
117+
// Mapping from each shape type that substitutes a type param, to its
118+
// type bound (which is also substitued with shapes if it is parameterized)
119+
shapeToBound map[*types.Type]*types.Type
120+
111121
// For type switches on nonempty interfaces, a map from OTYPE entries of
112-
// HasTParam type, to the interface type we're switching from.
113-
// TODO: what if the type we're switching from is a shape type?
122+
// HasShape type, to the interface type we're switching from.
114123
type2switchType map[ir.Node]*types.Type
124+
125+
startSubDict int // Start of dict entries for subdictionaries
126+
startItabConv int // Start of dict entries for itab conversions
127+
dictLen int // Total number of entries in dictionary
115128
}
116129

117-
// instInfo is information gathered on an gcshape (or fully concrete)
118-
// instantiation of a function.
130+
// instInfo is information gathered on an shape instantiation of a function.
119131
type instInfo struct {
120132
fun *ir.Func // The instantiated function (with body)
121133
dictParam *ir.Name // The node inside fun that refers to the dictionary param
122134

123-
gf *ir.Name // The associated generic function
124-
gfInfo *gfInfo
125-
126-
startSubDict int // Start of dict entries for subdictionaries
127-
startItabConv int // Start of dict entries for itab conversions
128-
dictLen int // Total number of entries in dictionary
129-
130-
// Map from nodes in instantiated fun (OCALL, OCALLMETHOD, OFUNCINST, and
131-
// OMETHEXPR) to the associated dictionary entry for a sub-dictionary
132-
dictEntryMap map[ir.Node]int
135+
dictInfo *dictInfo
133136
}
134137

135138
type irgen struct {
@@ -155,13 +158,8 @@ type irgen struct {
155158

156159
dnum int // for generating unique dictionary variables
157160

158-
// Map from generic function to information about its type params, derived
159-
// types, and subdictionaries.
160-
gfInfoMap map[*types.Sym]*gfInfo
161-
162161
// Map from a name of function that been instantiated to information about
163-
// its instantiated function, associated generic function/method, and the
164-
// mapping from IR nodes to dictionary entries.
162+
// its instantiated function (including dictionary format).
165163
instInfoMap map[*types.Sym]*instInfo
166164

167165
// dictionary syms which we need to finish, by writing out any itabconv
@@ -179,10 +177,11 @@ func (g *irgen) later(fn func()) {
179177
}
180178

181179
type delayInfo struct {
182-
gf *ir.Name
183-
targs []*types.Type
184-
sym *types.Sym
185-
off int
180+
gf *ir.Name
181+
targs []*types.Type
182+
sym *types.Sym
183+
off int
184+
isMeth bool
186185
}
187186

188187
type typeDelayInfo struct {

0 commit comments

Comments
 (0)