Skip to content

Commit 55cbd3d

Browse files
committed
CodeInstance: remove relocatability field
This field lost its meaning awhile back and is better tracked only as part of the compressed CodeInfo instead of trying to accurately copy and update this field.
1 parent a23a6de commit 55cbd3d

File tree

13 files changed

+41
-75
lines changed

13 files changed

+41
-75
lines changed

Compiler/src/typeinfer.jl

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState)
120120
end
121121
inferred_result = nothing
122122
uncompressed = inferred_result
123-
relocatability = 0x1
124123
const_flag = is_result_constabi_eligible(result)
125124
discard_src = caller.cache_mode === CACHE_MODE_NULL || const_flag
126125
if !discard_src
@@ -139,22 +138,14 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState)
139138
elseif ci.owner === nothing
140139
# The global cache can only handle objects that codegen understands
141140
inferred_result = nothing
142-
else
143-
relocatability = 0x0
144-
end
145-
if isa(inferred_result, String)
146-
t = @_gc_preserve_begin inferred_result
147-
relocatability = unsafe_load(unsafe_convert(Ptr{UInt8}, inferred_result), Core.sizeof(inferred_result))
148-
@_gc_preserve_end t
149141
end
150142
end
151-
# n.b. relocatability = !isa(inferred_result, String) || inferred_result[end]
152143
if !@isdefined di
153144
di = DebugInfo(result.linfo)
154145
end
155-
ccall(:jl_update_codeinst, Cvoid, (Any, Any, Int32, UInt, UInt, UInt32, Any, UInt8, Any, Any),
146+
ccall(:jl_update_codeinst, Cvoid, (Any, Any, Int32, UInt, UInt, UInt32, Any, Any, Any),
156147
ci, inferred_result, const_flag, first(result.valid_worlds), last(result.valid_worlds), encode_effects(result.ipo_effects),
157-
result.analysis_results, relocatability, di, edges)
148+
result.analysis_results, di, edges)
158149
engine_reject(interp, ci)
159150
if !discard_src && isdefined(interp, :codegen) && uncompressed isa CodeInfo
160151
# record that the caller could use this result to generate code when required, if desired, to avoid repeating n^2 work
@@ -176,7 +167,6 @@ end
176167
function finish!(interp::AbstractInterpreter, mi::MethodInstance, ci::CodeInstance, src::CodeInfo)
177168
user_edges = src.edges
178169
edges = user_edges isa SimpleVector ? user_edges : user_edges === nothing ? Core.svec() : Core.svec(user_edges...)
179-
relocatability = 0x1
180170
const_flag = false
181171
di = src.debuginfo
182172
rettype = Any
@@ -196,8 +186,8 @@ function finish!(interp::AbstractInterpreter, mi::MethodInstance, ci::CodeInstan
196186
end
197187
ccall(:jl_fill_codeinst, Cvoid, (Any, Any, Any, Any, Int32, UInt, UInt, UInt32, Any, Any, Any),
198188
ci, rettype, exctype, nothing, const_flags, min_world, max_world, ipo_effects, nothing, di, edges)
199-
ccall(:jl_update_codeinst, Cvoid, (Any, Any, Int32, UInt, UInt, UInt32, Any, UInt8, Any, Any),
200-
ci, nothing, const_flag, min_world, max_world, ipo_effects, nothing, relocatability, di, edges)
189+
ccall(:jl_update_codeinst, Cvoid, (Any, Any, Int32, UInt, UInt, UInt32, Any, Any, Any),
190+
ci, nothing, const_flag, min_world, max_world, ipo_effects, nothing, di, edges)
201191
code_cache(interp)[mi] = ci
202192
if isdefined(interp, :codegen)
203193
interp.codegen[ci] = src
@@ -523,7 +513,6 @@ function finishinfer!(me::InferenceState, interp::AbstractInterpreter)
523513
rettype_const = nothing
524514
const_flags = 0x0
525515
end
526-
relocatability = 0x1
527516
di = nothing
528517
edges = empty_edges # `edges` will be updated within `finish!`
529518
ci = result.ci
@@ -827,7 +816,7 @@ function codeinst_as_edge(interp::AbstractInterpreter, sv::InferenceState, @nosp
827816
end
828817
end
829818
ci = CodeInstance(mi, cache_owner(interp), Any, Any, nothing, nothing, zero(Int32),
830-
min_world, max_world, zero(UInt32), nothing, zero(UInt8), nothing, edges)
819+
min_world, max_world, zero(UInt32), nothing, nothing, edges)
831820
if max_world == typemax(UInt)
832821
# if we can record all of the backedges in the global reverse-cache,
833822
# we can now widen our applicability in the global cache too

Compiler/test/abioverride.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let world = Base.tls_world_age()
4646
#=owner=#SecondArgConstOverride(1), new_source.rettype, Any#=new_source.exctype is missing=#,
4747
#=inferred_const=#nothing, #=code=#nothing, #=const_flags=#Int32(0),
4848
new_source.min_world, new_source.max_world, #=new_source.ipo_purity_bits is missing=#UInt32(0),
49-
#=analysis_results=#nothing, #=not relocatable?=#UInt8(0), new_source.debuginfo, new_source.edges)
49+
#=analysis_results=#nothing, new_source.debuginfo, new_source.edges)
5050

5151
# Poke the CI into the global cache
5252
# This isn't necessary, but does conveniently give it the mandatory permanent GC-root before calling `invoke`

base/boot.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,11 @@ function CodeInstance(
561561
mi::Union{MethodInstance, ABIOverride}, owner, @nospecialize(rettype), @nospecialize(exctype), @nospecialize(inferred_const),
562562
@nospecialize(inferred), const_flags::Int32, min_world::UInt, max_world::UInt,
563563
effects::UInt32, @nospecialize(analysis_results),
564-
relocatability::UInt8, di::Union{DebugInfo,Nothing}, edges::SimpleVector)
564+
di::Union{DebugInfo,Nothing}, edges::SimpleVector)
565565
return ccall(:jl_new_codeinst, Ref{CodeInstance},
566-
(Any, Any, Any, Any, Any, Any, Int32, UInt, UInt, UInt32, Any, UInt8, Any, Any),
566+
(Any, Any, Any, Any, Any, Any, Int32, UInt, UInt, UInt32, Any, Any, Any),
567567
mi, owner, rettype, exctype, inferred_const, inferred, const_flags, min_world, max_world,
568-
effects, analysis_results, relocatability, di, edges)
568+
effects, analysis_results, di, edges)
569569
end
570570
GlobalRef(m::Module, s::Symbol) = ccall(:jl_module_globalref, Ref{GlobalRef}, (Any, Any), m, s)
571571
Module(name::Symbol=:anonymous, std_imports::Bool=true, default_names::Bool=true) = ccall(:jl_f_new_module, Ref{Module}, (Any, Bool, Bool), name, std_imports, default_names)

