// #5 alias arc F2b (B5 train): the cstage cgen helper + // funnel internalization through type_chase_named (c1), the #73 tripwire // graduation (c2), the #89 cgreturn return-position widen (c3) and the #93 // deref-index pointee chase (c4). Each was a 2-level (alias-over-alias) or // 1-level-over-named type whose cgen site single-peeled the TY_NAMED layer: // tagged_arg_size sized a union param to 0, the #73 tripwire fataled at indexed // struct-field store/read, cgreturn dropped the un-widened payload (silent exit // 1), and the N_UN(STAR) pointee classify missed the array skip on a 2-level // alias array (one spurious MOVQ (AX),AX → SEGV). All graduated to 0/0 byte-id // by chasing the alias at the cgen site; ww was the runtime-correct reference // for the #263-polarity rows. Migrated from test/wcc/944_alias_cgen_b5_run.c // (#5-C3); the C driver ran each row both stages + asserted cs==ww exit, here // the cstage run is test-lang (T1) and byte-id is test-lang-byteid (T2). The // fill0/fill2 loud-pair, g73_static_str (#129 loud) and g73_heapfill // (compile-only) rows live elsewhere (separate kinds). package alias_cgen_b5_test; type signed_s0 = i8; type signed_s1 = signed_s0; type signed_st = struct { f: signed_s1, g: signed_s1 }; type targ_u0 = (void | i64); type targ_u = targ_u0; fn targ_h(v: targ_u) i32 = { match (v) { case let n: i64 => { if (n != 42) { return 1; }; return 0; }; case void => { return 2; }; }; }; // >48B MEMORY-class twin of targ_2lvl. type tmem_big = struct { a: i64, b: i64, c: i64, d: i64, e: i64, f: i64, g: i64 }; type tmem_m0 = (void | tmem_big); type tmem_m = tmem_m0; fn tmem_h(v: tmem_m) i32 = { match (v) { case let s: tmem_big => { if (s.g != 77) { return 1; }; return 0; }; case void => { return 2; }; }; }; type wstore_u0 = (void | i64); type wstore_u = wstore_u0; type wstore1_u = (void | i64); type wstorea_u0 = (void | i64); type wstorea_u = wstorea_u0; // `?`-success remap over a 2-lvl alias result. type succ_e0 = !i64; type succ_r0 = (i64 | succ_e0); type succ_r = succ_r0; fn succ_w(bad: bool) succ_r = { if (bad) { return 7: succ_e0; }; return 42; }; fn succ_outer() succ_r = { let v = succ_w(false)?; return v + 1; }; type null_np0 = (*i64 | void); type null_np = null_np0; type f32p_in0 = struct { a: f64 }; type f32p_in1 = f32p_in0; type f32p_pt = struct { x: f32p_in1, y: f64 }; fn f32p_g(p: f32p_pt) f64 = { return p.x.a + p.y; }; type tparg_tp0 = (i64, i64); type tparg_tp = tparg_tp0; fn tparg_f(t: tparg_tp) i64 = { return t.0 + t.1; }; // 1-level control (not alias-depth). type tparg1_tp = (i64, i64); fn tparg1_f(t: tparg1_tp) i64 = { return t.0 + t.1; }; type tpglob_tp0 = (i64, i64); type tpglob_tp = tpglob_tp0; let tpglob_G: tpglob_tp = (4, 9); type g73is_sl = []int; type g73is_sl2 = g73is_sl; type g73is_box = struct { s: g73is_sl2, n: int }; type g73sf_s1t = str; type g73sf_s2t = g73sf_s1t; type g73sf_box = struct { s: g73sf_s2t, n: int }; fn g73sf_noise(x: int) int = { return x * 7 + 3; }; type g73tf_tu0 = (void | i64); type g73tf_tu = g73tf_tu0; type g73tf_box = struct { u: g73tf_tu, n: int }; type g73ir_sl = []int; type g73ir_sl2 = g73ir_sl; type g73ir_box = struct { s: g73ir_sl2, n: int }; fn g73ir_noise(x: int) int = { return x * 7 + 3; }; type g73pr_sl = []int; type g73pr_sl2 = g73pr_sl; type g73pr_inner = struct { s: g73pr_sl2, n: int }; type g73pr_outer = struct { pi: *g73pr_inner }; fn g73pr_noise(x: int) int = { return x * 7 + 3; }; type g73tr_sl = []int; type g73tr_sl2 = g73tr_sl; type g73ss_in0 = struct { a: i64, b: i64 }; type g73ss_in1 = g73ss_in0; type g73ss_box = struct { i: g73ss_in1, n: i64 }; let g73ss_g: g73ss_box = g73ss_box { i = g73ss_in0 { a = 4, b = 9 }, n = 5 }; type g89w_base = struct { a: size, b: size }; type g89w_ali = g89w_base; fn g89w_mk() (void | g89w_ali) = { let x: g89w_ali; x.a = 4; x.b = 9; return x; }; type g89e_failure = struct { code: i32, aux: size }; type g89e_myerr = g89e_failure; fn g89e_work(bad: bool) (i32 | g89e_myerr) = { if (bad) { let e: g89e_myerr; e.code = 7; e.aux = 99; return e; }; return 42; }; type g89c_base = struct { a: size, b: size }; fn g89c_make() (void | g89c_base) = { let x: g89c_base; x.a = 4; x.b = 9; return x; }; type g93l_arr = [3]int; type g93l_arr2 = g93l_arr; type g93d_arr0 = [3]i64; type g93d_arr = g93d_arr0; def g93d_D: g93d_arr = [18i64, 29i64, 40i64]; type g93c_arr = [3]int; @test fn signed_ctl() void = { let x: signed_st; x.f = -5; x.g = 3; assert(x.f < 0); let w: i64 = x.f: i64; assert(w == -5); }; @test fn targ_2lvl() void = { let x: targ_u = 42i64; assert(targ_h(x) == 0); }; @test fn tmem_2lvl() void = { let s: tmem_big; s.a = 11; s.b = 22; s.c = 33; s.d = 44; s.e = 55; s.f = 66; s.g = 77; let x: tmem_m = s; assert(tmem_h(x) == 0); }; @test fn wpush_2lvl() void = { assert(targ_h(42i64) == 0); }; @test fn wstore_2lvl() void = { let v: wstore_u = 42i64; match (v) { case let n: i64 => { assert(n == 42); }; case void => { assert(false); }; }; }; @test fn wstore_1lvl() void = { let v: wstore1_u = 42i64; match (v) { case let n: i64 => { assert(n == 42); }; case void => { assert(false); }; }; }; @test fn wstore_a_2lvl() void = { let v: wstorea_u = void; v = 42i64; match (v) { case let n: i64 => { assert(n == 42); }; case void => { assert(false); }; }; }; @test fn succ_2lvl() void = { match (succ_outer()) { case let n: i64 => { assert(n == 43); }; case succ_e0 => { assert(false); }; }; }; @test fn null_2lvl() void = { let n: i64 = 31; let p: null_np = &n; match (p) { case let q: *i64 => { assert(*q == 31); }; case void => { assert(false); }; }; }; @test fn f32p_2lvl() void = { let p: f32p_pt; p.x.a = 2.5; p.y = 1.5; assert(f32p_g(p) == 4.0); }; @test fn tuparg_bound99() void = { let t: tparg_tp = (4, 9); assert(tparg_f(t) == 13); }; @test fn tuparg1_bound99() void = { let t: tparg1_tp = (4, 9); assert(tparg1_f(t) == 13); }; @test fn tuparg_cast_bound99() void = { let t: tparg_tp = (4, 9): tparg_tp; assert(tparg_f(t) == 13); }; @test fn tupglobal_bound99() void = { assert(tpglob_G.0 + tpglob_G.1 == 13); }; @test fn g73_idxstore() void = { let a: [3]int = [700: int, 800: int, 900: int]; let xs: [2]g73is_box; xs[0].s = a[0:3]; assert(xs[0].s.len == 3); }; @test fn g73_strfield() void = { let xs: [2]g73sf_box; xs[1].s = "hello"; xs[1].n = 4; let k = g73sf_noise(9); assert(k == 66); let w = xs[1].s; assert(w.len == 5); }; @test fn g73_tagfield() void = { let xs: [2]g73tf_box; xs[0].n = 5; xs[0].u = 42i64; assert(xs[0].n == 5); match (xs[0].u) { case let v: i64 => { assert(v == 42); }; case void => { assert(false); }; }; }; @test fn g73_idxread() void = { let a: [3]int = [700: int, 800: int, 900: int]; let xs: [2]g73ir_box; let p = &xs[1]; p.s = a[0:3]; p.n = 4; let k = g73ir_noise(9); assert(k == 66); let w = xs[1].s; assert(w.len == 3); assert(w[2] == 900); }; @test fn g73_ptrread() void = { let a: [3]int = [700: int, 800: int, 900: int]; let i: g73pr_inner; i.s = a[0:3]; i.n = 1; let v: g73pr_outer; v.pi = &i; let k = g73pr_noise(9); assert(k == 66); let w = v.pi.s; assert(w.len == 3); assert(w[2] == 900); }; @test fn g73_tupread() void = { let a: [3]int = [700: int, 800: int, 900: int]; let t: (g73tr_sl2, int) = (a[0:3], 5); let s = t.0; assert(s.len == 3); assert(t.1 == 5); }; @test fn g73_static_struct() void = { assert(g73ss_g.n == 5); assert(g73ss_g.i.b == 9); }; @test fn g89_ret_widen() void = { match (g89w_mk()) { case let s: g89w_ali => { assert(s.b == 9); }; case void => { assert(false); }; }; }; @test fn g89_ret_errunion() void = { match (g89e_work(true)) { case let e: g89e_myerr => { assert(e.aux == 99); }; case i32 => { assert(false); }; }; }; @test fn g89_ret_named_ctl() void = { let v = g89c_make(); match (v) { case let s: g89c_base => { assert(s.b == 9); }; case void => { assert(false); }; }; }; @test fn g93_l2_local() void = { let a: g93l_arr2 = [1000: int, 2000: int, 3000: int]; let p: *g93l_arr2 = &a; assert((*p)[2] == 3000); }; @test fn g93_def() void = { let p: *g93d_arr = &g93d_D; assert((*p)[2] == 40i64); }; @test fn g93_1lvl_ctl() void = { let a: g93c_arr = [1000: int, 2000: int, 3000: int]; let p: *g93c_arr = &a; assert((*p)[2] == 3000); };