Skip to content

Commit

Permalink
Update SemanticModel.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Sep 28, 2023
1 parent f15ae77 commit 1834caf
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Draco.Compiler/Api/Semantics/SemanticModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using Draco.Compiler.Api.Diagnostics;
using Draco.Compiler.Api.Syntax;
using Draco.Compiler.Internal;
Expand Down Expand Up @@ -61,6 +62,7 @@ private ImmutableArray<Diagnostic> GetDiagnostics(SourceSpan? span = null)
? this.Tree.PreOrderTraverse()
: this.Tree.TraverseSubtreesIntersectingSpan(span.Value);

var tasks = new List<Task>();
var addedImportBinders = new HashSet<ImportBinder>();

foreach (var syntaxNode in syntaxNodes)
Expand All @@ -81,17 +83,20 @@ private ImmutableArray<Diagnostic> GetDiagnostics(SourceSpan? span = null)
case CompilationUnitSyntax:
case FunctionDeclarationSyntax:
{
containingSymbol?.Bind(this);
tasks.Add(Task.Run(() => containingSymbol?.Bind(this)));
break;
}
// NOTE: Only globals need binding
case VariableDeclarationSyntax when containingSymbol is SourceModuleSymbol containingModule:
{
// We need to search for this global
var globalSymbol = containingModule.Members
.OfType<SourceGlobalSymbol>()
.Single(s => s.DeclaringSyntax == syntaxNode);
globalSymbol.Bind(this);
tasks.Add(Task.Run(() =>
{
// We need to search for this global
var globalSymbol = containingModule.Members
.OfType<SourceGlobalSymbol>()
.Single(s => s.DeclaringSyntax == syntaxNode);
globalSymbol.Bind(this);
}));
break;
}
case ImportDeclarationSyntax:
Expand All @@ -110,6 +115,7 @@ private ImmutableArray<Diagnostic> GetDiagnostics(SourceSpan? span = null)
}
}

Task.WaitAll(tasks.ToArray());
return this.DiagnosticBag.ToImmutableArray();
}

Expand Down

0 comments on commit 1834caf

Please sign in to comment.