Stefan pushed to branch master at Stefan / Typer
Commits:
-
cf67844d
by Stefan Monnier at 2019-09-13T21:06:03Z
3 changed files:
Changes:
| ... | ... | @@ -171,7 +171,8 @@ let elab_check_def (ctx : elab_context) var lxp ltype = |
| 171 | 171 |
elab_check_proper_type ctx ltype var
|
| 172 | 172 |
else
|
| 173 | 173 |
(EV.debug_messages fatal loc "Type check error: ¡¡ctx_define error!!" [
|
| 174 |
- lexp_string lxp ^ " !: " ^ lexp_string ltype;
|
|
| 174 |
+ (match var with (_, Some n) -> n | _ -> "<anon>")
|
|
| 175 |
+ ^ " = " ^ lexp_string lxp ^ " !: " ^ lexp_string ltype;
|
|
| 175 | 176 |
" because";
|
| 176 | 177 |
lexp_string ltype' ^ " != " ^ lexp_string ltype])
|
| 177 | 178 |
|
| ... | ... | @@ -650,7 +651,15 @@ and check_case rtype (loc, target, ppatterns) ctx = |
| 650 | 651 |
let add_branch pctor pargs =
|
| 651 | 652 |
let loc = sexp_location pctor in
|
| 652 | 653 |
let lctor, ct = infer pctor ctx in
|
| 653 |
- match OL.lexp_whnf lctor (ectx_to_lctx ctx) with
|
|
| 654 |
+ let rec inst_args ctx e = match OL.lexp_whnf e (ectx_to_lctx ctx) with
|
|
| 655 |
+ | Lambda (Aerasable, v, t, body)
|
|
| 656 |
+ -> let arg = newMetavar (ectx_to_lctx ctx) (ectx_to_scope_level ctx)
|
|
| 657 |
+ v t in
|
|
| 658 |
+ let nctx = ctx_extend ctx v Variable t in
|
|
| 659 |
+ let body = inst_args nctx body in
|
|
| 660 |
+ mkSusp body (S.substitute arg)
|
|
| 661 |
+ | e -> e in
|
|
| 662 |
+ match nosusp (inst_args ctx lctor) with
|
|
| 654 | 663 |
| Cons (it', (_, cons_name))
|
| 655 | 664 |
-> let _ = match Unif.unify it' it (ectx_to_lctx ctx) with
|
| 656 | 665 |
| (None | Some (_::_))
|
| ... | ... | @@ -676,7 +685,7 @@ and check_case rtype (loc, target, ppatterns) ctx = |
| 676 | 685 |
pargs (* Pattern arguments. *)
|
| 677 | 686 |
cargs (* Constructor arguments. *)
|
| 678 | 687 |
pe (* Pending explicit pattern args. *)
|
| 679 |
- acc = (* Accumulated reult. *)
|
|
| 688 |
+ acc = (* Accumulated result. *)
|
|
| 680 | 689 |
match (pargs, cargs) with
|
| 681 | 690 |
| (_, []) when not (SMap.is_empty pe)
|
| 682 | 691 |
-> let pending = SMap.bindings pe in
|
| ... | ... | @@ -281,8 +281,7 @@ let rec sunshift n = |
| 281 | 281 |
else (assert (n >= 0);
|
| 282 | 282 |
S.cons impossible (sunshift (n - 1)))
|
| 283 | 283 |
|
| 284 |
-let _ = assert (S.identity (* Sanity check! *)
|
|
| 285 |
- = scompose (S.shift 5) (sunshift 5))
|
|
| 284 |
+let _ = assert (S.identity_p (scompose (S.shift 5) (sunshift 5)))
|
|
| 286 | 285 |
|
| 287 | 286 |
(* The quick test below seemed to indicate that about 50% of the "sink"s
|
| 288 | 287 |
* are applied on top of another "sink" and hence cound be combined into
|
| 1 | 1 |
(* unification.ml --- Unification of Lexp terms
|
| 2 | 2 |
|
| 3 |
-Copyright (C) 2016-2018 Free Software Foundation, Inc.
|
|
| 3 |
+Copyright (C) 2016-2019 Free Software Foundation, Inc.
|
|
| 4 | 4 |
|
| 5 | 5 |
Author: Vincent Bonnevalle <tiv.crb@gmail.com>
|
| 6 | 6 |
|
| ... | ... | @@ -132,14 +132,16 @@ let rec unify (e1: lexp) (e2: lexp) |
| 132 | 132 |
and unify' (e1: lexp) (e2: lexp)
|
| 133 | 133 |
(ctx : DB.lexp_context) (vs : OL.set_plexp)
|
| 134 | 134 |
: return_type =
|
| 135 |
+ if e1 == e2 then Some [] else
|
|
| 135 | 136 |
let e1' = OL.lexp_whnf e1 ctx in
|
| 136 | 137 |
let e2' = OL.lexp_whnf e2 ctx in
|
| 137 |
- let changed = not (e1 == e1' && e2 == e2') in
|
|
| 138 |
+ if e1' == e2' then Some [] else
|
|
| 139 |
+ let changed = true (* not (e1 == e1' && e2 == e2') *) in
|
|
| 138 | 140 |
if changed && OL.set_member_p vs e1' e2' then Some [] else
|
| 139 | 141 |
let vs' = if changed then OL.set_add vs e1' e2' else vs in
|
| 140 | 142 |
match (e1', e2') with
|
| 141 | 143 |
| ((Imm _, Imm _) | (Cons _, Cons _) | (Builtin _, Builtin _)
|
| 142 |
- | (Var _, Var _) | (Inductive _, Inductive _))
|
|
| 144 |
+ | (Var _, Var _))
|
|
| 143 | 145 |
-> if OL.conv_p ctx e1' e2' then Some [] else None
|
| 144 | 146 |
| (l, (Metavar (idx, s, _) as r)) -> unify_metavar ctx idx s r l
|
| 145 | 147 |
| ((Metavar (idx, s, _) as l), r) -> unify_metavar ctx idx s l r
|
| ... | ... | @@ -152,7 +154,17 @@ and unify' (e1: lexp) (e2: lexp) |
| 152 | 154 |
(* | (Inductive _ as l, r) -> unify_induct l r subst *)
|
| 153 | 155 |
| (Sort _ as l, r) -> unify_sort l r ctx vs'
|
| 154 | 156 |
| (SortLevel _ as l, r) -> unify_sortlvl l r ctx vs'
|
| 155 |
- | _ -> Some (if OL.conv_p ctx e1' e2' then [] else [(e1, e2)])
|
|
| 157 |
+ | (Inductive (_loc1, label1, args1, consts1),
|
|
| 158 |
+ Inductive (_loc2, label2, args2, consts2))
|
|
| 159 |
+ -> (* print_string ("Unifying inductives "
|
|
| 160 |
+ * ^ snd label1
|
|
| 161 |
+ * ^ " and "
|
|
| 162 |
+ * ^ snd label2
|
|
| 163 |
+ * ^ "\n"); *)
|
|
| 164 |
+ unify_inductive ctx vs' args1 args2 consts1 consts2
|
|
| 165 |
+ | _ -> Some (if OL.conv_p ctx e1' e2' then []
|
|
| 166 |
+ else ((* print_string "Unification failure on default\n"; *)
|
|
| 167 |
+ [(e1, e2)]))
|
|
| 156 | 168 |
|
| 157 | 169 |
(********************************* Type specific unify *******************************)
|
| 158 | 170 |
|
| ... | ... | @@ -401,6 +413,26 @@ and is_same arglist arglist2 = |
| 401 | 413 |
* | None -> test e subst)
|
| 402 | 414 |
* ) None lst *)
|
| 403 | 415 |
|
| 416 |
+and unify_inductive ctx vs args1 args2 consts1 consts2 =
|
|
| 417 |
+ let unif_formals ctx vs args1 args2
|
|
| 418 |
+ = if not (List.length args1 == List.length args2) then (ctx, vs, None) else
|
|
| 419 |
+ List.fold_left (fun (ctx, vs, residue) ((ak1, v1, t1), (ak2, v2, t2))
|
|
| 420 |
+ -> (DB.lexp_ctx_cons ctx v1 Variable t1,
|
|
| 421 |
+ OL.set_shift vs,
|
|
| 422 |
+ if not (ak1 == ak2) then None
|
|
| 423 |
+ else unify_and (unify' t1 t2 ctx vs) residue))
|
|
| 424 |
+ (ctx, vs, Some [])
|
|
| 425 |
+ (List.combine args1 args2) in
|
|
| 426 |
+ let (ctx, vs, residue) = unif_formals ctx vs args1 args2 in
|
|
| 427 |
+ if not (SMap.cardinal consts1 == SMap.cardinal consts2) then None else
|
|
| 428 |
+ SMap.fold (fun cname args1 residue
|
|
| 429 |
+ -> match SMap.find cname consts2 with
|
|
| 430 |
+ | args2 -> let (_ctx, _vs, residue')
|
|
| 431 |
+ = unif_formals ctx vs args1 args2 in
|
|
| 432 |
+ unify_and residue' residue
|
|
| 433 |
+ | exception Not_found -> None)
|
|
| 434 |
+ consts1 residue
|
|
| 435 |
+ |
|
| 404 | 436 |
(** unify the SMap of list in Inductive *)
|
| 405 | 437 |
(* and unify_induct_sub_list l1 l2 subst =
|
| 406 | 438 |
* let test l1 l2 subst =
|