Skip to content

Recognize GlobalRef callees in ismethod_with_name and remove is_Typeof_for_anonymous_methoddef - #170

Merged
aviatesk merged 2 commits into
masterfrom
avi/globalref-callees
Oct 3, 2026
Merged

aviatesk merged 2 commits into
masterfrom
avi/globalref-callees

Conversation

@aviatesk

@aviatesk aviatesk commented Oct 3, 2026

Copy link
Copy Markdown
Member

ismethod_with_name recognized calls to Core.svec, Core.Typeof, Core.apply_type and UnionAll only when the callee was a QuoteNode. JuliaInterpreter produces that form only when it folds const globals: for optimized frames, and on Julia 1.12+ not in top-level code. Without folding, the callees are GlobalRefs. For example, on Julia 1.12+ ismethod_with_name failed to find Foo in the signature of (::Foo)(x) = x. On Julia 1.10, the selective evaluation of struct NoParam end in the tests broke for a frame built with optimize=false. Match the callees with callee_matches, which accepts both forms, as the other callee checks in this package already do.

is_Typeof_for_anonymous_methoddef had the same problem, but is removed instead. It made signature return nothing on reaching Core.Typeof(name) for an undefined name, so that rename_framemethods! left the name of a gensymmed method as it is when the method's caller is not defined. Since Julia 1.11, lowering loads name in a separate statement that Core.Typeof refers to. signature evaluates that statement first and throws an UndefVarError before it reaches the check, so the check no longer fires. This was the warning reported in #110. #111 fixed it by having set_to_running_name! catch the UndefVarError, which leaves the name as it is, the same result the check gives. The check still fires on Julia 1.10, but the catch handles those cases as well. The only difference is that signature(frame, pc) throws in such a case on Julia 1.10, as it already does on Julia 1.11+.

The LoweredCodeUtils tests pass on Julia 1.13 and 1.10, including with a JuliaInterpreter that never folds const globals. The Revise test suite gives the same results as before on Julia 1.13 and 1.10, without new warnings.

aviatesk and others added 2 commits October 3, 2026 17:20
…Typeof_for_anonymous_methoddef`

`ismethod_with_name` recognized calls to `Core.svec`, `Core.Typeof`,
`Core.apply_type` and `UnionAll` only when the callee was a `QuoteNode`.
JuliaInterpreter produces that form only when it folds `const` globals:
for optimized frames, and on Julia 1.12+ not in top-level code. Without
folding, the callees are `GlobalRef`s. For example, on Julia 1.12+
`ismethod_with_name` failed to find `Foo` in the signature of
`(::Foo)(x) = x`. On Julia 1.10, the selective evaluation of
`struct NoParam end` in the tests broke for a frame built with
`optimize=false`. Match the callees with `callee_matches`, which accepts
both forms, as the other callee checks in this package already do.

`is_Typeof_for_anonymous_methoddef` had the same problem, but is removed
instead. It made `signature` return `nothing` on reaching
`Core.Typeof(name)` for an undefined `name`, so that
`rename_framemethods!` left the name of a gensymmed method as it is when
the method's caller is not defined. Since Julia 1.11, lowering loads
`name` in a separate statement that `Core.Typeof` refers to. `signature`
evaluates that statement first and throws an `UndefVarError` before it
reaches the check, so the check no longer fires. This was the warning
reported in #110. #111 fixed it by having `set_to_running_name!` catch
the `UndefVarError`, which leaves the name as it is, the same result the
check gives. The check still fires on Julia 1.10, but the catch handles
those cases as well. The only difference is that `signature(frame, pc)`
throws in such a case on Julia 1.10, as it already does on Julia 1.11+.

The LoweredCodeUtils tests pass on Julia 1.13 and 1.10, including with a
JuliaInterpreter that never folds `const` globals. The Revise test suite
gives the same results as before on Julia 1.13 and 1.10, without new
warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Julia 1.14, lowering defines methods with
`Core.define_method(mod, name, sigdata, codeinfo)` calls instead of
3-argument `:method` expressions. For a method without a name,
`ismethod_with_name` walks the signature to find the target name, but
it took the signature only from a `:method` expression. It thus missed
the name in the `define_method` form, e.g. `Callable` in the signature
of `(::Callable)(x) = x`, which the test added in the previous commit
caught on nightly.

Add `method_sig`, which returns the signature data of either form, and
use it in `ismethod_with_name` and `signature_top`, which already
handled both forms inline.

The LoweredCodeUtils tests pass on Julia 1.14.0-DEV.3439, 1.13 and 1.10.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aviatesk
aviatesk merged commit c11c8d7 into master Oct 3, 2026
11 checks passed
@aviatesk
aviatesk deleted the avi/globalref-callees branch October 3, 2026 10:52
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