Skip to content

Commit

Permalink
optimize yield search
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel committed Dec 14, 2023
1 parent b379c8b commit ea6cf74
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ func Compile(path string, options ...Option) error {

type compiler struct {
onlyListFiles bool

prog *ssa.Program
generics map[*ssa.Function][]*ssa.Function
coroutinePkg *packages.Package

fset *token.FileSet
prog *ssa.Program
coroutinePkg *packages.Package
fset *token.FileSet
}

func (c *compiler) compile(path string) error {
Expand Down Expand Up @@ -120,19 +117,6 @@ func (c *compiler) compile(path string) error {
functions := ssautil.AllFunctions(c.prog)
cg := vta.CallGraph(functions, cha.CallGraph(c.prog))

log.Printf("collecting generic instances")
c.generics = map[*ssa.Function][]*ssa.Function{}
for fn := range functions {
if fn.Signature.TypeParams() != nil {
if _, ok := c.generics[fn]; !ok {
c.generics[fn] = nil
}
}
if origin := fn.Origin(); origin != nil {
c.generics[origin] = append(c.generics[origin], fn)
}
}

log.Printf("finding yield points")
packages.Visit(pkgs, func(p *packages.Package) bool {
if p.PkgPath == coroutinePackage {
Expand All @@ -146,8 +130,8 @@ func (c *compiler) compile(path string) error {
}
yieldFunc := c.prog.FuncValue(c.coroutinePkg.Types.Scope().Lookup("Yield").(*types.Func))
yieldInstances := functionColors{}
if fns, ok := c.generics[yieldFunc]; ok {
for _, fn := range fns {
for fn := range functions {
if fn.Origin() == yieldFunc {
yieldInstances[fn] = fn.Signature
}
}
Expand Down

0 comments on commit ea6cf74

Please sign in to comment.