Skip to content

Commit 155da9f

Browse files
authored
Rearrange files for easier VS Code integration (#36)
1 parent 6903b43 commit 155da9f

File tree

2 files changed

+56
-45
lines changed

2 files changed

+56
-45
lines changed

src/LoweredCodeUtils.jl

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,19 @@
11
module LoweredCodeUtils
22

3-
if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@optlevel"))
4-
@eval Base.Experimental.@optlevel 1
5-
end
3+
# We use a code structure where all `using` and `import`
4+
# statements in the package that load anything other than
5+
# a Julia base or stdlib package are located in this file here.
6+
# Nothing else should appear in this file here, apart from
7+
# the `include("packagedef.jl")` statement, which loads what
8+
# we would normally consider the bulk of the package code.
9+
# This somewhat unusual structure is in place to support
10+
# the VS Code extension integration.
611

7-
using Core: SimpleVector, CodeInfo, NewvarNode, GotoNode
8-
using Base.Meta: isexpr
912
using JuliaInterpreter
1013
using JuliaInterpreter: SSAValue, SlotNumber, Frame
1114
using JuliaInterpreter: @lookup, moduleof, pc_expr, step_expr!, is_global_ref, is_quotenode, whichtt,
1215
next_until!, finish_and_return!, get_return, nstatements, codelocation, linetable
1316

14-
const SSAValues = Union{Core.Compiler.SSAValue, JuliaInterpreter.SSAValue}
15-
16-
const structheads = VERSION >= v"1.5.0-DEV.702" ? () : (:struct_type, :abstract_type, :primitive_type)
17-
const trackedheads = (:method, structheads...)
18-
19-
export signature, rename_framemethods!, methoddef!, methoddefs!, bodymethod
20-
export CodeEdges, lines_required, lines_required!, selective_eval!, selective_eval_fromstart!
21-
22-
include("utils.jl")
23-
include("signatures.jl")
24-
include("codeedges.jl")
25-
26-
# precompilation
27-
28-
if ccall(:jl_generating_output, Cint, ()) == 1
29-
kwdefine = NamedTuple{(:define,),Tuple{Bool}}
30-
for ct in (Vector{Any}, Set{Any})
31-
f = methoddef!
32-
m = which(f, Tuple{Function, ct, Frame, Expr, Int})
33-
@assert precompile(Tuple{typeof(f), Function, ct, Frame, Expr, Int})
34-
mbody = bodymethod(m)
35-
# @assert precompile(Tuple{mbody.sig.parameters[1], Bool, typeof(f), Function, ct, Frame, Expr, Int})
36-
@assert precompile(Tuple{Core.kwftype(typeof(f)), kwdefine, typeof(f), Function, ct, Frame, Expr, Int})
37-
f = methoddefs!
38-
@assert precompile(Tuple{typeof(f), Any, ct, Frame})
39-
@assert precompile(Tuple{Core.kwftype(typeof(f)), kwdefine, typeof(f), Function, ct, Frame})
40-
end
41-
@assert precompile(Tuple{typeof(rename_framemethods!), Any, Frame, Dict{Symbol,MethodInfo},
42-
Vector{NamedTuple{(:linetop, :linebody, :callee, :caller),Tuple{Int64,Int64,Symbol,Union{Bool, Symbol}}}},
43-
Dict{Symbol,Union{Bool, Symbol}}})
44-
@assert precompile(Tuple{typeof(identify_framemethod_calls), Frame})
45-
@assert precompile(Tuple{typeof(callchain), Vector{NamedTuple{(:linetop, :linebody, :callee, :caller),Tuple{Int64,Int64,Symbol,Union{Bool, Symbol}}}}})
46-
47-
@assert precompile(CodeEdges, (CodeInfo,))
48-
@assert precompile(add_links!, (Pair{Union{SSAValue,SlotNumber,NamedVar},Links}, Any, CodeLinks))
49-
@assert precompile(lines_required!, (Vector{Bool}, Set{NamedVar}, CodeInfo, CodeEdges))
50-
51-
precompile(Tuple{typeof(setindex!),Dict{Union{GlobalRef, Symbol},Links},Links,Symbol})
52-
precompile(Tuple{typeof(setindex!),Dict{Union{GlobalRef, Symbol},Variable},Variable,Symbol})
53-
end
17+
include("packagedef.jl")
5418

5519
end # module

src/packagedef.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@optlevel"))
2+
@eval Base.Experimental.@optlevel 1
3+
end
4+
5+
using Core: SimpleVector, CodeInfo, NewvarNode, GotoNode
6+
using Base.Meta: isexpr
7+
8+
const SSAValues = Union{Core.Compiler.SSAValue, JuliaInterpreter.SSAValue}
9+
10+
const structheads = VERSION >= v"1.5.0-DEV.702" ? () : (:struct_type, :abstract_type, :primitive_type)
11+
const trackedheads = (:method, structheads...)
12+
13+
export signature, rename_framemethods!, methoddef!, methoddefs!, bodymethod
14+
export CodeEdges, lines_required, lines_required!, selective_eval!, selective_eval_fromstart!
15+
16+
include("utils.jl")
17+
include("signatures.jl")
18+
include("codeedges.jl")
19+
20+
# precompilation
21+
22+
if ccall(:jl_generating_output, Cint, ()) == 1
23+
kwdefine = NamedTuple{(:define,),Tuple{Bool}}
24+
for ct in (Vector{Any}, Set{Any})
25+
f = methoddef!
26+
m = which(f, Tuple{Function, ct, Frame, Expr, Int})
27+
@assert precompile(Tuple{typeof(f), Function, ct, Frame, Expr, Int})
28+
mbody = bodymethod(m)
29+
# @assert precompile(Tuple{mbody.sig.parameters[1], Bool, typeof(f), Function, ct, Frame, Expr, Int})
30+
@assert precompile(Tuple{Core.kwftype(typeof(f)), kwdefine, typeof(f), Function, ct, Frame, Expr, Int})
31+
f = methoddefs!
32+
@assert precompile(Tuple{typeof(f), Any, ct, Frame})
33+
@assert precompile(Tuple{Core.kwftype(typeof(f)), kwdefine, typeof(f), Function, ct, Frame})
34+
end
35+
@assert precompile(Tuple{typeof(rename_framemethods!), Any, Frame, Dict{Symbol,MethodInfo},
36+
Vector{NamedTuple{(:linetop, :linebody, :callee, :caller),Tuple{Int64,Int64,Symbol,Union{Bool, Symbol}}}},
37+
Dict{Symbol,Union{Bool, Symbol}}})
38+
@assert precompile(Tuple{typeof(identify_framemethod_calls), Frame})
39+
@assert precompile(Tuple{typeof(callchain), Vector{NamedTuple{(:linetop, :linebody, :callee, :caller),Tuple{Int64,Int64,Symbol,Union{Bool, Symbol}}}}})
40+
41+
@assert precompile(CodeEdges, (CodeInfo,))
42+
@assert precompile(add_links!, (Pair{Union{SSAValue,SlotNumber,NamedVar},Links}, Any, CodeLinks))
43+
@assert precompile(lines_required!, (Vector{Bool}, Set{NamedVar}, CodeInfo, CodeEdges))
44+
45+
precompile(Tuple{typeof(setindex!),Dict{Union{GlobalRef, Symbol},Links},Links,Symbol})
46+
precompile(Tuple{typeof(setindex!),Dict{Union{GlobalRef, Symbol},Variable},Variable,Symbol})
47+
end

0 commit comments

Comments
 (0)