-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parallelisation of metadata definition
- Loading branch information
1 parent
31c8f55
commit 6c32f16
Showing
7 changed files
with
145 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
namespace Pure.DI.Core; | ||
|
||
internal readonly record struct InvocationVisitor( | ||
SemanticModel SemanticModel, | ||
InvocationExpressionSyntax Invocation, | ||
IMetadataVisitor BaseVisitor, | ||
CancellationToken CancellationToken) | ||
: IMetadataVisitor | ||
{ | ||
private readonly List<IRunnable> _actions = []; | ||
|
||
public void Apply() | ||
{ | ||
foreach (var action in _actions) | ||
{ | ||
CancellationToken.ThrowIfCancellationRequested(); | ||
action.Run(); | ||
} | ||
} | ||
|
||
public void VisitSetup(in MdSetup setup) => | ||
AddAction((visitor, i) => visitor.VisitSetup(i), BaseVisitor, setup); | ||
|
||
public void VisitUsingDirectives(in MdUsingDirectives usingDirectives) => | ||
AddAction((visitor, i) => visitor.VisitUsingDirectives(i), BaseVisitor, usingDirectives); | ||
|
||
public void VisitBinding(in MdBinding binding) => | ||
AddAction((visitor, i) => visitor.VisitBinding(i), BaseVisitor, binding); | ||
|
||
public void VisitContract(in MdContract contract) => | ||
AddAction((visitor, i) => visitor.VisitContract(i), BaseVisitor, contract); | ||
|
||
public void VisitImplementation(in MdImplementation implementation) => | ||
AddAction((visitor, i) => visitor.VisitImplementation(i), BaseVisitor, implementation); | ||
|
||
public void VisitFactory(in MdFactory factory) => | ||
AddAction((visitor, i) => visitor.VisitFactory(i), BaseVisitor, factory); | ||
|
||
public void VisitResolve(in MdResolver resolver) => | ||
AddAction((visitor, i) => visitor.VisitResolve(i), BaseVisitor, resolver); | ||
|
||
public void VisitDefaultLifetime(in MdDefaultLifetime defaultLifetime) => | ||
AddAction((visitor, i) => visitor.VisitDefaultLifetime(i), BaseVisitor, defaultLifetime); | ||
|
||
public void VisitDependsOn(in MdDependsOn dependsOn) => | ||
AddAction((visitor, i) => visitor.VisitDependsOn(i), BaseVisitor, dependsOn); | ||
|
||
public void VisitArg(in MdArg arg) => | ||
AddAction((visitor, i) => visitor.VisitArg(i), BaseVisitor, arg); | ||
|
||
public void VisitRoot(in MdRoot root) => | ||
AddAction((visitor, i) => visitor.VisitRoot(i), BaseVisitor, root); | ||
|
||
public void VisitTypeAttribute(in MdTypeAttribute typeAttribute) => | ||
AddAction((visitor, i) => visitor.VisitTypeAttribute(i), BaseVisitor, typeAttribute); | ||
|
||
public void VisitTagAttribute(in MdTagAttribute tagAttribute) => | ||
AddAction((visitor, i) => visitor.VisitTagAttribute(i), BaseVisitor, tagAttribute); | ||
|
||
public void VisitOrdinalAttribute(in MdOrdinalAttribute ordinalAttribute) => | ||
AddAction((visitor, i) => visitor.VisitOrdinalAttribute(i), BaseVisitor, ordinalAttribute); | ||
|
||
public void VisitLifetime(in MdLifetime lifetime) => | ||
AddAction((visitor, i) => visitor.VisitLifetime(i), BaseVisitor, lifetime); | ||
|
||
public void VisitTag(in MdTag tag) => | ||
AddAction((visitor, i) => visitor.VisitTag(i), BaseVisitor, tag); | ||
|
||
public void VisitAccumulator(in MdAccumulator accumulator) => | ||
AddAction((visitor, i) => visitor.VisitAccumulator(i), BaseVisitor, accumulator); | ||
|
||
public void VisitHint(in MdHint hint) => | ||
AddAction((visitor, i) => visitor.VisitHint(i), BaseVisitor, hint); | ||
|
||
public void VisitFinish() => | ||
AddAction((visitor, _) => visitor.VisitFinish(), BaseVisitor, 0); | ||
|
||
private void AddAction<T>(Action<IMetadataVisitor, T> action, IMetadataVisitor visitor, in T state) => | ||
_actions.Add(new VisitorAction<T>(action, visitor, state)); | ||
|
||
private interface IRunnable | ||
{ | ||
void Run(); | ||
} | ||
|
||
private class VisitorAction<T>( | ||
Action<IMetadataVisitor, T> action, | ||
IMetadataVisitor visitor, | ||
T state) | ||
: IRunnable | ||
{ | ||
public void Run() => action(visitor, state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace Pure.DI.Core.Models; | ||
|
||
internal readonly record struct MdHint(Hint Key, string Value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters