Skip to content

Remove the delegate cache left by a discarded method-group conversion - #4133

Open
dualfroz wants to merge 1 commit into
icsharpcode:masterfrom
dualfroz:fix-discarded-method-group-cache
Open

Remove the delegate cache left by a discarded method-group conversion#4133
dualfroz wants to merge 1 commit into
icsharpcode:masterfrom
dualfroz:fix-discarded-method-group-cache

Conversation

@dualfroz

Copy link
Copy Markdown

_ = (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

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
@siegfriedpammer

Copy link
Copy Markdown
Member

Did you use AI to implement this? Please read https://github.com/icsharpcode/ILSpy/blob/master/CONTRIBUTING.md#contributing especially bullet 2.

@dualfroz

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discarded method-group conversion leaks the <>O delegate cache into the output

2 participants