Skip to content

Conversation

@serenity4
Copy link
Collaborator

This PR splits the compiler integration functionality, such that we only need to re-include the corresponding few compiler-related files when we load the Compiler extension, instead of re-loading most of Cthulhu. These files live under src/compiler/*.jl and essentially hold the interpreter and default provider bits (see src/CthulhuCompiler.jl which includes these).

A major benefit of this approach is that we now have a single API regardless of whether to use the compiler extension: most user-facing data structures live in Cthulhu, and only the parts related to the interfacing with the compiler are either in Cthulhu or CthulhuCompilerExt. No more Cthulhu.AbstractProvider !== CthulhuCompilerExt.AbstractProvider. However, Cthulhu.DefaultProvider !== CthulhuCompilerExt.DefaultProvider may still be true. When we load the Compiler extension, we fall in one of two situations:

  • The compiler stdlib is just a reexport of Base.Compiler, in which case we don't need to do anything (Base.Compiler.AbstractInterpreter === Compiler.AbstractInterpreter).
  • The compiler stdlib defines data structures that are different than those from Base.Compiler, so we re-include src/CthulhuCompiler.jl which defines new structs and functions, and adds methods to Cthulhu functions.

Another benefit that comes from this is that we won't pay the cost of recompilation in the most common case, i.e. Compiler may be loaded but simply aliases Base.Compiler, as the Cthulhu extension is virtually a no-op in this situation.

serenity4 and others added 30 commits July 22, 2025 14:59
This way, commands merely register shortcuts
to execute callbacks, so they get simplified,
and at the same time we no longer have to worry
about keeping command "values" and configuration values
in sync.
…nnotations

The renaming was done to improve consistency with similar settings,
`remarks` and `exception_type`.
`IRCode` is now used primarily for callsite detection and display.
`CodeInfo` may also be used for that purpose, if no `IRCode` is
available. The main requirement is that they are consistent with the
provided call infos.

`CodeInfo` is mainly used to extract slotnames, get more accurate
sources via TypedSyntax, and for module dumping for LLVM/native views.
@serenity4 serenity4 requested a review from aviatesk November 4, 2025 14:24
@serenity4 serenity4 self-assigned this Nov 4, 2025
@codecov-commenter
Copy link

codecov-commenter commented Nov 4, 2025

Codecov Report

❌ Patch coverage is 0% with 428 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (2c33b9a) to head (7b5ec0d).
⚠️ Report is 86 commits behind head on master.

Files with missing lines Patch % Lines
src/compiler/callsite.jl 0.00% 288 Missing ⚠️
src/compiler/interface.jl 0.00% 58 Missing ⚠️
src/compiler/lookup.jl 0.00% 24 Missing ⚠️
src/callsite.jl 0.00% 12 Missing ⚠️
src/Cthulhu.jl 0.00% 11 Missing ⚠️
src/compiler/provider.jl 0.00% 8 Missing ⚠️
src/interface.jl 0.00% 7 Missing ⚠️
src/bookmark.jl 0.00% 5 Missing ⚠️
ext/CthulhuCompilerExt.jl 0.00% 4 Missing ⚠️
src/descend.jl 0.00% 4 Missing ⚠️
... and 5 more
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #677    +/-   ##
=======================================
  Coverage    0.00%   0.00%            
=======================================
  Files           9      22    +13     
  Lines        1556    1807   +251     
=======================================
- Misses       1556    1807   +251     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aviatesk
Copy link
Member

Sorry for the delay in reviewing this. After reading the PR description, I think it's a great change overall.

There are a few things I can't understand just by reading the code, so I'd like to clarify them:

  • If I load a custom Compiler.jl and want to use Cthulhu with it, how should I do that? With the previous CthulhuCompilerExt implementation, I believe that when a custom Compiler.jl was loaded, the descend implementation would automatically switch, and descend would then work with that new compiler. From what I can tell by following the current implementation, this doesn't seem to happen, but am I missing something? I don't necessarily think it should happen automatically, but I'd like to confirm the steps needed to use descend with a new compiler.
  • If an external AbstractInterpreter package wants to use Cthulhu's AbstractProvider interface, my understanding is that it should primarily use Cthulhu.get_module_for_compiler_integration(; use_compiler_stdlib = true) to get the Cthulhu module to overload. Is that correct? And my understanding is that this Cthulhu module will be correctly switched depending on the Compiler.jl implementation.

@aviatesk
Copy link
Member

If I load a custom Compiler.jl and want to use Cthulhu with it, how should I do that?

Looks like I can just do

julia> using Cthulhu

julia> using Compiler # load custom Compiler impl

julia> descend(sin, (Int,); interp=Compiler.NativeInterpreter())

and it's using the new Compiler implementation. That's impressive.

@aviatesk
Copy link
Member

I see, so AbstractProvider(::[Base.Compiler|Compiler].NativeInterpreter) in src/compiler/interface.jl provides a DefaultProvider based on the interpreter that's passed to it. I think that's a good design.

And I guess the external abstract interpreter package XXX.jl is supposed to overload Cthulhu.AbstractProvider, and then also can opt in with its XXXCompilerExt to overload CthulhuExt.AbstractProvider (where CthulhuExt is retrieved by Cthulhu.get_module_for_compiler_integration(; use_compiler_stdlib=true)).intended design?

@serenity4
Copy link
Collaborator Author

serenity4 commented Nov 13, 2025

Thanks for the review!

And I guess the external abstract interpreter package XXX.jl is supposed to overload Cthulhu.AbstractProvider, and then also can opt in with its XXXCompilerExt to overload CthulhuExt.AbstractProvider (where CthulhuExt is retrieved by Cthulhu.get_module_for_compiler_integration(; use_compiler_stdlib=true))

More accurately, there is now always a single AbstractProvider, so CthulhuExt.AbstractProvider === Cthulhu.AbstractProvider. Usually, XXX.jl will simply choose to use Base.Compiler or Compiler and provide a single interpreter, and they will integrate with most of Cthulhu's interface. Only for the Compiler-related parts will they have to use Cthulhu.get_module_for_compiler_integration(; use_compiler_stdlib), e.g. to pull in the LookupResult symbol to construct an instance of that type to return in the lookup interface function. If they choose to integrate with both (e.g. by registering a new abstract interpreter type in XXXCompilerExt to provide a similar functionality as their abstract interpreter using Base.Compiler), they will simply satisfy the interface for their other XXXInterp <: Compiler.AbstractInterpreter type, and descend will dispatch on the relevant code just like you observed for NativeInterpreter.

I'll add a few more docs to provide guidelines and explanations about how to do all that integration before merging, hopefully this PR simplifies the whole process.

Copy link
Member

@aviatesk aviatesk left a comment

Choose a reason for hiding this comment

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

I'll add a few more docs to provide guidelines and explanations about how to do all that integration before merging, hopefully this PR simplifies the whole process.

That's great.

I haven't completed the JET integration with AbstractProvider on my side yet, but I'll try it again on this branch. Last time I tried, I remember running into an error related to this Compiler extension complexity, but looking at the changes in this PR, it seems that's been fixed entirely. (the challenge of integrating with JET is actually the other thing, specifically, I need to properly manage CodeInfo in JET.AbstractAnalyzer for passing them to AbstractProvider. But after this PR, once that's done, Cthulhu should be usable with JET.)

@aviatesk
Copy link
Member

Feel free to merge this whenever you are satisfied.

@serenity4
Copy link
Collaborator Author

Feel free to merge this whenever you are satisfied.

That should be good now, I'll proceed with the merge and tagging of the breaking release 3.0.0 with adequate release notes.

@serenity4 serenity4 merged commit 8274a67 into JuliaDebug:master Nov 18, 2025
7 checks passed
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.

3 participants