Skip to content
Merged
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
15 changes: 6 additions & 9 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,21 +547,18 @@ void jl_generate_fptr_for_unspecialized_impl(jl_code_instance_t *unspec)
jl_method_t *def = unspec->def->def.method;
if (jl_is_method(def)) {
src = (jl_code_info_t*)def->source;
if (src == NULL) {
// TODO: this is wrong
assert(def->generator);
// TODO: jl_code_for_staged can throw
src = jl_code_for_staged(unspec->def, ~(size_t)0);
}
if (src && (jl_value_t*)src != jl_nothing)
src = jl_uncompress_ir(def, NULL, (jl_value_t*)src);
}
else {
src = (jl_code_info_t*)jl_atomic_load_relaxed(&unspec->def->uninferred);
assert(src);
}
if (src) {
assert(jl_is_code_info(src));
++UnspecFPtrCount;
_jl_compile_codeinst(unspec, src, unspec->min_world, *jl_ExecutionEngine->getContext(), 0);
}
assert(src && jl_is_code_info(src));
++UnspecFPtrCount;
_jl_compile_codeinst(unspec, src, unspec->min_world, *jl_ExecutionEngine->getContext(), 0);
jl_callptr_t null = nullptr;
// if we hit a codegen bug (or ran into a broken generated function or llvmcall), fall back to the interpreter as a last resort
jl_atomic_cmpswap(&unspec->invoke, &null, jl_fptr_interpret_call_addr);
Expand Down
19 changes: 19 additions & 0 deletions test/compiler/contextual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,22 @@ finally
@show err
end
end

# Test that writing a bad cassette-style pass gives the expected error (#49715)
function generator49715(world, source, self, f, tt)
tt = tt.parameters[1]
sig = Tuple{f, tt.parameters...}
mi = Base._which(sig; world)

error("oh no")

stub = Core.GeneratedFunctionStub(identity, Core.svec(:methodinstance, :ctx, :x, :f), Core.svec())
stub(world, source, :(nothing))
end

@eval function doit49715(f, tt)
$(Expr(:meta, :generated, generator49715))
$(Expr(:meta, :generated_only))
end

@test_throws "oh no" doit49715(sin, Tuple{Int})
2 changes: 1 addition & 1 deletion test/staged.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ let gf_err, tsk = @async nothing # create a Task for yield to try to run
Expected = ErrorException("task switch not allowed from inside staged nor pure functions")
@test_throws Expected gf_err()
@test_throws Expected gf_err()
@test gf_err_ref[] == 4
@test gf_err_ref[] < 1000
end

gf_err_ref[] = 0
Expand Down