Skip to content

Preserve member initializer receivers across exception regions - #627

Open
jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/member-binding-exceptions-independent
Open

jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/member-binding-exceptions-independent

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

A member assignment value containing try/finally can invalidate the pending initializer receiver. Keep the constructed object and assignment receiver in locals while the value is evaluated, then reload the receiver and value for assignment. Record the affected initializer and RHS nodes during collection in existing complex-argument metadata, so an unrelated try does not activate spilling.

Class and struct field/property assignments, result values and left/right/finally effects, compared with System compilation. On .NET Framework the struct EH initializer uses equivalent direct C# as its oracle because the Framework System compiler rejects that shape; class cases use System compilation. Regressions require strict FEC compilation. Native suites cover Standard and LightExpression.

Validation

Local validation uses master baseline 094d067 plus this change. Release solution build: zero warnings/errors.

Runtime TestX groups Legacy tests
.NET 10 489 passed 1,756 passed
.NET 8 489 passed 1,755 passed
.NET Framework 4.7.2 468 passed 1,639 passed

Measurements

Master baseline 094d0678 → this change, Release, Windows ARM64, .NET 8.0.28 / 10.0.9. Compilation uses prebuilt trees; runtime measures invocation through the same wrapper. Two fresh process rounds with reversed load order, seven samples per round, about 30 ms calibration, one logical CPU and tiered compilation disabled. Tables use the median of the two per-round medians.

The controls below produce correct results on master for their measured inputs. Newly supported trees have no valid before/after execution comparison because master rejects them, produces incorrect results or emits invalid IL. Timings include machine and JIT/code-placement variation; the unchanged add control helps show that variation. These observations do not prove universal performance neutrality.

net8.0 results (master → change)
API / workload Compile ns Invoke ns Compile B/op Invoke B/op
Standard / add_control 1121.5 → 1100.7 1.9 → 1.9 872.0 → 872.0 0.0 → 0.0
Standard / member_init 1520.6 → 1703.8 3.8 → 3.7 1064.1 → 1064.1 24.0 → 24.0
Standard / member_init_unrelated_try 1954.8 → 2031.0 4.0 → 4.3 1664.1 → 1664.1 24.0 → 24.0
Light / add_control 1058.1 → 1144.7 2.0 → 2.0 872.0 → 872.0 0.0 → 0.0
Light / member_init 1251.1 → 1327.5 3.5 → 4.0 1064.0 → 1064.0 24.0 → 24.0
Light / member_init_unrelated_try 1895.5 → 1673.6 3.6 → 3.7 1664.0 → 1664.0 24.0 → 24.0
net10.0 results (master → change)
API / workload Compile ns Invoke ns Compile B/op Invoke B/op
Standard / add_control 5567.0 → 7312.5 4.1 → 4.1 872.1 → 872.1 0.0 → 0.0
Standard / member_init 5366.1 → 5381.5 6.2 → 6.1 1064.3 → 1064.3 24.0 → 24.0
Standard / member_init_unrelated_try 6088.3 → 6220.2 6.8 → 6.8 1664.3 → 1664.3 24.0 → 24.0
Light / add_control 3559.9 → 3226.7 2.2 → 2.3 872.0 → 872.0 0.0 → 0.0
Light / member_init 3712.2 → 3352.5 4.4 → 4.2 1064.0 → 1064.0 24.0 → 24.0
Light / member_init_unrelated_try 3931.1 → 4111.3 4.5 → 4.4 1664.0 → 1664.0 24.0 → 24.0

Emitted IL differs in these measured workloads: none.
No measured allocation increase above 0.1 B/op in these controls.

A member assignment value containing try/finally can invalidate the pending initializer receiver. Keep the constructed object and assignment receiver in locals while the value is evaluated, then reload the receiver and value for assignment. Record the affected initializer and RHS nodes during collection in existing complex-argument metadata, so an unrelated try does not activate spilling.

Validation: Release solution build; full Standard and LightExpression .NET 8, .NET 10 and Framework runners pass.

Measurements: master 094d067 versus this change, compilation and invocation, both APIs, .NET 8/10, two opposite-order process rounds with seven samples each. No measured allocation increase above 0.1 B/op in the selected working controls. Timings and emitted IL are recorded in the PR description; these controls do not establish universal performance neutrality.
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.

1 participant