Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ projects = ["docs", "test"]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
JuliaInterpreter = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
CodeTracking = "3"
Compiler = "0.1"
JuliaInterpreter = "0.12"
PrecompileTools = "1.2.1"
julia = "1.10"
6 changes: 5 additions & 1 deletion src/LoweredCodeUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ module LoweredCodeUtils
# a Julia base or stdlib package are located in this file here.
# Nothing else should appear in this file here, apart from
# the `include("packagedef.jl")` statement, which loads what
# we would normally consider the bulk of the package code.
# we would normally consider the bulk of the package code,
# and the precompile workload in precompile.jl, which uses
# PrecompileTools.
# This somewhat unusual structure is in place to support
# the VS Code extension integration.

Expand All @@ -19,7 +21,9 @@ using JuliaInterpreter:
is_quotenode_egal, is_return, linetable, lookup, lookup_return, moduleof, next_until!,
nstatements, pc_expr, step_expr!, whichtt
using Compiler: Compiler as CC
using PrecompileTools: PrecompileTools

include("packagedef.jl")
include("precompile.jl")

end # module
33 changes: 0 additions & 33 deletions src/packagedef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,3 @@ export CodeEdges, SelectiveEvalController, SelectiveInterpreter,
include("utils.jl")
include("signatures.jl")
include("codeedges.jl")

# precompilation

if ccall(:jl_generating_output, Cint, ()) == 1
ex = :(f(x; color::Symbol=:green) = 2x)
lwr = Meta.lower(@__MODULE__, ex)
frame = Frame(@__MODULE__, lwr.args[1])
rename_framemethods!(frame)
ex = quote
s = 0
k = 5
for i = 1:3
global s, k
s += rand(1:5)
k += i
end
end
lwr = Meta.lower(@__MODULE__, ex)
src = lwr.args[1]
edges = CodeEdges(@__MODULE__, src)
isrequired = lines_required(GlobalRef(@__MODULE__, :s), src, edges)
lines_required(GlobalRef(@__MODULE__, :s), src, edges; norequire=())
lines_required(GlobalRef(@__MODULE__, :s), src, edges; norequire=exclude_named_typedefs(src))
for isreq in (isrequired, convert(Vector{Bool}, isrequired))
lines_required!(isreq, src, edges; norequire=())
lines_required!(isreq, src, edges; norequire=exclude_named_typedefs(src))
end
frame = Frame(@__MODULE__, src)
# selective_eval_fromstart!(frame, isrequired, true)
precompile(selective_eval_fromstart!, (typeof(frame), typeof(isrequired), Bool)) # can't @eval during precompilation
print_with_code(Base.inferencebarrier(devnull)::IO, src, edges)
print_with_code(Base.inferencebarrier(devnull)::IO, src, isrequired)
end
30 changes: 30 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
PrecompileTools.@setup_workload let
kwsrc = Meta.lower(@__MODULE__, :(f(x; color::Symbol=:green) = 2x)).args[1]
ex = quote
s = 0
k = 5
for i = 1:3
global s, k
s += rand(1:5)
k += i
end
end
src = Meta.lower(@__MODULE__, ex).args[1]
PrecompileTools.@compile_workload let
frame = Frame(@__MODULE__, kwsrc)
rename_framemethods!(frame)
edges = CodeEdges(@__MODULE__, src)
isrequired = lines_required(GlobalRef(@__MODULE__, :s), src, edges)
lines_required(GlobalRef(@__MODULE__, :s), src, edges; norequire=())
lines_required(GlobalRef(@__MODULE__, :s), src, edges; norequire=exclude_named_typedefs(src))
for isreq in (isrequired, convert(Vector{Bool}, isrequired))
lines_required!(isreq, src, edges; norequire=())
lines_required!(isreq, src, edges; norequire=exclude_named_typedefs(src))
end
frame = Frame(@__MODULE__, src)
# selective_eval_fromstart!(frame, isrequired, true)
precompile(selective_eval_fromstart!, (typeof(frame), typeof(isrequired), Bool)) # can't @eval during precompilation
print_with_code(Base.inferencebarrier(devnull)::IO, src, edges)
print_with_code(Base.inferencebarrier(devnull)::IO, src, isrequired)
end
end
Loading