Skip to content

Commit 9480919

Browse files
committed
split proof.ml in two + move Pure.goal to Goal.info
1 parent 46dfce7 commit 9480919

File tree

11 files changed

+29
-202
lines changed

11 files changed

+29
-202
lines changed

src/handle/command.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open Common open Error open Pos
66
open Core open Term open Sign open Sig_state open Print
77
open Parsing open Syntax open Scope
88
open Proof
9+
open Goal
910

1011
(** Type alias for a function that compiles a Lambdapi module. *)
1112
type compiler = Path.t -> Sign.t
@@ -582,7 +583,7 @@ let get_proof_data : compiler -> sig_state -> p_command -> cmd_output =
582583
in
583584
(* Create the proof state. *)
584585
let pdata_state =
585-
let proof_goals = Proof.add_goals_of_problem p [] in
586+
let proof_goals = add_goals_of_problem p [] in
586587
if p_sym_def then
587588
(* Add a new focused goal and refine on it. *)
588589
let m = LibMeta.fresh p a 0 in

src/handle/proof.ml

Lines changed: 5 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,10 @@
1-
(** Proofs and tactics. *)
1+
(** Proof state. *)
22

3-
open Lplib open Base open Extra
3+
open Lplib open Base
44
open Timed
5-
open Core open Term open Print
5+
open Core open Term
66
open Common open Pos
7-
8-
(** Type of goals. *)
9-
type goal_typ =
10-
{ goal_meta : meta (** Goal metavariable. *)
11-
; goal_hyps : Env.t (** Precomputed scoping environment. *)
12-
; goal_type : term (** Precomputed type. *) }
13-
14-
type goal =
15-
| Typ of goal_typ (** Typing goal. *)
16-
| Unif of constr (** Unification goal. *)
17-
18-
let is_typ : goal -> bool = function Typ _ -> true | Unif _ -> false
19-
let is_unif : goal -> bool = function Typ _ -> false | Unif _ -> true
20-
21-
let get_constr : goal -> constr =
22-
function Unif c -> c | Typ _ -> invalid_arg (__FILE__ ^ "get_constr")
23-
24-
let get_names : goal -> int StrMap.t = function
25-
| Unif(c,_,_) -> Ctxt.names c
26-
| Typ gt -> Env.names gt.goal_hyps
27-
28-
module Goal = struct
29-
30-
type t = goal
31-
32-
(** [ctxt g] returns the typing context of the goal [g]. *)
33-
let ctxt : goal -> ctxt = fun g ->
34-
match g with
35-
| Typ gt -> Env.to_ctxt gt.goal_hyps
36-
| Unif (c,_,_) -> c
37-
38-
(** [env g] returns the scoping environment of the goal [g]. *)
39-
let env : goal -> Env.t = fun g ->
40-
match g with
41-
| Unif (c,_,_) ->
42-
let t, n = Ctxt.to_prod c mk_Type in
43-
(try fst (Env.of_prod_nth c n t)
44-
with Invalid_argument _ -> assert false)
45-
| Typ gt -> gt.goal_hyps
46-
47-
(** [of_meta m] creates a goal from the meta [m]. *)
48-
let of_meta : meta -> goal = fun m ->
49-
let goal_hyps, goal_type =
50-
try Env.of_prod_nth [] m.meta_arity !(m.meta_type)
51-
with Invalid_argument _ -> assert false
52-
in
53-
Typ {goal_meta = m; goal_hyps; goal_type }
54-
55-
(** [simpl_opt f g] tries to simplify the goal [g] with the function [f]. *)
56-
let simpl_opt : (ctxt -> term -> term option) -> goal -> goal option =
57-
fun f g ->
58-
match g with
59-
| Typ gt ->
60-
begin
61-
match f (Env.to_ctxt gt.goal_hyps) gt.goal_type with
62-
| None -> None
63-
| Some goal_type -> Some(Typ {gt with goal_type})
64-
end
65-
| Unif (c,t,u) ->
66-
begin
67-
match f c t, f c u with
68-
| Some t, Some u -> Some(Unif(c,t,u))
69-
| _ -> None
70-
end
71-
72-
(** [simpl f g] simplifies the goal [g] with the function [f]. *)
73-
let simpl : (ctxt -> term -> term) -> goal -> goal = fun f g ->
74-
match g with
75-
| Typ gt ->
76-
Typ {gt with goal_type = f (Env.to_ctxt gt.goal_hyps) gt.goal_type}
77-
| Unif (c,t,u) -> Unif (c, f c t, f c u)
78-
79-
(** [hyps ppf g] prints on [ppf] the beta-normal forms of the hypotheses of
80-
the goal [g]. *)
81-
let hyps : int StrMap.t -> goal pp =
82-
let hyps elt ppf l =
83-
if l <> [] then
84-
out ppf "%a---------------------------------------------\
85-
---------------------------------\n"
86-
(List.pp (fun ppf -> out ppf "%a\n" elt) "") (List.rev l)
87-
in
88-
fun idmap ppf g ->
89-
let term = term_in idmap in
90-
match g with
91-
| Typ gt ->
92-
let elt ppf (s,(_,ty,def)) =
93-
match def with
94-
| None -> out ppf "%a: %a" uid s term (Eval.snf_beta ty)
95-
| Some u -> out ppf "%a ≔ %a" uid s term u
96-
in
97-
hyps elt ppf gt.goal_hyps
98-
| Unif (c,_,_) ->
99-
let elt ppf (x,a,t) =
100-
out ppf "%a: %a" var x term a;
101-
match t with
102-
| None -> ()
103-
| Some t -> out ppf " ≔ %a" term t
104-
in
105-
hyps elt ppf c
106-
107-
(** [concl ppf g] prints on [ppf] the beta-normal form of the conclusion of
108-
the goal [g]. *)
109-
let concl : int StrMap.t -> goal pp = fun idmap ppf g ->
110-
let term = term_in idmap in
111-
match g with
112-
| Typ gt ->
113-
out ppf "?%d: %a" gt.goal_meta.meta_key
114-
term (Eval.snf_beta gt.goal_type)
115-
| Unif (_, t, u) -> out ppf "%a ≡ %a" term t term u
116-
117-
(** [pp ppf g] prints on [ppf] the beta-normal form of the goal [g] with its
118-
hypotheses. *)
119-
let pp ppf g =
120-
let idmap = get_names g in hyps idmap ppf g; concl idmap ppf g
121-
122-
(** [pp_no_hyp ppf g] prints on [ppf] the beta-normal form of the conclusion
123-
of the goal [g] without its hypotheses. *)
124-
let pp_no_hyp ppf g = concl (get_names g) ppf g
125-
126-
end
127-
128-
(** [add_goals_of_problem p gs] extends the list of goals [gs] with the
129-
metavariables and constraints of [p]. *)
130-
let add_goals_of_problem : problem -> goal list -> goal list = fun p gs ->
131-
let gs = MetaSet.fold (fun m gs -> Goal.of_meta m :: gs) !p.metas gs in
132-
let f gs c = Unif c :: gs in
133-
let gs = List.fold_left f gs !p.to_solve in
134-
List.fold_left f gs !p.unsolved
7+
open Goal
1358

