@@ -224,6 +224,17 @@ namespace tc {
224224 split-pf [X|Xs] Old [X|Ys] L :- name X, not (std.mem! Old X), !, split-pf Xs [X|Old] Ys L.
225225 split-pf Xs _ [] Xs.
226226
227+ pred used i:term, i:term.
228+ used X (uvar _ S) :- std.mem! S X, !.
229+ used X (fun _ _ Bo) :- pi x\ used X (Bo x).
230+
231+ pred close-term-prune-safe-fun i:(term -> list term), i:term, o:list term.
232+ close-term-prune-safe-fun (x\ []) _ [] :- !.
233+ close-term-prune-safe-fun (x\ [X x | Xs x]) Ty [fun _ _ X | Xs'] :-
234+ pi x\ used x (X x), !, close-term-prune-safe-fun Xs Ty Xs'.
235+ close-term-prune-safe-fun (x\ [X | Xs x]) Ty [X | Xs'] :-
236+ close-term-prune-safe-fun Xs Ty Xs'.
237+
227238 pred precompile-aux i:term, i:list term, o:term, o:list term.
228239 precompile-aux X A Y A :- name X, !, X = Y, !. % avoid loading "precompile-aux x A x A" at binders
229240 precompile-aux (global _ as C) A C A :- !.
@@ -243,7 +254,7 @@ namespace tc {
243254 precompile-aux (fun Name Ty B as T) N (tc.maybe-eta-tm (fun Name Ty' B') Scope) M :-
244255 maybe-eta T, !,
245256 names Scope,
246- std.assert! (pi x\ precompile-aux (B x) N (B' x) (MM x), close-term-no- prune-fun MM Ty M') "[TC] should not fail1",
257+ std.assert! (pi x\ precompile-aux (B x) N (B' x) (MM x), close-term-prune-safe -fun MM Ty M') "[TC] should not fail1",
247258 precompile-aux Ty M' Ty' M.
248259
249260 % Detect maybe-beta term
@@ -255,7 +266,7 @@ namespace tc {
255266
256267 precompile-aux (prod Name Ty B) N (tc.prod-range (prod Name Ty' B') (r-ar z MaxAr)) P :- !,
257268 count-prod Ty MaxAr,
258- std.assert! (pi x\ precompile-aux (B x) N (B' x) (MM x), close-term-no- prune-fun MM Ty M) "[TC] should not fail2",
269+ std.assert! (pi x\ precompile-aux (B x) N (B' x) (MM x), close-term-prune-safe -fun MM Ty M) "[TC] should not fail2",
259270 precompile-aux Ty M Ty' P.
260271
261272 % Working with fun
0 commit comments