Skip to content

Commit

Permalink
Merge pull request #499 from JuliaDebug/avi/lts
Browse files Browse the repository at this point in the history
update LTS version, drop v1.0 support
  • Loading branch information
pfitzseb authored Dec 8, 2021
2 parents 716d7f6 + 988d98b commit 10fd8fc
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 167 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.0'
- '1'
- '1.6' # LTS
- '1' # current stable
- 'nightly'
os:
- ubuntu-latest
Expand Down
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "JuliaInterpreter"
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
version = "0.8.21"
version = "0.9.0"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand All @@ -10,7 +10,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
CodeTracking = "0.5.9, 1"
julia = "1"
julia = "1.6"

[extras]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand All @@ -22,9 +22,8 @@ Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
TableReader = "70df011a-6618-58d7-8e16-3cf9e384cb47"
Tensors = "48a634ad-e948-5137-8d70-aa71f2a747f4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Dates", "Distributed", "HTTP", "LinearAlgebra", "Mmap", "PyCall", "SHA", "SparseArrays", "Tensors", "TableReader", "DataFrames"]
test = ["DataFrames", "Dates", "Distributed", "HTTP", "LinearAlgebra", "Mmap", "PyCall", "SHA", "SparseArrays", "Tensors", "Test"]
3 changes: 1 addition & 2 deletions src/commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ function maybe_step_through_wrapper!(@nospecialize(recurse), frame::Frame)
length(stmts) < 2 && return frame
last = stmts[end-1]
isexpr(last, :(=)) && (last = last.args[2])
comp = VERSION < v"1.4.0-DEV.215" ? startswith : endswith
is_kw = isa(scope, Method) && comp(String(Base.unwrap_unionall(Base.unwrap_unionall(scope.sig).parameters[1]).name.name), "#kw")
is_kw = isa(scope, Method) && endswith(String(Base.unwrap_unionall(Base.unwrap_unionall(scope.sig).parameters[1]).name.name), "#kw")
has_selfarg = isexpr(last, :call) && any(isequal(SlotNumber(1)), last.args)
issplatcall, _callee = unpack_splatcall(last)
if is_kw || has_selfarg || (issplatcall && is_bodyfunc(_callee))
Expand Down
36 changes: 2 additions & 34 deletions src/construct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,6 @@ function get_source(g::GeneratedFunctionStub, env)
return eval(b)
end

function copy_codeinfo(code::CodeInfo)
@static if VERSION < v"1.1.0-DEV.762"
newcode = ccall(:jl_new_struct_uninit, Any, (Any,), CodeInfo)::CodeInfo
for (i, name) in enumerate(fieldnames(CodeInfo))
if isdefined(code, name)
val = getfield(code, name)
ccall(:jl_set_nth_field, Cvoid, (Any, Csize_t, Any), newcode, i-1, val===nothing || isa(val, Union{Type, Method}) ? val : copy(val))
end
end
return newcode
else
# Inline this when support for VERSION above is dropped
return copy(code)
end
end

