Skip to content

Commit 85151a7

Browse files
committed
feat: Remove elim constraint Type->s by default
1 parent 9ed12ce commit 85151a7

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
@@ -237,16 +236,11 @@ exception AlreadyDeclared = G.AlreadyDeclared
237236

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

251245
let enforce_eliminates_to src s1 s2 g =
252246
enforce_constraint src (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}).
@@ -210,17 +212,25 @@ Module Inductives.
210212
Definition R5f1_sprop (A:SProp) (r:R5 A) : A := let (f) := r in f.
211213
Fail Definition R5f1_prop (A:Prop) (r:R5 A) : A := let (f) := r in f.
212214

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

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

225235
Inductive sigma@{s;u v|} (A:Type@{s;u}) (B:A -> Type@{s;v}) : Type@{s;max(u,v)}
226236
:= pair : forall x : A, B x -> sigma A B.
@@ -283,7 +293,10 @@ Module Inductives.
283293

284294
Arguments exist3 {_ _}.
285295

286-
Definition π1@{s s';u v|} {A:Type@{s;u}} {P:A -> Type@{s';v}} (p : sigma3@{_ _ Type;_ _} A P) : A :=
296+
(* This is now invalid since Type does not eliminate to arbitrary sorts by default *)
297+
Fail Definition π1@{s s';u v|} {A:Type@{s;u}} {P:A -> Type@{s';v}} (p : sigma3@{_ _ Type;_ _} A P) : A :=
287298
match p return A with exist3 a _ => a end.
288-
299+
Definition π1@{s s';u v|Type -> s} {A:Type@{s;u}} {P:A -> Type@{s';v}} (p : sigma3@{_ _ Type;_ _} A P) : A :=
300+
match p return A with exist3 a _ => a end.
301+
(* s s' ; u v |= Type -> s *)
289302
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)