Skip to content

Commit

Permalink
MethodInstance -> MethodSpecialization{D}
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed May 7, 2024
1 parent 785713e commit 7eeed85
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 27 deletions.
4 changes: 2 additions & 2 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ eval(Core, quote
PartialOpaque(@nospecialize(typ), @nospecialize(env), parent::MethodInstance, source) = $(Expr(:new, :PartialOpaque, :typ, :env, :parent, :source))
InterConditional(slot::Int, @nospecialize(thentype), @nospecialize(elsetype)) = $(Expr(:new, :InterConditional, :slot, :thentype, :elsetype))
MethodMatch(@nospecialize(spec_types), sparams::SimpleVector, method::Method, fully_covers::Bool) = $(Expr(:new, :MethodMatch, :spec_types, :sparams, :method, :fully_covers))
DefaultSpecialization(sparam_vals::SimpleVector, inInference::Bool, cache_with_orig::Bool, precompiled::Bool) =
$(Expr(:new, DefaultSpecialization, :sparam_vals, :inInference, :cache_with_orig, :precompiled))
DefaultSpec(sparam_vals::SimpleVector, inInference::Bool, cache_with_orig::Bool, precompiled::Bool) =
$(Expr(:new, DefaultSpec, :sparam_vals, :inInference, :cache_with_orig, :precompiled))
end)

