Skip to content

Box nullable values directly for reference conversions - #611

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

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

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

Converting an empty nullable value to an interface can throw InvalidOperationException instead of returning null. Box the nullable itself for reference conversions, retaining runtime casts for interfaces not implemented by the underlying type.

Parameters, constants and locals; null and non-null values; object, interface and value-type base classes. Regressions use strict FEC compilation for both Standard and LightExpression.

Validation

Release solution build: zero warnings/errors.

Runtime TestX groups Legacy tests
.NET 10 447 passed 1,756 passed
.NET 8 447 passed 1,755 passed
.NET Framework 4.7.2 426 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 1151.4 → 1204.9 2.1 → 2.0 872.0 → 872.0 0.0 → 0.0
Standard / nullable_box_object 1473.5 → 1508.3 24.2 → 24.3 976.0 → 976.0 24.0 → 24.0
Standard / nullable_box_interface 1611.5 → 1666.3 27.4 → 26.8 1104.0 → 1072.0 48.0 → 48.0
Light / add_control 1106.1 → 1062.7 2.5 → 2.0 872.0 → 872.0 0.0 → 0.0
Light / nullable_box_object 1525.7 → 1348.1 21.7 → 24.6 976.0 → 976.0 24.0 → 24.0
Light / nullable_box_interface 1376.6 → 1474.8 42.4 → 33.0 1104.0 → 1072.0 48.0 → 48.0
net10.0 results (master → change)
API / workload Compile ns Invoke ns Compile B/op Invoke B/op
Standard / add_control 4761.6 → 4883.8 2.9 → 2.7 872.1 → 872.1 0.0 → 0.0
Standard / nullable_box_object 4799.6 → 4880.5 17.5 → 17.2 976.0 → 976.0 24.0 → 24.0
Standard / nullable_box_interface 6274.9 → 5765.8 112.7 → 130.8 1104.0 → 1072.0 48.0 → 48.0
Light / add_control 4273.3 → 4269.5 3.0 → 3.1 872.0 → 872.0 0.0 → 0.0
Light / nullable_box_object 5495.8 → 6697.9 18.9 → 18.2 976.0 → 976.0 24.0 → 24.0
Light / nullable_box_interface 4128.5 → 4356.3 99.6 → 98.6 1104.0 → 1072.0 48.0 → 48.0

Emitted IL differs in these measured workloads: nullable_box_interface.
No measured allocation increase above 0.1 B/op in these controls.
nullable_box_interface compile allocation: 32 B/op less than master.

Converting an empty nullable value to an interface can throw InvalidOperationException instead of returning null. Box the nullable itself for reference conversions, retaining runtime casts for interfaces not implemented by the underlying type.
@dadhi
dadhi merged commit ac80c20 into dadhi:master Nov 10, 2026
4 checks passed
@jogibear9988
jogibear9988 deleted the fix/nullable-reference-boxing-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