Repository navigation
Preserve runtime numeric switch-case evaluation - #605
Merged
dadhi merged 2 commits intoNov 9, 2026
Merged
Conversation
Fall back to ordered comparisons for numeric case tests that are evaluated at runtime. Stop constant-switch folding at a runtime-dependent test so its effects and first-match semantics are preserved.
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.
Numeric switch cases evaluated at runtime are rejected, and constant-input folding can skip an earlier runtime-dependent case and its effects. Use ordered comparisons when a numeric case cannot use the constant table; stop folding before runtime-dependent tests.
Validation
The focused regression reproduces a failure or crash on master
a0950432and passes with this change. Release solution build passes with zero warnings/errors. Both Standard and LightExpression native suites run.Measurements
Compare master
a0950432with this commitc62a22c4. 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/opis allocated bytes per operation.add_controlconstant_switchstring_runtime_switchadd_controlconstant_switchstring_runtime_switchadd_controlconstant_switchstring_runtime_switchadd_controlconstant_switchstring_runtime_switch