Raise value-type using statements (constrained dispose)#712
Merged
Conversation
Extend UsingStatementPass to the value-type slice #711 deferred: csc emits no null guard for a struct IDisposable resource — the finally is a bare constrained `V_0.Dispose();` disposing through the local's address — so the reference-type-only match left it as a hand-rolled try/finally. - TryMatch now recognizes both finally shapes: the reference-type `if (V_0) ((IDisposable)V_0).Dispose();` null guard and the value-type unguarded `V_0.Dispose();`. A shared IsDisposeOf helper accepts a LoadLocal (reference) or LoadLocalAddress (value-type constrained) receiver. - Fixture StructUsing (List<int>.Enumerator) in CfgSampleClass; tests assert the raise, the Enumerator resource type, and the rendered `using` header with no finally/Dispose left. - Ledger annotation broadened: reference-type IDisposable null-guard and value-type constrained dispose now covered; ref-struct pattern dispose and await using remain the open slices. 357 decompiler + 1157 product tests green. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c329158 to
89a1dd1
Compare
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.
Summary
Follow-up to #711, which raised the reference-type
usinglowering and explicitly deferred "value-type/constrained dispose ... for a later slice." This PR is that slice.For a struct
IDisposableresource (e.g.List<T>.Enumerator), csc emits no null guard — the finally is a bare constrainedV_0.Dispose();disposing through the local's address. #711's reference-type-only match left it as a hand-rolled try/finally; now it raises tousing (...).What changed
UsingStatementPass.TryMatchrecognizes both finally shapes:if (V_0) ((IDisposable)V_0).Dispose();(null guard)V_0.Dispose();(no guard)A shared
IsDisposeOfhelper accepts aLoadLocal(reference) orLoadLocalAddress(value-type constrained) receiver.Fixture
StructUsing(List<int>.Enumerator) inCfgSampleClass; tests assert the raise, theEnumeratorresource type, and the renderedusingheader with nofinally/Disposeleft.Ledger annotation broadened: reference-type IDisposable null-guard and value-type constrained dispose now covered; ref-struct pattern dispose and
await usingremain the open slices.Tests
357 decompiler + 1157 product tests green.
🤖 Generated with Copilot