From b6274f3455d0545a64f2cc866b39d409e0a73427 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Sun, 10 Nov 2024 20:30:35 +0100 Subject: [PATCH] fixing yet another edge case --- lang/README.md | 16 +++-- lang/src/son.rs | 22 ++++--- ...son_tests_storing_into_nullable_struct.txt | 62 ++++++++++--------- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/lang/README.md b/lang/README.md index aa7dbcfb..f5c97293 100644 --- a/lang/README.md +++ b/lang/README.md @@ -617,12 +617,14 @@ main := fn(): uint { #### storing_into_nullable_struct ```hb -StructA := struct {b: StructB} +StructA := struct {b: StructB, c: ^uint, d: uint} -StructB := struct {c: uint} +StructB := struct {g: ^uint, c: StructC} + +StructC := struct {c: uint} optionala := fn(): ?StructA { - return .(.(1)) + return .(.(&0, .(1)), &0, 0) } Struct := struct {inner: uint} @@ -635,13 +637,17 @@ do_stuff := fn(arg: uint): uint { return arg } +just_read := fn(s: StructA): void { +} + main := fn(): uint { a := optionala() if a == null { return 10 } - a.b = .(0) - innera := do_stuff(a.b.c) + a.b.c = .(0) + just_read(a) + innera := do_stuff(a.b.c.c) val := optional() if val == null { diff --git a/lang/src/son.rs b/lang/src/son.rs index 8a998640..eb73dbed 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -1247,20 +1247,22 @@ impl Nodes { }, ); let size = tys.size_of(ty); + let mut offset = 0; loop { - break match s[region].kind { - _ if region == loc => 0..size as usize, + match s[region].kind { + _ if region == loc => { + break offset as usize..offset as usize + size as usize + } Kind::Assert { kind: AssertKind::NullCheck, .. } => { - region = s[region].inputs[2]; - continue; + region = s[region].inputs[2] } Kind::BinOp { op: TokenKind::Add | TokenKind::Sub } - if let Kind::CInt { value } = s[s[region].inputs[2]].kind - && s[region].inputs[1] == loc => + if let Kind::CInt { value } = s[s[region].inputs[2]].kind => { - value as usize..value as usize + size as usize + offset += value; + region = s[region].inputs[1]; } - _ => 0..full_size as usize, + _ => break 0..full_size as usize, }; } } @@ -1280,6 +1282,8 @@ impl Nodes { if range.start >= load_range.end || range.end <= load_range.start { cursor = self[cursor].inputs[3]; } else { + let reg = self.aclass_index(self[cursor].inputs[2]).1; + self[reg].peep_triggers.push(target); break; } } @@ -4327,7 +4331,7 @@ impl<'a> Codegen<'a> { self.ci.nodes.basic_blocks(); self.ci.nodes.graphviz(self.ty_display(ty::Id::VOID)); } else { - //self.ci.nodes.graphviz_in_browser(self.ty_display(ty::Id::VOID)); + self.ci.nodes.graphviz_in_browser(self.ty_display(ty::Id::VOID)); } self.errors.borrow().len() == prev_err_len diff --git a/lang/tests/son_tests_storing_into_nullable_struct.txt b/lang/tests/son_tests_storing_into_nullable_struct.txt index ac3afdd2..3b70861b 100644 --- a/lang/tests/son_tests_storing_into_nullable_struct.txt +++ b/lang/tests/son_tests_storing_into_nullable_struct.txt @@ -1,40 +1,42 @@ do_stuff: CP r1, r2 JALA r0, r31, 0a +just_read: + JALA r0, r31, 0a main: - ADDI64 r254, r254, -104d - ST r31, r254, 32a, 72h + ADDI64 r254, r254, -120d + ST r31, r254, 48a, 72h ADDI64 r32, r254, 16d + CP r1, r32 JAL r31, r0, :optionala - ST r1, r254, 16a, 16h - LI8 r33, 0b - LD r34, r254, 16a, 1h - ANDI r34, r34, 255d - ANDI r33, r33, 255d + CP r2, r32 + LI64 r33, 0d + LD r34, r254, 16a, 8h JNE r34, r33, :0 LI64 r1, 10d JMP :1 - 0: LI64 r35, 0d - ST r35, r254, 24a, 8h + 0: ST r33, r254, 24a, 8h + JAL r31, r0, :just_read LD r2, r254, 24a, 8h JAL r31, r0, :do_stuff - CP r36, r1 - ADDI64 r37, r254, 0d + CP r35, r1 + ADDI64 r36, r254, 0d JAL r31, r0, :optional ST r1, r254, 0a, 16h + LI8 r37, 0b LD r38, r254, 0a, 1h ANDI r38, r38, 255d - ANDI r33, r33, 255d - JNE r38, r33, :2 + ANDI r37, r37, 255d + JNE r38, r37, :2 LI64 r1, 20d JMP :1 2: LI64 r39, 100d ST r39, r254, 8a, 8h LD r2, r254, 8a, 8h JAL r31, r0, :do_stuff - ADD64 r1, r1, r36 - 1: LD r31, r254, 32a, 72h - ADDI64 r254, r254, 104d + ADD64 r1, r1, r35 + 1: LD r31, r254, 48a, 72h + ADDI64 r254, r254, 120d JALA r0, r31, 0a optional: ADDI64 r254, r254, -16d @@ -47,18 +49,22 @@ optional: ADDI64 r254, r254, 16d JALA r0, r31, 0a optionala: - ADDI64 r254, r254, -24d - ADDI64 r1, r254, 0d - LI64 r3, 1d - LI8 r7, 1b - ADDI64 r6, r254, 8d - ST r3, r254, 0a, 8h - ST r7, r254, 8a, 1h - ADDI64 r11, r6, 8d - BMC r1, r11, 8h - LD r1, r6, 0a, 16h - ADDI64 r254, r254, 24d + ADDI64 r254, r254, -56d + ADDI64 r7, r254, 0d + LI64 r8, 1d + ADDI64 r9, r254, 16d + ADDI64 r6, r254, 24d + ST r8, r254, 0a, 8h + ST r9, r254, 24a, 8h + ADDI64 r3, r6, 8d + BMC r7, r3, 8h + ADDI64 r4, r254, 8d + ST r4, r254, 40a, 8h + LI64 r2, 0d + ST r2, r254, 48a, 8h + BMC r6, r1, 32h + ADDI64 r254, r254, 56d JALA r0, r31, 0a -code size: 568 +code size: 604 ret: 100 status: Ok(())