feat: match guards, HOF inference, ownership C.2/C.3, LSP sema hover

Sessions 18–23 quality work:

- B.3c match arm guards + sequential found-flag lower (bootstrap + selfhost)
- Generic HOF type inference (Array/Iter map/filter/fold without type args)
- Pattern binding shadowing via unique C locals (__pN_src)
- Ownership C.2 exclusive &mut data-flow + C.4 goldens; *p= store-through fix
- Ownership C.3 auto-drop on early return/branches: scoped defers, move-on-return,
  Drop monomorphization, materialize return before Drop
- LSP 0.3.0: hover from real sema types
- Examples and QUALITY_PLAN session log; selfhost-loop identical
This commit is contained in:
2026-07-18 21:52:14 +03:00
parent 66f11d1869
commit 3eb1ad3a82
25 changed files with 2246 additions and 457 deletions
+62
View File
@@ -0,0 +1,62 @@
// C.3 — Auto-drop on early return and if branches
// @[Drop] types call Type_Drop at every exit (return + branch scope end).
import Std::Io::{PrintLine, PrintInt};
import Std::Test::{Test_AssertEqInt, Test_Pass};
@[Drop]
struct Token {
id: int,
counter: *int
}
func Token_Drop(self: *Token) {
if self.counter != null as *int {
*self.counter = *self.counter + 1;
}
}
// Drop t on both early return and fallthrough return.
func Early(flag: int, counter: *int) -> int {
let t: Token = Token { id: 1, counter: counter };
if flag == 0 {
return 0;
}
return 1;
}
// Branch-local Tokens: only the taken branch's Drop runs.
func Branched(flag: int, counter: *int) -> int {
if flag == 1 {
let a: Token = Token { id: 10, counter: counter };
return a.id;
} else {
let b: Token = Token { id: 20, counter: counter };
return b.id;
}
}
// Fallthrough: Drop at end of block without return.
func Scoped(counter: *int) {
let s: Token = Token { id: 99, counter: counter };
discard s.id;
}
func Main() -> int {
var drops: int = 0;
discard Early(0, &drops);
discard Early(1, &drops);
Test_AssertEqInt(drops, 2);
discard Branched(1, &drops);
discard Branched(0, &drops);
Test_AssertEqInt(drops, 4);
Scoped(&drops);
Test_AssertEqInt(drops, 5);
PrintInt(drops);
PrintLine("");
Test_Pass("drop_early_return");
return 0;
}