Skip to content

Commit

Permalink
undo breaking change of removing parent from CodeInfo
Browse files Browse the repository at this point in the history
The loss provided no value, as it is easy to provide this info, and has
downstream users as well as being documented for use.
  • Loading branch information
vtjnash committed Feb 21, 2024
1 parent 4e72944 commit f2c6334
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 17 deletions.
2 changes: 2 additions & 0 deletions base/compiler/ssair/legacy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Mainly used for testing or interactive use.
inflate_ir(ci::CodeInfo, linfo::MethodInstance) = inflate_ir!(copy(ci), linfo)
inflate_ir(ci::CodeInfo, sptypes::Vector{VarState}, argtypes::Vector{Any}) = inflate_ir!(copy(ci), sptypes, argtypes)
function inflate_ir(ci::CodeInfo)
parent = ci.parent
isa(parent, MethodInstance) && return inflate_ir(ci, parent)
# XXX the length of `ci.slotflags` may be different from the actual number of call
# arguments, but we really don't know that information in this case
argtypes = Any[ Any for i = 1:length(ci.slotflags) ]
Expand Down
1 change: 1 addition & 0 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ function codeinfo_for_const(interp::AbstractInterpreter, mi::MethodInstance, @no
tree.linetable = LineInfoNode[LineInfoNode(method.module, method.name, method.file, method.line, Int32(0))]
tree.ssaflags = UInt32[0]
set_inlineable!(tree, true)
tree.parent = mi
return tree
end

Expand Down
1 change: 1 addition & 0 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function retrieve_code_info(linfo::MethodInstance, world::UInt)
end
end
if c isa CodeInfo
c.parent = linfo
return c
end
return nothing
Expand Down
4 changes: 2 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,8 @@ uncompressed_ir(m::Method) = isdefined(m, :source) ? _uncompressed_ir(m, m.sourc
isdefined(m, :generator) ? error("Method is @generated; try `code_lowered` instead.") :
error("Code for this Method is not available.")
_uncompressed_ir(m::Method, s::CodeInfo) = copy(s)
_uncompressed_ir(m::Method, s::String) = ccall(:jl_uncompress_ir, Any, (Any, Any), m, s)::CodeInfo
_uncompressed_ir(ci::Core.CodeInstance, s::String) = ccall(:jl_uncompress_ir, Any, (Any, Any), ci.def.def::Method, s)::CodeInfo
_uncompressed_ir(m::Method, s::String) = ccall(:jl_uncompress_ir, Any, (Any, Ptr{Cvoid}, Any), m, C_NULL, s)::CodeInfo
_uncompressed_ir(ci::Core.CodeInstance, s::String) = ccall(:jl_uncompress_ir, Any, (Any, Any, Any), ci.def.def::Method, ci, s)::CodeInfo
# for backwards compat
const uncompressed_ast = uncompressed_ir
const _uncompressed_ast = _uncompressed_ir
Expand Down
6 changes: 3 additions & 3 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static void jl_ci_cache_lookup(const jl_cgparams_t &cgparams, jl_method_instance
if ((jl_value_t*)*src_out == jl_nothing)
*src_out = NULL;
if (*src_out && jl_is_method(def))
*src_out = jl_uncompress_ir(def, (jl_value_t*)*src_out);
*src_out = jl_uncompress_ir(def, codeinst, (jl_value_t*)*src_out);
}
if (*src_out == NULL || !jl_is_code_info(*src_out)) {
if (cgparams.lookup != jl_rettype_inferred_addr) {
Expand Down Expand Up @@ -1950,7 +1950,7 @@ extern "C" JL_DLLEXPORT_CODEGEN jl_code_info_t *jl_gdbdumpcode(jl_method_instanc
src = (jl_code_info_t*)jl_atomic_load_relaxed(&codeinst->inferred);
if ((jl_value_t*)src != jl_nothing && !jl_is_code_info(src) && jl_is_method(mi->def.method)) {
JL_GC_PUSH2(&codeinst, &src);
src = jl_uncompress_ir(mi->def.method, (jl_value_t*)src);
src = jl_uncompress_ir(mi->def.method, codeinst, (jl_value_t*)src);
JL_GC_POP();
}
}
Expand Down Expand Up @@ -1989,7 +1989,7 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, siz
}
if (src) {
if ((jl_value_t*)src != jl_nothing && !jl_is_code_info(src) && jl_is_method(mi->def.method))
src = jl_uncompress_ir(mi->def.method, (jl_value_t*)src);
src = jl_uncompress_ir(mi->def.method, codeinst, (jl_value_t*)src);
}

// emit this function into a new llvm module
Expand Down
4 changes: 2 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6015,7 +6015,7 @@ static std::pair<Function*, Function*> get_oc_function(jl_codectx_t &ctx, jl_met

if (it == ctx.emission_context.compiled_functions.end()) {
++EmittedOpaqueClosureFunctions;
jl_code_info_t *ir = jl_uncompress_ir(closure_method, (jl_value_t*)inferred);
jl_code_info_t *ir = jl_uncompress_ir(closure_method, ci, (jl_value_t*)inferred);
JL_GC_PUSH1(&ir);
// TODO: Emit this inline and outline it late using LLVM's coroutine support.
orc::ThreadSafeModule closure_m = jl_create_ts_module(
Expand Down Expand Up @@ -9570,7 +9570,7 @@ jl_llvm_functions_t jl_emit_codeinst(
return jl_emit_oc_wrapper(m, params, codeinst->def, codeinst->rettype);
}
if (src && (jl_value_t*)src != jl_nothing && jl_is_method(def))
src = jl_uncompress_ir(def, (jl_value_t*)src);
src = jl_uncompress_ir(def, codeinst, (jl_value_t*)src);
if (!src || !jl_is_code_info(src)) {
JL_GC_POP();
m = orc::ThreadSafeModule();
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ jl_code_info_t *jl_code_for_interpreter(jl_method_instance_t *mi, size_t world)
}
if (src && (jl_value_t*)src != jl_nothing) {
JL_GC_PUSH1(&src);
src = jl_uncompress_ir(mi->def.method, (jl_value_t*)src);
src = jl_uncompress_ir(mi->def.method, NULL, (jl_value_t*)src);
jl_atomic_store_release(&mi->uninferred, (jl_value_t*)src);
jl_gc_wb(mi, src);
JL_GC_POP();
Expand Down Expand Up @@ -758,7 +758,7 @@ JL_DLLEXPORT const jl_callptr_t jl_fptr_interpret_call_addr = &jl_fptr_interpret
jl_value_t *jl_interpret_opaque_closure(jl_opaque_closure_t *oc, jl_value_t **args, size_t nargs)
{
jl_method_t *source = oc->source;
jl_code_info_t *code = jl_uncompress_ir(source, (jl_value_t*)source->source);
jl_code_info_t *code = jl_uncompress_ir(source, NULL, (jl_value_t*)source->source);
interpreter_state *s;
unsigned nroots = jl_source_nslots(code) + jl_source_nssavalues(code) + 2;
jl_task_t *ct = jl_current_task;
Expand Down
5 changes: 4 additions & 1 deletion src/ircode.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code)
return v;
}

JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_string_t *data)
JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_code_instance_t *metadata, jl_string_t *data)
{
if (jl_is_code_info(data))
return (jl_code_info_t*)data;
Expand Down Expand Up @@ -969,6 +969,9 @@ JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_string_t *data)
jl_gc_enable(en);
JL_UNLOCK(&m->writelock); // Might GC
JL_GC_POP();
if (metadata) {
code->parent = metadata->def;
}

return code;
}
Expand Down
2 changes: 1 addition & 1 deletion src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ void jl_generate_fptr_for_unspecialized_impl(jl_code_instance_t *unspec)
if (jl_is_method(def)) {
src = (jl_code_info_t*)def->source;
if (src && (jl_value_t*)src != jl_nothing)
src = jl_uncompress_ir(def, (jl_value_t*)src);
src = jl_uncompress_ir(def, NULL, (jl_value_t*)src);
}
else {
src = (jl_code_info_t*)jl_atomic_load_relaxed(&unspec->def->uninferred);
Expand Down
8 changes: 5 additions & 3 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3142,7 +3142,7 @@ void jl_init_types(void) JL_GC_DISABLED
jl_code_info_type =
jl_new_datatype(jl_symbol("CodeInfo"), core,
jl_any_type, jl_emptysvec,
jl_perm_symsvec(19,
jl_perm_symsvec(20,
"code",
"codelocs",
"ssavaluetypes",
Expand All @@ -3151,6 +3151,7 @@ void jl_init_types(void) JL_GC_DISABLED
"slotnames",
"slotflags",
"slottypes",
"parent",
"method_for_inference_limit_heuristics",
"edges",
"min_world",
Expand All @@ -3162,7 +3163,7 @@ void jl_init_types(void) JL_GC_DISABLED
"constprop",
"purity",
"inlining_cost"),
jl_svec(19,
jl_svec(20,
jl_array_any_type,
jl_array_int32_type,
jl_any_type,
Expand All @@ -3173,6 +3174,7 @@ void jl_init_types(void) JL_GC_DISABLED
jl_any_type,
jl_any_type,
jl_any_type,
jl_any_type,
jl_ulong_type,
jl_ulong_type,
jl_bool_type,
Expand All @@ -3183,7 +3185,7 @@ void jl_init_types(void) JL_GC_DISABLED
jl_uint16_type,
jl_uint16_type),
jl_emptysvec,
0, 1, 19);
0, 1, 20);

jl_method_type =
jl_new_datatype(jl_symbol("Method"), core,
Expand Down
3 changes: 2 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ typedef struct _jl_code_info_t {
jl_array_t *slotflags; // local var bit flags
// the following are optional transient properties (not preserved by compression--as they typically get stored elsewhere):
jl_value_t *slottypes; // inferred types of slots
jl_method_instance_t *parent; // context (after inference, otherwise nothing)

// These may be used by generated functions to further constrain the resulting inputs.
// They are not used by any other part of the system and may be moved elsewhere in the
Expand Down Expand Up @@ -2134,7 +2135,7 @@ JL_DLLEXPORT jl_value_t *jl_copy_ast(jl_value_t *expr JL_MAYBE_UNROOTED);

// IR representation
JL_DLLEXPORT jl_value_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code);
JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_value_t *data);
JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_code_instance_t *metadata, jl_value_t *data);
JL_DLLEXPORT uint8_t jl_ir_flag_inlining(jl_value_t *data) JL_NOTSAFEPOINT;
JL_DLLEXPORT uint8_t jl_ir_flag_has_fcall(jl_value_t *data) JL_NOTSAFEPOINT;
JL_DLLEXPORT uint16_t jl_ir_inlining_cost(jl_value_t *data) JL_NOTSAFEPOINT;
Expand Down
1 change: 1 addition & 0 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ JL_DLLEXPORT jl_code_info_t *jl_new_code_info_uninit(void)
src->slotflags = NULL;
src->slotnames = NULL;
src->slottypes = jl_nothing;
src->parent = (jl_method_instance_t*)jl_nothing;
src->min_world = 1;
src->max_world = ~(size_t)0;
src->edges = jl_nothing;
Expand Down
2 changes: 1 addition & 1 deletion src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2344,7 +2344,7 @@ static jl_value_t *strip_codeinfo_meta(jl_method_t *m, jl_value_t *ci_, int orig
int compressed = 0;
if (!jl_is_code_info(ci_)) {
compressed = 1;
ci = jl_uncompress_ir(m, (jl_value_t*)ci_);
ci = jl_uncompress_ir(m, NULL, (jl_value_t*)ci_);
}
else {
ci = (jl_code_info_t*)ci_;
Expand Down
3 changes: 2 additions & 1 deletion stdlib/Serialization/src/Serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ function deserialize(s::AbstractSerializer, ::Type{CodeInfo})
ci.slottypes = deserialize(s)
if format_version(s) <= 26
deserialize(s) # rettype
deserialize(s) # parent
ci.parent = deserialize(s)
world_or_edges = deserialize(s)
pre_13 = isa(world_or_edges, Integer)
if pre_13
Expand All @@ -1223,6 +1223,7 @@ function deserialize(s::AbstractSerializer, ::Type{CodeInfo})
ci.max_world = reinterpret(UInt, deserialize(s))
end
else
ci.parent = deserialize(s)
ci.method_for_inference_limit_heuristics = deserialize(s)
ci.edges = deserialize(s)
ci.min_world = reinterpret(UInt, deserialize(s))
Expand Down

0 comments on commit f2c6334

Please sign in to comment.