@@ -55,10 +55,10 @@ type wrong-arity term -> typ -> list term -> err.
5555type unknown term -> err.
5656type assert prop -> err -> prop.
5757
58- type error list (pair (ctype "Loc.t") string) -> prop.
59- :name "default-typechecking-error"
58+ type error list (pair (ctype "Loc.t") string) -> bool -> prop.
6059
61- error Msg :- iter (x\ sigma L M\ fst x L, snd x M, print L "Error:" M) Msg.
60+ :name "default-typechecking-error"
61+ error Msg tt :- iter (x\ sigma L M\ fst x L, snd x M, print L "Error:" M) Msg.
6262
6363type warning (ctype "Loc.t") -> string -> prop.
6464:name "default-typechecking-warning"
@@ -69,25 +69,25 @@ assert _ (type-err T Ty ETy) :- !,
6969 checking LOC,
7070 MSG is {pp T} ^ " has type " ^ {ppt Ty} ^
7171 " but is used with type " ^ {ppt ETy},
72- error [pr LOC MSG].
72+ error [pr LOC MSG] _ .
7373assert _ (wrong-arity T Ty A) :- !,
7474 checking LOC,
7575 MSG is {pp T} ^ " has type " ^ {ppt Ty} ^
7676 " but is applied to " ^ {pp-list A},
77- error [pr LOC MSG].
77+ error [pr LOC MSG] _ .
7878
7979stash-new E S :- open_safe E L, ( mem L S ; stash_in_safe E S ), !.
8080
81- report-all-failures-if-no-success P :-
81+ report-all-failures-if-no-success P RC :-
8282 new_safe E,
83- (((pi ML\ error ML :- !, iter (stash-new E) ML, fail) => P)
83+ (((pi ML\ error ML _ :- !, iter (stash-new E) ML, fail) => P)
8484 ;
85- (error {open_safe E})).
86- report-all-failures-and-fail-if-no-success P :-
85+ (error {open_safe E} RC )).
86+ report-all-failures-and-fail-if-no-success P RC :-
8787 new_safe E,
88- (((pi ML\ error ML :- !, iter (stash-new E) ML, fail) => P)
88+ (((pi ML\ error ML _ :- !, iter (stash-new E) ML, fail) => P)
8989 ;
90- (error {open_safe E}, fail)).
90+ (error {open_safe E} RC , fail)).
9191
9292mode (pp i o).
9393type pp term -> string -> prop.
@@ -135,19 +135,20 @@ unif Y (uvar as X) :- X = Y.
135135mode (of i o).
136136
137137of (cdata CData) Ty :-
138- is_cdata CData CTy, !, assert (unif Ty CTy) (type-err (cdata CData) CTy Ty).
138+ is_cdata CData (ctype CTy), !,
139+ assert (unif Ty (ctype CTy)) (type-err (cdata CData) (ctype CTy) Ty).
139140
140141of (app [HD|ARGS]) TY :- !,
141142 report-all-failures-if-no-success % HD may have multiple types
142- (of HD HDTY, of-app HDTY ARGS TY HD (Done - Done)).
143+ (of HD HDTY, of-app HDTY ARGS TY HD (Done - Done)) _ .
143144of (lam F) (arrow T B) :- !, pi x\
144145 (of x T :- !) => of (F x) B.
145146
146147mode (of-app i i o o o).
147148
148149:if "DEBUG:CHECKER"
149150of-app Ty Args Tgt Hd _ :-
150- print {counter "run"} "of-app" {pp Hd} ":" {pp Ty} "@" {pp-list Args} "=" {pp Tgt}, fail.
151+ print {counter "run"} "of-app" {pp Hd} ":" {ppt Ty} "@" {pp-list Args} "=" {ppt Tgt}, fail.
151152
152153of-app (tapp [tconst "variadic", T, _] as V) [X|XS] TGT HD (B - BT) :- !,
153154 of X TX, assert (unif T TX) (type-err X TX T), BT = X :: TL, of-app V XS TGT HD (B - TL).
@@ -179,15 +180,15 @@ type checking (ctype "Loc.t") -> prop.
179180log-tc-clause Loc Query :- !, print {counter "run"} "typecheck" Loc Query.
180181log-tc-clause _ _.
181182
182- typecheck [] (clause Loc Names Query) :-
183+ typecheck [] (clause Loc Names Query) RC :-
183184 log-tc-clause Loc Query,
184185 checking Loc =>
185- report-all-failures-if-no-success (of-clause Names Query).
186- typecheck [ (clause Loc Names Clause) |Rest] Q :-
186+ report-all-failures-if-no-success (of-clause Names Query) RC .
187+ typecheck [ (clause Loc Names Clause) |Rest] Q RC :-
187188 log-tc-clause Loc Clause,
188189 checking Loc =>
189- report-all-failures-if-no-success (of-clause Names Clause), !,
190- typecheck Rest Q.
190+ report-all-failures-if-no-success (of-clause Names Clause) RC , !,
191+ typecheck Rest Q RC .
191192
192193mode (refresh i o).
193194refresh (forall F) T :- !, refresh (F FRESH_) T.
@@ -197,8 +198,6 @@ refresh X X.
197198safe-dest-app (app [X | A]) X A :- !.
198199safe-dest-app X X [].
199200
200- macro @vdash :- ":-".
201-
202201collect-symbols-term N _ X X :- name N, !.
203202collect-symbols-term (cdata _) _ X X :- !.
204203collect-symbols-term (app []) _ X X :- !.
@@ -245,6 +244,9 @@ warn-undeclared Known ((const S) `: LOC) :-
245244 MSG is "constant " ^ S ^ " has no declared type." ^ H,
246245 warning LOC MSG.
247246
247+ type (`:) term -> typ -> entry.
248+ type (`:) term -> ctype "Loc.t" -> entry.
249+
248250under-decl-env [] P :- P.
249251under-decl-env [ X `: PT | XS ] P :-
250252 %print "Assume" X PT,
@@ -255,7 +257,7 @@ under-undecl-env [ X `: _ | XS ] P :-
255257 %print "Assume" X PT,
256258 (of X Ty_ :- !) => under-undecl-env XS P.
257259
258- typecheck-program P Q DeclaredTypes :-
260+ typecheck-program P Q DeclaredTypes RC :-
259261 KnownTypes = [
260262 ((const "pi") `: forall x\ (arrow (arrow x prop) prop)),
261263 ((const "sigma") `: forall x\ (arrow (arrow x prop) prop)),
@@ -264,7 +266,7 @@ typecheck-program P Q DeclaredTypes :-
264266 collect-symbols-clause Q KnownTypes TMP Undeclared,
265267 iter (warn-undeclared KnownTypes) {rev Undeclared},
266268 under-decl-env {rev KnownTypes}
267- (under-undecl-env Undeclared (typecheck P Q)).
269+ (under-undecl-env Undeclared (typecheck P Q RC )).
268270
269271% ---------- warnings ------------------------------------------------------
270272
@@ -319,23 +321,13 @@ warn-linear [ (clause Loc Names Clause) |CS] :-
319321
320322% ---------- test ----------------------------------------------------------
321323
322- type foo int -> prop.
323- type foo string -> prop.
324-
325- main :- test1, test2, test3, test4, test5, test6, test7,
326- warn1.
327- test1 :- app lam.
328- test2 :- lam app.
329- test3 :- app "oops".
330- test4 :- app [] 2.
331- test5 :- print x 2 "3x".
332- test6 :- foo "x", foo 1, foo app.
333- test7 :- foo (foo app).
334- warn1 :- LINEAR.
324+ main.
335325
336326% ------- entry ---------------------------------------
337327
338328check P Q DeclaredTypes :-
339- typecheck-program P Q DeclaredTypes, !, warn-linear P.
329+ typecheck-program P Q DeclaredTypes RC, !,
330+ warn-linear P, !,
331+ if (var RC) (true) (fail).
340332
341333% vim: set ft=lprolog:
0 commit comments