fix(compiler): make named-fn self-reference the fn value#58
Merged
Conversation
identical?/= between a named fn and its self-reference returned false where JVM and ClojureCLR return true. Two causes: reader source meta wrapped every fn in withMeta so the fn value was a MetaWrapper while the self-reference resolved to the wrapped instance, and under direct-linking the static body emitted the self-name as a fresh newobj. fn* parsing now strips line/column/file/source-span/rettag from fn meta like upstream FnExpr, and a method that uses the fn's own name as a value (not as a direct callee) keeps the instance compilation so the name resolves to this. Upstream's any-self-reference guard would strip invokeStatic from every recursive defn since MAGIC's defn names the fn form. The meta strip also fixes fn literals carrying reader source-location metadata: (meta (fn [] 1)) is now nil, matching JVM and ClojureCLR (#53).
Broad ripple: the old compiler emitted a runtime withMeta wrap for every literal fn expression, so every stdlib namespace with one changes.
skydread1
force-pushed
the
fix/named-fn-self-reference
branch
from
July 20, 2026 02:14
5ced510 to
a50e522
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.
Closes #52, Closes #53
line/column/file/source-span/rettag) from fn forms at analysis, as stock Clojure does. A fn is no longer wrapped inwithMeta, so the fn value and its self-reference are the same object. Also removes a wrapper + map allocation per fn-literal evaluation.*direct-linking*, an arity that uses the fn's own name as a value compiles as an instance method, so the name resolves tothis. Plain self-calls keepinvokeStatic; recursive defns stay direct-linked.magic.test.fn, plus two smoke-suite checks verified under IL2CPP.