src/gf.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ jl_datatype_t *jl_mk_builtin_func(jl_datatype_t *dt, const char *name, jl_fptr_a
323323

324324
jl_code_instance_t *codeinst = jl_new_codeinst(mi, jl_nothing,
325325
(jl_value_t*)jl_any_type, (jl_value_t*)jl_any_type, jl_nothing, jl_nothing,
326-
0, 1, ~(size_t)0, 0, jl_nothing, 0, NULL, NULL);
326+
0, 1, ~(size_t)0, 0, jl_nothing, NULL, NULL);
327327
jl_mi_cache_insert(mi, codeinst);
328328
jl_atomic_store_relaxed(&codeinst->specptr.fptr1, fptr);
329329
jl_atomic_store_relaxed(&codeinst->invoke, jl_fptr_args);
@@ -564,7 +564,7 @@ JL_DLLEXPORT jl_code_instance_t *jl_get_method_inferred(
564564
}
565565
codeinst = jl_new_codeinst(
566566
mi, owner, rettype, (jl_value_t*)jl_any_type, NULL, NULL,
567-
0, min_world, max_world, 0, jl_nothing, 0, di, edges);
567+
0, min_world, max_world, 0, jl_nothing, di, edges);
568568
jl_mi_cache_insert(mi, codeinst);
569569
return codeinst;
570570
}
@@ -614,7 +614,6 @@ JL_DLLEXPORT jl_code_instance_t *jl_new_codeinst(
614614
jl_value_t *inferred_const, jl_value_t *inferred,
615615
int32_t const_flags, size_t min_world, size_t max_world,
616616
uint32_t effects, jl_value_t *analysis_results,
617-
uint8_t relocatability,
618617
jl_debuginfo_t *di, jl_svec_t *edges /*, int absolute_max*/)
619618
{
620619
assert(min_world <= max_world && "attempting to set invalid world constraints");
@@ -645,19 +644,17 @@ JL_DLLEXPORT jl_code_instance_t *jl_new_codeinst(
645644
jl_atomic_store_relaxed(&codeinst->next, NULL);
646645
jl_atomic_store_relaxed(&codeinst->ipo_purity_bits, effects);
647646
codeinst->analysis_results = analysis_results;
648-
codeinst->relocatability = relocatability;
649647
return codeinst;
650648
}
651649

652650
JL_DLLEXPORT void jl_update_codeinst(
653651
jl_code_instance_t *codeinst, jl_value_t *inferred,
654652
int32_t const_flags, size_t min_world, size_t max_world,
655653
uint32_t effects, jl_value_t *analysis_results,
656-
uint8_t relocatability, jl_debuginfo_t *di, jl_svec_t *edges /* , int absolute_max*/)
654+
jl_debuginfo_t *di, jl_svec_t *edges /* , int absolute_max*/)
657655
{
658656
assert(min_world <= max_world && "attempting to set invalid world constraints");
659657
//assert((!jl_is_method(codeinst->def->def.value) || max_world != ~(size_t)0 || min_world <= 1 || jl_svec_len(edges) != 0) && "missing edges");
660-
codeinst->relocatability = relocatability;
661658
codeinst->analysis_results = analysis_results;
662659
jl_gc_wb(codeinst, analysis_results);
663660
jl_atomic_store_relaxed(&codeinst->ipo_purity_bits, effects);
@@ -715,7 +712,7 @@ JL_DLLEXPORT void jl_fill_codeinst(
715712

716713
JL_DLLEXPORT jl_code_instance_t *jl_new_codeinst_uninit(jl_method_instance_t *mi, jl_value_t *owner)
717714
{
718-
jl_code_instance_t *codeinst = jl_new_codeinst(mi, owner, NULL, NULL, NULL, NULL, 0, 0, 0, 0, NULL, 0, NULL, NULL);
715+
jl_code_instance_t *codeinst = jl_new_codeinst(mi, owner, NULL, NULL, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL);
719716
jl_atomic_store_relaxed(&codeinst->min_world, 1); // make temporarily invalid before returning, so that jl_fill_codeinst is valid later
720717
return codeinst;
721718
}
@@ -2908,7 +2905,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
29082905
jl_read_codeinst_invoke(unspec, &specsigflags, &invoke, &fptr, 1);
29092906
jl_code_instance_t *codeinst = jl_new_codeinst(mi, jl_nothing,
29102907
(jl_value_t*)jl_any_type, (jl_value_t*)jl_any_type, NULL, NULL,
2911-
0, 1, ~(size_t)0, 0, jl_nothing, 0, NULL, NULL);
2908+
0, 1, ~(size_t)0, 0, jl_nothing, NULL, NULL);
29122909
codeinst->rettype_const = unspec->rettype_const;
29132910
jl_atomic_store_relaxed(&codeinst->specptr.fptr, fptr);
29142911
jl_atomic_store_relaxed(&codeinst->invoke, invoke);
@@ -2929,7 +2926,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
29292926
if (!jl_code_requires_compiler(src, 0)) {
29302927
jl_code_instance_t *codeinst = jl_new_codeinst(mi, jl_nothing,
29312928
(jl_value_t*)jl_any_type, (jl_value_t*)jl_any_type, NULL, NULL,
2932-
0, 1, ~(size_t)0, 0, jl_nothing, 0, NULL, NULL);
2929+
0, 1, ~(size_t)0, 0, jl_nothing, NULL, NULL);
29332930
jl_atomic_store_release(&codeinst->invoke, jl_fptr_interpret_call);
29342931
jl_mi_cache_insert(mi, codeinst);
29352932
record_precompile_statement(mi, 0, 0);
@@ -3019,7 +3016,7 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t
30193016
jl_read_codeinst_invoke(ucache, &specsigflags, &invoke, &fptr, 1);
30203017
codeinst = jl_new_codeinst(mi, jl_nothing,
30213018
(jl_value_t*)jl_any_type, (jl_value_t*)jl_any_type, NULL, NULL,
3022-
0, 1, ~(size_t)0, 0, jl_nothing, 0, NULL, NULL);
3019+
0, 1, ~(size_t)0, 0, jl_nothing, NULL, NULL);
30233020
codeinst->rettype_const = ucache->rettype_const;
30243021
// unspec is always not specsig, but might use specptr
30253022
jl_atomic_store_relaxed(&codeinst->specptr.fptr, fptr);

