Skip to content

Commit b1ec3df

Browse files
committed
Hi-level error message when subst fails
1 parent cd3ed71 commit b1ec3df

5 files changed

Lines changed: 49 additions & 8 deletions

File tree

src/ecCorePrinting.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ module type PrinterAPI = sig
7373

7474
val pp_codepos : PPEnv.t -> EcMatching.Position.codepos pp
7575

76+
(* ------------------------------------------------------------------ *)
77+
type vsubst = [
78+
| `Local of EcIdent.t
79+
| `Glob of EcIdent.t * EcMemory.memory
80+
| `PVar of EcTypes.prog_var * EcMemory.memory
81+
]
82+
83+
val pp_vsubst : PPEnv.t -> vsubst pp
84+
7685
(* ------------------------------------------------------------------ *)
7786
val pp_typedecl : PPEnv.t -> (path * tydecl ) pp
7887
val pp_opdecl : ?long:bool -> PPEnv.t -> (path * operator ) pp

src/ecHiGoal.ml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,9 +1964,24 @@ let process_subst syms (tc : tcenv1) =
19641964
"this formula is not subject to substitution"
19651965
in
19661966

1967-
match List.map resolve syms with
1968-
| [] -> t_repeat t_subst tc
1969-
| syms -> FApi.t_seqs (List.map (fun var tc -> t_subst ~var tc) syms) tc
1967+
let exception NothingToSubstitute of vsubst in
1968+
1969+
try
1970+
match List.map resolve syms with
1971+
| [] -> t_repeat t_subst tc
1972+
| syms ->
1973+
FApi.t_seqs
1974+
(List.map
1975+
(fun var tc -> t_subst ~exn:(NothingToSubstitute var) ~var tc)
1976+
syms)
1977+
tc
1978+
1979+
with NothingToSubstitute v ->
1980+
tc_error_lazy !!tc (fun fmt ->
1981+
let ppe = EcPrinting.PPEnv.ofenv (FApi.tc1_env tc) in
1982+
Format.fprintf fmt "nothing to substitute for `%a'"
1983+
(EcPrinting.pp_vsubst ppe) v
1984+
)
19701985

19711986
(* -------------------------------------------------------------------- *)
19721987
type cut_t = intropattern * pformula * (ptactics located) option

src/ecLowGoal.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ let t_rw_for_subst y togen concl side eqid tc =
19371937
(* pre'; id: x = f |- (hpost => post => concl){x <- f} *)
19381938
t_intros_i ids] tc
19391939

1940-
let t_subst_x ?kind ?(except = Sid.empty) ?(clear = SCall) ?var ?tside ?eqid (tc : tcenv1) =
1940+
let t_subst_x ?(exn = InvalidGoalShape) ?kind ?(except = Sid.empty) ?(clear = SCall) ?var ?tside ?eqid (tc : tcenv1) =
19411941
let env, hyps, concl = FApi.tc1_eflat tc in
19421942

19431943
let subst_pre (subst, check, depend) moved (id, lk) =
@@ -2047,11 +2047,11 @@ let t_subst_x ?kind ?(except = Sid.empty) ?(clear = SCall) ?var ?tside ?eqid (tc
20472047
in
20482048

20492049
try List.find_map try1 eqs
2050-
with Not_found -> raise InvalidGoalShape
2050+
with Not_found -> raise exn
20512051

2052-
let t_subst ?kind ?except ?(clear = true) ?var ?tside ?eqid (tc : tcenv1) =
2052+
let t_subst ?exn ?kind ?except ?(clear = true) ?var ?tside ?eqid (tc : tcenv1) =
20532053
let clear = if clear then SCall else SChyp in
2054-
fst (t_subst_x ?kind ?except ~clear ?var ?tside ?eqid tc)
2054+
fst (t_subst_x ?exn ?kind ?except ~clear ?var ?tside ?eqid tc)
20552055

20562056
(* -------------------------------------------------------------------- *)
20572057
let t_absurd_hyp ?(conv = `AlphaEq) id tc =

src/ecLowGoal.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ val t_rewrite_hyp :
232232
type tside = [`All of [`LtoR | `RtoL] option | `LtoR | `RtoL]
233233

234234
val t_subst:
235-
?kind:subst_kind
235+
?exn:exn
236+
-> ?kind:subst_kind
236237
-> ?except:Sid.t
237238
-> ?clear:bool
238239
-> ?var:vsubst

src/ecPrinting.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,22 @@ let pp_memtype (ppe : PPEnv.t) (fmt : Format.formatter) (mt : memtype) =
820820
let lty = Mty.bindings mty in
821821
Format.fprintf fmt "@[{%a}@]" (pp_list ",@ " pp_bind) lty
822822

823+
(* -------------------------------------------------------------------- *)
824+
type vsubst = [
825+
| `Local of EcIdent.t
826+
| `Glob of EcIdent.t * EcMemory.memory
827+
| `PVar of EcTypes.prog_var * EcMemory.memory
828+
]
829+
830+
let pp_vsubst (ppe : PPEnv.t) (fmt : Format.formatter) (v : vsubst) =
831+
match v with
832+
| `Local x ->
833+
Format.fprintf fmt "%a" (pp_local ppe) x
834+
| `Glob (mp, m) ->
835+
Format.fprintf fmt "(glob %a){%a}" (pp_topmod ppe) (EcPath.mident mp) (pp_mem ppe) m
836+
| `PVar (pv, m) ->
837+
Format.fprintf fmt "%a{%a}" (pp_pv ppe) pv (pp_mem ppe) m
838+
823839
(* -------------------------------------------------------------------- *)
824840
let pp_opname (fmt : Format.formatter) ((nm, op) : symbol list * symbol) =
825841
let op =

0 commit comments

Comments
 (0)