Refactor ecPhlConseq.ml: restructure, deduplicate, document, and annotate#965
Refactor ecPhlConseq.ml: restructure, deduplicate, document, and annotate#965
Conversation
…tate
- Split the ~500-line monolithic t_hi_conseq dispatcher into 8
per-goal-type functions (hoareS/F, bdHoareS/F, ehoareS/F, equivS/F)
with a thin top-level dispatcher
- Extract shared helpers (t_hi_trivial, t_hi_apply_r, etc.) to module
level
- Unify three identical gen_conseq_nm variants into a single polymorphic
one
- Factor shared proof-term processing pipeline into process_conseq_core;
rename process_conseq_1/2 to process_conseq_hs/ss for clarity
- Extract cond_F_notmod_core / cond_S_notmod_core shared helpers,
reducing cond_{hoare,bdHoare}{F,S}_notmod to 3-line wrappers
- Remove unnecessary ~recurse indirection from equivS/equivF dispatchers
(make them directly recursive instead)
- Introduce hi_arg type alias and add type annotations to all top-level
functions
- Add inference-rule comments to every goal-closing tactic and document
the processing pipeline, naming conventions, and section structure
| * —————————————————————————————————————————————————————————— | ||
| * ehoare[f] P ==> Q | ||
| * | ||
| * Note: for ehoare, the direction is reversed (xreal_le) compared |
There was a problem hiding this comment.
Somewhat confusing comment, I would suggest "xreal_le (<=) is the ehoare analogue of implication (=>)"
| let t_bdHoareF_conseq pre post tc = | ||
| (* bdHoareF consequence rule: | ||
| * | ||
| * ∀m, P m ⇒ P' m ∀m, Q' m ⇒/⇔ Q m phoare[f] P' ==> Q' cmp bd |
There was a problem hiding this comment.
Minor: missing one of the directions for postcondition implication
| (* t_*_conseq_nm: combines notmod with consequence *) | ||
| (* -------------------------------------------------------------------- *) | ||
|
|
||
| let mk_bind_pvar (m : memory) (id,_) (x, ty) = |
There was a problem hiding this comment.
Maybe move utility functions to other file?
| let mk_bind_globs (env : env) (m : memory) (bd1,bd2) = | ||
| List.map2 (mk_bind_glob env m) bd1 bd2 | ||
|
|
||
| let cond_equivF_notmod ?(mk_other=false) (tc : tcenv1) (cond : ts_inv) = |
There was a problem hiding this comment.
Add small description of notmod condition
| let t_equivF_notmod post tc = | ||
| (* equivF notmod rule: | ||
| * | ||
| * ∀ml mr, P ml mr ⇒ ∀res_L res_R modified_vars, Q' ml mr ⇒ Q ml mr |
There was a problem hiding this comment.
Slightly unclear term separation, quantifier bindings and what modified_vars is here
| let f = hf.hf_f in | ||
| let mpr,mpo = Fun.hoareF_memenv hf.hf_m f env in | ||
| (* Shared core for F-level notmod: substitutes the result variable, *) | ||
| (* generalizes over modified variables, quantifies over the result, *) |
There was a problem hiding this comment.
Maybe be a bit clearer on what the result of this function is? (return type + what holds over the return objects)
| (* hoareF notmod rule: | ||
| * | ||
| * ∀m, P m ⇒ ∀res modified_vars, Q' m ⇒ Q m [∧ Qe] | ||
| * hoare[f] P ==> Q'[/Qe'] |
| let t_bdHoareF_notmod post tc = | ||
| (* bdHoareF notmod rule: | ||
| * | ||
| * ∀m, P m ⇒ ∀res modified_vars, Q' m ⇒/⇔ Q m |
There was a problem hiding this comment.
Same as above, slightly unclear
|
|
||
| (* -------------------------------------------------------------------- *) | ||
| let t_ehoareF_conseq_nm pre post tc = | ||
| let t_ehoareF_conseq_nm (pre : ss_inv) (post : ss_inv) (tc : tcenv1) = |
There was a problem hiding this comment.
Suggestion: maybe move above concavity to group not mod rules? Results in a bigger diff but better organization
| * hoare[c] P ==> post phoare[c] P ==> post' ∧ post cmp bd | ||
| * ————————————————————————————————————————————————————————————— | ||
| * phoare[c] P ==> post' cmp bd | ||
| * |
There was a problem hiding this comment.
Difference between add=false and add=true unclear
|
|
||
| let t_ehoareF_conseq_equiv f2 p q p2 q2 tc = | ||
| (* ehoareF via equivalence: similar to hoareF but with xreal ordering. | ||
| * cond1: ∀m1, ∃m2, P1 m1 = ⊥ ∨ (P m1 m2 ∧ P2 m2 ≤ P1 m1) |
| let t_apply_r (pt, _f) tc = | ||
| match pt with | ||
| | Some pt -> EcLowGoal.Apply.t_apply_bwd_hi ~dpe:true pt tc | ||
| let t_hi_trivial = |
There was a problem hiding this comment.
Move helper + print functions? From here to L1333
| (* ehoareF via equivalence: similar to hoareF but with xreal ordering. | ||
| * cond1: ∀m1, ∃m2, P1 m1 = ⊥ ∨ (P m1 m2 ∧ P2 m2 ≤ P1 m1) | ||
| * cond2: ∀m1 m2, Q m1 m2 ⇒ Q1 m1 ≤ Q2 m2 *) | ||
| let t_ehoareF_conseq_equiv |
There was a problem hiding this comment.
Missing ehoareS version?
| (* Supported combinations (goal / f1 / f2 / f3): *) | ||
| (* bdhoareF / bdhoareF / ⊥ / ⊥ — consequence with bound change *) | ||
| (* bdhoareF / bdhoareF / hoareF / ⊥ — conjunction with hoare side-cond *) | ||
| (* bdhoareF / equivF / bdhoareF/ _ — transitivity via equiv *) |
There was a problem hiding this comment.
Also no transitivity for S?
| (* *) | ||
| (* Supported combinations (goal / f1 / f2 / f3): *) | ||
| (* equivS / equivS / ⊥ / ⊥ — simple consequence *) | ||
| (* equivS / equivS / hoareS / hoareS — conjunction (L+R+rel) *) |
| (* *) | ||
| (* Supported combinations (goal / f1 / f2 / f3): *) | ||
| (* equivF / equivF / ⊥ / ⊥ — simple consequence *) | ||
| (* equivF / equivF / hoareF / hoareF — conjunction (L+R+rel) *) |
There was a problem hiding this comment.
Same as above, rel + L + R?
per-goal-type functions (hoareS/F, bdHoareS/F, ehoareS/F, equivS/F)
with a thin top-level dispatcher
level
one
rename process_conseq_1/2 to process_conseq_hs/ss for clarity
reducing cond_{hoare,bdHoare}{F,S}_notmod to 3-line wrappers
(make them directly recursive instead)
functions
the processing pipeline, naming conventions, and section structure