const NullDebugInfo = DebugInfo(:none)
Expand Down
3 changes: 2 additions & 1 deletion src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,8 @@ void jl_init_primitives(void) JL_GC_DISABLED
add_builtin("IntrinsicFunction", (jl_value_t*)jl_intrinsic_type);
add_builtin("Function", (jl_value_t*)jl_function_type);
add_builtin("Builtin", (jl_value_t*)jl_builtin_type);
add_builtin("DefaultSpecialization", (jl_value_t*)jl_default_specialization_type);
add_builtin("DefaultSpec", (jl_value_t*)jl_default_spec_type);
add_builtin("MethodSpecialization", (jl_value_t*)jl_method_specialization_type);
add_builtin("MethodInstance", (jl_value_t*)jl_method_instance_type);
add_builtin("CodeInfo", (jl_value_t*)jl_code_info_type);
add_builtin("LLVMPtr", (jl_value_t*)jl_llvmpointer_type);
Expand Down
3 changes: 2 additions & 1 deletion src/jl_exported_data.inc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
XX(jl_memoryref_uint8_type) \
XX(jl_methoderror_type) \
XX(jl_method_instance_type) \
XX(jl_default_specialization_type) \
XX(jl_method_specialization_type) \
XX(jl_default_spec_type) \
XX(jl_method_match_type) \
XX(jl_method_type) \
XX(jl_methtable_type) \
Expand Down
43 changes: 25 additions & 18 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2273,20 +2273,22 @@ static jl_svec_t *inst_ftypes(jl_svec_t *p, jl_typeenv_t *env, jl_typestack_t *s
size_t i;
size_t lp = jl_svec_len(p);
jl_svec_t *np = jl_alloc_svec(lp);
jl_value_t *pi = NULL;
jl_value_t *orig_pi = NULL, *pi = NULL;
JL_GC_PUSH2(&np, &pi);
for (i = 0; i < lp; i++) {
pi = jl_svecref(p, i);
orig_pi = jl_svecref(p, i);
JL_TRY {
pi = inst_type_w_(pi, env, stack, 1);
pi = inst_type_w_(orig_pi, env, stack, 1);
if (!jl_is_type(pi) && !jl_is_typevar(pi)) {
pi = jl_bottom_type;
}
}
JL_CATCH {
pi = jl_bottom_type;
}
jl_value_t *globalpi = jl_as_global_root(pi, cacheable);
jl_value_t *globalpi = NULL;
if (orig_pi != pi)
globalpi = jl_as_global_root(pi, cacheable);
jl_svecset(np, i, globalpi ? globalpi : pi);
}
JL_GC_POP();
Expand Down Expand Up @@ -3280,8 +3282,8 @@ void jl_init_types(void) JL_GC_DISABLED
const static uint32_t method_atomicfields[1] = { 0x00000030 }; // (1<<4)|(1<<5)
jl_method_type->name->atomicfields = method_atomicfields;

jl_default_specialization_type =
jl_new_datatype(jl_symbol("DefaultSpecialization"), core,
jl_default_spec_type =
jl_new_datatype(jl_symbol("DefaultSpec"), core,
jl_any_type, jl_emptysvec,
jl_perm_symsvec(4,
"sparam_vals",
Expand All @@ -3295,9 +3297,10 @@ void jl_init_types(void) JL_GC_DISABLED
jl_bool_type),
jl_emptysvec, 0, 0, 4);

jl_method_instance_type =
jl_new_datatype(jl_symbol("MethodInstance"), core,
jl_any_type, jl_emptysvec,
tv = jl_svec1(tvar("D"));
jl_datatype_t *jl_meth_spec_type =
jl_new_datatype(jl_symbol("MethodSpecialization"), core,
jl_any_type, tv,
jl_perm_symsvec(6,
"def",
"specTypes",
Expand All @@ -3310,16 +3313,18 @@ void jl_init_types(void) JL_GC_DISABLED
jl_any_type,
jl_array_any_type,
jl_any_type,/*jl_code_instance_type*/
jl_any_type,/*jl_method_instance_type*/
jl_default_specialization_type),
jl_any_type,/*jl_method_specialization_type*/
jl_svecref(tv, 0)),
jl_emptysvec,
0, 1, 2);
jl_method_specialization_type =
(jl_unionall_t*)jl_meth_spec_type->name->wrapper;
// These fields should be constant, but Serialization wants to mutate them in initialization
//const static uint32_t method_instance_constfields[1] = { 0x00000007 }; // (1<<0)|(1<<1);
const static uint32_t method_instance_atomicfields[1] = { 0x0000008 }; // (1<<3)
//Fields 3 and 4 must be protected by method->write_lock, and thus all operations on jl_method_instance_t are threadsafe. TODO: except inInference
//jl_method_instance_type->name->constfields = method_instance_constfields;
jl_method_instance_type->name->atomicfields = method_instance_atomicfields;
jl_meth_spec_type->name->atomicfields = method_instance_atomicfields;

jl_code_instance_type =
jl_new_datatype(jl_symbol("CodeInstance"), core,
Expand All @@ -3341,7 +3346,7 @@ void jl_init_types(void) JL_GC_DISABLED
"specsigflags", "precompile", "relocatability",
"invoke", "specptr"), // function object decls
jl_svec(18,
jl_method_instance_type,
jl_method_specialization_type,
jl_any_type,
jl_any_type,
jl_ulong_type,
Expand Down Expand Up @@ -3479,7 +3484,7 @@ void jl_init_types(void) JL_GC_DISABLED

jl_partial_opaque_type = jl_new_datatype(jl_symbol("PartialOpaque"), core, jl_any_type, jl_emptysvec,
jl_perm_symsvec(4, "typ", "env", "parent", "source"),
jl_svec(4, jl_type_type, jl_any_type, jl_method_instance_type, jl_any_type),
jl_svec(4, jl_type_type, jl_any_type, jl_method_specialization_type, jl_any_type),
jl_emptysvec, 0, 0, 4);

// complete builtin type metadata
Expand All @@ -3503,10 +3508,9 @@ void jl_init_types(void) JL_GC_DISABLED
jl_svecset(jl_methtable_type->types, 8, jl_long_type); // uint32_t plus alignment
jl_svecset(jl_methtable_type->types, 9, jl_uint8_type);
jl_svecset(jl_methtable_type->types, 10, jl_uint8_type);
jl_svecset(jl_method_type->types, 13, jl_method_instance_type);
//jl_svecset(jl_debuginfo_type->types, 0, jl_method_instance_type); // union(jl_method_instance_type, jl_method_type, jl_symbol_type)
jl_svecset(jl_method_instance_type->types, 3, jl_code_instance_type);
jl_svecset(jl_method_instance_type->types, 4, jl_method_instance_type);
jl_svecset(jl_meth_spec_type->types, 3, jl_code_instance_type);
jl_svecset(jl_meth_spec_type->types, 4, jl_method_specialization_type);
jl_svecset(jl_code_instance_type->types, 16, jl_voidpointer_type);
jl_svecset(jl_code_instance_type->types, 17, jl_voidpointer_type);
jl_svecset(jl_binding_type->types, 1, jl_globalref_type);
Expand All @@ -3528,8 +3532,11 @@ void jl_init_types(void) JL_GC_DISABLED
assert(((jl_datatype_t*)jl_array_any_type)->ismutationfree == 0);
assert(((jl_datatype_t*)jl_array_uint8_type)->ismutationfree == 0);

jl_method_instance_type = (jl_datatype_t*)jl_apply_type1((jl_value_t*)jl_method_specialization_type, (jl_value_t*)jl_default_spec_type);
jl_svecset(jl_method_type->types, 13, jl_method_instance_type);

jl_compute_field_offsets(jl_simplevector_type);
jl_compute_field_offsets(jl_default_specialization_type);
jl_compute_field_offsets(jl_default_spec_type);
jl_compute_field_offsets(jl_method_instance_type);
jl_compute_field_offsets(jl_code_instance_type);

Expand Down
3 changes: 2 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ extern JL_DLLIMPORT jl_unionall_t *jl_opaque_closure_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_opaque_closure_typename JL_GLOBALLY_ROOTED;

extern JL_DLLIMPORT jl_value_t *jl_bottom_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_default_specialization_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_default_spec_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_method_specialization_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_method_instance_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_code_instance_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_code_info_type JL_GLOBALLY_ROOTED;
Expand Down
7 changes: 6 additions & 1 deletion src/rtutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,12 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
}
else if (vt == jl_method_type) {
jl_method_t *m = (jl_method_t*)v;
n += jl_static_show_func_sig(out, m->sig);
if (m->sig == (jl_value_t*)jl_anytuple_type) {
jl_printf(out, "Builtin Method for ");
jl_static_show_x(out, (jl_value_t*)m->name, depth, ctx);
} else {
n += jl_static_show_func_sig(out, m->sig);
}
}
else if (vt == jl_method_instance_type) {
jl_method_instance_t *li = (jl_method_instance_t*)v;
Expand Down
5 changes: 3 additions & 2 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ extern "C" {
// TODO: put WeakRefs on the weak_refs list during deserialization
// TODO: handle finalizers

#define NUM_TAGS 191
#define NUM_TAGS 192

// 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 All @@ -126,7 +126,8 @@ jl_value_t **const*const get_tags(void) {
INSERT_TAG(jl_string_type);
INSERT_TAG(jl_module_type);
INSERT_TAG(jl_tvar_type);
INSERT_TAG(jl_default_specialization_type);
INSERT_TAG(jl_default_spec_type);
INSERT_TAG(jl_method_specialization_type);
INSERT_TAG(jl_method_instance_type);
INSERT_TAG(jl_method_type);
INSERT_TAG(jl_code_instance_type);
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Serialization/src/Serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ function deserialize(s::AbstractSerializer, ::Type{Core.MethodInstance})
_rettype = deserialize(s) # for backwards compat
linfo.specTypes = deserialize(s)
linfo.def = deserialize(s)
linfo.data = DefaultSpecialization(sparam_vals, false, false, false)
linfo.data = DefaultSpec(sparam_vals, false, false, false)
return linfo
end

Expand Down

0 comments on commit 7eeed85

Please sign in to comment.