feat(free): run vcgen over free programs on the canonical WP stack - #189
Draft
dtumad wants to merge 1 commit into
Draft
feat(free): run vcgen over free programs on the canonical WP stack#189dtumad wants to merge 1 commit into
dtumad wants to merge 1 commit into
Conversation
Put the free monad on core's lattice-generic weakest-precondition stack (Std.Internal.Do, the stack vcgen consumes) and retire the legacy Std.Do bridge. - PFunctor/Free/WP/Upstream.lean: OpSpec.toWPMonad (the syntactic fold as a core WPMonad), FreeM.wpMonadOfHandler (transport along liftMHom), and wpFold_le_wp_liftM (op-spec soundness against any core WPMonad). - PFunctor/Free/Do.lean rewritten: scoped DemonicWP / AngelicWP instances, soundness and conjunctivity instances, and the @[spec] rules Spec.lift, Spec.liftBind, Spec.lift_angelic, Spec.lift_ofHandler. - PFunctor/Free/Support.lean: allOutputs_lift / someOutput_lift. - Control/Do/Basic.lean deleted; PolyFun.lean regenerated. - Tests ported to vcgen (Do/FreeM, Do/Transport) plus a new Do/Loops canary: for loops with invariants, if-let, StateT over FreeM, and tail-position operations. - Docs: layer table and coverage row, gotcha 11e on vcgen's structural matcher versus dependent value types, landscape follow-up, quarantine and alignment wording. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Nb4g3Vxgjhnhsca7BzAsFc
dtumad
marked this pull request as draft
September 3, 2026 18:32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #188. Puts the free monad on core's lattice-generic weakest-precondition stack (
Std.Internal.Do, the stackvcgenconsumes) and retires the legacyStd.Dobridge, sodoprograms overFreeM Pwith uninterpreted operations are verified byvcgenend to end.PFunctor/Free/WP/Upstream.lean—OpSpec.toWPMonad(the syntactic foldwpFoldas a coreWPMonad, byrfl),FreeM.wpMonadOfHandler(transport of any coreWPMonadon the target alongliftMHom, withwp = wp (x.liftM s)byrfl), andwpFold_le_wp_liftM: an op-spec sound for a handler bounds the handler'swpof the interpretation, against any coreWPMonadon the target.PFunctor/Free/Do.leanrewritten — scopedDemonicWP(wp x Q = AllOutputs Q x, withLawfulWPMonadAttachandWPConjunctiveinstances) andAngelicWP(wp x Q = SomeOutput Q x) interpretations, and the@[spec]rulesSpec.lift(every response),Spec.liftBind,Spec.lift_angelic(some response),Spec.lift_ofHandler(the handler'swp).PFunctor/Free/Support.lean—allOutputs_lift/someOutput_lift(@[simp]).Control/Do/Basic.lean(theStd.Do/mvcgenbridge);PolyFun.leanregenerated. Nomvcgenuse remains.Canaries
PolyFunTest/Do/FreeM.lean(bind chains throughSpec.lift, soundness back toCanReturn/AllOutputs, the angelic reading),PolyFunTest/Do/Transport.lean(a handler-relative interpretation installed locally), and the newPolyFunTest/Do/Loops.lean:let mutoverforwithvcgen … invariants,if let,StateT Nat (FreeM coinP)with a state invariant through core's lifted instance, and tail-position operations.Found on the way (recorded as gotcha 11e and a landscape follow-up)
vcgenapplies@[spec]lemmas through core'sSymmatcher, which compares the program and its value type structurally (only instances go throughisDefEq).Spec.liftis stated at the dependent value typeP.B a, so it applies underbind(where the type comes from the operation) but not to an operation in tail position once the elaborated triple carries the normalized type (Boolon anabbrevinterface); registeringFreeM.lift a = FreeM.liftBind a pureas an equation spec does not help becauseSpec.purethen meets the same mismatch. The canary shows the fallback (vcgen -errorOnMissingSpec, thenrw [DemonicWP.wp_apply_eq, FreeM.allOutputs_lift (P := …)]) and the generic-interface form wherevcgencloses tail position directly. Worth raising upstream.Validation
./scripts/validate.sh --lint --test --axioms— lint passes forPolyFunandToCslib; 11031 declarations, zero sorry/axiom taint.🤖 Generated with Claude Code
https://claude.ai/code/session_01Nb4g3Vxgjhnhsca7BzAsFc