Skip to content

RFC: ir: splice recorded post-proof state to fix mid-proof segment init#231

Open
ike-mulder-aws wants to merge 1 commit into
awslabs:mainfrom
ike-mulder-aws:fix-in-proof-segment-init
Open

RFC: ir: splice recorded post-proof state to fix mid-proof segment init#231
ike-mulder-aws wants to merge 1 commit into
awslabs:mainfrom
ike-mulder-aws:fix-in-proof-segment-init

Conversation

@ike-mulder-aws
Copy link
Copy Markdown
Contributor

Issue #, if available: #230

Description of changes:

When a theory is built with record_theories=true AND parallel proofs enabled, Toplevel.element_result forks each lemma body via Proof.future_proof, which rewrites the goal's after_qed to a stub that does NOT call Local_Theory.notes_kind. Every segment recorded inside that future captures the stubbed Proof.state, so initing a REPL at a mid-proof segment and stepping through qed fails to register the theorem (#230).

The fix introduces a per-REPL "segment_proof_splicer": at init we stash the recorded state of the next segment that exits the proof. When the user's stepping crosses the proof-exit boundary via a non-oops finisher, we splice that recorded state in for the post-state. oops disarms the splicer without firing, preserving "abandon proof, no theorem" semantics. The splicer is correctly re-armed across truncate, edit, and replay. Locale/context/experiment state is preserved through both splice (qed) and disarm (oops) paths.

Detection of oops is keyword-based via Keyword.is_qed_global, which is brittle: keyword classification is decoupled from semantic effects, and custom declared keywords might break this (see the comment on splice_step in ir.ML for details). Stock Pure/HOL ships only oops as qed_global, so these limitations are deemed acceptable.

Tests cover the original regression (segment_init_mid_proof_qed), oops behavior (segment_init_mid_proof_oops, _deep_oops), nested sub-proofs, splicer re-arming on truncate and on replay-via-edit, and locale preservation through both finishers.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment thread ir/ir.ML Outdated
When a theory is built with record_theories=true AND parallel proofs
enabled, Toplevel.element_result forks each lemma body via
Proof.future_proof, which rewrites the goal's after_qed to a stub that
does NOT call Local_Theory.notes_kind. Every segment recorded inside
that future captures the stubbed Proof.state, so initing a REPL at a
mid-proof segment and stepping through qed fails to register the
theorem (AutoCorrode#230).

The fix introduces a per-REPL "segment_proof_splicer": at init we stash
the recorded state of the next segment that exits the proof. When the
user's stepping crosses the proof-exit boundary via a non-oops finisher,
we splice that recorded state in for the post-state. oops disarms the
splicer without firing, preserving "abandon proof, no theorem"
semantics. The splicer is correctly re-armed across truncate, edit, and
replay. Locale/context/experiment state is preserved through both
splice (qed) and disarm (oops) paths.

Detection of oops is keyword-based via Keyword.is_qed_global, which is
brittle: keyword classification is decoupled from semantic effects, and
custom declared keywords might break this (see the comment on
splice_step in ir.ML for details). Stock Pure/HOL ships only `oops` as
qed_global, so these limitations are deemed acceptable.

Tests cover the original regression (segment_init_mid_proof_qed), oops
behavior (segment_init_mid_proof_oops, _deep_oops), nested sub-proofs,
splicer re-arming on truncate and on replay-via-edit, and locale
preservation through both finishers.

Signed-off-by: Ike Mulder <ikemul@amazon.com>
@ike-mulder-aws ike-mulder-aws force-pushed the fix-in-proof-segment-init branch from 473bfb7 to e0047f2 Compare May 18, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant