Add primitive integration with JuliaLowering#752
Open
aviatesk wants to merge 2 commits into
Open
Conversation
aviatesk
force-pushed
the
avi/JL-integration
branch
6 times, most recently
from
October 2, 2025 12:13
0e1d87b to
8054b1f
Compare
This implements a very basic integration with JL.
You can retrieve inferred trees in the following way:
```julia
julia> using JET, JuliaSyntax
julia> result = @report_call sum("julia")
═════ 2 possible errors found ═════
┌ sum(a::String) @ Base ./reduce.jl:553
│┌ sum(a::String; kw::@kwargs{}) @ Base ./reduce.jl:553
││┌ sum(f::typeof(identity), a::String) @ Base ./reduce.jl:524
│││┌ sum(f::typeof(identity), a::String; kw::@kwargs{}) @ Base ./reduce.jl:524
││││┌ mapreduce(f::typeof(identity), op::typeof(Base.add_sum), itr::String) @ Base ./reduce.jl:299
│││││┌ mapreduce(f::typeof(identity), op::typeof(Base.add_sum), itr::String; kw::@kwargs{}) @ Base ./reduce.jl:299
││││││┌ mapfoldl(f::typeof(identity), op::typeof(Base.add_sum), itr::String) @ Base ./reduce.jl:167
│││││││┌ mapfoldl(f::typeof(identity), op::typeof(Base.add_sum), itr::String; init::Base._InitialValue) @ Base ./reduce.jl:167
││││││││┌ mapfoldl_impl(f::typeof(identity), op::typeof(Base.add_sum), nt::Base._InitialValue, itr::String) @ Base ./:36
│││││││││┌ foldl_impl(op::Base.BottomRF{typeof(Base.add_sum)}, nt::Base._InitialValue, itr::String) @ Base ./:40
││││││││││┌ _foldl_impl(op::Base.BottomRF{typeof(Base.add_sum)}, init::Base._InitialValue, itr::String) @ Base ./reduce.jl:54
│││││││││││┌ (::Base.BottomRF{typeof(Base.add_sum)})(acc::Char, x::Char) @ Base ./:78
││││││││││││┌ add_sum(x::Char, y::Char) @ Base ./:16
│││││││││││││ no matching method found `+(::Char, ::Char)`: (x::Char + y::Char)
││││││││││││└────────────────────
│││││││││┌ foldl_impl(op::Base.BottomRF{typeof(Base.add_sum)}, nt::Base._InitialValue, itr::String) @ Base ./:41
││││││││││┌ reduce_empty_iter(op::Base.BottomRF{typeof(Base.add_sum)}, itr::String) @ Base ./:372
│││││││││││┌ reduce_empty_iter(op::Base.BottomRF{typeof(Base.add_sum)}, itr::String, ::Base.HasEltype) @ Base ./:373
││││││││││││┌ reduce_empty(op::Base.BottomRF{typeof(Base.add_sum)}, ::Type{Char}) @ Base ./:349
│││││││││││││┌ reduce_empty(::typeof(Base.add_sum), ::Type{Char}) @ Base ./:342
││││││││││││││┌ reduce_empty(::typeof(+), ::Type{Char}) @ Base ./:335
│││││││││││││││ no matching method found `zero(::Type{Char})`: zero(T::Type{Char})
││││││││││││││└────────────────────
julia> inferred = JET.get_trees(result, :add_sum)
1-element Vector{JuliaLowering.SyntaxTree}:
(method core.nothing %₈ (code_info (block Base.+ (call %₁ slot₂/x slot₃/y) (return %₂))))
julia> JuliaSyntax.sourcetext(inferred[1])
"add_sum(x, y) = x + y"
```
There are several things to note:
- Please run `Pkg.instantiate()` after checking out to this branch to
install JL
- I couldn't think of a good way to integrate this system with the existing
cache system, so for now I disabled all the global cache for now on
this branch.
- In cases where retrieval of the `JL.SyntaxTree` corresponding to the
target `CodeInfo` for inference fails, no inferred tree will exist.
Currently, retrieval likely doesn't work well for keyword methods and
methods with default arguments either
aviatesk
force-pushed
the
avi/JL-integration
branch
from
October 13, 2025 05:13
8054b1f to
9ea8be0
Compare
aviatesk
force-pushed
the
avi/JL-integration
branch
from
October 13, 2025 05:29
9ea8be0 to
9e93284
Compare
mlechu
reviewed
Oct 17, 2025
| ps = ParseStream!(s; rule=:statement) | ||
| st0 = JS.build_tree(JL.SyntaxTree, ps; first_line) | ||
| stlwr = try | ||
| JL.lower(m.module, st0) |
There was a problem hiding this comment.
Suggested change
| JL.lower(m.module, st0) | |
| JL.lower(m.module, st0; expr_compat_mode=true) |
Do we want expr_compat_mode on here? The types of quoted code and the signatures of new macro definitions will be different otherwise.
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.
Add primitive integration with JuliaLowering
This implements a very basic integration with JL.
You can retrieve inferred trees in the following way:
There are several things to note:
Pkg.instantiate()after checking out to this branch toinstall JL
cache system, so for now I disabled all the global cache for now on
this branch.
JL.SyntaxTreecorresponding to thetarget
CodeInfofor inference fails, no inferred tree will exist.Currently, retrieval likely doesn't work well for keyword methods and
methods with default arguments eit