// alias_global_decl_test — g-fold (#77 + #78 fused): alias-typed GLOBAL // declarations, migrated from test/wcc/944_alias_global_decl_run.c (#5-C3). // The decl/emit dispatch was alias-blind on both sides: cs (#78) single-peeled // the let_* helper family so a 2-level alias chain (or one user alias over a // named struct) left the type TY_NAMED, emitted no DATA, and read frame-local // at offset 0 (saved-BP reads / SEGV); ww (#77) keyed emitletdataw's array gate // on the UNCHASED N_TARRAY tnode so an alias-typed global ARRAY got `undefined // reference to main.g`. Both fixed by ONE tichase at the dispatch entry. // // This table is the PERMANENT GUARD for the global-declaration dispatch path: // ww starts from a raw type node while cs starts from resolved type metadata. // Values exceed 255 (no little-endian prefix-luck) and readbacks assert the // LAST element. 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 *_ord rows' decl-after-let dimension is subsumed by module-level // resolution (already order-independent), kept for row-count fidelity. package alias_global_decl_test; type t_arr = [4]int; type t_arr2 = t_arr; type t_au = [4]u32; type t_myint = int; type t_myint2 = t_myint; type t_ms = str; type t_ms2 = t_ms; type t_mf = f64; type t_mf2 = t_mf; type t_mg = f32; type t_mg2 = t_mg; type t_pt = struct { x: int, y: int }; type t_pt1 = t_pt; type t_pt2 = t_pt1; type t_sl = []int; type t_sl2 = t_sl; type t_sa = [2]str; type t_sa2 = t_sa; type t_row = [3]int; let g_ctl: [4]int = [1001: int, 1002: int, 1003: int, 1004: int]; let g_a1r: t_arr = [1001: int, 1002: int, 1003: int, 1004: int]; let g_a1w: t_arr = [1001: int, 1002: int, 1003: int, 1004: int]; let g_aord: t_arr = [1001: int, 1002: int, 1003: int, 1004: int]; let g_a2r: t_arr2 = [1001: int, 1002: int, 1003: int, 1004: int]; let g_a2o: t_arr2 = [1001: int, 1002: int, 1003: int, 1004: int]; let g_u32: t_au = [1001: u32, 1002: u32, 1003: u32, 1004: u32]; let g_sc2: t_myint2 = 4242; let g_sc2o: t_myint2 = 4242; let g_str2: t_ms2 = "hello"; let g_flt2: t_mf2 = 1.5; let g_flt2f: t_mg2 = 1.5f32; let g_st1: t_pt1; let g_st2: t_pt2; let g_stlit: t_pt1 = t_pt { x = 1001, y = 2002 }; let g_sl2: t_sl2 = [1001: int, 1002: int, 1003: int]; let g_sarr1: t_sa = ["hello", "worlds!"]; let g_sarr2: t_sa2 = ["hello", "worlds!"]; def G_a2: t_arr2 = [1001: int, 1002: int, 1003: int, 1004: int]; def G_st: t_pt1 = t_pt { x = 1001, y = 2002 }; def G_f2: t_mf2 = 1.5; let g_hsl: t_sl = [1001: int, 1002: int, 1003: int]; let g_helem: [2]t_row = [[1010: int, 1020: int, 1030: int], [1040: int, 1050: int, 1060: int]]; @test fn ctl_plain() void = { assert(g_ctl[3] == 1004); g_ctl[3] = 9999; assert(g_ctl[3] == 9999); }; @test fn garr1_read() void = { assert(g_a1r[0] == 1001); assert(g_a1r[3] == 1004); }; @test fn garr1_wr() void = { g_a1w[3] = 8888; assert(g_a1w[3] == 8888); assert(g_a1w[2] == 1003); }; @test fn garr_ord() void = { assert(g_aord[3] == 1004); }; // #78 headline: pre-fix cs emitted NO DATA and read the saved-BP word. @test fn garr2_read() void = { assert(g_a2r[0] == 1001); assert(g_a2r[3] == 1004); }; @test fn garr2_ordwr() void = { assert(g_a2o[3] == 1004); g_a2o[1] = 7777; assert(g_a2o[1] == 7777); }; @test fn garr_u32() void = { assert(g_u32[3] == 1004); g_u32[3] = 8888; assert(g_u32[3] == 8888); assert(g_u32[2] == 1003); }; @test fn gsc2() void = { assert(g_sc2 == 4242); g_sc2 = 9999; assert(g_sc2 == 9999); }; @test fn gsc2_ord() void = { assert(g_sc2o == 4242); }; @test fn gstr2() void = { assert(g_str2.len == 5); }; @test fn gflt2() void = { assert(g_flt2 == 1.5); }; @test fn gflt2_f32() void = { assert(g_flt2f == 1.5f32); }; // one user alias level sufficed to SEGV cs pre-fix (the named struct already // costs the single peel, so `pt1 = pt` is two TY_NAMED layers at the decl). @test fn gst1() void = { g_st1.y = 2002; assert(g_st1.y == 2002); }; @test fn gst2() void = { g_st2.y = 2002; assert(g_st2.y == 2002); }; @test fn gstlit() void = { assert(g_stlit.y == 2002); }; @test fn gsl2() void = { assert(g_sl2.len == 3); assert(g_sl2[2] == 1003); }; // [N]str rows also pin letpreintern's chased array-leg gate: a missed // pre-intern desyncs _S_ label order vs cstage (byte-id catches it). @test fn gstrarr1() void = { assert(g_sarr1[1].len == 7); }; @test fn gstrarr2() void = { assert(g_sarr2[1].len == 7); }; @test fn gdef_a2() void = { assert(G_a2[3] == 1004); }; @test fn gdef_st() void = { assert(G_st.y == 2002); }; @test fn gdef_f2() void = { assert(G_f2 == 1.5); }; // no-regression holds: alias global SLICE (green before the fold) and alias // ELEMENT type (batch-1 win). @test fn hold_slice1() void = { assert(g_hsl.len == 3); assert(g_hsl[2] == 1003); }; @test fn hold_elem() void = { assert(g_helem[0][0] == 1010); assert(g_helem[1][2] == 1060); };