Skip to content

Commit 4c17325

Browse files
aykevldeadprogram
authored andcommitted
compiler: only calculate functionInfo once
This is a small change that's not really important in itself, but it avoids duplicate errors in a future commit that adds error messages to //go:wasmimport.
1 parent 76f54b3 commit 4c17325

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

compiler/compiler.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type compilerContext struct {
8282
uintptrType llvm.Type
8383
program *ssa.Program
8484
diagnostics []error
85+
functionInfos map[*ssa.Function]functionInfo
8586
astComments map[string]*ast.CommentGroup
8687
embedGlobals map[string][]*loader.EmbedFile
8788
pkg *types.Package
@@ -93,13 +94,14 @@ type compilerContext struct {
9394
// importantly with a newly created LLVM context and module.
9495
func newCompilerContext(moduleName string, machine llvm.TargetMachine, config *Config, dumpSSA bool) *compilerContext {
9596
c := &compilerContext{
96-
Config: config,
97-
DumpSSA: dumpSSA,
98-
difiles: make(map[string]llvm.Metadata),
99-
ditypes: make(map[types.Type]llvm.Metadata),
100-
machine: machine,
101-
targetData: machine.CreateTargetData(),
102-
astComments: map[string]*ast.CommentGroup{},
97+
Config: config,
98+
DumpSSA: dumpSSA,
99+
difiles: make(map[string]llvm.Metadata),
100+
ditypes: make(map[types.Type]llvm.Metadata),
101+
machine: machine,
102+
targetData: machine.CreateTargetData(),
103+
functionInfos: map[*ssa.Function]functionInfo{},
104+
astComments: map[string]*ast.CommentGroup{},
103105
}
104106

105107
c.ctx = llvm.NewContext()

compiler/symbol.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,16 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
239239
// present in *ssa.Function, such as the link name and whether it should be
240240
// exported.
241241
func (c *compilerContext) getFunctionInfo(f *ssa.Function) functionInfo {
242+
if info, ok := c.functionInfos[f]; ok {
243+
return info
244+
}
242245
info := functionInfo{
243246
// Pick the default linkName.
244247
linkName: f.RelString(nil),
245248
}
246249
// Check for //go: pragmas, which may change the link name (among others).
247250
info.parsePragmas(f)
251+
c.functionInfos[f] = info
248252
return info
249253
}
250254

0 commit comments

Comments
 (0)