Skip to content

Keep switch case labels in a shared switch scope - #667

Open
jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/switch-case-label-scope-20261114
Open

jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:fix/switch-case-label-scope-20261114

Conversation

@jogibear9988

@jogibear9988 jogibear9988 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Direct case-body labels share the switch’s statement-label scope. Give the switch an outer boundary so cross-case jumps work while jumps from outside into the switch remain invalid. Preserve the existing public collection signature.

Tests compare cross-case/default jumps with System and verify rejection of outside entry.

Validation

Full Release solution build and Standard/LightExpression native runners pass for net8.0, net10.0 and net472. net8.0: 688 TestX and 1744 legacy cases; net10.0: 688 TestX and 1745 legacy cases; net472: 669 TestX and 1610 legacy cases.

Measurements

FEC on master da14580f10fd19ae2361a8e91cfad4b2dfec182a → this change 61420b4f301e899b2d459e15c71b9a2a1900daf9. Windows ARM64; .NET 8.0.28 and 10.0.9; SDK 10.0.301.

Trees, API conversions and invocation adapters are built before measurement. Compilation includes delegate creation; runtime measures the compiled delegate through the same adapter. Both sides are FEC: “System trees” names the expression API, not the System compiler.

Two opposite-load-order process rounds; seven alternating paired samples per round; medians of 14 samples, 100 ms calibration target. Verified task-local runtimes; tiered compilation disabled; each process pinned to one logical CPU. Allocations use GC.GetAllocatedBytesForCurrentThread. Slower observations are retained. Timing variation, including unchanged IL controls, prevents a blanket speedup or no-regression claim.

Runtime / API Workload Compile μs, master → patch Compile B/op Runtime ns, master → patch Runtime B/op
net10.0 / LightExpression inline_lambda 5.250 → 5.073 992.0 2.841 → 3.104 0.0
net10.0 / LightExpression nested_lambda 7.527 → 7.846 2048.0 2.560 → 2.577 0.0
net10.0 / LightExpression scalar_add 3.985 → 3.741 872.0 3.330 → 3.299 0.0
net10.0 / LightExpression switch_control 4.651 → 5.051 1104.0 2.303 → 2.403 0.0
net10.0 / System trees inline_lambda 11.275 → 12.328 1376.0 2.727 → 3.044 0.0
net10.0 / System trees nested_lambda 7.134 → 7.025 2048.0 2.503 → 2.341 0.0
net10.0 / System trees scalar_add 5.235 → 5.137 872.0 2.946 → 2.979 0.0
net10.0 / System trees switch_control 4.875 → 4.991 1104.0 2.577 → 2.322 0.0
net8.0 / LightExpression inline_lambda 7.121 → 6.618 992.0 3.646 → 3.645 0.0
net8.0 / LightExpression nested_lambda 10.632 → 10.076 2048.0 2.529 → 2.767 0.0
net8.0 / LightExpression scalar_add 4.993 → 5.374 872.0 4.850 → 5.290 0.0
net8.0 / LightExpression switch_control 5.064 → 5.376 1104.0 3.542 → 3.503 0.0
net8.0 / System trees inline_lambda 22.562 → 16.925 1432.0 6.195 → 6.271 0.0
net8.0 / System trees nested_lambda 13.875 → 14.806 2048.1 3.237 → 3.748 0.0
net8.0 / System trees scalar_add 5.106 → 5.541 872.0 4.294 → 4.528 0.0
net8.0 / System trees switch_control 7.845 → 7.899 1104.0 5.678 → 6.109 0.0

Shared-workload emitted IL is unchanged.

Allocation changes: none beyond measurement rounding in these shared workloads.

Affected cases without a valid master baseline

Master rejects these trees or generates a delegate with incorrect behavior, so they are excluded from comparative timings. Patch-only measurements use 14 samples, a 30 ms calibration target, and the same compilation/runtime separation. fixed_case exercises this PR’s added behavior.

Runtime / API Case Compile μs Compile B/op Runtime ns Runtime B/op
net10.0 / LightExpression fixed_case 8.779 1240.0 4.941 0.0
net10.0 / System trees fixed_case 4.811 1240.1 5.374 0.0
net8.0 / LightExpression fixed_case 8.732 1240.0 7.451 0.0
net8.0 / System trees fixed_case 9.099 1240.0 7.340 0.0

Direct case-body labels share the switch’s statement-label scope. Give the switch an outer boundary so cross-case jumps work while jumps from outside into the switch remain invalid. Preserve the existing public collection signature.

Tests compare cross-case/default jumps with System and verify rejection of outside entry.
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