@@ -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"));
0 commit comments