Skip to content

Commit 49e9dd4

Browse files
committed
New implementation of test_axioms
1 parent 14bbdf9 commit 49e9dd4

File tree

5 files changed

+50
-56
lines changed

5 files changed

+50
-56
lines changed

src/coq_cw.ml

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,47 @@ let passed msg = Feedback.msg_notice (str ("\n<PASSED::> " ^ msg ^ "\n"))
66

77
let failed msg = Feedback.msg_notice (str ("\n<FAILED::> " ^ msg ^ "\n"))
88

9-
(* unused *)
10-
(* let extract_axioms s =
11-
let fold t typ accu =
12-
match t with
13-
| Printer.Variable _ -> failwith "Variable"
14-
| Printer.Opaque _ -> failwith "Opaque"
15-
| Printer.Transparent _ -> failwith "Transparent"
16-
| Printer.Axiom _ -> typ :: accu
17-
in
18-
Printer.ContextObjectMap.fold fold s [] *)
9+
(* Based on the PrintAssumptions code from vernac/vernacentries.ml *)
10+
let assumptions r =
11+
try
12+
let gr = Smartlocate.locate_global_with_alias r in
13+
let cstr = Globnames.printable_constr_of_global gr in
14+
let st = Conv_oracle.get_transp_state (Environ.oracle (Global.env())) in
15+
Assumptions.assumptions st gr cstr
16+
with Not_found -> CErrors.user_err (str "Not found: " ++ Libnames.pr_qualid r)
1917

20-
(* TODO: compare axiom names (constants) also *)
21-
let test_assumptions msg env sigma s ax_tys =
22-
let unify ty1 ty2 =
23-
match Reductionops.infer_conv env sigma ty1 ty2 with
24-
| Some _ -> true
25-
| None -> false
26-
in
18+
let locate_constant r =
19+
try
20+
let gr = Smartlocate.locate_global_with_alias r in
21+
match gr with
22+
| Globnames.ConstRef cst -> cst
23+
| _ -> CErrors.user_err (str "A constant is expected: " ++ Printer.pr_global gr)
24+
with Not_found -> CErrors.user_err (str "Not found: " ++ Libnames.pr_qualid r)
25+
26+
let pr_axiom env sigma ax ty =
27+
match ax with
28+
| Printer.Constant kn ->
29+
Printer.pr_constant env kn ++ str " : " ++ Printer.pr_ltype_env env sigma ty
30+
| _ -> str "? : " ++ Printer.pr_ltype_env env sigma ty
31+
32+
let test_axioms ?(msg = "Axiom Test") c_ref ax_refs =
33+
let env = Global.env() in
34+
let sigma = Evd.from_env env in
35+
let ax_csts = List.map locate_constant ax_refs in
36+
let ax_objs = List.map (fun c -> Printer.Axiom (Printer.Constant c, [])) ax_csts in
37+
let ax_set = Printer.ContextObjectSet.of_list ax_objs in
38+
let assums = assumptions c_ref in
2739
let iter t ty =
2840
match t with
29-
| Printer.Axiom _ ->
30-
let ety = EConstr.of_constr ty in
31-
if List.exists (unify ety) ax_tys then ()
41+
| Printer.Axiom (ax, _) ->
42+
if Printer.ContextObjectSet.mem t ax_set then ()
3243
else begin
3344
failed msg;
34-
CErrors.user_err (str "Axiom: " ++ Printer.pr_econstr_env env sigma ety)
45+
CErrors.user_err (str "Prohibited Axiom: " ++ pr_axiom env sigma ax ty)
3546
end
3647
| _ -> ()
3748
in
38-
Printer.ContextObjectMap.iter iter s
39-
40-
(* Based on the PrintAssumptions code from vernac/vernacentries.ml *)
41-
let locate r =
42-
try
43-
let gr = Smartlocate.locate_global_with_alias r in
44-
(gr, Globnames.printable_constr_of_global gr)
45-
with Not_found -> CErrors.user_err (str "Not found: " ++ Libnames.pr_qualid r)
46-
47-
let test ?(msg = "Axioms") c_ref ax_refs =
48-
let env = Global.env() in
49-
let sigma = Evd.from_env env in
50-
let (gr, cstr) = locate c_ref in
51-
let st = Conv_oracle.get_transp_state (Environ.oracle (Global.env())) in
52-
let assumptions = Assumptions.assumptions st gr cstr in
53-
let ax_grs_cstrs = List.map locate ax_refs in
54-
let sigma, ax_tys =
55-
List.fold_left
56-
(fun (sigma, tys) (_, c) ->
57-
let sigma, ty = Typing.type_of env sigma (EConstr.of_constr c) in
58-
sigma, ty :: tys) (sigma, []) ax_grs_cstrs in
59-
test_assumptions msg env sigma assumptions ax_tys;
49+
let () = Printer.ContextObjectMap.iter iter assums in
6050
passed msg
6151

