Skip to content

Commit b4af504

Browse files
committed
feat: Remove elim constraint Type->s by default
1 parent 5668706 commit b4af504

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

kernel/qGraph.ml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module ElimTable = struct
2121

2222
let eliminates_to q q' =
2323
match q, q' with
24-
| QConstant QType, _ -> true
2524
| QConstant q, QConstant q' -> const_eliminates_to q q'
2625
| QVar q, QVar q' -> QVar.equal q q'
2726
| (QConstant _ | QVar _), _ -> false
@@ -234,16 +233,11 @@ exception AlreadyDeclared = G.AlreadyDeclared
234233

235234
let add_quality q g =
236235
let graph = G.add q g.graph in
237-
let g = enforce_constraint (Quality.qtype, ElimConstraint.ElimTo, q) { g with graph } in
238-
let (paths,ground_and_global_sorts) =
236+
let ground_and_global_sorts =
239237
if Quality.is_qglobal q
240-
then (RigidPaths.add_elim_to Quality.qtype q g.rigid_paths, Quality.Set.add q g.ground_and_global_sorts)
241-
else (g.rigid_paths,g.ground_and_global_sorts) in
242-
(* As Type ~> s, set Type to be the dominant sort of q if q is a variable. *)
243-
let dominant = match q with
244-
| Quality.QVar qv -> QMap.add qv Quality.qtype g.dominant
245-
| Quality.QConstant _ -> g.dominant in
246-
{ g with rigid_paths = paths; ground_and_global_sorts; dominant }
238+
then Quality.Set.add q g.ground_and_global_sorts
239+
else g.ground_and_global_sorts in
240+
{ g with graph; ground_and_global_sorts }
247241

248242
let enforce_eliminates_to s1 s2 g =
249243
enforce_constraint (s1, ElimConstraint.ElimTo, s2) g

test-suite/success/sort_poly.v

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ Module Inductives.
109109
Inductive foo2@{s; |} := Foo2 : Type@{s;Set} -> foo2.
110110
Check foo2_rect.
111111

112-
Inductive foo3@{s; |} (A:Type@{s;Set}) := Foo3 : A -> foo3 A.
112+
(* This is now invalid since Type does not eliminate to arbitrary sorts by default *)
113+
Fail Inductive foo3@{s; |} (A:Type@{s;Set}) := Foo3 : A -> foo3 A.
114+
Inductive foo3@{s; |Type->s} (A:Type@{s;Set}) := Foo3 : A -> foo3 A.
113115
Check foo3_rect.
114116

115117
Fail Inductive foo4@{s;u v|v < u} : Type@{v} := C (_:Type@{s;u}).
@@ -212,17 +214,25 @@ Module Inductives.
212214
Definition R5f1_sprop (A:SProp) (r:R5 A) : A := let (f) := r in f.
213215
Fail Definition R5f1_prop (A:Prop) (r:R5 A) : A := let (f) := r in f.
214216

215-
Record R6@{s; |} (A:Type@{s;Set}) := { R6f1 : A; R6f2 : nat }.
217+
(* This is now invalid since Type does not eliminate to arbitrary sorts by default *)
218+
Fail Record R6@{s; |} (A:Type@{s;Set}) := { R6f1 : A; R6f2 : nat }.
219+
Record R6@{s; |Type->s} (A:Type@{s;Set}) := { R6f1 : A; R6f2 : nat }.
216220
Check fun (A:SProp) (x y : R6 A) =>
217221
eq_refl : Conversion.box _ x.(R6f1 _) = Conversion.box _ y.(R6f1 _).
218222
Fail Check fun (A:Prop) (x y : R6 A) =>
219223
eq_refl : Conversion.box _ x.(R6f1 _) = Conversion.box _ y.(R6f1 _).
220224
Fail Check fun (A:SProp) (x y : R6 A) =>
221225
eq_refl : Conversion.box _ x.(R6f2 _) = Conversion.box _ y.(R6f2 _).
222226

