Stefan pushed to branch master at Stefan / Typer
Commits:
-
e3a0fe68
by Stefan Monnier at 2019-09-13T18:31:03Z
6 changed files:
Changes:
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 |
*
|
| 4 | 4 |
* ---------------------------------------------------------------------------
|
| 5 | 5 |
*
|
| 6 |
- * Copyright (C) 2011-2018 Free Software Foundation, Inc.
|
|
| 6 |
+ * Copyright (C) 2011-2019 Free Software Foundation, Inc.
|
|
| 7 | 7 |
*
|
| 8 | 8 |
* Author: Pierre Delaunay <pierre.delaunay@hec.ca>
|
| 9 | 9 |
* Keywords: languages, lisp, dependent types.
|
| ... | ... | @@ -85,8 +85,8 @@ let sort_level = mkSort (dloc, StypeLevel) |
| 85 | 85 |
let sort_omega = mkSort (dloc, StypeOmega)
|
| 86 | 86 |
let type_level = mkBuiltin ((dloc, "TypeLevel"), sort_level, None)
|
| 87 | 87 |
let level0 = mkSortLevel SLz
|
| 88 |
-let level1 = mkSortLevel (SLsucc level0)
|
|
| 89 |
-let level2 = mkSortLevel (SLsucc level1)
|
|
| 88 |
+let level1 = mkSortLevel (mkSLsucc level0)
|
|
| 89 |
+let level2 = mkSortLevel (mkSLsucc level1)
|
|
| 90 | 90 |
let type0 = mkSort (dloc, Stype level0)
|
| 91 | 91 |
let type1 = mkSort (dloc, Stype level1)
|
| 92 | 92 |
let type2 = mkSort (dloc, Stype level2)
|
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 |
*
|
| 4 | 4 |
* ---------------------------------------------------------------------------
|
| 5 | 5 |
*
|
| 6 |
- * Copyright (C) 2011-2018 Free Software Foundation, Inc.
|
|
| 6 |
+ * Copyright (C) 2011-2019 Free Software Foundation, Inc.
|
|
| 7 | 7 |
*
|
| 8 | 8 |
* Author: Pierre Delaunay <pierre.delaunay@hec.ca>
|
| 9 | 9 |
* Keywords: languages, lisp, dependent types.
|
| ... | ... | @@ -297,8 +297,8 @@ let rec meta_to_var ids o (e : lexp) = |
| 297 | 297 |
let rec loop e = match e with
|
| 298 | 298 |
| Imm _ -> e
|
| 299 | 299 |
| SortLevel SLz -> e
|
| 300 |
- | SortLevel (SLsucc e) -> mkSortLevel (SLsucc (loop e))
|
|
| 301 |
- | SortLevel (SLlub (e1, e2)) -> mkSortLevel (SLlub (loop e1, loop e2))
|
|
| 300 |
+ | SortLevel (SLsucc e) -> mkSortLevel (mkSLsucc (loop e))
|
|
| 301 |
+ | SortLevel (SLlub (e1, e2)) -> mkSortLevel (mkSLlub' (loop e1, loop e2))
|
|
| 302 | 302 |
| Sort (l, Stype e) -> mkSort (l, Stype (loop e))
|
| 303 | 303 |
| Sort (_, (StypeOmega | StypeLevel)) -> e
|
| 304 | 304 |
| Builtin _ -> e
|
| ... | ... | @@ -1526,7 +1526,7 @@ let sform_type ctx loc sargs ot = |
| 1526 | 1526 |
match sargs with
|
| 1527 | 1527 |
| [l] -> let l, _ = infer l ctx in
|
| 1528 | 1528 |
(mkSort (loc, Stype l),
|
| 1529 |
- Inferred (mkSort (loc, Stype (SortLevel (SLsucc l)))))
|
|
| 1529 |
+ Inferred (mkSort (loc, Stype (SortLevel (mkSLsucc l)))))
|
|
| 1530 | 1530 |
| _ -> sexp_error loc "##Type_ expects one argument";
|
| 1531 | 1531 |
sform_dummy_ret ctx loc
|
| 1532 | 1532 |
|
| ... | ... | @@ -251,9 +251,10 @@ let rec compose_inv_subst (s' : subst) (s : subst) = match s' with |
| 251 | 251 |
and apply_inv_subst (e : lexp) (s : subst) : lexp = match e with
|
| 252 | 252 |
| Imm _ -> e
|
| 253 | 253 |
| SortLevel (SLz) -> e
|
| 254 |
- | SortLevel (SLsucc e) -> mkSortLevel (SLsucc (apply_inv_subst e s))
|
|
| 254 |
+ | SortLevel (SLsucc e) -> mkSortLevel (mkSLsucc (apply_inv_subst e s))
|
|
| 255 | 255 |
| SortLevel (SLlub (e1, e2))
|
| 256 |
- -> mkSortLevel (SLlub (apply_inv_subst e1 s, apply_inv_subst e2 s))
|
|
| 256 |
+ (* Should we use mkSLlub? *)
|
|
| 257 |
+ -> mkSortLevel (mkSLlub' (apply_inv_subst e1 s, apply_inv_subst e2 s))
|
|
| 257 | 258 |
| Sort (l, Stype e) -> mkSort (l, Stype (apply_inv_subst e s))
|
| 258 | 259 |
| Sort (l, (StypeOmega | StypeLevel)) -> e
|
| 259 | 260 |
| Builtin _ -> e
|
| ... | ... | @@ -205,6 +205,21 @@ let mkCall (f, es) |
| 205 | 205 |
| _, [] -> f
|
| 206 | 206 |
| _ -> hc (Call (f, es))
|
| 207 | 207 |
|
| 208 |
+let mkSLlub' (e1, e2) = match (e1, e2) with
|
|
| 209 |
+ | (SortLevel SLz, _) | (_, SortLevel SLz)
|
|
| 210 |
+ -> U.msg_fatal "internal" U.dummy_location "lub of SLz"
|
|
| 211 |
+ | (SortLevel (SLsucc _), SortLevel (SLsucc _))
|
|
| 212 |
+ -> U.msg_fatal "internal" U.dummy_location "lub of two SLsucc"
|
|
| 213 |
+ | ((SortLevel _ | Var _ | Metavar _ | Susp _),
|
|
| 214 |
+ (SortLevel _ | Var _ | Metavar _ | Susp _))
|
|
| 215 |
+ -> SLlub (e1, e2)
|
|
| 216 |
+ | _ -> U.msg_fatal "internal" U.dummy_location "SLlub of non-level"
|
|
| 217 |
+ |
|
| 218 |
+let mkSLsucc e = match e with
|
|
| 219 |
+ | SortLevel _ | Var _ | Metavar _ | Susp _
|
|
| 220 |
+ -> SLsucc e
|
|
| 221 |
+ | _ -> U.msg_fatal "internal" U.dummy_location "SLsucc of non-level"
|
|
| 222 |
+
|
|
| 208 | 223 |
(********* Helper functions to use the Subst operations *********)
|
| 209 | 224 |
(* This basically "ties the knot" between Subst and Lexp.
|
| 210 | 225 |
* Maybe it would be cleaner to just move subst.ml into lexp.ml
|
| ... | ... | @@ -260,6 +275,15 @@ and slookup s l v = S.lookup (fun l i -> mkVar (l, i)) |
| 260 | 275 |
s l v
|
| 261 | 276 |
let ssink = S.sink (fun l i -> mkVar (l, i))
|
| 262 | 277 |
|
| 278 |
+(* Shift by a negative amount! *)
|
|
| 279 |
+let rec sunshift n =
|
|
| 280 |
+ if n = 0 then S.identity
|
|
| 281 |
+ else (assert (n >= 0);
|
|
| 282 |
+ S.cons impossible (sunshift (n - 1)))
|
|
| 283 |
+ |
|
| 284 |
+let _ = assert (S.identity (* Sanity check! *)
|
|
| 285 |
+ = scompose (S.shift 5) (sunshift 5))
|
|
| 286 |
+ |
|
| 263 | 287 |
(* The quick test below seemed to indicate that about 50% of the "sink"s
|
| 264 | 288 |
* are applied on top of another "sink" and hence cound be combined into
|
| 265 | 289 |
* a single "Lift^n" constructor. Doesn't seem high enough to justify
|
| ... | ... | @@ -316,8 +340,9 @@ let rec push_susp e s = (* Push a suspension one level down. *) |
| 316 | 340 |
match e with
|
| 317 | 341 |
| Imm _ -> e
|
| 318 | 342 |
| SortLevel (SLz) -> e
|
| 319 |
- | SortLevel (SLsucc e') -> mkSortLevel (SLsucc (mkSusp e' s))
|
|
| 320 |
- | SortLevel (SLlub (e1, e2)) -> mkSortLevel (SLlub (mkSusp e1 s, mkSusp e2 s))
|
|
| 343 |
+ | SortLevel (SLsucc e') -> mkSortLevel (mkSLsucc (mkSusp e' s))
|
|
| 344 |
+ | SortLevel (SLlub (e1, e2))
|
|
| 345 |
+ -> mkSortLevel (mkSLlub' (mkSusp e1 s, mkSusp e2 s))
|
|
| 321 | 346 |
| Sort (l, Stype e) -> mkSort (l, Stype (mkSusp e s))
|
| 322 | 347 |
| Sort (l, _) -> e
|
| 323 | 348 |
| Builtin _ -> e
|
| ... | ... | @@ -381,8 +406,10 @@ let clean e = |
| 381 | 406 |
let rec clean s e = match e with
|
| 382 | 407 |
| Imm _ -> e
|
| 383 | 408 |
| SortLevel (SLz) -> e
|
| 384 |
- | SortLevel (SLsucc e) -> mkSortLevel (SLsucc (clean s e))
|
|
| 385 |
- | SortLevel (SLlub (e1, e2)) -> mkSortLevel (SLlub (clean s e1, clean s e2))
|
|
| 409 |
+ | SortLevel (SLsucc e) -> mkSortLevel (mkSLsucc (clean s e))
|
|
| 410 |
+ | SortLevel (SLlub (e1, e2))
|
|
| 411 |
+ (* FIXME: The new SLlub could have `succ` on both sides! *)
|
|
| 412 |
+ -> mkSortLevel (mkSLlub' (clean s e1, clean s e2))
|
|
| 386 | 413 |
| Sort (l, Stype e) -> mkSort (l, Stype (clean s e))
|
| 387 | 414 |
| Sort (l, _) -> e
|
| 388 | 415 |
| Builtin _ -> e
|
| ... | ... | @@ -332,7 +332,7 @@ let rec mkSLlub ctx e1 e2 = |
| 332 | 332 |
let ce2 = level_canon (L.clean e2') in
|
| 333 | 333 |
if level_leq ce1 ce2 then e1
|
| 334 | 334 |
else if level_leq ce2 ce1 then e2
|
| 335 |
- else mkSortLevel (SLlub (e1, e2))
|
|
| 335 |
+ else mkSortLevel (mkSLlub' (e1, e2)) (* FIXME: Could be more canonical *)
|
|
| 336 | 336 |
|
| 337 | 337 |
type sort_compose_result
|
| 338 | 338 |
= SortResult of ltype
|
| ... | ... | @@ -535,10 +535,9 @@ let rec check'' erased ctx e = |
| 535 | 535 |
-> level
|
| 536 | 536 |
| Sort (_, Stype level')
|
| 537 | 537 |
-> mkSLlub ctx level
|
| 538 |
- (* FIXME: We shouldn't use Inverse_subst
|
|
| 539 |
- * in the plain `check` code! *)
|
|
| 540 |
- (Inverse_subst.apply_inv_subst level'
|
|
| 541 |
- (S.shift n))
|
|
| 538 |
+ (* We need to unshift because the final type
|
|
| 539 |
+ * cannot refer to the fields! *)
|
|
| 540 |
+ (mkSusp level' (L.sunshift n))
|
|
| 542 | 541 |
| tt -> U.msg_error "TC" (lexp_location t)
|
| 543 | 542 |
("Field type "
|
| 544 | 543 |
^ lexp_string t
|
| ... | ... | @@ -789,7 +788,7 @@ let rec get_type ctx e = |
| 789 | 788 |
| Imm (Block (_, _, _) | Symbol _ | Node (_, _)) -> DB.type_int
|
| 790 | 789 |
| Builtin (_, t, _) -> t
|
| 791 | 790 |
| SortLevel _ -> DB.type_level
|
| 792 |
- | Sort (l, Stype e) -> mkSort (l, Stype (mkSortLevel (SLsucc e)))
|
|
| 791 |
+ | Sort (l, Stype e) -> mkSort (l, Stype (mkSortLevel (mkSLsucc e)))
|
|
| 793 | 792 |
| Sort (_, StypeLevel) -> DB.sort_omega
|
| 794 | 793 |
| Sort (_, StypeOmega) -> DB.sort_omega
|
| 795 | 794 |
| Var (((_, name), idx) as v) -> lookup_type ctx v
|
| ... | ... | @@ -835,9 +834,9 @@ let rec get_type ctx e = |
| 835 | 834 |
-> level
|
| 836 | 835 |
| Sort (_, Stype level')
|
| 837 | 836 |
-> mkSLlub ctx level
|
| 838 |
- (try Inverse_subst.apply_inv_subst level'
|
|
| 839 |
- (S.shift n)
|
|
| 840 |
- with _ -> level)
|
|
| 837 |
+ (* We need to unshift because the final type
|
|
| 838 |
+ * cannot refer to the fields! *)
|
|
| 839 |
+ (mkSusp level' (L.sunshift n))
|
|
| 841 | 840 |
| tt -> level),
|
| 842 | 841 |
DB.lctx_extend ictx v Variable t,
|
| 843 | 842 |
n + 1))
|
| ... | ... | @@ -159,7 +159,7 @@ let mkShift s (m:db_offset) = |
| 159 | 159 |
* context ΔₛΔₜ where Δₜ has size M. *)
|
| 160 | 160 |
let shift (m:db_offset) = Identity m
|
| 161 | 161 |
|
| 162 |
-(* Return a substitution which replaces #0 with `e` and the applies `s`
|
|
| 162 |
+(* Return a substitution which replaces #0 with `e` and then applies `s`
|
|
| 163 | 163 |
* to the rest. *)
|
| 164 | 164 |
let cons e s = Cons (e, s, 0)
|
| 165 | 165 |
|