src/jltypes.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,7 +3638,7 @@ void jl_init_types(void) JL_GC_DISABLED
36383638
jl_code_instance_type =
36393639
jl_new_datatype(jl_symbol("CodeInstance"), core,
36403640
jl_any_type, jl_emptysvec,
3641-
jl_perm_symsvec(18,
3641+
jl_perm_symsvec(17,
36423642
"def",
36433643
"owner",
36443644
"next",
@@ -3653,9 +3653,9 @@ void jl_init_types(void) JL_GC_DISABLED
36533653
//"absolute_max",
36543654
"ipo_purity_bits",
36553655
"analysis_results",
3656-
"specsigflags", "precompile", "relocatability",
3656+
"specsigflags", "precompile",
36573657
"invoke", "specptr"), // function object decls
3658-
jl_svec(18,
3658+
jl_svec(17,
36593659
jl_any_type,
36603660
jl_any_type,
36613661
jl_any_type,
@@ -3672,13 +3672,12 @@ void jl_init_types(void) JL_GC_DISABLED
36723672
jl_any_type,
36733673
jl_bool_type,
36743674
jl_bool_type,
3675-
jl_uint8_type,
36763675
jl_any_type, jl_any_type), // fptrs
36773676
jl_emptysvec,
36783677
0, 1, 1);
36793678
jl_svecset(jl_code_instance_type->types, 2, jl_code_instance_type);
3680-
const static uint32_t code_instance_constfields[1] = { 0b000001000011100011 }; // Set fields 1, 2, 6-8, 13 as const
3681-
const static uint32_t code_instance_atomicfields[1] = { 0b110110111100011100 }; // Set fields 3-5, 9-12, 14-15, 17-18 as atomic
3679+
const static uint32_t code_instance_constfields[1] = { 0b00001000011100011 }; // Set fields 1, 2, 6-8, 13 as const
3680+
const static uint32_t code_instance_atomicfields[1] = { 0b11010111100011100 }; // Set fields 3-5, 9-12, 14-17 as atomic
36823681
// Fields 4-5 are only operated on by construction and deserialization, so are effectively const at runtime
36833682
// Fields ipo_purity_bits and analysis_results are not currently threadsafe or reliable, as they get mutated after optimization, but are not declared atomic
36843683
// and there is no way to tell (during inference) if their value is finalized yet (to wait for them to be narrowed if applicable)
@@ -3854,8 +3853,8 @@ void jl_init_types(void) JL_GC_DISABLED
38543853
jl_svecset(jl_method_type->types, 13, jl_method_instance_type);
38553854
//jl_svecset(jl_debuginfo_type->types, 0, jl_method_instance_type); // union(jl_method_instance_type, jl_method_type, jl_symbol_type)
38563855
jl_svecset(jl_method_instance_type->types, 4, jl_code_instance_type);
3856+
jl_svecset(jl_code_instance_type->types, 15, jl_voidpointer_type);
38573857
jl_svecset(jl_code_instance_type->types, 16, jl_voidpointer_type);
3858-
jl_svecset(jl_code_instance_type->types, 17, jl_voidpointer_type);
38593858
jl_svecset(jl_binding_type->types, 0, jl_globalref_type);
38603859
jl_svecset(jl_binding_partition_type->types, 3, jl_binding_partition_type);
38613860

src/julia.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ typedef struct _jl_code_instance_t {
468468
// & 0b010 == invokeptr matches specptr
469469
// & 0b100 == From image
470470
_Atomic(uint8_t) precompile; // if set, this will be added to the output system image
471-
uint8_t relocatability; // nonzero if all roots are built into sysimg or tagged by module key
472471
_Atomic(jl_callptr_t) invoke; // jlcall entry point usually, but if this codeinst belongs to an OC Method, then this is an jl_fptr_args_t fptr1 instead, unless it is not, because it is a special token object instead
473472
union _jl_generic_specptr_t {
474473
_Atomic(void*) fptr;

src/julia_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ JL_DLLEXPORT jl_code_instance_t *jl_new_codeinst(
691691
jl_value_t *inferred_const, jl_value_t *inferred,
692692
int32_t const_flags, size_t min_world, size_t max_world,
693693
uint32_t effects, jl_value_t *analysis_results,
694-
uint8_t relocatability, jl_debuginfo_t *di, jl_svec_t *edges /* , int absolute_max*/);
694+
jl_debuginfo_t *di, jl_svec_t *edges /* , int absolute_max*/);
695695
JL_DLLEXPORT jl_code_instance_t *jl_get_ci_equiv(jl_code_instance_t *ci JL_PROPAGATES_ROOT, int compiled) JL_NOTSAFEPOINT;
696696

697697
STATIC_INLINE jl_method_instance_t *jl_get_ci_mi(jl_code_instance_t *ci JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT

src/method.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,10 +1384,6 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata,
13841384
// at the time of writing the system image (such occur first in the list of
13851385
// roots). These are the cases with `key = 0` that do not prevent
13861386
// serialization.
1387-
// - CodeInstances have a `relocatability` field which when 1 indicates that
1388-
// every root is "safe," meaning it was either added at sysimg creation or is
1389-
// tagged with a non-zero `key`. Even a single unsafe root will cause this to
1390-
// have value 0.
13911387

13921388
// Get the key of the current (final) block of roots
13931389
static uint64_t current_root_id(jl_array_t *root_blocks)

src/opaque_closure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ JL_DLLEXPORT jl_opaque_closure_t *jl_new_opaque_closure_from_code_info(jl_tuplet
169169
if (!jl_is_svec(edges))
170170
edges = jl_emptysvec; // OC doesn't really have edges, so just drop them for now
171171
inst = jl_new_codeinst(mi, jl_nothing, rt_ub, (jl_value_t*)jl_any_type, NULL, (jl_value_t*)ci,
172-
0, world, world, 0, jl_nothing, 0, ci->debuginfo, edges);
172+
0, world, world, 0, jl_nothing, ci->debuginfo, edges);
173173
jl_mi_cache_insert(mi, inst);
174174
}
175175

0 commit comments

Comments
 (0)