Skip to content

Commit 085e970

Browse files
authored
Merge pull request #522 from mtzguido/fix
Pulse.Checker.Abs: tweak checking of expected type of abstractions
2 parents eb676d5 + 2314016 commit 085e970

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

src/checker/Pulse.Checker.Abs.fst

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -393,39 +393,54 @@ let check_effect_annotation g r (asc:comp_ascription) (c_computed:comp) : T.Tac
393393

394394

395395
#push-options "--z3rlimit_factor 2 --fuel 0 --ifuel 1"
396+
(* Rewrite the comp c into the annotated one, if any,
397+
preserving the st_typing derivation d *)
396398
let maybe_rewrite_body_typing
397399
(#g:_) (#e:st_term) (#c:comp)
398400
(d:st_typing g e c)
399401
(asc:comp_ascription)
400402
: T.Tac (c':comp & st_typing g e c')
401-
= match asc.annotated with
402-
| None -> (| c, d |)
403-
| Some (C_Tot t) -> (
404-
match c with
405-
| C_Tot t' -> (
403+
= let open Pulse.PP in
404+
match asc.annotated, c with
405+
| None, _ -> (| c, d |)
406+
| Some (C_Tot t), C_Tot t' -> (
406407
let t, _ = Pulse.Checker.Pure.instantiate_term_implicits g t None false in
407408
let (| u, t_typing |) = Pulse.Checker.Pure.check_universe g t in
408-
match Pulse.Checker.Base.norm_st_typing_inverse
409-
#_ #_ #t' d t t_typing [hnf;delta]
410-
with
411-
| None ->
412-
Env.fail g (Some e.range)
413-
(Printf.sprintf "Inferred type is incompatible with annotation.\nInferred: %s\nAnnotated: %s"
414-
(P.term_to_string t')
415-
(P.term_to_string t))
416-
| Some d ->
417-
debug_abs g
418-
(fun _ -> Printf.sprintf "maybe_rewrite_body_typing:{\nfrom %s\nto %s}\n"
419-
(P.comp_to_string c)
420-
(P.comp_to_string (C_Tot t)));
421-
(| C_Tot t, d |)
422-
)
423-
| _ ->
424-
Env.fail g (Some e.range) "Inferred type is incompatible with annotation"
409+
match T.t_check_equiv true true (elab_env g) t t' with
410+
| None, _ ->
411+
Env.fail_doc g (Some e.range) [
412+
text "Inferred type is incompatible with annotation.";
413+
text "Inferred:" ^/^ pp t';
414+
text "Annotated:" ^/^ pp t;
415+
]
416+
| Some tok, _ ->
417+
debug_abs g
418+
(fun _ -> Printf.sprintf "maybe_rewrite_body_typing:{\nfrom %s\nto %s}\n"
419+
(show c)
420+
(show (C_Tot t)));
421+
let sq : squash (RT.equiv_token (elab_env g) t t') = () in
422+
let t'_typing : universe_of g t' u =
423+
(* t is equiv to t', and t has universe t. *)
424+
magic ()
425+
in
426+
let tok' : st_equiv g (C_Tot t') (C_Tot t) =
427+
ST_TotEquiv _ t' t u t'_typing
428+
(RT.Rel_sym _ _ _ (RT.Rel_eq_token _ _ _ sq))
429+
in
430+
(| C_Tot t, T_Equiv _ _ _ _ d tok' |)
425431
)
426-
| Some c ->
427-
let st = st_comp_of_comp c in
428-
Env.fail g (Some (RU.range_of_term st.pre)) "Unexpected annotation on a function body"
432+
433+
(* c is not a C_Tot *)
434+
| Some (C_Tot _), _ ->
435+
Env.fail_doc g (Some e.range) [
436+
text "Inferred type is incompatible with annotation.";
437+
]
438+
439+
(* The annotation is not a C_Tot *)
440+
| Some c, _ ->
441+
Env.fail_doc g (Some (range_of_comp c)) [
442+
Pulse.PP.text "Unexpected annotation on a function body."
443+
]
429444
#pop-options
430445

431446
let open_ascription (c:comp_ascription) (nv:nvar) : comp_ascription =

src/ml/FStarC_Parser_Parse.mly

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,6 @@ rawDecl:
417417
{
418418
let r = rr $loc in
419419
let lbs = focusLetBindings lbs r in
420-
if q <> Rec && FStarC_List.length lbs > Prims.parse_int "1"
421-
then raise_error_text (fst (nth lbs (Prims.parse_int "1"))).prange Fatal_MultipleLetBinding "Unexpected multiple let-binding (Did you forget some rec qualifier ?)";
422420
TopLevelLet(q, lbs)
423421
}
424422
| VAL c=constant

0 commit comments

Comments
 (0)