compiler: refactor named types to create them lazily

This commit refactors named types to be created lazily. Instead of
defining all types in advance, do it only when necessary.
This commit is contained in:
Ayke van Laethem
2019-06-07 21:04:56 +02:00
committed by Ron Evans
parent 88bb61f287
commit 6b5b4a681d
9 changed files with 51 additions and 63 deletions
-16
View File
@@ -26,7 +26,6 @@ type Program struct {
Globals []*Global
globalMap map[*ssa.Global]*Global
comments map[string]*ast.CommentGroup
NamedTypes []*NamedType
}
// Function or method.
@@ -50,19 +49,6 @@ type Global struct {
extern bool // go:extern
}
// Type with a name and possibly methods.
type NamedType struct {
*ssa.Type
LLVMType llvm.Type
}
// Type that is at some point put in an interface.
type TypeWithMethods struct {
t types.Type
Num int
Methods map[string]*types.Selection
}
// Interface type that is at some point used in a type assert (to check whether
// it implements another interface).
type Interface struct {
@@ -210,8 +196,6 @@ func (p *Program) AddPackage(pkg *ssa.Package) {
case *ssa.Function:
p.addFunction(member)
case *ssa.Type:
t := &NamedType{Type: member}
p.NamedTypes = append(p.NamedTypes, t)
methods := getAllMethods(pkg.Prog, member.Type())
if !types.IsInterface(member.Type()) {
// named type