Add Constr.map_with_full_binders to Ltac2#22062
Open
JasonGross wants to merge 2 commits into
Open
Conversation
ae36c10 to
c84f772
Compare
Add a new Unsafe.in_context primitive that extends the proof context with either a LocalAssum (when body_opt is None) or LocalDef (when body_opt is Some) and returns a (binder, body) pair. Three Ltac2 wrappers use this primitive: - in_context: wraps the result in Lambda (same behavior as the old external) - in_context_prod: wraps the result in Prod - in_context_letin: wraps the result in LetIn The old constr_in_context external is kept for backward compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ers to Ltac2 Unsafe.map_with_full_binders maps a function on the immediate subterms of a constr, using Unsafe.in_context to traverse under binders so that the mapped function operates on well-typed terms in proper contexts. The safe Constr.map_with_full_binders wrapper checks the result with Unsafe.check and raises on failure. Since Unsafe.in_context returns (binder, body) directly, there is no need for strip_lambda/strip_prod/strip_letin helpers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c84f772 to
75011a8
Compare
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
Constr.map_with_full_bindersto Ltac2, which maps a functionfon the immediate subterms of a constr, usingin_context/in_context_letinto traverse under binders so thatfoperates on well-typed terms in proper contextsin_contextcalls) before processing each bodyfNamed to match the OCaml-side
map_constr_with_full_binders(intermops.ml), which similarly provides the full binder context rather than just a de Bruijn shift likeConstr.map_with_binders.Stacked on #22060 (
Constr.in_context_prodandConstr.in_context_letin).Signature
Behavior
For each constructor kind:
fto the binder type, usesin_contextto open the binder, appliesfto the body, then rebuildsfto type and value, usesin_context_letinto open the binder, appliesfto the body, then rebuildsfto each binder type, then for each body opens all mutual binders via nestedin_contextcalls, appliesf, strips the lambda wrappers, and rebuildsfto each sub-constrThis is analogous to the existing
Constr.Unsafe.mapbut usesin_contextto ensurefsees well-typed terms with proper binder scoping, rather than operating on raw de Bruijn terms.Test plan
test-suite/ltac2/map_with_full_binders.vwith tests for identity mapping and transformations through Lambda, Prod, LetIn, App, and Fix🤖 Generated with Claude Code