Conversation
…loop variable Inlining may extend a named-argument block: CanExtendNamedArgument moves an expression into the first named-argument store (or the second one for an instance call) and checks reordering against the stored values. The reverse move was refused: Block.CanInlineIntoSlot rejected every slot of a CallWithNamedArgs block, and CanMoveInto checked reordering against the whole store instruction, which counts as a write to a local. The foreach pattern relies on CanUninline to pull the Current getter back out of the loop body's first statement, so once the getter had been inlined into a named-argument block the loop was emitted as using + while (MoveNext()). Both checks now mirror what inlining allows, so an expression inlined into a named-argument block can always be un-inlined again. Assisted-by: Claude:claude-fable-5-1:Claude Code
Member
|
Thank you for the contribution! |
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.
ILSpy lost the
foreachwhenever the loop variable was used in a named argument. The cause: inlining was allowed to move an expression into a named-argument block, but nothing was allowed to move it back out. Two test cases added, full decompiler test suite green on Linux.The description below was written by an AI agent (Claude, Claude Code) under my supervision.
Fixes #4153.
Cause. Inlining may extend a
CallWithNamedArgsblock (NamedArgumentTransform.CanExtendNamedArgument): it moves an expression into the first named-argument store, or the second one for an instance call, and checks reordering against the stored values. The reverse move was refused on both counts:Block.CanInlineIntoSlotreturnedfalsefor every slot of aCallWithNamedArgsblock;ILInlining.CanMoveIntochecked reordering against the wholestlocof the named-argument temporary, which carriesMayWriteLocalsand therefore never reorders with theCurrentgetter call.StatementBuilder.DetectGetCurrentTransformationrelies onILInlining.CanUninlineto pull theCurrentgetter back out of the loop body's first statement. Once the getter had been inlined into a named-argument block, that failed and the loop was emitted asusing+while (MoveNext()).Fix. Both checks now mirror what inlining allows:
CanInlineIntoSlotaccepts slot 0 of a named-argument block (and slot 1 for an instance call, whose slot 0 holds thethisargument), and the predecessor reorder check inCanMoveInto/CanMoveIntoCallVirtlooks at the stored value of a named-argument store rather than the store itself. A named-argument temporary is read only by the block's final call, so the store imposes no ordering constraint of its own.Tests. Two cases added to
TestCases/Pretty/NamedArguments.cs: a static call over aDictionary<,>enumerator (the repro from the issue) and an instance call over aList<KeyValuePair<,>>enumerator (thethis-argument slot). Red before the fix on all 16 configurations, green after. FullICSharpCode.Decompiler.Testsrun on Linux: 3765 tests, 0 failed, 249 skipped (Windows-only / missing fixtures).