"""
frun, allargs = prepare_args(fcall, fargs, kwargs)
Expand Down Expand Up @@ -148,13 +132,6 @@ function prepare_args(@nospecialize(f), allargs, kwargs)
return f, allargs
end

if VERSION < v"1.2-" || !isdefined(Core.Compiler, :specialize_method)
specialize_method(method::Method, @nospecialize(atypes), sparams::SimpleVector) =
Core.Compiler.code_for_method(method, atypes, sparams, typemax(UInt))
else
const specialize_method = Core.Compiler.specialize_method
end

function prepare_framecode(method::Method, @nospecialize(argtypes); enter_generated=false)
sig = method.sig
if (method.module compiled_modules || method compiled_methods) && !(method interpreted_methods)
Expand All @@ -174,7 +151,7 @@ function prepare_framecode(method::Method, @nospecialize(argtypes); enter_genera
# If we're stepping into a staged function, we need to use
# the specialization, rather than stepping through the
# unspecialized method.
code = Core.Compiler.get_staged(specialize_method(method, argtypes, lenv))
code = Core.Compiler.get_staged(Core.Compiler.specialize_method(method, argtypes, lenv))
code === nothing && return nothing
generator = false
else
Expand Down Expand Up @@ -282,7 +259,7 @@ end

function prepare_framedata(framecode, argvals::Vector{Any}, lenv::SimpleVector=empty_svec, caller_will_catch_err::Bool=false)
src = framecode.src
slotnames = src.slotnames::SlotNamesType
slotnames = src.slotnames
ssavt = src.ssavaluetypes
ng, ns = isa(ssavt, Int) ? ssavt : length(ssavt::Vector{Any}), length(src.slotflags)
if length(junk_framedata) > 0
Expand Down Expand Up @@ -514,15 +491,6 @@ function queuenext!(iter::ExprSplitter)
ex = ex.args[3]::Expr
push_modex!(iter, mod, ex)
return queuenext!(iter)
elseif VERSION < v"1.2" && is_function_def(ex)
# Newer Julia versions insert a LineNumberNode between statements, but at least Julia 1.0 does not.
# Scan the function body for a LNN
lnn = firstline(ex)
if isa(lnn, LineNumberNode)
if iter.lnn === nothing || iter.lnn.line < lnn.line
iter.lnn = LineNumberNode(lnn.line-1, lnn.file)
end
end
elseif head === :macrocall
iter.lnn = ex.args[2]::LineNumberNode
elseif head === :block || head === :toplevel
Expand Down
9 changes: 2 additions & 7 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,13 @@ function evaluate_structtype(@nospecialize(recurse), frame, node)
end
end
Core.eval(mod, newstructexpr)
VERSION < v"1.2.0-DEV.239" && set_structtype_const(mod, name)
end

function evaluate_abstracttype(@nospecialize(recurse), frame, node)
name, mod = structname(frame, node)
params = lookup_or_eval(recurse, frame, node.args[2])::SimpleVector
supertype = lookup_or_eval(recurse, frame, node.args[3])::Type
Core.eval(mod, Expr(:abstract_type, name, params, supertype))
VERSION < v"1.2.0-DEV.239" && set_structtype_const(mod, name)
end

function evaluate_primitivetype(@nospecialize(recurse), frame, node)
Expand All @@ -346,7 +344,6 @@ function evaluate_primitivetype(@nospecialize(recurse), frame, node)
nbits = node.args[3]::Int
supertype = lookup_or_eval(recurse, frame, node.args[4])::Type
Core.eval(mod, Expr(:primitive_type, name, params, nbits, supertype))
VERSION < v"1.2.0-DEV.239" && set_structtype_const(mod, name)
end

function do_assignment!(frame, @nospecialize(lhs), @nospecialize(rhs))
Expand Down Expand Up @@ -407,7 +404,7 @@ function eval_rhs(@nospecialize(recurse), frame, node::Expr)
return length(frame.framedata.exception_frames)
elseif head === :boundscheck
return true
elseif head === :meta || head === :inbounds || head == (@static VERSION >= v"1.2.0-DEV.462" ? :loopinfo : :simdloop) ||
elseif head === :meta || head === :inbounds || head == :loopinfo ||
head === :gc_preserve_begin || head === :gc_preserve_end
return nothing
elseif head === :method && length(node.args) == 1
Expand Down Expand Up @@ -517,9 +514,7 @@ function step_expr!(@nospecialize(recurse), frame, @nospecialize(node), istoplev
else
mod, name = moduleof(frame), g::Symbol
end
if VERSION >= v"1.2.0-DEV.239" # depends on https://github.com/JuliaLang/julia/pull/30893
Core.eval(mod, Expr(:const, name))
end
Core.eval(mod, Expr(:const, name))
elseif node.head === :thunk
newframe = Frame(moduleof(frame), node.args[1])
if isa(recurse, Compiled)
Expand Down
7 changes: 2 additions & 5 deletions src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ function lookup_global_refs!(ex::Expr)
return nothing
end

# See https://github.com/JuliaLang/julia/pull/32800
const foreigncall_version = VERSION < v"1.3.0-alpha.108" ? 0 : 1

"""
optimize!(code::CodeInfo, mod::Module)
Expand Down Expand Up @@ -190,7 +187,7 @@ function optimize!(code::CodeInfo, scope)
append!(delete_idxs, delete_idx)
end
elseif stmt.head === :foreigncall && scope isa Method
nargs = foreigncall_version == 0 ? stmt.args[5]::Int : length(stmt.args[3]::SimpleVector)
nargs = length(stmt.args[3]::SimpleVector)
# Call via `invokelatest` to avoid compiling it until we need it
delete_idx = Base.invokelatest(build_compiled_call!, stmt, :ccall, code, idx, nargs, sparams, evalmod)
if delete_idx !== nothing
Expand Down Expand Up @@ -365,7 +362,7 @@ function build_compiled_call!(stmt::Expr, fcall, code, idx, nargs::Int, sparams:
push!(wrapargs, :(::$TVal{$sparam}))
end
methname = gensym("compiledcall")
calling_convention = stmt.args[foreigncall_version == 0 ? 4 : 5]
calling_convention = stmt.args[5]
if calling_convention === :(:llvmcall)
def = :(
function $methname($(wrapargs...)) where {$(sparams...)}
Expand Down
15 changes: 3 additions & 12 deletions src/packagedef.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Base.Meta
import Base: +, -, convert, isless
import Base: +, -, convert, isless, get_world_counter
using Core: CodeInfo, SimpleVector, LineInfoNode, GotoNode, Slot,
GeneratedFunctionStub, MethodInstance, NewvarNode, TypeName

Expand All @@ -18,18 +18,9 @@ module CompiledCalls
# This module is for handling intrinsics that must be compiled (llvmcall) as well as ccalls
end

# "Backport" of https://github.com/JuliaLang/julia/pull/31536
if VERSION < v"1.2.0-DEV.572"
Base.convert(::Type{Some{T}}, x::Some{T}) where {T} = x
end

const SlotNamesType = VERSION < v"1.2.0-DEV.606" ? Vector{Any} : Vector{Symbol}
const SlotNamesType = Vector{Symbol}

@static if VERSION < v"1.3.0-DEV.179"
const append_any = Base.append_any
else
append_any(@nospecialize x...) = append!([], Core.svec((x...)...))
end
append_any(@nospecialize x...) = append!([], Core.svec((x...)...))

if isdefined(Base, :mapany)
const mapany = Base.mapany
Expand Down
7 changes: 2 additions & 5 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ function _precompile_()
@assert precompile(Tuple{typeof(extract_args), Module, Expr})
@assert precompile(Tuple{typeof(enter_call), Int, Int})
@assert precompile(Tuple{typeof(enter_call_expr), Expr})
@assert precompile(Tuple{typeof(copy_codeinfo), Core.CodeInfo})
@assert precompile(Tuple{typeof(optimize!), Core.CodeInfo, Module})
@assert precompile(Tuple{typeof(optimize!), Core.CodeInfo, Method})
@assert precompile(Tuple{typeof(build_compiled_call!), Expr, Symbol, Core.CodeInfo, Int, Int, Vector{Symbol}, Module})
Expand All @@ -48,9 +47,7 @@ function _precompile_()
@assert precompile(Tuple{typeof(find_used), Core.CodeInfo})
@assert precompile(Tuple{typeof(do_assignment!), Frame, Any, Any})
@assert precompile(Tuple{typeof(pc_expr), Frame})
if VERSION >= v"1.3.0-DEV.179" # there are different definitions depending on Julia version
@assert precompile(Tuple{typeof(append_any), Any})
@assert precompile(Tuple{typeof(append_any), Any, Vararg{Any, 100}})
end
@assert precompile(Tuple{typeof(append_any), Any})
@assert precompile(Tuple{typeof(append_any), Any, Vararg{Any, 100}})
@assert precompile(Tuple{typeof(whichtt), Any})
end
4 changes: 2 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ function is_breakpoint_expr(ex::Expr)
end
function FrameCode(scope, src::CodeInfo; generator=false, optimize=true)
if optimize
src, methodtables = optimize!(copy_codeinfo(src), scope)
src, methodtables = optimize!(copy(src), scope)
else
src = replace_coretypes!(copy_codeinfo(src))
src = replace_coretypes!(copy(src))
methodtables = Vector{Union{Compiled,DispatchableMethod}}(undef, length(src.code))
end
breakpoints = Vector{BreakpointState}(undef, length(src.code))
Expand Down
57 changes: 12 additions & 45 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ function to_function(@nospecialize(x))
isa(x, GlobalRef) ? getfield(x.mod, x.name) : x
end

@static if isdefined(Base, :get_world_counter)
import Base: get_world_counter
else
get_world_counter() = ccall(:jl_get_world_counter, UInt, ())
end

"""
method = whichtt(tt)
Expand Down Expand Up @@ -199,20 +193,11 @@ is_call_or_return(@nospecialize(node)) = is_call(node) || is_return(node)

is_dummy(bpref::BreakpointRef) = bpref.stmtidx == 0 && bpref.err === nothing

if VERSION >= v"1.4.0-DEV.304"
function unpack_splatcall(stmt)
if isexpr(stmt, :call) && length(stmt.args) >= 3 && is_quotenode_egal(stmt.args[1], Core._apply_iterate)
return true, stmt.args[3]
end
return false, nothing
end
else
function unpack_splatcall(stmt)
if isexpr(stmt, :call) && length(stmt.args) >= 2 && is_quotenode_egal(stmt.args[1], Core._apply)
return true, stmt.args[2]
end
return false, nothing
function unpack_splatcall(stmt)
if isexpr(stmt, :call) && length(stmt.args) >= 3 && is_quotenode_egal(stmt.args[1], Core._apply_iterate)
return true, stmt.args[3]
end
return false, nothing
end

function is_bodyfunc(@nospecialize(arg))
Expand Down Expand Up @@ -324,28 +309,10 @@ function getline(ln::Union{LineTypes,Expr})
_getline(ln::Expr) = ln.args[1] # assuming ln.head === :line
return Int(_getline(ln))::Int
end
# work around compiler error on 1.2
@static if v"1.2.0" <= VERSION < v"1.3"
getfile(ln) = begin
path = if isexpr(ln, :line)
String(ln.args[2])
else
try
file = String(ln.file)
isfile(file)
file
catch err
""
end
end
CodeTracking.maybe_fixup_stdlib_path(path)
end
else
function getfile(ln::Union{LineTypes,Expr})
_getfile(ln::LineTypes) = ln.file::Symbol
_getfile(ln::Expr) = ln.args[2]::Symbol # assuming ln.head === :line
return CodeTracking.maybe_fixup_stdlib_path(String(_getfile(ln)))
end
function getfile(ln::Union{LineTypes,Expr})
_getfile(ln::LineTypes) = ln.file::Symbol
_getfile(ln::Expr) = ln.args[2]::Symbol # assuming ln.head === :line
return CodeTracking.maybe_fixup_stdlib_path(String(_getfile(ln)))
end

function firstline(ex::Expr)
Expand Down Expand Up @@ -460,7 +427,7 @@ function framecode_lines(src::CodeInfo)
buf = IOBuffer()
if isdefined(Base.IRShow, :show_ir_stmt)
lines = String[]
src = replace_coretypes!(copy_codeinfo(src); rev=true)
src = replace_coretypes!(copy(src); rev=true)
reverse_lookup_globalref!(src.code)
io = IOContext(buf, :displaysize => displaysize(stdout),
:SOURCE_SLOTNAMES => Base.sourceinfo_slotnames(src))
Expand Down Expand Up @@ -497,7 +464,7 @@ function print_framecode(io::IO, framecode::FrameCode; pc=0, range=1:nstatements
offset = lineoffset(framecode)
ndline = isempty(lt) ? 0 : ndigits(getline(lt[end]) + offset)
nullline = " "^ndline
src = copy_codeinfo(framecode.src)
src = copy(framecode.src)
replace_coretypes!(src; rev=true)
code = framecode_lines(src)
isfirst = true
Expand Down Expand Up @@ -527,7 +494,7 @@ function locals(frame::Frame)
vars, var_counter = Variable[], Int[]
varlookup = Dict{Symbol,Int}()
data, code = frame.framedata, frame.framecode
slotnames = code.src.slotnames::SlotNamesType
slotnames = code.src.slotnames
for (sym, counter, val) in zip(slotnames, data.last_reference, data.locals)
counter == 0 && continue
val = something(val)
Expand Down Expand Up @@ -714,7 +681,7 @@ function Base.StackTraces.StackFrame(frame::Frame)
atypes = Tuple{mapany(_Typeof, method_args)...}
sig = method.sig
sparams = Core.svec(frame.framedata.sparams...)
mi = specialize_method(method, atypes, sparams)
mi = Core.Compiler.specialize_method(method, atypes, sparams)
fname = frame.framecode.scope.name
else
mi = frame.framecode.src
Expand Down
6 changes: 1 addition & 5 deletions test/breakpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,7 @@ empty!(breakpoint_update_hooks)
# breakpoint in top-level line
mod, ex = exprs[1]
frame = Frame(mod, ex)
if VERSION < v"1.2"
@test_broken JuliaInterpreter.shouldbreak(frame, frame.pc)
else
@test JuliaInterpreter.shouldbreak(frame, frame.pc)
end
@test JuliaInterpreter.shouldbreak(frame, frame.pc)
ret = JuliaInterpreter.finish_and_return!(frame, true)
@test ret === 2

Expand Down
18 changes: 8 additions & 10 deletions test/eval_code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,14 @@ fr, bp = debug_command(fr, :c)
eval_code(fr, "non_accessible_variable = 5.0")
@test eval_code(fr, "non_accessible_variable") == 5.0

if VERSION >= v"1.4" # for var"" syntax
# Evaluating SSAValues
f(x) = x^2
frame = JuliaInterpreter.enter_call(f, 5)
JuliaInterpreter.step_expr!(frame)
JuliaInterpreter.step_expr!(frame)
# This could change with changes to Julia lowering
@test eval_code(frame, "var\"%2\"") == Val(2)
@test eval_code(frame, "var\"@_1\"") == f
end
# Evaluating SSAValues
f(x) = x^2
frame = JuliaInterpreter.enter_call(f, 5)
JuliaInterpreter.step_expr!(frame)
JuliaInterpreter.step_expr!(frame)
# This could change with changes to Julia lowering
@test eval_code(frame, "var\"%2\"") == Val(2)
@test eval_code(frame, "var\"@_1\"") == f

function fun(;output=:sym)
x = 5
Expand Down
Loading

0 comments on commit 10fd8fc

Please sign in to comment.