Skip to content

Commit 7e6bf73

Browse files
oskgostrub
authored andcommitted
add clear to clear all unused items in the context recursively
add exclude filters and test
1 parent b91e29c commit 7e6bf73

File tree

5 files changed

+51
-12
lines changed

5 files changed

+51
-12
lines changed

src/ecHiGoal.ml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,23 @@ let process_coq ~loc ~name (ttenv : ttenv) coqmode pi (tc : tcenv1) =
163163
t_seq (t_simplify ~delta:`No) (t_coq ~loc ~name ~mode:(`Report (Some loc)) coqmode pi) tc
164164

165165
(* -------------------------------------------------------------------- *)
166-
let process_clear symbols tc =
166+
let process_clear (info : clear_info) tc =
167167
let hyps = FApi.tc1_hyps tc in
168-
169168
let toid s =
170169
if not (LDecl.has_name (unloc s) hyps) then
171170
tc_lookup_error !!tc ~loc:s.pl_loc `Local ([], unloc s);
172171
fst (LDecl.by_name (unloc s) hyps)
173172
in
174-
175-
try t_clears (List.map toid symbols) tc
176-
with (ClearError _) as err -> tc_error_exn !!tc err
173+
match info with
174+
| `Include symbols -> begin
175+
try t_clears (List.map toid symbols) tc
176+
with (ClearError _) as err -> tc_error_exn !!tc err
177+
end
178+
| `Exclude symbols ->
179+
let excluded = List.map toid symbols in
180+
let hyp_ids = List.map fst (LDecl.tohyps hyps).h_local in
181+
let clear_list = List.filter (fun x -> not (List.mem x excluded)) hyp_ids in
182+
t_clears ~leniant:true clear_list tc
177183

178184
(* -------------------------------------------------------------------- *)
179185
let process_algebra mode kind eqs (tc : tcenv1) =
@@ -1413,7 +1419,7 @@ let rec process_mintros_1 ?(cf = true) ttenv pis gs =
14131419
t_simplify_lg ~delta:`IfApplied (ttenv, logic) tc
14141420

14151421
and intro1_clear (_ : ST.state) xs tc =
1416-
process_clear xs tc
1422+
process_clear (`Include xs) tc
14171423

14181424
and intro1_case (st : ST.state) nointro pis gs =
14191425
let onsub gs =
@@ -1826,7 +1832,7 @@ let rec process_mgenintros ?cf ttenv pis tc =
18261832
| `Gen gn ->
18271833
t_onall (
18281834
t_seqs [
1829-
process_clear gn.pr_clear;
1835+
process_clear (`Include gn.pr_clear);
18301836
process_generalize gn.pr_genp
18311837
]) tc
18321838
in process_mgenintros ~cf:false ttenv pis tc
@@ -1838,7 +1844,7 @@ let process_genintros ?cf ttenv pis tc =
18381844
(* -------------------------------------------------------------------- *)
18391845
let process_move ?doeq views pr (tc : tcenv1) =
18401846
t_seqs
1841-
[process_clear pr.pr_clear;
1847+
[process_clear (`Include pr.pr_clear);
18421848
process_generalize ?doeq pr.pr_genp;
18431849
process_view views]
18441850
tc
@@ -2078,7 +2084,7 @@ let process_case ?(doeq = false) gp tc =
20782084
| _ -> ()
20792085
end;
20802086
t_seqs
2081-
[process_clear gp.pr_rev.pr_clear; t_case f;
2087+
[process_clear (`Include gp.pr_rev.pr_clear); t_case f;
20822088
t_simplify_with_info EcReduction.betaiota_red]
20832089
tc
20842090

src/ecHiGoal.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ val process_mgenintros : ?cf:bool -> ttenv -> introgenpattern list -> tactical
7171
val process_genintros : ?cf:bool -> ttenv -> introgenpattern list -> backward
7272
val process_generalize : ?doeq:bool -> genpattern list -> backward
7373
val process_move : ?doeq:bool -> ppterm list -> prevert -> backward
74-
val process_clear : psymbol list -> backward
74+
val process_clear : clear_info -> backward
7575
val process_smt : ?loc:EcLocation.t -> ttenv -> pprover_infos option -> backward
7676
val process_coq : loc:EcLocation.t -> name:string -> ttenv -> EcProvers.coq_mode option -> pprover_infos -> backward
7777
val process_apply : implicits:bool -> apply_t * prevert option -> backward

src/ecParser.mly

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2682,8 +2682,14 @@ logtactic:
26822682
| MOVE vw=prefix(SLASH, pterm)* gp=prefix(COLON, revert)?
26832683
{ Pmove { pr_rev = odfl prevert0 gp; pr_view = vw; } }
26842684

2685+
| CLEAR
2686+
{ Pclear (`Exclude []) }
2687+
2688+
| CLEAR MINUS l=loc(ipcore_name)+
2689+
{ Pclear (`Exclude l) }
2690+
26852691
| CLEAR l=loc(ipcore_name)+
2686-
{ Pclear l }
2692+
{ Pclear (`Include l) }
26872693

26882694
| CONGR
26892695
{ Pcongr }

src/ecParsetree.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,12 @@ type apply_info = [
957957
| `ExactType of pqsymbol
958958
]
959959

960+
(* -------------------------------------------------------------------- *)
961+
type clear_info = [
962+
| `Exclude of psymbol list
963+
| `Include of psymbol list
964+
]
965+
960966
(* -------------------------------------------------------------------- *)
961967
type pgenhave = psymbol * intropattern option * psymbol list * pformula
962968

@@ -979,7 +985,7 @@ type logtactic =
979985
| Pcut of pcut
980986
| Pcutdef of (intropattern * pcutdef)
981987
| Pmove of prevertv
982-
| Pclear of psymbol list
988+
| Pclear of clear_info
983989
| Prewrite of (rwarg list * osymbol_r)
984990
| Prwnormal of pformula * pqsymbol list
985991
| Psubst of pformula list

tests/clear.ec

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
lemma L: true.
2+
pose x:=false.
3+
clear x.
4+
(* `x` is now unbound *)
5+
pose x:=false.
6+
pose y:=x.
7+
pose z:=y.
8+
clear -y.
9+
(* `z` is unbound, but `x` is not, since `y` depends on it *)
10+
pose z:=x.
11+
clear y.
12+
pose y:=z.
13+
clear.
14+
(* everything is unbound, since nothing is in the goal *)
15+
pose x:=true.
16+
pose y:=false.
17+
clear.
18+
(* we cannot clear `x` since it is in the goal,
19+
but `y` is not used so it becomes unbound *)
20+
pose y:= x.
21+
abort.

0 commit comments

Comments
 (0)