-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add optimization to reduce extra iterations of the safe init checker. #17057
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8595d95
Add optimization to reduce extra iterations of the safe init checker.
q-ata 1b5a2ff
Remove benchmarking output
q-ata 170b36d
Add documentation for new field.
q-ata ddafb78
Implement suggested change.
q-ata 7347e03
Fix * alignment in comment.
q-ata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -75,6 +75,12 @@ class Cache[Config, Res]: | |
*/ | ||
protected var changed: Boolean = false | ||
|
||
/** Whether any value in the cache was accessed after being added. | ||
* If no cached values are used after they are added for the first time | ||
* then another iteration of analysis is not needed. | ||
*/ | ||
protected var cacheUsed: Boolean = false | ||
|
||
/** Used to avoid allocation, its state does not matter */ | ||
protected given MutableTreeWrapper = new MutableTreeWrapper | ||
|
||
|
@@ -99,7 +105,9 @@ class Cache[Config, Res]: | |
*/ | ||
def cachedEval(config: Config, expr: Tree, cacheResult: Boolean, default: Res)(eval: Tree => Res): Res = | ||
this.get(config, expr) match | ||
case Some(value) => value | ||
case Some(value) => | ||
cacheUsed = true | ||
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. For the init checker, if we read from global cache, we can think it's still not used. Maybe move it to the method def get(config: Config, expr: Tree): Option[Res] =
val res = current.get(config, expr)
cacheUsed = cacheUsed || res.nonEmpty
res |
||
value | ||
case None => | ||
val assumeValue: Res = | ||
this.last.get(config, expr) match | ||
|
@@ -124,6 +132,8 @@ class Cache[Config, Res]: | |
|
||
def hasChanged = changed | ||
|
||
def isUsed = cacheUsed | ||
|
||
/** Prepare cache for the next iteration | ||
* | ||
* 1. Reset changed flag. | ||
|
@@ -132,6 +142,7 @@ class Cache[Config, Res]: | |
*/ | ||
def prepareForNextIteration()(using Context) = | ||
this.changed = false | ||
this.cacheUsed = false | ||
this.last = this.current | ||
this.current = Map.empty | ||
end Cache | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider make it more precise in the comment: Whether any value in the output cache (
this.current
).Minor: the comment
*
is not aligned.