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
4 changes: 3 additions & 1 deletion Compiler/src/Compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ using Base: @_foldable_meta, @_gc_preserve_begin, @_gc_preserve_end, @nospeciali
structdiff, tls_world_age, unconstrain_vararg_length, unionlen, uniontype_layout,
uniontypes, unsafe_convert, unwrap_unionall, unwrapva, vect, widen_diagonal,
_uncompressed_ir, maybe_add_binding_backedge!, datatype_min_ninitialized,
partialstruct_init_undefs, fieldcount_noerror, _eval_import, _eval_using
partialstruct_init_undefs, fieldcount_noerror, _eval_import, _eval_using,
get_ci_mi

using Base.Order

import Base: ==, _topmod, append!, convert, copy, copy!, findall, first, get, get!,
Expand Down
6 changes: 0 additions & 6 deletions Compiler/src/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2221,12 +2221,6 @@ function get_ci_abi(ci::CodeInstance)
(def::MethodInstance).specTypes
end

function get_ci_mi(ci::CodeInstance)
def = ci.def
isa(def, ABIOverride) && return def.def
return def::MethodInstance
end

function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::StmtInfo, sv::AbsIntState)
argtypes = arginfo.argtypes
ft′ = argtype_by_index(argtypes, 2)
Expand Down
2 changes: 1 addition & 1 deletion base/invalidation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ invalidate_code_for_globalref!(gr::GlobalRef, invalidated_bpart::Core.BindingPar
invalidate_code_for_globalref!(convert(Core.Binding, gr), invalidated_bpart, new_bpart, new_max_world)

function maybe_add_binding_backedge!(b::Core.Binding, edge::Union{Method, CodeInstance})
meth = isa(edge, Method) ? edge : Compiler.get_ci_mi(edge).def
meth = isa(edge, Method) ? edge : get_ci_mi(edge).def
ccall(:jl_maybe_add_binding_backedge, Cint, (Any, Any, Any), b, edge, meth)
return nothing
end
Expand Down
9 changes: 9 additions & 0 deletions base/runtime_internals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,15 @@ end
_uncompressed_ir(codeinst::CodeInstance, s::String) =
ccall(:jl_uncompress_ir, Ref{CodeInfo}, (Any, Any, Any), codeinst.def.def::Method, codeinst, s)

function get_ci_mi(codeinst::CodeInstance)
def = codeinst.def
if def isa Core.ABIOverride
return def.def
else
return def::MethodInstance
end
end

"""
Base.generating_output([incremental::Bool])::Bool

Expand Down
12 changes: 11 additions & 1 deletion base/stacktraces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,12 @@ function show_spec_linfo(io::IO, frame::StackFrame)
if linfo isa Union{MethodInstance, CodeInstance}
def = frame_method_or_module(frame)
if def isa Module
Base.show_mi(io, linfo, #=from_stackframe=#true)
Base.show_mi(io, linfo::MethodInstance, #=from_stackframe=#true)
elseif linfo isa CodeInstance && linfo.owner !== nothing
show_custom_spec_sig(io, linfo.owner, linfo, frame)
else
# Equivalent to the default implementation of `show_custom_spec_sig`
# for `linfo isa CodeInstance`, but saves an extra dynamic dispatch.
show_spec_sig(io, def, frame_mi(frame).specTypes)
end
else
Expand All @@ -284,6 +288,12 @@ function show_spec_linfo(io::IO, frame::StackFrame)
end
end

# Can be extended by compiler packages to customize backtrace display of custom code instance frames
function show_custom_spec_sig(io::IO, @nospecialize(owner), linfo::CodeInstance, frame::StackFrame)
mi = get_ci_mi(linfo)
return show_spec_sig(io, mi.def, mi.specTypes)
end

function show_spec_sig(io::IO, m::Method, @nospecialize(sig::Type))
if get(io, :limit, :false)::Bool
if !haskey(io, :displaysize)
Expand Down
11 changes: 1 addition & 10 deletions base/staticdata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@
module StaticData

using .Core: CodeInstance, MethodInstance
using .Base: JLOptions, Compiler, get_world_counter, _methods_by_ftype, get_methodtable
using .Base: JLOptions, Compiler, get_world_counter, _methods_by_ftype, get_methodtable, get_ci_mi

const WORLD_AGE_REVALIDATION_SENTINEL::UInt = 1
const _jl_debug_method_invalidation = Ref{Union{Nothing,Vector{Any}}}(nothing)
debug_method_invalidation(onoff::Bool) =
_jl_debug_method_invalidation[] = onoff ? Any[] : nothing

function get_ci_mi(codeinst::CodeInstance)
def = codeinst.def
if def isa Core.ABIOverride
return def.def
else
return def::MethodInstance
end
end

# Restore backedges to external targets
# `edges` = [caller1, ...], the list of worklist-owned code instances internally
# `ext_ci_list` = [caller1, ...], the list of worklist-owned code instances externally
Expand Down
7 changes: 7 additions & 0 deletions contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ precompile(Base.CoreLogging.current_logger_for_env, (Base.CoreLogging.LogLevel,
precompile(Base.CoreLogging.env_override_minlevel, (Symbol, Module))
precompile(Base.StackTraces.lookup, (Ptr{Nothing},))
precompile(Tuple{typeof(Base.run_module_init), Module, Int})
precompile(Tuple{Type{Base.VersionNumber}, Int32, Int32, Int32})

# Presence tested in the tests
precompile(Tuple{typeof(Base.print), Base.IOStream, String})
Expand Down Expand Up @@ -140,6 +141,9 @@ for match = Base._methods(+, (Int, Int), -1, Base.get_world_counter())
end
empty!(Set())
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
get!(ENV, "___DUMMY", "")
ENV["___DUMMY"]
delete!(ENV, "___DUMMY")
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
Expand Down Expand Up @@ -209,6 +213,9 @@ if Artifacts !== nothing
end
dlopen("libjulia$(Base.isdebugbuild() ? "-debug" : "")", RTLD_LAZY | RTLD_DEEPBIND)
"""
hardcoded_precompile_statements *= """
precompile(Tuple{typeof(Artifacts._artifact_str), Module, String, Base.SubString{String}, String, Base.Dict{String, Any}, Base.SHA1, Base.BinaryPlatforms.Platform, Base.Val{Artifacts}})
"""
end

FileWatching = get(Base.loaded_modules,
Expand Down
14 changes: 8 additions & 6 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4990,8 +4990,10 @@ static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, bool is_opaque_clos
}
jl_value_t *jt = jl_nth_slot_type(specTypes, i);
jl_cgval_t arg = update_julia_type(ctx, argv[i], jt);
if (arg.typ == jl_bottom_type)
if (arg.typ == jl_bottom_type) {
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Argument type mismatch in Expr(:invoke)");
return jl_cgval_t();
}
if (is_uniquerep_Type(jt)) {
continue;
}
Expand Down Expand Up @@ -5028,7 +5030,7 @@ static jl_cgval_t emit_call_specfun_other(jl_codectx_t &ctx, bool is_opaque_clos
Value *val = emit_unbox(ctx, et, arg, jt);
if (!val) {
// There was a type mismatch of some sort - exit early
CreateTrap(ctx.builder);
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Argument type mismatch in Expr(:invoke)");
return jl_cgval_t();
}
argvals[idx] = val;
Expand Down Expand Up @@ -5295,7 +5297,7 @@ static jl_cgval_t emit_invoke(jl_codectx_t &ctx, const jl_cgval_t &lival, ArrayR
}
if (result.typ == jl_bottom_type) {
#ifndef JL_NDEBUG
emit_error(ctx, "(Internal Error - IR Validity): Returned from function we expected not to.");
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Returned from function we expected not to.");
#endif
CreateTrap(ctx.builder);
}
Expand Down Expand Up @@ -5647,7 +5649,7 @@ static jl_cgval_t emit_local(jl_codectx_t &ctx, jl_value_t *slotload)
if (sym == jl_unused_sym) {
// This shouldn't happen in well-formed input, but let's be robust,
// since we otherwise cause undefined behavior here.
emit_error(ctx, "(INTERNAL ERROR): Tried to use `#undef#` argument.");
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Tried to use `#undef#` argument.");
return jl_cgval_t();
}
return emit_varinfo(ctx, vi, sym);
Expand Down Expand Up @@ -6494,7 +6496,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaidx_
if (source.constant == NULL) {
// For now, we require non-constant source to be handled by using
// eval. This should probably be a verifier error and an abort here.
emit_error(ctx, "(internal error) invalid IR: opaque closure source must be constant");
emit_error(ctx, "(INTERNAL ERROR - IR Validity): opaque closure source must be constant");
return jl_cgval_t();
}
bool can_optimize = argt.constant != NULL && lb.constant != NULL && ub.constant != NULL &&
Expand Down Expand Up @@ -9380,7 +9382,7 @@ static jl_llvm_functions_t
// Probably dead code, but let's be loud about it in case it isn't, so we fail
// at the point of the miscompile, rather than later when something attempts to
// read the scope.
emit_error(ctx, "(INTERNAL ERROR): Attempted to execute EnterNode with bad scope");
emit_error(ctx, "(INTERNAL ERROR - IR Validity): Attempted to execute EnterNode with bad scope");
find_next_stmt(-1);
continue;
}
Expand Down