1369
(** Representation of the proof state of a theorem. *)
13710
type proof_state =
@@ -149,7 +22,7 @@ let goals : proof_state pp = fun ppf ps ->
14922
match ps.proof_goals with
15023
| [] -> out ppf "No goal."
15124
| g::gs ->
152-
let idmap = get_names g in
25+
let idmap = Goal.get_names g in
15326
out ppf "%a0. %a" (Goal.hyps idmap) g (Goal.concl idmap) g;
15427
let goal ppf i g = out ppf "\n%d. %a" (i+1) Goal.pp_no_hyp g in
15528
List.iteri (goal ppf) gs

src/handle/rewrite.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
open Lplib
44
open Common open Pos open Error open Debug
55
open Core open Term open Print
6-
open Proof
6+
open Goal
77

88
(** Logging function for the rewrite tactic. *)
99
let log = Logger.make 'r' "rewr" "the rewrite tactic"

src/handle/tactic.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open Parsing open Syntax
66
open Core open Term open Print
77
open Proof
88
open Timed
9+
open Goal
910

1011
(** Logging function for tactics. *)
1112
let log = Logger.make 't' "tact" "tactics"
@@ -132,7 +133,7 @@ let tac_refine : ?check:bool ->
132133
log (Color.gre "%a ≔ %a") meta gt.goal_meta term t;
133134
LibMeta.set p gt.goal_meta (bind_mvar (Env.vars gt.goal_hyps) t);
134135
(* Convert the metas and constraints of [p] not in [gs] into new goals. *)
135-
tac_solve pos {ps with proof_goals = Proof.add_goals_of_problem p gs}
136+
tac_solve pos {ps with proof_goals = add_goals_of_problem p gs}
136137

