Skip to content

Commit 75b6197

Browse files
authored
Merge pull request #570 from LPCIC/fix-tc-options
avoid declaring options twice
2 parents e4960ad + 08a6554 commit 75b6197

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

apps/tc/theories/tc.v

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ Elpi Accumulate File solver.
4242
Elpi Query lp:{{
4343
sigma Options\
4444
all-options Options,
45-
std.forall Options (x\ sigma L\ x L,
46-
coq.option.add L (coq.option.bool ff) ff).
45+
std.forall Options (x\ sigma L\ x L,
46+
if (coq.option.available? L _)
47+
true
48+
(coq.option.add L (coq.option.bool ff) ff)).
4749
}}.
4850
Elpi Typecheck.
4951

src/coq_elpi_arg_HOAS.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,8 @@ let in_elpi_cmd ~depth ?calldepth coq_ctx state ~raw (x : Cmd.top) =
960960
let open Vernacentries.Preprocessed_Mind_decl in
961961
let { flags = { template; poly; cumulative; udecl; finite }; primitive_proj; kind; records } = raw_rdecl in
962962
let template = handle_template_polymorphism template in
963+
(* Definitional type classes cannot be interpreted using this function (why?) *)
964+
let kind = if kind = Vernacexpr.Class true then Vernacexpr.Class false else kind in
963965
let e = Record.interp_structure ~template udecl kind ~cumulative ~poly ~primitive_proj finite records in
964966
record_entry2lp ~depth coq_ctx E.no_constraints state ~loose_udecl:(udecl = None) e
965967
| IndtDecl (_ist,(glob_sign,raw_indt)) when raw ->

src/coq_elpi_glob_quotation.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,22 @@ let is_restricted_name =
5959
fun s -> Str.(string_match rex (Id.to_string s) 0)
6060

6161

62-
let glob_environment : Environ.env S.component =
62+
let glob_environment : Environ.env option S.component =
6363
S.declare_component ~name:"coq-elpi:glob-environment" ~descriptor:interp_state
64-
~pp:(fun _ _ -> ()) ~init:(fun () -> Global.env ())
65-
~start:(fun _ -> Global.env ()) ()
64+
~pp:(fun _ _ -> ()) ~init:(fun () -> None)
65+
~start:(fun _ -> Some (Global.env ())) ()
66+
67+
(* Since Accumulate runs before the interpreter starts, the state
68+
may be empty: ~start not called, ~init called too early *)
69+
let ensure_some f = function None -> Some (f (Global.env ())) | Some x -> Some (f x)
6670

6771
let push_env state name =
6872
let open Context.Rel.Declaration in
69-
S.update glob_environment state (Environ.push_rel (LocalAssum(Context.make_annot name Sorts.Relevant,Constr.mkProp)))
73+
S.update glob_environment state (ensure_some (Environ.push_rel (LocalAssum(Context.make_annot name Sorts.Relevant,Constr.mkProp))))
7074
let pop_env state =
71-
S.update glob_environment state (Environ.pop_rel_context 1)
75+
S.update glob_environment state (ensure_some (Environ.pop_rel_context 1))
7276

73-
let get_glob_env state = S.get glob_environment state
77+
let get_glob_env state = Option.get @@ ensure_some (fun x -> x) @@ S.get glob_environment state
7478

7579
(* XXX: I don't get why we use a coq_ctx here *)
7680
let under_ctx name ty bo gterm2lp ~depth state x =
@@ -396,7 +400,7 @@ let coq_quotation ~depth state loc src =
396400
Constrintern.intern_constr (get_glob_env state) (get_sigma state) ce
397401
with e ->
398402
CErrors.user_err
399-
Pp.(str(API.Ast.Loc.show loc) ++str":" ++ spc() ++ CErrors.print_no_report e)
403+
Pp.(str(API.Ast.Loc.show loc) ++ spc() ++ CErrors.print_no_report e)
400404
in
401405
gterm2lp ~depth state glob
402406

tests/test_arg_HOAS.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ End full_definition.
245245

246246
(*****************************************)
247247

248+
Module classes.
249+
Elpi declarations Class foo := bar : True.
250+
End classes.
251+
252+
(*****************************************)
253+
248254
Module copy.
249255
Import inductive_nup.
250256

tests/test_quotation.v

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,14 @@ Fail Elpi Query lp:{{ std.do! [
8383
std.assert-ok! (coq.typecheck T _) "does not typecheck",
8484
]
8585
}}.
86+
87+
Section A.
88+
Variable A : Type.
89+
Check 1.
90+
Elpi Accumulate lp:{{
91+
92+
pred p i:term.
93+
p {{ A }}.
94+
95+
}}.
96+
End A.

0 commit comments

Comments
 (0)