6252
(** Tests that the file size is less than a given number *)
@@ -72,7 +62,7 @@ let test_file_size ?(fname = solution_file) size =
7262
end
7363
with Unix.Unix_error _ -> CErrors.user_err (str ("Bad file name: " ^ fname))
7464

75-
(** Tests that the file's content matches a given regular expression*)
65+
(** Tests that the file's content matches a given regular expression *)
7666
let test_file_regex ?(fname = solution_file) match_flag regex =
7767
let re = Str.regexp regex in
7868
let ic = open_in fname in
@@ -87,5 +77,3 @@ let test_file_regex ?(fname = solution_file) match_flag regex =
8777
failed "Bad match";
8878
CErrors.user_err (str "Bad match")
8979
end
90-
91-

src/coq_cw.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
val test : ?msg:string -> Libnames.qualid -> Libnames.qualid list -> unit
1+
val test_axioms : ?msg:string -> Libnames.qualid -> Libnames.qualid list -> unit
22

33
val test_file_size : ?fname:string -> int -> unit
44

src/g_coq_cw.ml4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open Stdarg
55

66
VERNAC COMMAND EXTEND CWTest CLASSIFIED AS QUERY
77
| [ "CWTest" string_opt(msg) ref(e) "Assumes" ref_list(axioms)] -> [
8-
Coq_cw.test ?msg e axioms
8+
Coq_cw.test_axioms ?msg e axioms
99
]
1010
END
1111

theories/Demo.v

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,30 @@ Qed.
1010
Lemma lemma2 : True = False.
1111
Admitted.
1212

13-
From Coq Require Import Classical.
13+
From Coq Require Classical.
14+
15+
Module Test.
16+
17+
Import Classical.
1418

1519
Lemma lemma3 : (2 = 3) \/ ~(2 = 3).
1620
Proof.
1721
apply classic.
1822
Qed.
1923

24+
End Test.
25+
2026
CWGroup "Assumption Tests".
2127

2228
Fail CWTest lemma1 Assumes.
2329
CWTest lemma1 Assumes my_ax.
24-
Fail CWTest lemma1 Assumes classic.
25-
CWTest "lemma1" lemma1 Assumes lemma2.
26-
CWTest lemma1 Assumes classic my_ax.
27-
CWTest "lemma2" lemma2 Assumes my_ax.
30+
Fail CWTest lemma1 Assumes Classical_Prop.classic.
31+
Fail CWTest "lemma1" lemma1 Assumes lemma2.
32+
CWTest lemma1 Assumes Classical_Prop.classic my_ax.
33+
Fail CWTest "lemma2" lemma2 Assumes my_ax.
2834

29-
CWTest lemma3 Assumes classic my_ax.
30-
Fail CWTest lemma3 Assumes my_ax.
35+
CWTest Test.lemma3 Assumes Classical_Prop.classic my_ax.
36+
Fail CWTest Test.lemma3 Assumes my_ax.
3137

3238
CWEndGroup.
3339

theories/Demo2.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ From Coq Require Import Reals.
4343
Print Assumptions sqrt_pos.
4444

4545
Fail CWTest sqrt_pos Assumes.
46-
CWTest sqrt_pos Assumes R R1 R1_neq_R0 Rinv total_order_T
46+
CWTest sqrt_pos Assumes R R0 R1 R1_neq_R0 Rinv total_order_T
4747
completeness archimed Rplus_opp_r Rplus_lt_compat_l
4848
Rplus_comm Rplus_assoc Rplus_0_l Rplus Ropp
4949
Rmult_plus_distr_l Rmult_lt_compat_l Rmult_comm

0 commit comments

Comments
 (0)