Dedup: share the alpha-renaming binder __eq__ body (refs #813) - #1155
Open
jsiek wants to merge 1 commit into
Open
Dedup: share the alpha-renaming binder __eq__ body (refs #813)#1155jsiek wants to merge 1 commit into
jsiek wants to merge 1 commit into
Conversation
FunctionType, Lambda, All, Some, and TLet each had the same __eq__
shape -- guard the operand type, then delegate to a per-node
alpha-equivalence walk with empty rename environments. Extract that
shared body into abstract_syntax/ops.binder_eq so the five methods
become one-liners and the 'bypass the _alpha_equiv fast path to avoid
== recursion' rationale lives in one place.
Behavior is unchanged: binder_eq(self, other, Cls, alpha) is exactly
'isinstance(other, Cls) and alpha(self, other, {}, {})'.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Deduplicate the alpha-renaming binder
__eq__methods.FunctionType,Lambda,All,Some, andTLet(all inabstract_syntax/terms.py) eachcarried the same three-line body:
The only things that vary are the operand class and the per-node
alpha-equivalence helper. This PR extracts the shared body into
abstract_syntax/ops.binder_eq(self, other, cls, alpha)so the five methodsbecome one-liners, and the subtle "these deliberately bypass the
_alpha_equivempty-env fast path, which calls==and would recurse backhere" rationale is documented in exactly one place instead of being implicit
in five.
Why this is safe
binder_eq(self, other, Cls, alpha)is exactlyisinstance(other, Cls) and alpha(self, other, {}, {}), which short-circuitsto
Falseon a type mismatch just like the original guard. No semanticchange.
Verification
Local (this container has no ruff/mypy/pytest; those run in CI):
python3 test-deduce.py --passable— passpython3 test-deduce.py --lib— passpython3 test-deduce.py --equiv— pass (grammar + should-error corpus +round-trip; canonical-AST comparison exercises these
__eq__methods)python3 test-deduce.py --errors --warns— passall x. x=x == all y. y=y(True),vs
all y. y=zero(False), analogous cases forsome/fun/term-let, andAll != Lambda/All != 5(False) all behave as before.Scope / coordination
Touches only
abstract_syntax/terms.pyandabstract_syntax/ops.py, disjointfrom the other in-flight #813 slices (#1153 error.py, #1151 declarations.py,
#1147 proofs.py, #1148 uniquify binder, #1149 checker view-law).
Refs #813 (this is one slice of the standing dedup umbrella, which stays open).
Resume this session on ginger:
~/deduce-runner/resume.sh 2a46bc68-a6b2-4e22-82b2-a48cd10d0ef8 routine/20260728-080201🤖 Generated with Claude Code