Skip to content

Commit

Permalink
Don't create a new Binder for every function call
Browse files Browse the repository at this point in the history
I'm not sure why this was ever needed.
  • Loading branch information
Neme12 committed May 21, 2019
1 parent 6c9402f commit 9c1b460
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/Minsk/CodeAnalysis/Binding/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@ internal sealed class Binder

private BoundScope _scope;

public Binder(BoundScope parent, FunctionSymbol function)
public Binder(BoundScope parent)
{
_scope = new BoundScope(parent);

if (function != null)
{
foreach (var p in function.Parameters)
_scope.TryDeclareVariable(p);
}
}

public static BoundGlobalScope BindGlobalScope(BoundGlobalScope previous, CompilationUnitSyntax syntax)
{
var parentScope = previous == null ? CreateRootScope() : previous.Scope;
var binder = new Binder(parentScope, function: null);
var binder = new Binder(parentScope);

var statements = binder.BindStatements(syntax.Statements);

Expand Down Expand Up @@ -96,13 +90,16 @@ private BoundStatement BindFunctionDeclaration(FunctionDeclarationSyntax syntax)
var result = _scope.TryLookupFunction(syntax.Identifier.Text, out var function);
Debug.Assert(result);

var binder = new Binder(_scope, function);
_scope = new BoundScope(_scope);

var body = binder.BindBlockStatement(function.Declaration.Body);
_functionBodies.Add((function, body));
foreach (var p in function.Parameters)
_scope.TryDeclareVariable(p);

_diagnostics.AddRange(binder.Diagnostics);
_functionBodies.AddRange(binder._functionBodies);
var body = BindBlockStatement(function.Declaration.Body);

_scope = _scope.Parent;

_functionBodies.Add((function, body));

// Function declaration is a no-op.
return new BoundBlockStatement(ImmutableArray<BoundStatement>.Empty);
Expand Down

0 comments on commit 9c1b460

Please sign in to comment.