From fc12bf172369d1d5546467ffeba6ae17e3ccd0ed Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 3 Nov 2024 14:53:55 +0100 Subject: [PATCH 1/6] test --- lang/src/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/src/parser.rs b/lang/src/parser.rs index 91de4b5..4718098 100644 --- a/lang/src/parser.rs +++ b/lang/src/parser.rs @@ -136,7 +136,7 @@ impl<'a, 'b> Parser<'a, 'b> { f } - fn next(&mut self) -> Token { + fn next(&mut self) -> Token { core::mem::replace(&mut self.token, self.lexer.eat()) } -- 2.44.1 From 4e5db5109160e7f888fd10f5d10940a6d5b321ca Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 3 Nov 2024 14:54:18 +0100 Subject: [PATCH 2/6] another quick git test --- lang/src/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/src/parser.rs b/lang/src/parser.rs index 4718098..91de4b5 100644 --- a/lang/src/parser.rs +++ b/lang/src/parser.rs @@ -136,7 +136,7 @@ impl<'a, 'b> Parser<'a, 'b> { f } - fn next(&mut self) -> Token { + fn next(&mut self) -> Token { core::mem::replace(&mut self.token, self.lexer.eat()) } -- 2.44.1 From 92cc1f00a842b33847b63c4c65181eccfb74a5fc Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 3 Nov 2024 15:03:59 +0100 Subject: [PATCH 3/6] Added `null_check_test` --- lang/README.md | 14 ++++++++++++++ lang/src/son.rs | 1 + 2 files changed, 15 insertions(+) diff --git a/lang/README.md b/lang/README.md index e82e146..f75e8f0 100644 --- a/lang/README.md +++ b/lang/README.md @@ -965,6 +965,20 @@ main := fn(): uint { } ``` +#### null_check_test +```hb +main := fn(): unit { + ptr := @as(?^uint, null) + *ptr = 0 + + if ptr == null { + return 1 + } + + return *ptr +} +``` + ### Just Testing Optimizations #### const_folding_with_arg diff --git a/lang/src/son.rs b/lang/src/son.rs index 74bcaad..779e819 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -4058,6 +4058,7 @@ mod tests { writing_into_string; request_page; tests_ptr_to_ptr_copy; + null_check_test; // Just Testing Optimizations; const_folding_with_arg; -- 2.44.1 From e27a21874648bc9d426dda704a8a3ca81991195a Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 3 Nov 2024 15:17:59 +0100 Subject: [PATCH 4/6] Fixed some issues with `null_check_test`` --- lang/README.md | 22 +++++++++++++++++++--- lang/tests/son_tests_null_check_test.txt | 0 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 lang/tests/son_tests_null_check_test.txt diff --git a/lang/README.md b/lang/README.md index 5c7d021..7aae452 100644 --- a/lang/README.md +++ b/lang/README.md @@ -1042,16 +1042,32 @@ main := fn(): uint { } ``` +#### inlining_loops +```hb +x := 1 + +foo := fn(): int { + loop if true break + x = 0 +} + +main := fn(): int { + @inline(foo) + return x +} +``` + #### null_check_test ```hb -main := fn(): unit { +main := fn(): uint { ptr := @as(?^uint, null) - *ptr = 0 + value := 0 + ptr = &value if ptr == null { return 1 } - + return *ptr } ``` diff --git a/lang/tests/son_tests_null_check_test.txt b/lang/tests/son_tests_null_check_test.txt new file mode 100644 index 0000000..e69de29 -- 2.44.1 From d4a52b6342595a941be262d12acf3b6b265b99c6 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 3 Nov 2024 15:22:29 +0100 Subject: [PATCH 5/6] Fixed `inlining_loops` --- lang/README.md | 4 ++-- lang/src/son.rs | 1 + lang/tests/son_tests_inlining_loops.txt | 0 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 lang/tests/son_tests_inlining_loops.txt diff --git a/lang/README.md b/lang/README.md index 7aae452..a1301fe 100644 --- a/lang/README.md +++ b/lang/README.md @@ -1046,12 +1046,12 @@ main := fn(): uint { ```hb x := 1 -foo := fn(): int { +foo := fn(): void { loop if true break x = 0 } -main := fn(): int { +main := fn(): uint { @inline(foo) return x } diff --git a/lang/src/son.rs b/lang/src/son.rs index 900f704..707ae74 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -4412,6 +4412,7 @@ mod tests { writing_into_string; request_page; tests_ptr_to_ptr_copy; + inlining_loops; null_check_test; // Just Testing Optimizations; diff --git a/lang/tests/son_tests_inlining_loops.txt b/lang/tests/son_tests_inlining_loops.txt new file mode 100644 index 0000000..e69de29 -- 2.44.1 From 191c49ff1d0b7d9186d0df089bfebb63f9db8b16 Mon Sep 17 00:00:00 2001 From: peony Date: Sun, 3 Nov 2024 15:58:42 +0100 Subject: [PATCH 6/6] Made sure `null_check_test` reproduces exact issue. --- lang/README.md | 15 ++++++++++----- lang/tests/son_tests_inlining_loops.txt | 8 ++++++++ lang/tests/son_tests_null_check_test.txt | 6 ++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lang/README.md b/lang/README.md index a1301fe..e853f92 100644 --- a/lang/README.md +++ b/lang/README.md @@ -1059,16 +1059,21 @@ main := fn(): uint { #### null_check_test ```hb -main := fn(): uint { - ptr := @as(?^uint, null) +get_ptr := fn(): ?^uint { value := 0 - ptr = &value + return &value +} + +main := fn(): void { + ptr := get_ptr() if ptr == null { - return 1 + return } - return *ptr + loop { + *ptr += 1 + } } ``` diff --git a/lang/tests/son_tests_inlining_loops.txt b/lang/tests/son_tests_inlining_loops.txt index e69de29..f02533a 100644 --- a/lang/tests/son_tests_inlining_loops.txt +++ b/lang/tests/son_tests_inlining_loops.txt @@ -0,0 +1,8 @@ +main: + LRA r2, r0, :x + LI64 r1, 0d + ST r1, r2, 0a, 8h + JALA r0, r31, 0a +code size: 57 +ret: 0 +status: Ok(()) diff --git a/lang/tests/son_tests_null_check_test.txt b/lang/tests/son_tests_null_check_test.txt index e69de29..c9727f8 100644 --- a/lang/tests/son_tests_null_check_test.txt +++ b/lang/tests/son_tests_null_check_test.txt @@ -0,0 +1,6 @@ +test.hb:15:4: can't prove the value is not 'null', use '@unwrap()' if you believe compiler is stupid, or explicitly check for null and handle it ('if == null { /* handle */ } else { /* use opt */ }') + *ptr += 1 + ^ +test.hb:15:4: can't prove the value is not 'null', use '@unwrap()' if you believe compiler is stupid, or explicitly check for null and handle it ('if == null { /* handle */ } else { /* use opt */ }') + *ptr += 1 + ^ -- 2.44.1