Skip to content

Commit

Permalink
Handle world-age errors in incremental lowering
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Feb 11, 2019
1 parent 45c5368 commit 8683d6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,17 @@ function _step_expr!(stack, frame, @nospecialize(node), pc::JuliaProgramCounter,
rhs = @lookup(frame, node)
end
catch err
# Check for world age errors, which generally indicate a failure to go back to toplevel
if isa(err, MethodError)
is_arg_types = isa(err.args, DataType)
arg_types = is_arg_types ? err.args : Base.typesof(err.args...)
if (err.world != typemax(UInt) &&
hasmethod(err.f, arg_types) &&
!hasmethod(err.f, arg_types, world = err.world))
@warn "likely failure to return to toplevel, try Base.invokelatest"
rethrow(err)
end
end
isempty(frame.exception_frames) && rethrow(err)
frame.last_exception[] = err
return JuliaProgramCounter(frame.exception_frames[end])
Expand Down
12 changes: 7 additions & 5 deletions test/juliatests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ else
@warn "Julia's test/ directory not found, skipping Julia tests"
end

module JuliaTests end
module JuliaTests
using Test
end

@testset "Julia tests" begin
stack = JuliaStackFrame[]
function runtest(frame)
empty!(stack)
empty!(JuliaInterpreter.framedict)
empty!(JuliaInterpreter.genframedict)
# empty!(JuliaInterpreter.framedict)
# empty!(JuliaInterpreter.genframedict)
return JuliaInterpreter.finish_and_return!(stack, frame, true)
end
function dotest!(failed, test)
Expand All @@ -29,13 +31,13 @@ module JuliaTests end
if isexpr(ex, :error)
@warn "error parsing $test: $ex"
else
ex = Expr(:toplevel, :(using Test), ex)
try
lower_incrementally(runtest, JuliaTests, ex)
println("Succeeded on ", test)
catch err
@show test err
push!(failed, (test, err))
# rethrow(err)
end
end
end
Expand All @@ -44,7 +46,7 @@ module JuliaTests end
delayed = []
failed = []
for test in tests
if startswith(test, "compiler")
if startswith(test, "compiler") || test == "subarray"
push!(delayed, test)
else
dotest!(failed, test)
Expand Down
2 changes: 1 addition & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function lower!(@nospecialize(f), docexprs, mod::Module, ex::Expr)
lwr = Meta.lower(mod, ex)
if isexpr(lwr, :thunk)
frame = JuliaInterpreter.prepare_thunk(mod, lwr)
f(frame)
Base.invokelatest(f, frame) # if previous thunks define new methods, we need to update world age
elseif isa(lwr, Expr) && (lwr.head == :export || lwr.head == :using || lwr.head == :import)
elseif isa(lwr, Symbol) || isa(lwr, Nothing)
else
Expand Down

0 comments on commit 8683d6f

Please sign in to comment.