125_switch_dense_boundaries.toy (1032B)
1 // Dense case range with default; exercises the boundary selectors that a 2 // jump-table lowering must bounds-check correctly: vmin, vmax, vmin-1, 3 // vmax+1, an interior gap. Sum encodes which arm fired for each call. 4 // At O0 today this lowers to a chain; at O1 (once density-based promotion 5 // lands) it lowers to a table. Behavior must match. 6 7 fn pick(x: i64): i64 { 8 return switch x { 9 10 { 100 } 10 11 { 101 } 11 12 { 102 } 12 13 { 103 } 13 14 { 104 } 14 15 { 105 } 15 // deliberate gap at 16 16 17 { 107 } 17 18 { 108 } 18 19 { 109 } 19 20 { 110 } 20 default { 999 } 21 }; 22 } 23 24 fn __user_main(): i64 { 25 var s: i64 = 0; 26 s = s + pick(10); // vmin -> 100 27 s = s + pick(20); // vmax -> 110 28 s = s + pick(9); // vmin - 1 -> 999 29 s = s + pick(21); // vmax + 1 -> 999 30 s = s + pick(16); // interior gap -> 999 31 s = s + pick(15); // mid hit -> 105 32 return s - 3000; // 100+110+999+999+999+105 - 3000 = 312 33 } 34 35 fn main(): i32 { return __user_main() as i32; }