223-
#[projections(primitive=no)] Record R7@{s; |} (A:Type@{s;Set}) := { R7f1 : A; R7f2 : nat }.
227+
(* This is now invalid since Type does not eliminate to arbitrary sorts by default *)
228+
Fail #[projections(primitive=no)] Record R7@{s; |} (A:Type@{s;Set}) := { R7f1 : A; R7f2 : nat }.
229+
#[projections(primitive=no)] Record R7@{s; |Type -> s} (A:Type@{s;Set}) := { R7f1 : A; R7f2 : nat }.
224230
Check R7@{SProp;} : SProp -> Set.
225231
Check R7@{Type;} : Set -> Set.
232+
#[universes(polymorphic=no)]
233+
Sort s7.
234+
Fail Check R7@{s7;} : 𝒰@{s7;0} -> Set.
235+
(* This expression would enforce a non-declared elimination constraint between Type and s7 *)
226236

227237
Inductive sigma@{s;u v|} (A:Type@{s;u}) (B:A -> Type@{s;v}) : Type@{s;max(u,v)}
228238
:= pair : forall x : A, B x -> sigma A B.
@@ -284,7 +294,10 @@ Module Inductives.
284294

285295
Arguments exist3 {_ _}.
286296

287-
Definition π1@{s s';u v|} {A:Type@{s;u}} {P:A -> Type@{s';v}} (p : sigma3@{_ _ Type;_ _} A P) : A :=
297+
(* This is now invalid since Type does not eliminate to arbitrary sorts by default *)
298+
Fail Definition π1@{s s';u v|} {A:Type@{s;u}} {P:A -> Type@{s';v}} (p : sigma3@{_ _ Type;_ _} A P) : A :=
288299
match p return A with exist3 a _ => a end.
289-
300+
Definition π1@{s s';u v|Type -> s} {A:Type@{s;u}} {P:A -> Type@{s';v}} (p : sigma3@{_ _ Type;_ _} A P) : A :=
301+
match p return A with exist3 a _ => a end.
302+
(* s s' ; u v |= Type -> s *)
290303
End Inductives.

test-suite/success/sort_poly_extraction.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Definition foo1 := foo@{Type SProp|}.
3131

3232
Inductive T@{s| |} : Type@{s|Set} := O : T | S : T -> T.
3333

34-
Inductive box@{s1 s2| |} (A : Type@{s1|Set}) (B : Type@{s2|Set}) : Type@{Set} := Box : A -> B -> box A B.
34+
Inductive box@{s1 s2; |Type->s1, Type->s2} (A : Type@{s1;Set}) (B : Type@{s2;Set}) : Type@{Set} := Box : A -> B -> box A B.
3535

3636
Definition bar (A : Type) (x : A) := 0.
3737

@@ -44,11 +44,11 @@ Extraction TestCompile Foo.
4444
(* Check module subtyping *)
4545

4646
Module Type S.
47-
Inductive box@{s1 s2| |} (A : Type@{s1|Set}) (B : Type@{s2|Set}) : Type@{Set} := Box : A -> B -> box A B.
47+
Inductive box@{s1 s2; |Type->s1, Type->s2} (A : Type@{s1;Set}) (B : Type@{s2;Set}) : Type@{Set} := Box : A -> B -> box A B.
4848
End S.
4949

5050
Module Bar : S.
51-
Inductive box@{s1 s2| |} (A : Type@{s1|Set}) (B : Type@{s2|Set}) : Type@{Set} := Box : A -> B -> box A B.
51+
Inductive box@{s1 s2; |Type->s1, Type->s2} (A : Type@{s1;Set}) (B : Type@{s2;Set}) : Type@{Set} := Box : A -> B -> box A B.
5252
End Bar.
5353

5454
Extraction TestCompile Bar.

0 commit comments

Comments
 (0)