Skip to content

[JuliaLowering] Invoke lowering hook + runtime utilities in fixed world#62302

Merged
topolarity merged 5 commits into
JuliaLang:masterfrom
topolarity:ct/fix-JL-invalidations
Jul 11, 2026
Merged

[JuliaLowering] Invoke lowering hook + runtime utilities in fixed world#62302
topolarity merged 5 commits into
JuliaLang:masterfrom
topolarity:ct/fix-JL-invalidations

Conversation

@topolarity

@topolarity topolarity commented Jul 8, 2026

Copy link
Copy Markdown
Member

This helps some severe slowdowns when precompiling common packages due to invalidations:

┌────────────────────────────┬─────────────┬────────────┬─────────┐
│          package           │ before (JL) │ after (JL) │ flisp   │
├────────────────────────────┼─────────────┼────────────┼─────────┤
│ CEnum                      │      65.5 s │     0.66 s │ 0.037 s │
├────────────────────────────┼─────────────┼────────────┼─────────┤
│ IterTools                  │      50.2 s │     1.71 s │ 0.152 s │
├────────────────────────────┼─────────────┼────────────┼─────────┤
│ InlineStrings              │     159.6 s │     0.81 s │ 0.315 s │
├────────────────────────────┼─────────────┼────────────┼─────────┤
│ OrderedCollections         │      90.7 s │     1.09 s │ 0.179 s │
├────────────────────────────┼─────────────┼────────────┼─────────┤
│ StaticArrays (@generated)  │      43.4 s │     6.20 s │  4.01 s │
└────────────────────────────┴─────────────┴────────────┴─────────┘

Not quite up to flisp parity, but we're getting somewhere.

Invalidations and barrier locations found by Claude Fable 🤖 , but sensible IMO
(I tried to edit away any AI over-verbosity, etc.)

@topolarity
topolarity requested a review from mlechu July 8, 2026 18:30
@topolarity
topolarity force-pushed the ct/fix-JL-invalidations branch 5 times, most recently from 91f4192 to c85256f Compare July 8, 2026 21:22
@mlechu

mlechu commented Jul 9, 2026

Copy link
Copy Markdown
Member

Thanks! Would you (or claude) be willing to rebase onto #62221?

@topolarity
topolarity force-pushed the ct/fix-JL-invalidations branch 3 times, most recently from b242f1a to e621978 Compare July 10, 2026 19:50
@topolarity

Copy link
Copy Markdown
Member Author

Thanks! Would you (or claude) be willing to rebase onto #62221?

Done - 951c980 picked up some fixes from the PkgEval and e621978 is new fyi

@mlechu mlechu 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.

SGTM. If you want to do Expr(:error) too while you're touching hooks.jl go ahead, since it should only be a few lines (though maybe make lowering in the REPL still pretty-print if possible)

@topolarity

Copy link
Copy Markdown
Member Author

I'll leave it out for now just because weekend - but I'll roll it up next week

@topolarity topolarity added the merge me PR is reviewed. Merge when all tests are passing label Jul 10, 2026
topolarity and others added 5 commits July 10, 2026 22:15
This shields JuliaLowering from invalidations, esp. those triggered by the
code being lowered.

Also resolve the macro MethodInstance once, before invoking the macro
body, at the resolved macro_world (matching flisp's single lookup in
jl_invoke_julia_macro): the body may load packages that perturb
method-table visibility, so a post-hoc lookup for module attribution
can return nothing, and it must not receive the raw typemax(UInt)
"latest world" sentinel as a lookup world.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
These runtime utilities are easily invalidated (like the rest of
JuliaLowering) but don't dispatch on user types so we can shield them
by invoking in the lowering world.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Another runtime utility that requires invalidation shielding.

Standalone CEnum include: 65s -> 0.66s (flisp: 0.04s).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Generated functions themselves run in a different world, but the
lowering harness around them should still run in the lowering world to
make it resilient to invalidations

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VBmeULb6ehNsozSJoqDUJq
@topolarity
topolarity force-pushed the ct/fix-JL-invalidations branch from e621978 to b17d4ed Compare July 11, 2026 02:16
@topolarity
topolarity merged commit 6c69a8c into JuliaLang:master Jul 11, 2026
7 of 9 checks passed
@topolarity topolarity removed the merge me PR is reviewed. Merge when all tests are passing label Jul 11, 2026
macro_mi = lookup_method_instance(macfunc, macro_args, macro_world)
expanded = try
Base.invoke_in_world(ctx.world, macfunc, macro_args...)
_invoke_in_world(ctx.world, macfunc, macro_args...)

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.

Specializing on the function makes sense for calling our own runtime functions, but doesn't this compile a new specialization of _invoke_in_world for every unique macro we call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants