-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C#: Populate labels earlier #6012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,12 +35,14 @@ public class Context | |
| // A recursion guard against writing to the trap file whilst writing an id to the trap file. | ||
| private bool writingLabel = false; | ||
|
|
||
| private readonly Queue<IEntity> labelQueue = new(); | ||
|
|
||
| protected void DefineLabel(IEntity entity) | ||
| { | ||
| if (writingLabel) | ||
| { | ||
| // Don't define a label whilst writing a label. | ||
| PopulateLater(() => DefineLabel(entity)); | ||
| labelQueue.Enqueue(entity); | ||
| } | ||
| else | ||
| { | ||
|
|
@@ -52,6 +54,10 @@ protected void DefineLabel(IEntity entity) | |
| finally | ||
| { | ||
| writingLabel = false; | ||
| if (labelQueue.Any()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This recursion might result in strange behavior: the first item (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order is not super important, what matters is that we populate the labels as early as possible. For example, for a method like IEnumerable<int> M(string s) { }we will (simplified) generate the following TRAP: so we are still using labels before their definition, but the definition will follow shortly after, as opposed to the old implementation. |
||
| { | ||
| DefineLabel(labelQueue.Dequeue()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a guarantee that
labelQueuegets emptied? It seems possible that there are items left in the queue:Thread 1 starts defining label on entity A (
writingLabel == true), Thread 2 entersif (writingLabel), Thread 1 finishes all the work even thefinallyblock, and then Thread 2 enqueues the entity.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's all single threaded: Multi-threading is only for extracting different files in parallel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I should have known this. 🤦