137138
(** [ind_data t] returns the [ind_data] structure of [s] if [t] is of the
138139
form [s t1 .. tn] with [s] an inductive type. Fails otherwise. *)
@@ -560,7 +561,7 @@ let rec handle :
560561
LibMeta.set p gt.goal_meta (bind_mvar (Env.vars env) u);
561562
(*let g = Goal.of_meta m in*)
562563
let g = Typ {goal_meta=m; goal_hyps=e'; goal_type=v} in
563-
{ps with proof_goals = g :: Proof.add_goals_of_problem p gs}
564+
{ps with proof_goals = g :: add_goals_of_problem p gs}
564565
end else fatal pos "The unification constraints for %a \
565566
to be typable are not satisfiable." term t
566567
end
@@ -705,7 +706,7 @@ let handle :
705706
| [] -> fatal pos "No remaining goals."
706707
| g::_ ->
707708
if Logger.log_enabled() then
708-
log ("Goal %a%a") Proof.Goal.pp_no_hyp g Pretty.tactic tac;
709+
log ("Goal %a%a") Goal.pp_no_hyp g Pretty.tactic tac;
709710
handle ss sym_pos prv ps tac, None
710711

711712
(** [handle sym_pos prv r tac n] applies the tactic [tac] from the previous

src/handle/why3_tactic.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open Timed
55
open Common open Error
66
open Core open Term open Print
77
open Fol
8-
open Proof
8+
open Goal
99

1010
(** Logging function for external prover calling with Why3. *)
1111
let log = Logger.make 'y' "why3" "why3 provers"

src/handle/why3_tactic.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ val timeout : int ref
1515
(** [handle ss pos ps prover_name gt] runs the Why3 prover corresponding to
1616
[prover_name] (if given or a default one otherwise) on the goal type [gt],
1717
and fails if no proof is found. *)
18-
val handle: Sig_state.t -> Pos.popt -> string option -> Proof.goal_typ -> unit
18+
val handle: Sig_state.t -> Pos.popt -> string option -> Goal.goal_typ -> unit

src/lsp/lp_doc.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
open Common
1414
open Lplib
15+
open Handle
1516

1617
module LSP = Lsp_base
1718

@@ -24,7 +25,7 @@ type doc_node =
2425
{ ast : Pure.Command.t
2526
; exec : bool
2627
(*; tactics : Proof.Tactic.t list*)
27-
; goals : (Pure.goal list * Pos.popt) list
28+
; goals : (Goal.info list * Pos.popt) list
2829
}
2930

3031
(* Private. A doc is a list of nodes for now. The first element in

src/lsp/lsp_base.ml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,19 @@ let mk_range (p : Pos.pos) : J.t =
3838
`Assoc ["start", `Assoc ["line", `Int (line1 - 1); "character", `Int col1];
3939
"end", `Assoc ["line", `Int (line2 - 1); "character", `Int col2]]
4040

41-
let json_of_goal (hyps, concl) =
41+
let json_of_goal (hyps, typ_goal, lhs, rhs) =
4242
let json_of_hyp (s,t) = `Assoc ["hname", `String s; "htype", `String t] in
43-
match concl with
44-
| Pure.Typ (meta, typ) ->
43+
if typ_goal then
4544
`Assoc [
4645
"typeofgoal", `String "Typ"
47-
; "gid", `String meta
46+
; "gid", `String lhs
4847
; "hyps", `List (List.map json_of_hyp hyps)
49-
; "type", `String typ]
50-
| Pure.Unif (t,u) ->
48+
; "type", `String rhs]
49+
else
5150
`Assoc [
5251
"typeofgoal", `String "Unif"
5352
; "hyps", `List (List.map json_of_hyp hyps)
54-
; "constr", `String (t ^ "" ^ u)]
53+
; "constr", `String (lhs ^ "" ^ rhs)]
5554

5655
let json_of_goals ?logs goals =
5756
let logs = match logs with None -> "" | Some s -> s in

src/lsp/lsp_base.mli

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
(************************************************************************)
1212

1313
open Common
14+
open Handle
1415

1516
module J = Yojson.Basic
1617

@@ -23,7 +24,7 @@ val mk_reply : id:int -> result:J.t -> J.t
2324
val mk_diagnostics
2425
: uri:string
2526
-> version: int
26-
-> (Pos.pos * int * string * Pure.goal list option) list
27+
-> (Pos.pos * int * string * Goal.info list option) list
2728
-> J.t
2829

29-
val json_of_goals : ?logs:string -> Pure.goal list option -> J.t
30+
val json_of_goals : ?logs:string -> Goal.info list option -> J.t

src/pure/pure.ml

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -81,54 +81,11 @@ type proof_finalizer = Sig_state.t -> Proof.proof_state -> Sig_state.t
8181
type proof_state =
8282
Time.t * Sig_state.t * Proof.proof_state * proof_finalizer * bool * Pos.popt
8383

84-
type conclusion =
85-
| Typ of string * string
86-
| Unif of string * string
87-
88-
type goal = (string * string) list * conclusion
89-
90-
let string_of_goal : Proof.goal -> goal =
91-
let buf = Buffer.create 80 in
92-
let fmt = Format.formatter_of_buffer buf in
93-
let to_string f x =
94-
f fmt x;
95-
Format.pp_print_flush fmt ();
96-
let res = Buffer.contents buf in
97-
Buffer.clear buf;
98-
res
99-
in
100-
fun g ->
101-
let open Print in
102-
let ids = Proof.get_names g in
103-
let term = term_in ids in
104-
let env_elt (s,(_,ty,def)) =
105-
let ty = to_string term (Eval.snf_beta ty) in
106-
s,
107-
match def with
108-
| None -> ty
109-
| Some d -> ""^to_string term d
110-
in
111-
let ctx_elt (x,ty,def) =
112-
let ty = to_string term (Eval.snf_beta ty) in
113-
to_string var x,
114-
match def with
115-
| None -> ty
116-
| Some d -> ""^to_string term d
117-
in
118-
match g with
119-
| Proof.Typ gt ->
120-
let meta = "?"^to_string int gt.goal_meta.meta_key in
121-
let typ = to_string term (Eval.snf_beta gt.goal_type) in
122-
List.rev_map env_elt gt.goal_hyps, Typ (meta, typ)
123-
| Proof.Unif (c,t,u) ->
124-
let t = to_string term t and u = to_string term u in
125-
List.rev_map ctx_elt c, Unif (t,u)
126-
127-
let current_goals : proof_state -> goal list =
84+
let current_goals : proof_state -> Goal.info list =
12885
fun (time, st, ps, _, _, _) ->
12986
Time.restore time;
13087
Print.sig_state := st;
131-
List.map string_of_goal ps.proof_goals
88+
List.map Goal.to_info ps.proof_goals
13289

13390
type command_result =
13491
| Cmd_OK of state * string option

0 commit comments

Comments
 (0)