Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn Method Overwritten Error into a PrecompileError -- turning off caching #52214

Merged
merged 5 commits into from
Nov 24, 2023
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
2 changes: 2 additions & 0 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ struct InitError <: WrappedException
error
end

struct PrecompilableError <: Exception end

String(s::String) = s # no constructor yet

const Cvoid = Nothing
Expand Down
2 changes: 1 addition & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ function include_dependency(path::AbstractString)
end

# we throw PrecompilableError when a module doesn't want to be precompiled
struct PrecompilableError <: Exception end
import Core: PrecompilableError
function show(io::IO, ex::PrecompilableError)
print(io, "Error when precompiling module, potentially caused by a __precompile__(false) declaration in the module.")
end
Expand Down
6 changes: 4 additions & 2 deletions src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1572,8 +1572,10 @@ static void method_overwrite(jl_typemap_entry_t *newentry, jl_method_t *oldvalue
jl_printf(s, ".\n");
jl_uv_flush(s);
}
if (jl_generating_output())
jl_error("Method overwriting is not permitted during Module precompile.");
if (jl_generating_output()) {
jl_printf(JL_STDERR, "ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.\n");
jl_throw(jl_precompilable_error);
}
}

static void update_max_args(jl_methtable_t *mt, jl_value_t *type)
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 @@ -145,6 +145,7 @@
XX(jl_weakref_type) \
XX(jl_libdl_module) \
XX(jl_libdl_dlopen_func) \
XX(jl_precompilable_error) \

// Data symbols that are defined inside the public libjulia
#define JL_EXPORTED_DATA_SYMBOLS(XX) \
Expand Down
1 change: 1 addition & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3510,6 +3510,7 @@ void post_boot_hooks(void)
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_precompilable_error = jl_new_struct_uninit((jl_datatype_t*)core("PrecompilableError"));
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 @@ -837,6 +837,7 @@ extern JL_DLLIMPORT jl_value_t *jl_readonlymemory_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_diverror_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_undefref_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_interrupt_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_precompilable_error JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_boundserror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_an_empty_vec_any JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_an_empty_memory_any 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 @@ -98,7 +98,7 @@ extern "C" {
// TODO: put WeakRefs on the weak_refs list during deserialization
// TODO: handle finalizers

#define NUM_TAGS 174
#define NUM_TAGS 175

// 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_readonlymemory_exception);
INSERT_TAG(jl_atomicerror_type);
INSERT_TAG(jl_missingcodeerror_type);
INSERT_TAG(jl_precompilable_error);

// other special values
INSERT_TAG(jl_emptysvec);
Expand Down
10 changes: 10 additions & 0 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,16 @@ precompile_test_harness(false) do dir

@test Base.compilecache(Base.PkgId("Baz")) == Base.PrecompilableError() # due to __precompile__(false)

OverwriteMethodError_file = joinpath(dir, "OverwriteMethodError.jl")
write(OverwriteMethodError_file,
"""
module OverwriteMethodError
Base.:(+)(x::Bool, y::Bool) = false
end
""")

@test Base.compilecache(Base.PkgId("OverwriteMethodError")) == Base.PrecompilableError() # due to piracy
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is noisy during CI:

precompile                                       (1) |        started at 2023-11-25T02:42:26.767
WARNING: Method definition +(Bool, Bool) in module Base at bool.jl:166 overwritten in module OverwriteMethodError at C:\Users\julia\AppData\Local\Temp\jl_shtGYs\OverwriteMethodError.jl:2.
ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.

(needs @test_warn)


UseBaz_file = joinpath(dir, "UseBaz.jl")
write(UseBaz_file,
"""
Expand Down