Skip to content

Refactor ecPhlConseq.ml: restructure, deduplicate, document, and annotate#965

Open
strub wants to merge 1 commit intomainfrom
conseq-refactor
Open

Refactor ecPhlConseq.ml: restructure, deduplicate, document, and annotate#965
strub wants to merge 1 commit intomainfrom
conseq-refactor

Conversation

@strub
Copy link
Copy Markdown
Member

@strub strub commented Apr 3, 2026

  • 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

@strub strub requested a review from Gustavo2622 April 7, 2026 10:07
@strub strub self-assigned this Apr 7, 2026
@strub strub added chore Ungrateful tasks that need done but that nobody wants to do technical-debt labels Apr 7, 2026
@strub strub force-pushed the conseq-refactor branch from 765593d to b555fdc Compare April 7, 2026 14:57
…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
@strub strub force-pushed the conseq-refactor branch from b555fdc to 03238b5 Compare April 7, 2026 15:02
@strub strub changed the title Refactor ecPhlConseq.ml: break up monolithic dispatcher and document Refactor ecPhlConseq.ml: restructure, deduplicate, document, and annotate Apr 7, 2026
@strub strub marked this pull request as ready for review April 7, 2026 15:04
* ——————————————————————————————————————————————————————————
* ehoare[f] P ==> Q
*
* Note: for ehoare, the direction is reversed (xreal_le) compared
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, *)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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']
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear notation

let t_bdHoareF_notmod post tc =
(* bdHoareF notmod rule:
*
* ∀m, P m ⇒ ∀res modified_vars, Q' m ⇒/⇔ Q m
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extraneous \bot ?

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 =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 *)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also no transitivity for S?

(* *)
(* Supported combinations (goal / f1 / f2 / f3): *)
(* equivS / equivS / ⊥ / ⊥ — simple consequence *)
(* equivS / equivS / hoareS / hoareS — conjunction (L+R+rel) *)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rel + L + R?

(* *)
(* Supported combinations (goal / f1 / f2 / f3): *)
(* equivF / equivF / ⊥ / ⊥ — simple consequence *)
(* equivF / equivF / hoareF / hoareF — conjunction (L+R+rel) *)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, rel + L + R?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Ungrateful tasks that need done but that nobody wants to do technical-debt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants