func (g *irgen) instantiateMethods() {
for i := 0; i < len(g.instTypeList); i++ {
typ := g.instTypeList[i]
- if typ.HasShape() {
- // Shape types should not have any methods.
- continue
- }
+ assert(!typ.HasShape())
// Mark runtime type as needed, since this ensures that the
// compiler puts out the needed DWARF symbols, when this
// instantiated type has a different package from the local
if !t.HasShape() {
if s1 == nil {
s1 = make([]*types.Type, len(shapes))
- for j := 0; j < i; j++ {
- s1[j] = shapes[j]
- }
+ copy(s1[0:i], shapes[0:i])
}
s1[i] = typecheck.Shapify(t)
} else if s1 != nil {
// Shapify takes a concrete type and returns a GCshape type that can
// be used in place of the input type and still generate identical code.
+// No methods are added - all methods calls directly on a shape should
+// be done by converting to an interface using the dictionary.
+//
// TODO: this could take the generic function and base its decisions
// on how that generic function uses this type argument. For instance,
// if it doesn't use it as a function argument/return value, then
// differ in how they get passed as arguments). For now, we only
// unify two different types if they are identical in every possible way.
func Shapify(t *types.Type) *types.Type {
- if t.IsShape() {
- return t // TODO: is this right?
- }
+ assert(!t.HasShape())
// Map all types with the same underlying type to the same shape.
u := t.Underlying()
}
if s := shaped[u]; s != nil {
- return s //TODO: keep?
+ return s
}
sym := Lookup(fmt.Sprintf(".shape%d", snum))
s.SetHasShape(true)
name.SetType(s)
name.SetTypecheck(1)
- // TODO: add methods to s that the bound has?
shaped[u] = s
return s
}