Skip to content

Commit 4cac323

Browse files
authored
Merge pull request #484 from math-comp/fix-435
HB.instance: failure building a class is not fatal
2 parents 7539623 + 90ee6f7 commit 4cac323

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

HB/instance.elpi

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,19 @@ infer-class T Class Struct MLwP S Name STy Clauses:- std.do![
169169
private.optimize-class-body THD {std.length Params} KCApp KCAppNames Clauses,
170170
coq.mk-app (global KS) {std.append Params [T, KCAppNames]} S,
171171
if-verbose (coq.say {header} "structure instance for" Name "is" {coq.term->string S}),
172-
std.assert-ok! (coq.typecheck S STy) "infer-class: S illtyped",
172+
173+
coq.typecheck S STy ok, % failure may be due to a parameter not rich enough see #435
174+
173175
].
174176

175177
pred decl-const-in-struct i:string, i:term, i:term, i:constant.
176178
decl-const-in-struct Name S STy CS:- std.do![
177179

178-
log.coq.env.add-const-noimplicits Name S STy @transparent! CS, % Bug coq/coq#11155, could be a Let
180+
if (ground_term S) (S1 = S, STy1 = STy)
181+
(abstract-holes.main S S1,
182+
std.assert-ok! (coq.typecheck S1 STy1) "HB: structure instance illtyped after generalizing over holes"),
183+
184+
log.coq.env.add-const-noimplicits Name S1 STy1 @transparent! CS, % Bug coq/coq#11155, could be a Let
179185
with-locality (log.coq.CS.declare-instance CS), % Bug coq/coq#11155, should be local
180186
acc-clause current (local-canonical CS),
181187
if-verbose (coq.say {header} "structure instance" Name "declared"),

_CoqProject.test-suite

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ tests/unit/struct.v
9696
tests/factory_when_notation.v
9797

9898
tests/saturate_on.v
99+
tests/bug_435.v
100+
tests/bug_447.v
99101

100102
-R tests HB.tests
101103
-R examples HB.examples

tests/bug_435.v

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
From HB Require Import structures.
2+
3+
HB.mixin Record M T := { m : bool }.
4+
HB.structure Definition S := {T of M T}.
5+
6+
HB.mixin Record A1 X T := { a1 : bool }.
7+
HB.structure Definition B1 X := {T of A1 X T}.
8+
9+
HB.instance Definition _ (X : Type) := A1.Build X unit true.
10+
11+
HB.mixin Record A2 (X : Type) T := { a2 : bool }.
12+
HB.structure Definition B2 (X : Type) := {T of A2 X T}.
13+
14+
(* This should work but fails. *)
15+
Module should_work_but_fails.
16+
HB.structure Definition B (X : S.type) := {T of A1 X T & A2 X T}.
17+
#[verbose] HB.instance Definition _ (X : Type) := A2.Build X unit true.
18+
HB.saturate unit.
19+
Check unit : B.type _.
20+
End should_work_but_fails.
21+
22+
Module workaround.
23+
HB.instance Definition _ (X : Type) := A2.Build X unit true.
24+
HB.structure Definition B (X : S.type) := {T of A1 X T & A2 X T}.
25+
HB.saturate unit.
26+
Check unit : B.type _.
27+
End workaround.

tests/bug_447.v

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
From HB Require Import structures.
2+
3+
Variant testTy := A | B.
4+
HB.mixin Record Stack1 T := { prop1 : unit }.
5+
HB.structure Definition JustStack1 := { T of Stack1 T }.
6+
HB.mixin Record Stack1Param R T := { prop2 : unit }.
7+
HB.structure Definition JustStack1Param R := { T of Stack1Param R T }.
8+
9+
HB.mixin Record Stack2 T := { prop3 : unit }.
10+
HB.structure Definition JustStack2 := { T of Stack2 T }.
11+
HB.mixin Record Mixed T of Stack1 T & Stack2 T := { prop4 : unit }.
12+
HB.structure Definition JustMixed := { T of Mixed T & Stack1 T & Stack2 T}.
13+
HB.structure Definition JustMixedParam R :=
14+
{ T of Mixed T & Stack1 T & Stack1Param R T & Stack2 T}.
15+
16+
HB.instance Definition _ := @Stack1.Build testTy tt.
17+
HB.instance Definition _ := @Stack2.Build testTy tt.
18+
19+
HB.instance Definition _ {R} := @Stack1Param.Build R testTy tt.
20+
HB.instance Definition _ := @Mixed.Build testTy tt.
21+
22+
Check testTy : JustMixedParam.type _.

0 commit comments

Comments
 (0)