Skip to content

Pass underlying temporaries to lifted ref conversion methods - #606

Merged
dadhi merged 3 commits into
dadhi:masterfrom
jogibear9988:fix/ref-conversion-arguments-standalone
Nov 9, 2026
Merged

dadhi merged 3 commits into
dadhi:masterfrom
jogibear9988:fix/ref-conversion-arguments-standalone

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

Lifted conversions whose method takes a ref parameter can emit invalid IL or mishandle null propagation. Classify the formal underlying type, emit the nullable operand as a value and pass a typed underlying temporary to the method. Preserve nullable results, checked null unwrapping and copy semantics; leave nonlifted operand storage unchanged.

Validation

The focused regression reproduces a failure or crash on master a0950432 and passes with this change. Release solution build passes with zero warnings/errors. Both Standard and LightExpression native suites run; ref-conversion-method regressions target the System.Linq.Expressions input API.

Runtime TestX passed Legacy passed
.NET 10 359 1,756
.NET 8 359 1,755
.NET Framework 4.7.2 340 1,639

Measurements

Compare master a0950432 with this commit 48b0db7e. Windows ARM64, Release; .NET 8.0.28 and 10.0.9. Compilation uses prebuilt trees; invocation uses precompiled delegates and excludes expression construction/compilation. Standard and LightExpression are measured separately.

Two fresh process rounds reverse version-loading order, pin execution to one logical CPU, disable tiered compilation, warm both versions, and alternate measurement order. Values below are medians across 14 samples per side (seven per round; 30 ms calibration target).

Measured compilation and invocation allocations match master on every control. Control delegate IL matches master.

Identical-master control runs also varied: compilation -15.2% to +23.4%, invocation -21.5% to +8.9%. Timings below are observations, not a speedup or universal performance-neutrality claim. Cases that fail or produce invalid IL on master have no meaningful before/after invocation ratio; the table uses executable controls that return the expected result in both versions. Framework correctness is tested above; its performance is not measured here.

All table pairs are master → this change. B/op is allocated bytes per operation.

.NET / API Control Compile ns/op Compile B/op Invoke ns/op Invoke B/op
10 / Light add_control 2,487 → 2,474 872 → 872 1.92 → 1.93 0 → 0
10 / Light nullable_conversion 5,663 → 5,465 1648 → 1648 2.02 → 2.03 0 → 0
10 / Light numeric_conversion 2,394 → 2,326 872 → 872 1.95 → 1.93 0 → 0
10 / Standard add_control 3,022 → 2,958 872 → 872 1.90 → 1.91 0 → 0
10 / Standard method_conversion 3,119 → 3,155 928 → 928 1.99 → 1.95 0 → 0
10 / Standard method_nullable_conversion 5,672 → 5,807 1704 → 1704 1.93 → 1.96 0 → 0
10 / Standard nullable_conversion 5,769 → 5,883 1648 → 1648 1.96 → 1.93 0 → 0
10 / Standard numeric_conversion 3,052 → 3,064 872 → 872 1.96 → 1.95 0 → 0
8 / Light add_control 992 → 944 872 → 872 1.92 → 1.90 0 → 0
8 / Light nullable_conversion 2,129 → 2,272 1648 → 1648 2.22 → 2.08 0 → 0
8 / Light numeric_conversion 887 → 919 872 → 872 2.28 → 2.30 0 → 0
8 / Standard add_control 1,019 → 1,068 872 → 872 2.00 → 2.02 0 → 0
8 / Standard method_conversion 1,078 → 1,076 928 → 928 2.26 → 2.28 0 → 0
8 / Standard method_nullable_conversion 2,289 → 2,176 1704 → 1704 2.23 → 2.24 0 → 0
8 / Standard nullable_conversion 2,918 → 2,858 1648 → 1648 2.59 → 2.67 0 → 0
8 / Standard numeric_conversion 1,068 → 1,066 872 → 872 2.32 → 2.31 0 → 0

jogibear9988 and others added 3 commits November 9, 2026 10:15
For lifted conversions, classify the formal underlying ref type, emit the nullable operand by value and materialize an underlying typed temporary before calling the method. Preserve null propagation, checked null unwrapping and copy semantics while leaving nonlifted operand storage unchanged.
@dadhi
dadhi merged commit 703e5c4 into dadhi:master Nov 9, 2026
4 checks passed
@jogibear9988
jogibear9988 deleted the fix/ref-conversion-arguments-standalone branch November 9, 2026 23:18
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.

2 participants