Skip to content

Use typed unboxing for reference-to-nullable conversions - #612

Merged
dadhi merged 1 commit into
dadhi:masterfrom
jogibear9988:fix/nullable-reference-unboxing-standalone
Nov 10, 2026
Merged

dadhi merged 1 commit into
dadhi:masterfrom
jogibear9988:fix/nullable-reference-unboxing-standalone

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

Conversions from Enum or interface references to nullable value types can return incorrect values or mishandle null. Classify the reference conversion using the underlying target type and emit unbox.any for the complete target type.

Parameters and constants; null, matching and incompatible boxed values; checked and unchecked conversions across object, ValueType, Enum and interfaces. Regressions use strict FEC compilation for both Standard and LightExpression.

Validation

Release solution build: zero warnings/errors.

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

Measurements

Current master f1d2fb33 → 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 1501.5 → 1463.7 2.6 → 2.6 872.0 → 872.0 0.0 → 0.0
Standard / enum_unbox_value 1527.4 → 1537.2 5.3 → 4.9 912.0 → 912.0 24.0 → 24.0
Standard / nullable_unbox_object 1842.1 → 2162.9 8.4 → 8.5 976.0 → 976.0 0.0 → 0.0
Light / add_control 1348.8 → 1509.9 2.6 → 2.6 872.0 → 872.0 0.0 → 0.0
Light / enum_unbox_value 1621.3 → 1653.8 8.2 → 6.3 912.0 → 912.0 24.0 → 24.0
Light / nullable_unbox_object 1876.9 → 1885.9 8.5 → 8.5 976.0 → 976.0 0.0 → 0.0
net10.0 results (master → change)
API / workload Compile ns Invoke ns Compile B/op Invoke B/op
Standard / add_control 4096.2 → 4428.1 2.6 → 2.6 872.1 → 872.1 0.0 → 0.0
Standard / enum_unbox_value 4440.7 → 5293.3 6.0 → 5.2 912.0 → 912.0 24.0 → 24.0
Standard / nullable_unbox_object 4917.4 → 4727.2 2.8 → 2.8 976.0 → 976.0 0.0 → 0.0
Light / add_control 3122.5 → 3308.1 2.5 → 2.5 872.0 → 872.0 0.0 → 0.0
Light / enum_unbox_value 3516.0 → 3410.5 4.3 → 4.3 912.0 → 912.0 24.0 → 24.0
Light / nullable_unbox_object 3153.6 → 3180.8 2.3 → 2.3 976.0 → 976.0 0.0 → 0.0

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

Conversions from Enum or interface references to nullable value types can return incorrect values or mishandle null. Classify the reference conversion using the underlying target type and emit unbox.any for the complete target type.
@dadhi
dadhi merged commit d8bf146 into dadhi:master Nov 10, 2026
4 checks passed
@jogibear9988
jogibear9988 deleted the fix/nullable-reference-unboxing-standalone branch November 10, 2026 13:33
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