Skip to content

Commit

Permalink
add an exception type for missing IR (#52121)
Browse files Browse the repository at this point in the history
This makes it possible to suppress the output and easier to catch the
exception if a deployed application hits this situation.
  • Loading branch information
JeffBezanson authored Nov 13, 2023
1 parent 6d5787a commit 9754dbb
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ end
struct ConcurrencyViolationError <: Exception
msg::AbstractString
end
struct MissingCodeError <: Exception
mi::MethodInstance
end
struct InterruptException <: Exception end
struct DomainError <: Exception
val
Expand Down
2 changes: 1 addition & 1 deletion src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@ JL_CALLABLE(jl_f_intrinsic_call)
f = cglobal_auto;
unsigned fargs = intrinsic_nargs[f];
if (!fargs)
jl_errorf("`%s` must be compiled to be called", jl_intrinsic_name(f));
jl_errorf("`%s` requires the compiler", jl_intrinsic_name(f));
JL_NARGS(intrinsic_call, fargs, fargs);

union {
Expand Down
7 changes: 2 additions & 5 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
return codeinst;
}
if (compile_option == JL_OPTIONS_COMPILE_OFF) {
jl_printf(JL_STDERR, "code missing for ");
jl_printf(JL_STDERR, "No compiled code available for ");
jl_static_show(JL_STDERR, (jl_value_t*)mi);
jl_printf(JL_STDERR, " : sysimg may not have been built with --compile=all\n");
}
Expand All @@ -2505,10 +2505,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
if (ucache_invoke == NULL) {
if (def->source == jl_nothing && (jl_atomic_load_relaxed(&ucache->def->uninferred) == jl_nothing ||
jl_atomic_load_relaxed(&ucache->def->uninferred) == NULL)) {
jl_printf(JL_STDERR, "source not available for ");
jl_static_show(JL_STDERR, (jl_value_t*)mi);
jl_printf(JL_STDERR, "\n");
jl_error("source missing for method that needs to be compiled");
jl_throw(jl_new_struct(jl_missingcodeerror_type, (jl_value_t*)mi));
}
jl_generate_fptr_for_unspecialized(ucache);
ucache_invoke = jl_atomic_load_acquire(&ucache->invoke);
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ jl_code_info_t *jl_code_for_interpreter(jl_method_instance_t *mi, size_t world)
}
}
if (!src || !jl_is_code_info(src)) {
jl_error("source missing for method called in interpreter");
jl_throw(jl_new_struct(jl_missingcodeerror_type, (jl_value_t*)mi));
}
return src;
}
Expand Down
1 change: 1 addition & 0 deletions src/jl_exported_data.inc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
XX(jl_method_match_type) \
XX(jl_method_type) \
XX(jl_methtable_type) \
XX(jl_missingcodeerror_type) \
XX(jl_module_type) \
XX(jl_n_threads_per_pool) \
XX(jl_namedtuple_type) \
Expand Down
1 change: 1 addition & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3507,6 +3507,7 @@ void post_boot_hooks(void)
jl_methoderror_type = (jl_datatype_t*)core("MethodError");
jl_loaderror_type = (jl_datatype_t*)core("LoadError");
jl_initerror_type = (jl_datatype_t*)core("InitError");
jl_missingcodeerror_type = (jl_datatype_t*)core("MissingCodeError");
jl_pair_type = core("Pair");
jl_kwcall_func = core("kwcall");
jl_kwcall_mt = ((jl_datatype_t*)jl_typeof(jl_kwcall_func))->name->mt;
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ extern JL_DLLIMPORT jl_datatype_t *jl_typeerror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_methoderror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_undefvarerror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_atomicerror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_missingcodeerror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_lineinfonode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_stackovf_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_memory_exception JL_GLOBALLY_ROOTED;
Expand Down
3 changes: 2 additions & 1 deletion src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ extern "C" {
// TODO: put WeakRefs on the weak_refs list during deserialization
// TODO: handle finalizers

#define NUM_TAGS 173
#define NUM_TAGS 174

// An array of references that need to be restored from the sysimg
// This is a manually constructed dual of the gvars array, which would be produced by codegen for Julia code, for C.
Expand Down Expand Up @@ -237,6 +237,7 @@ jl_value_t **const*const get_tags(void) {
INSERT_TAG(jl_undefref_exception);
INSERT_TAG(jl_readonlymemory_exception);
INSERT_TAG(jl_atomicerror_type);
INSERT_TAG(jl_missingcodeerror_type);

// other special values
INSERT_TAG(jl_emptysvec);
Expand Down

0 comments on commit 9754dbb

Please sign in to comment.