fix(ir): preserve capture-free closure identity - #779
Open
nnunley wants to merge 1 commit into
Open
Conversation
nnunley
force-pushed
the
fix/ir-closure-identity
branch
from
August 24, 2026 19:50
ba4c7e5 to
3ecd2c7
Compare
nooga
approved these changes
Sep 1, 2026
nooga
left a comment
Owner
There was a problem hiding this comment.
LGTM. Identity across rebinding, multi-reference reuse via DUP_NTH, and the distinct-literal negative case are all covered by TestIRBytecodePreservesCaptureFreeClosureIdentity; read lower.lg's diff independently and found nothing. Only the manifest conflicts. Merging after a rebase.
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.
Why
Under
*ir-compile*, a capture-freefn*literal is a:constnode carrying a:fn-templateaux. The lowering treated it like any other cheap replayable constant: multiple local references re-rantemplate-valueat each use site, manufacturing a distinct*vm.Funcper reference.Observable damage: closure identity breaks.
(let* [f (fn* [x] ...) g f] (identical? f g))is false under IR compilation and true under the direct compiler;=on the rebound closure fails the same way.What changed
pkg/rt/core/ir/lower.lg:fn-template-const?recognizes:fn-template/:multi-fn-templateconst nodes.DUP_NTHof that one value.Distinct textual
fn*literals still produce distinct closures ((identical? (fn* [x] x) (fn* [x] x))stays false).pkg/rt/generated.manifest/generated.sumsare refreshed becauselower.lgis a declared generator input.Verification
New
TestIRBytecodePreservesCaptureFreeClosureIdentityinpkg/ir/lisp_closure_template_test.gopins rebinding identity, multi-reference identity, and the distinct-sites negative case under*ir-compile*.make generatetwice is deterministic,make check-generatedpasses, andgo test ./...including the e2e suite passes on this head.Complementary to #767: that fixes capturing closures at disagreeing joins in
lower_go.lg; this fixes capture-free closure identity in bytecodelower.lg. No file overlap.