Skip to content

Commit 5416caa

Browse files
authored
add precompilation statements to improve first-time-to-lower latency (#14)
Exercises the complete lowering pipeline during precompilation with a sample code thunks to create method and type definitions. This precompilation is enabled by default but can be disabled by setting the `JULIA_LOWERING_PRECOMPILE` environment variable to false-cy, which may be useful during development. Ideally we'd like to use Preferences.jl for this configuration, but my understanding is that JuliaLowering aims to be self-contained and should not add dependencies other than JuliaSyntax.
1 parent e15d232 commit 5416caa

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/JuliaLowering.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ function __init__()
3737
_register_kinds()
3838
end
3939

40+
_include("precompile.jl")
41+
4042
end

src/precompile.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# exercise the whole lowering pipeline
2+
if Base.get_bool_env("JULIA_LOWERING_PRECOMPILE", true)
3+
thunks = String[
4+
"""
5+
function foo(xxx, yyy)
6+
@nospecialize xxx
7+
return Pair{Any,Any}(typeof(xxx), typeof(yyy))
8+
end
9+
"""
10+
11+
"""
12+
struct Foo
13+
x::Int
14+
Foo(x::Int) = new(x)
15+
# Foo() = new()
16+
end
17+
"""
18+
]
19+
for thunk in thunks
20+
stream = JuliaSyntax.ParseStream(thunk)
21+
JuliaSyntax.parse!(stream; rule=:all)
22+
st0 = JuliaSyntax.build_tree(SyntaxTree, stream; filename=@__FILE__)
23+
lwrst = lower(@__MODULE__, st0[1])
24+
lwr = to_lowered_expr(@__MODULE__, lwrst)
25+
@assert Meta.isexpr(lwr, :thunk) && only(lwr.args) isa Core.CodeInfo
26+
end
27+
end

0 commit comments

Comments
 (0)