feat(Control/Monad): Weakest preconditions and mcvgen for free monads #604
All Vouch review confidence checks passed
Residual risk 0.25 = Change Risk (0.43) × (1 − Review Confidence (0.41)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 186 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.313
Real PR Conversation Timeline
1 comments
"Review active on #604"
general
weight: 0.35
tannerduve
This PR adds
Cslib/Foundations/Control/Monad/Free/WP.lean, which givesFreeMprograms aStd.Do.WPinterpretation by lifting logical handlers into the predicate-transformer monadPredTrans.A logical handler
{ι : Type u} → F ι → PredTrans ps ιassigns each operation of the effect signatureFaPredTrans psspecification. SincePredTrans psis a monad andFreeMis free,FreeM.liftMextends such a handler to a monad morphismFreeM F → PredTrans ps; this is the weakest precondition and is compositional wrt the monadic structure.A
FreeM.WP F pstypeclass selects a default handler forFand inducesWP (FreeM F) psandWPMonad (FreeM F) psinstances, so thatStd.Do.Tripleandmvcgenapply toFreeM Fprograms. The main coherence lemma isFreeM.liftM_wp_eq_wp_liftM, andFreeM.wp_liftexposes the one-operation case.Handlers are provided for cslib's existing
FreeStateandFreeReader, along with@[spec]lemmasSpec.get_FreeState,Spec.set_FreeState, andSpec.read_FreeReaderthat letmvcgenstep through state and reader programs.CslibTests/FreeMonadWP.leancontains exampleTriples discharged bymvcgen, covering the supplied state and reader handlers, custom effects, combined effects, and demonic choice.The design follows Vistrup, Sammler, Jung, Program Logics à la Carte (POPL 2025), which uses coinductive free monads (ITrees) and Iris separation logic. Here we use inductive free monads and
Std.Doprogram logic.