Remove the delegate cache left by a discarded method-group conversion - #4133
Open
dualfroz wants to merge 1 commit into
Open
Remove the delegate cache left by a discarded method-group conversion#4133dualfroz wants to merge 1 commit into
dualfroz wants to merge 1 commit into
Conversation
CachedDelegateInitializationWithField only fired when the instruction after the caching `if` read the cache field exactly once. A discarded conversion -- `_ = (Action<int>)M;` -- reads it zero times: Roslyn emits the null check and the store, and nothing else. The transform bailed out, so the `<>O` cache class and its `<0>__M` field survived into the output under names no C# compiler will accept. Zero usages is now handled: the `if` is replaced by the delegate construction it guarded, which is what the source expressed, and the caching disappears with the field. The rest of the method is checked for loads of the same field first, since only then is this `if` the sole initialization. Closes icsharpcode#3965
Member
|
Did you use AI to implement this? Please read https://github.com/icsharpcode/ILSpy/blob/master/CONTRIBUTING.md#contributing especially bullet 2. |
Author
|
Hi. I didn't use the AI to write the code itself. I did however use AI to make it easier to read. Same with the comment - i wrote it myself and then told ai to please make it look nicer. Will copy-paste this response in the other PR. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
_ = (Action<int>)M;never reads the cache field back, and the transform required exactly one read, so the output kept<>O.<0>__M, which does not compile.With zero reads, the cache check is now replaced by the delegate construction it guarded.
Closes #3965