Skip to content

reflection: Add world keyword argument to Base.bodyfunction - #63239

Merged
IanButterworth merged 1 commit into
masterfrom
avi/bodyfunction-world
Sep 19, 2026
Merged

IanButterworth merged 1 commit into
masterfrom
avi/bodyfunction-world

Conversation

@aviatesk

Copy link
Copy Markdown
Member

Base.bodyfunction resolved the keyword body function with getfield(mod, name), which looks up the binding in the world age of the calling task. A long-lived task that was spawned before the method was defined therefore hit the backdated binding path, which prints the access to binding in a world prior to its definition world warning and throws UndefVarError under --depwarn=error. JETLS ran into this when its analysis worker tasks inspected methods that were defined after the workers had started.

This change adds a world::UInt=get_world_counter() keyword argument and performs the binding lookup with invoke_in_world, consistently with other reflection utilities such as hasmethod and kwarg_decl. Existing positional calls keep working, and they now resolve the body function in the latest world regardless of the world age of the caller.

Assisted-by: Claude Code (Fable 5.1)

@adienes adienes added the observability metrics, timing, understandability, reflection, logging, ... label Sep 18, 2026
@adienes

adienes commented Sep 18, 2026

Copy link
Copy Markdown
Member

what makes this preferable over Base.invoke_in_world(world, Base.bodyfunction, m) ?

@aviatesk

Copy link
Copy Markdown
Member Author

To maintain consistency with the other reflection functions, I think it would be better to add a world argument.

@vtjnash vtjnash left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's too late to move this to InteractiveUtils where it likely belonged, so we should make it agree with the others anyways.

Comment thread base/reflection.jl
`Base.bodyfunction` resolved the keyword body function with
`getfield(mod, name)`, which looks up the binding in the world age of
the calling task. A long-lived task that was spawned before the method
was defined therefore hit the backdated binding path, which prints the
`access to binding in a world prior to its definition world` warning
and throws `UndefVarError` under `--depwarn=error`. JETLS ran into this
when its analysis worker tasks inspected methods that were defined
after the workers had started.

This change adds a `world::UInt=get_world_counter()` keyword argument
and performs the binding lookup with `invoke_in_world`, consistently
with other reflection utilities such as `hasmethod` and `kwarg_decl`.
Existing positional calls keep working, and they now resolve the body
function in the latest world regardless of the world age of the caller.

Assisted-by: Claude Code (Fable 5.1)
@aviatesk
aviatesk force-pushed the avi/bodyfunction-world branch from dfcdc8a to cd47e7d Compare September 18, 2026 14:51
@vtjnash vtjnash added merge me PR is reviewed. When all tests are passing merge, making sure commit message is good. backport 1.13 Change should be backported to release-1.13 backport 1.12 Change should be backported to release-1.12 and removed backport 1.12 Change should be backported to release-1.12 backport 1.13 Change should be backported to release-1.13 labels Sep 18, 2026
@IanButterworth
IanButterworth merged commit 346d02a into master Sep 19, 2026
14 of 15 checks passed
@IanButterworth
IanButterworth deleted the avi/bodyfunction-world branch September 19, 2026 02:06
@IanButterworth IanButterworth removed the merge me PR is reviewed. When all tests are passing merge, making sure commit message is good. label Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

observability metrics, timing, understandability, reflection, logging, ...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants