Skip to content

Commit d72b302

Browse files
authored
Merge pull request #2025 from andrew-johnson-4/fix-memory-leak-from-last-nonfix-fdsiosl
Fix memory leak from last nonfix fdsiosl
2 parents 16c58ba + 8777cdd commit d72b302

6 files changed

Lines changed: 3354 additions & 3327 deletions

File tree

BOOTSTRAP/cli.c

Lines changed: 3330 additions & 3324 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ dev: install-production
1212
#lm --showalloc SRC/unit-prop-core.lsts > out.txt
1313
#lm --showalloc SRC/unit-ascript-core.lsts > out.txt
1414
#lm --showalloc SRC/index.lsts > out.txt
15-
lm tests/promises/typechecking/misc-linear-error-1.lsts
15+
lm tests/promises/typechecking/misc-linear-error-1.lsts > out.txt
16+
gcc tmp.c;
17+
./a.out
1618

1719
build: compile-production
1820
time env $(LSTSFLAGS) ./production --v23 --c -o deploy1.c SRC/index.lsts

SRC/type-is-linear.lsts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
let .is-linear(tt: Type): Bool = non-zero(tt.slot(c"Phi::Id",1));

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
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
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
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
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"));

SRC/unit-type-core.lsts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ import SRC/type-cons-tail-or-self.lsts;
4040
import SRC/type-without-modifiers.lsts;
4141
import SRC/type-with-only-phi.lsts;
4242
import SRC/type-reify-type-variables.lsts;
43+
import SRC/type-is-linear.lsts;

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 == 0 );
14+
15+
g();
16+
assert( safe-alloc-block-count == 0 );

0 commit comments

Comments
 (0)