Skip to content

Commit 3b0ee78

Browse files
committed
GC OK
1 parent 16c58ba commit 3b0ee78

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

SRC/typecheck-infer-expr.lsts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
143143
(let tctx-cond, let new-cond) = std-infer-expr(tctx, cond, false, Tail(), ta);
144144
(tctx-t, let new-t) = std-infer-expr(tctx-cond, t, false, Tail(), ta);
145145
(tctx-f, let new-f) = std-infer-expr(tctx, f, false, Tail(), ta);
146+
if typeof-term(new-t).is-t(c"Nil",0) and typeof-term(new-f).is-linear-live
147+
then (tctx-f, new-f) = wrap-call(tctx-f, c".release", new-f);
148+
if typeof-term(new-f).is-t(c"Nil",0) and typeof-term(new-t).is-linear-live
149+
then (tctx-t, new-t) = wrap-call(tctx-t, c".release", new-t);
146150
if not(is(cond,new-cond)) or not(is(t,new-t)) or not(is(f,new-f))
147151
then { cond = new-cond; t = new-t; f = new-f; term = mk-app(mk-app(mk-app(ifv,new-cond),new-t),new-f) };
148152
tctx = tctx.with-pctx( phi-merge(tctx,tctx-t.get-or(mk-tctx()).pctx,tctx-f.get-or(mk-tctx()).pctx,term) );
@@ -151,6 +155,10 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
151155
(tctx-t, let new-t) = std-infer-expr(tctx, t, false, Tail(), ta);
152156
(tctx-f, let new-f) = std-infer-expr(tctx, f, false, Tail(), ta);
153157
(tctx-f, new-f) = release-locals(tctx, tctx-f, new-f, hint, false);
158+
if typeof-term(new-t).is-t(c"Nil",0) and typeof-term(new-f).is-linear-live
159+
then (tctx-f, new-f) = wrap-call(tctx-f, c".release", new-f);
160+
if typeof-term(new-f).is-t(c"Nil",0) and typeof-term(new-t).is-linear-live
161+
then (tctx-t, new-t) = wrap-call(tctx-t, c".release", new-t);
154162
tctx = tctx-t;
155163
if not(is(cond,new-cond)) or not(is(t,new-t)) or not(is(f,new-f))
156164
then { cond = new-cond; t = new-t; f = new-f; term = mk-app(mk-app(mk-app(ifv,new-cond),new-t),new-f) };
@@ -173,8 +181,6 @@ let std-infer-expr(tctx: Maybe<TypeContext>, term: AST, is-scoped: Bool, used: I
173181
};
174182
if non-zero(term-phi-id) and term-phi-id != t-phi-id then tctx = tctx.phi-move(typeof-term(t), t);
175183
if non-zero(term-phi-id) and term-phi-id != f-phi-id then tctx = tctx.phi-move(typeof-term(f), f);
176-
if (typeof-term(term).is-t(c"Nil",0) or typeof-term(term).is-t(c"Never",0)) and non-zero(t-phi-id) then tctx = tctx.phi-move(typeof-term(t), t);
177-
if (typeof-term(term).is-t(c"Nil",0) or typeof-term(term).is-t(c"Never",0)) and non-zero(f-phi-id) then tctx = tctx.phi-move(typeof-term(f), f);
178184
}
179185
);
180186
ASTEOF{} => tctx = tctx.ascript(term, t0(c"Nil"));

tests/promises/typechecking/misc-linear-error-1.lsts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ import lib/core/bedrock.lsts;
44
let f(): Nil = (
55
if true then "";
66
);
7+
8+
let g(): Nil = (
9+
if false then () else "";
10+
);
11+
12+
f();
13+
assert( safe-alloc-block-count-monotonic == 0 );
14+
15+
g();
16+
assert( safe-alloc-block-count-monotonic == 0 );

0 commit comments

Comments
 (0)