Skip to content

Commit 2910899

Browse files
authored
Merge 1224a17 into e9d678e
2 parents e9d678e + 1224a17 commit 2910899

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1155
-819
lines changed

base/boot.jl

+9-10
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ ccall(:jl_toplevel_eval_in, Any, (Any, Any),
245245
(f::typeof(Typeof))(x) = ($(_expr(:meta,:nospecialize,:x)); isa(x,Type) ? Type{x} : typeof(x))
246246
end)
247247

248-
249248
macro nospecialize(x)
250249
_expr(:meta, :nospecialize, x)
251250
end
@@ -256,7 +255,15 @@ TypeVar(n::Symbol, @nospecialize(lb), @nospecialize(ub)) = _typevar(n, lb, ub)
256255

257256
UnionAll(v::TypeVar, @nospecialize(t)) = ccall(:jl_type_unionall, Any, (Any, Any), v, t)
258257

259-
const Vararg = ccall(:jl_toplevel_eval_in, Any, (Any, Any), Core, _expr(:new, TypeofVararg))
258+
# simple convert for use by constructors of types in Core
259+
# note that there is no actual conversion defined here,
260+
# so the methods and ccall's in Core aren't permitted to use convert
261+
convert(::Type{Any}, @nospecialize(x)) = x
262+
convert(::Type{T}, x::T) where {T} = x
263+
cconvert(::Type{T}, x) where {T} = convert(T, x)
264+
unsafe_convert(::Type{T}, x::T) where {T} = x
265+
266+
const Vararg = ccall(:jl_wrap_vararg, Any, (Int, Int), 0, 0)
260267

261268
# dispatch token indicating a kwarg (keyword sorter) call
262269
function kwcall end
@@ -448,14 +455,6 @@ function _Task(@nospecialize(f), reserved_stack::Int, completion_future)
448455
return ccall(:jl_new_task, Ref{Task}, (Any, Any, Int), f, completion_future, reserved_stack)
449456
end
450457

451-
# simple convert for use by constructors of types in Core
452-
# note that there is no actual conversion defined here,
453-
# so the methods and ccall's in Core aren't permitted to use convert
454-
convert(::Type{Any}, @nospecialize(x)) = x
455-
convert(::Type{T}, x::T) where {T} = x
456-
cconvert(::Type{T}, x) where {T} = convert(T, x)
457-
unsafe_convert(::Type{T}, x::T) where {T} = x
458-
459458
_is_internal(__module__) = __module__ === Core
460459
# can be used in place of `@assume_effects :foldable` (supposed to be used for bootstrapping)
461460
macro _foldable_meta()

base/compiler/inferencestate.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ function IRInterpretationState(interp::AbstractInterpreter,
688688
code::CodeInstance, mi::MethodInstance, argtypes::Vector{Any}, world::UInt)
689689
@assert code.def === mi
690690
src = @atomic :monotonic code.inferred
691-
if isa(src, Vector{UInt8})
691+
if isa(src, String)
692692
src = ccall(:jl_uncompress_ir, Any, (Any, Ptr{Cvoid}, Any), mi.def, C_NULL, src)::CodeInfo
693693
else
694694
isa(src, CodeInfo) || return nothing

base/compiler/optimize.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const TOP_TUPLE = GlobalRef(Core, :tuple)
4343
const InlineCostType = UInt16
4444
const MAX_INLINE_COST = typemax(InlineCostType)
4545
const MIN_INLINE_COST = InlineCostType(10)
46-
const MaybeCompressed = Union{CodeInfo, Vector{UInt8}}
46+
const MaybeCompressed = Union{CodeInfo, String}
4747

4848
is_inlineable(@nospecialize src::MaybeCompressed) =
4949
ccall(:jl_ir_inlining_cost, InlineCostType, (Any,), src) != MAX_INLINE_COST

base/compiler/ssair/inlining.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ end
937937
function may_have_fcalls(m::Method)
938938
isdefined(m, :source) || return true
939939
src = m.source
940-
isa(src, CodeInfo) || isa(src, Vector{UInt8}) || return true
940+
isa(src, MaybeCompressed) || return true
941941
return ccall(:jl_ir_flag_has_fcall, Bool, (Any,), src)
942942
end
943943

@@ -975,8 +975,8 @@ function analyze_method!(match::MethodMatch, argtypes::Vector{Any},
975975
return resolve_todo(mi, match, argtypes, info, flag, state; invokesig)
976976
end
977977

978-
function retrieve_ir_for_inlining(mi::MethodInstance, src::Array{UInt8, 1})
979-
src = ccall(:jl_uncompress_ir, Any, (Any, Ptr{Cvoid}, Any), mi.def, C_NULL, src::Vector{UInt8})::CodeInfo
978+
function retrieve_ir_for_inlining(mi::MethodInstance, src::String)
979+
src = ccall(:jl_uncompress_ir, Any, (Any, Ptr{Cvoid}, Any), mi.def, C_NULL, src)::CodeInfo
980980
return inflate_ir!(src, mi)
981981
end
982982
retrieve_ir_for_inlining(mi::MethodInstance, src::CodeInfo) = inflate_ir(src, mi)

base/compiler/typeinfer.jl

+11-5
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,15 @@ function CodeInstance(interp::AbstractInterpreter, result::InferenceResult,
325325
const_flags = 0x00
326326
end
327327
end
328-
relocatability = isa(inferred_result, Vector{UInt8}) ? inferred_result[end] :
329-
inferred_result === nothing ? UInt8(1) : UInt8(0)
330-
# relocatability = isa(inferred_result, Vector{UInt8}) ? inferred_result[end] : UInt8(0)
328+
relocatability = 0x0
329+
if isa(inferred_result, String)
330+
t = @_gc_preserve_begin inferred_result
331+
relocatability = unsafe_load(unsafe_convert(Ptr{UInt8}, inferred_result), Core.sizeof(inferred_result))
332+
@_gc_preserve_end t
333+
elseif inferred_result === nothing
334+
relocatability = 0x1
335+
end
336+
# relocatability = isa(inferred_result, String) ? inferred_result[end] : UInt8(0)
331337
return CodeInstance(result.linfo,
332338
widenconst(result_type), rettype_const, inferred_result,
333339
const_flags, first(valid_worlds), last(valid_worlds),
@@ -352,7 +358,7 @@ function maybe_compress_codeinfo(interp::AbstractInterpreter, linfo::MethodInsta
352358
nslots = length(ci.slotflags)
353359
resize!(ci.slottypes::Vector{Any}, nslots)
354360
resize!(ci.slotnames, nslots)
355-
return ccall(:jl_compress_ir, Vector{UInt8}, (Any, Any), def, ci)
361+
return ccall(:jl_compress_ir, String, (Any, Any), def, ci)
356362
else
357363
return ci
358364
end
@@ -1031,7 +1037,7 @@ function typeinf_ext(interp::AbstractInterpreter, mi::MethodInstance)
10311037
inf.rettype = code.rettype
10321038
end
10331039
return inf
1034-
elseif isa(inf, Vector{UInt8})
1040+
elseif isa(inf, String)
10351041
ccall(:jl_typeinf_timing_end, Cvoid, (UInt64,), start_time)
10361042
inf = _uncompressed_ir(code, inf)
10371043
return inf

base/compiler/utilities.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function retrieve_code_info(linfo::MethodInstance, world::UInt)
137137
if src === nothing
138138
# can happen in images built with --strip-ir
139139
return nothing
140-
elseif isa(src, Array{UInt8,1})
140+
elseif isa(src, String)
141141
c = ccall(:jl_uncompress_ir, Any, (Any, Ptr{Cvoid}, Any), m, C_NULL, src)
142142
else
143143
c = copy(src::CodeInfo)

base/reflection.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,8 @@ uncompressed_ir(m::Method) = isdefined(m, :source) ? _uncompressed_ir(m, m.sourc
11631163
isdefined(m, :generator) ? error("Method is @generated; try `code_lowered` instead.") :
11641164
error("Code for this Method is not available.")
11651165
_uncompressed_ir(m::Method, s::CodeInfo) = copy(s)
1166-
_uncompressed_ir(m::Method, s::Array{UInt8,1}) = ccall(:jl_uncompress_ir, Any, (Any, Ptr{Cvoid}, Any), m, C_NULL, s)::CodeInfo
1167-
_uncompressed_ir(ci::Core.CodeInstance, s::Array{UInt8,1}) = ccall(:jl_uncompress_ir, Any, (Any, Any, Any), ci.def.def::Method, ci, s)::CodeInfo
1166+
_uncompressed_ir(m::Method, s::String) = ccall(:jl_uncompress_ir, Any, (Any, Ptr{Cvoid}, Any), m, C_NULL, s)::CodeInfo
1167+
_uncompressed_ir(ci::Core.CodeInstance, s::String) = ccall(:jl_uncompress_ir, Any, (Any, Any, Any), ci.def.def::Method, ci, s)::CodeInfo
11681168
# for backwards compat
11691169
const uncompressed_ast = uncompressed_ir
11701170
const _uncompressed_ast = _uncompressed_ir

cli/jl_exports.h

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ JL_EXPORTED_DATA_POINTERS(XX)
1616
JL_EXPORTED_DATA_SYMBOLS(XX)
1717
#undef XX
1818

19+
// define a copy of exported data
20+
#define jl_max_tags 64
21+
JL_DLLEXPORT void *small_typeof[(jl_max_tags << 4) / sizeof(void*)]; // 16-bit aligned, like the GC
22+
1923
// Declare list of exported functions (sans type)
2024
#define XX(name) JL_DLLEXPORT void name(void);
2125
typedef void (anonfunc)(void);

src/aotcompile.cpp

+25-8
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static void jl_ci_cache_lookup(const jl_cgparams_t &cgparams, jl_method_instance
238238
if ((jl_value_t*)*src_out == jl_nothing)
239239
*src_out = NULL;
240240
if (*src_out && jl_is_method(def))
241-
*src_out = jl_uncompress_ir(def, codeinst, (jl_array_t*)*src_out);
241+
*src_out = jl_uncompress_ir(def, codeinst, (jl_value_t*)*src_out);
242242
}
243243
if (*src_out == NULL || !jl_is_code_info(*src_out)) {
244244
if (cgparams.lookup != jl_rettype_inferred) {
@@ -1575,6 +1575,14 @@ void jl_dump_native_impl(void *native_code,
15751575
GlobalVariable::ExternalLinkage,
15761576
jlRTLD_DEFAULT_var,
15771577
"jl_RTLD_DEFAULT_handle_pointer"), TheTriple);
1578+
1579+
// let the compiler know we are going to internalize a copy of this,
1580+
// if it has a current usage with ExternalLinkage
1581+
auto small_typeof_copy = dataM->getGlobalVariable("small_typeof");
1582+
if (small_typeof_copy) {
1583+
small_typeof_copy->setVisibility(GlobalValue::HiddenVisibility);
1584+
small_typeof_copy->setDSOLocal(true);
1585+
}
15781586
}
15791587

15801588
// Reserve space for the output files and names
@@ -1651,13 +1659,21 @@ void jl_dump_native_impl(void *native_code,
16511659
auto shards = emit_shard_table(*sysimageM, T_size, T_psize, threads);
16521660
auto ptls = emit_ptls_table(*sysimageM, T_size, T_psize);
16531661
auto header = emit_image_header(*sysimageM, threads, nfvars, ngvars);
1654-
auto AT = ArrayType::get(T_psize, 4);
1662+
auto AT = ArrayType::get(T_size, sizeof(small_typeof) / sizeof(void*));
1663+
auto small_typeof_copy = new GlobalVariable(*sysimageM, AT, false,
1664+
GlobalVariable::ExternalLinkage,
1665+
Constant::getNullValue(AT),
1666+
"small_typeof");
1667+
small_typeof_copy->setVisibility(GlobalValue::HiddenVisibility);
1668+
small_typeof_copy->setDSOLocal(true);
1669+
AT = ArrayType::get(T_psize, 5);
16551670
auto pointers = new GlobalVariable(*sysimageM, AT, false,
16561671
GlobalVariable::ExternalLinkage,
16571672
ConstantArray::get(AT, {
16581673
ConstantExpr::getBitCast(header, T_psize),
16591674
ConstantExpr::getBitCast(shards, T_psize),
16601675
ConstantExpr::getBitCast(ptls, T_psize),
1676+
ConstantExpr::getBitCast(small_typeof_copy, T_psize),
16611677
ConstantExpr::getBitCast(target_ids, T_psize)
16621678
}),
16631679
"jl_image_pointers");
@@ -2012,17 +2028,18 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, siz
20122028
jl_value_t *jlrettype = (jl_value_t*)jl_any_type;
20132029
jl_code_info_t *src = NULL;
20142030
JL_GC_PUSH2(&src, &jlrettype);
2015-
if (jl_is_method(mi->def.method) && mi->def.method->source != NULL && jl_ir_flag_inferred((jl_array_t*)mi->def.method->source)) {
2031+
if (jl_is_method(mi->def.method) && mi->def.method->source != NULL && mi->def.method->source != jl_nothing && jl_ir_flag_inferred(mi->def.method->source)) {
20162032
src = (jl_code_info_t*)mi->def.method->source;
20172033
if (src && !jl_is_code_info(src))
2018-
src = jl_uncompress_ir(mi->def.method, NULL, (jl_array_t*)src);
2019-
} else {
2034+
src = jl_uncompress_ir(mi->def.method, NULL, (jl_value_t*)src);
2035+
}
2036+
else {
20202037
jl_value_t *ci = jl_rettype_inferred(mi, world, world);
20212038
if (ci != jl_nothing) {
20222039
jl_code_instance_t *codeinst = (jl_code_instance_t*)ci;
20232040
src = (jl_code_info_t*)jl_atomic_load_relaxed(&codeinst->inferred);
20242041
if ((jl_value_t*)src != jl_nothing && !jl_is_code_info(src) && jl_is_method(mi->def.method))
2025-
src = jl_uncompress_ir(mi->def.method, codeinst, (jl_array_t*)src);
2042+
src = jl_uncompress_ir(mi->def.method, codeinst, (jl_value_t*)src);
20262043
jlrettype = codeinst->rettype;
20272044
}
20282045
if (!src || (jl_value_t*)src == jl_nothing) {
@@ -2031,8 +2048,8 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, siz
20312048
jlrettype = src->rettype;
20322049
else if (jl_is_method(mi->def.method)) {
20332050
src = mi->def.method->generator ? jl_code_for_staged(mi, world) : (jl_code_info_t*)mi->def.method->source;
2034-
if (src && !jl_is_code_info(src) && jl_is_method(mi->def.method))
2035-
src = jl_uncompress_ir(mi->def.method, NULL, (jl_array_t*)src);
2051+
if (src && (jl_value_t*)src != jl_nothing && !jl_is_code_info(src) && jl_is_method(mi->def.method))
2052+
src = jl_uncompress_ir(mi->def.method, NULL, (jl_value_t*)src);
20362053
}
20372054
// TODO: use mi->uninferred
20382055
}

src/array.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ JL_DLLEXPORT jl_value_t *jl_alloc_string(size_t len)
509509
jl_throw(jl_memory_exception);
510510
s = jl_gc_big_alloc_noinline(ptls, allocsz);
511511
}
512-
jl_set_typeof(s, jl_string_type);
512+
jl_set_typetagof(s, jl_string_tag, 0);
513513
maybe_record_alloc_to_profile(s, len, jl_string_type);
514514
*(size_t*)s = len;
515515
jl_string_data(s)[len] = 0;
@@ -1255,16 +1255,16 @@ JL_DLLEXPORT void jl_array_ptr_copy(jl_array_t *dest, void **dest_p,
12551255

12561256
JL_DLLEXPORT void jl_array_ptr_1d_push(jl_array_t *a, jl_value_t *item)
12571257
{
1258-
assert(jl_typeis(a, jl_array_any_type));
1258+
assert(jl_typetagis(a, jl_array_any_type));
12591259
jl_array_grow_end(a, 1);
12601260
size_t n = jl_array_nrows(a);
12611261
jl_array_ptr_set(a, n - 1, item);
12621262
}
12631263

12641264
JL_DLLEXPORT void jl_array_ptr_1d_append(jl_array_t *a, jl_array_t *a2)
12651265
{
1266-
assert(jl_typeis(a, jl_array_any_type));
1267-
assert(jl_typeis(a2, jl_array_any_type));
1266+
assert(jl_typetagis(a, jl_array_any_type));
1267+
assert(jl_typetagis(a2, jl_array_any_type));
12681268
size_t i;
12691269
size_t n = jl_array_nrows(a);
12701270
size_t n2 = jl_array_nrows(a2);

src/ast.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -700,11 +700,11 @@ static value_t julia_to_scm_noalloc(fl_context_t *fl_ctx, jl_value_t *v, int che
700700
if (julia_to_scm_noalloc1(fl_ctx, v, &retval))
701701
return retval;
702702
assert(!jl_is_expr(v) &&
703-
!jl_typeis(v, jl_linenumbernode_type) &&
704-
!jl_typeis(v, jl_gotonode_type) &&
705-
!jl_typeis(v, jl_quotenode_type) &&
706-
!jl_typeis(v, jl_newvarnode_type) &&
707-
!jl_typeis(v, jl_globalref_type));
703+
!jl_typetagis(v, jl_linenumbernode_type) &&
704+
!jl_typetagis(v, jl_gotonode_type) &&
705+
!jl_typetagis(v, jl_quotenode_type) &&
706+
!jl_typetagis(v, jl_newvarnode_type) &&
707+
!jl_typetagis(v, jl_globalref_type));
708708
return julia_to_scm_noalloc2(fl_ctx, v, check_valid);
709709
}
710710

@@ -745,7 +745,7 @@ static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v, int check_vali
745745
// GC Note: jl_fieldref(v, 0) allocates for GotoNode
746746
// but we don't need a GC root here because julia_to_list2_noalloc
747747
// shouldn't allocate in this case.
748-
if (jl_typeis(v, jl_linenumbernode_type)) {
748+
if (jl_typetagis(v, jl_linenumbernode_type)) {
749749
jl_value_t *file = jl_fieldref_noalloc(v,1);
750750
jl_value_t *line = jl_fieldref(v,0);
751751
value_t args = julia_to_list2_noalloc(fl_ctx, line, file, check_valid);
@@ -755,13 +755,13 @@ static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v, int check_vali
755755
fl_free_gc_handles(fl_ctx, 1);
756756
return scmv;
757757
}
758-
if (jl_typeis(v, jl_gotonode_type))
758+
if (jl_typetagis(v, jl_gotonode_type))
759759
return julia_to_list2_noalloc(fl_ctx, (jl_value_t*)jl_goto_sym, jl_fieldref(v,0), check_valid);
760-
if (jl_typeis(v, jl_quotenode_type))
760+
if (jl_typetagis(v, jl_quotenode_type))
761761
return julia_to_list2(fl_ctx, (jl_value_t*)jl_inert_sym, jl_fieldref_noalloc(v,0), 0);
762-
if (jl_typeis(v, jl_newvarnode_type))
762+
if (jl_typetagis(v, jl_newvarnode_type))
763763
return julia_to_list2_noalloc(fl_ctx, (jl_value_t*)jl_newvar_sym, jl_fieldref(v,0), check_valid);
764-
if (jl_typeis(v, jl_globalref_type)) {
764+
if (jl_typetagis(v, jl_globalref_type)) {
765765
jl_module_t *m = jl_globalref_mod(v);
766766
jl_sym_t *sym = jl_globalref_name(v);
767767
if (m == jl_core_module)
@@ -1011,7 +1011,7 @@ static jl_value_t *jl_invoke_julia_macro(jl_array_t *args, jl_module_t *inmodule
10111011
// __source__ argument
10121012
jl_value_t *lno = jl_array_ptr_ref(args, 1);
10131013
margs[1] = lno;
1014-
if (!jl_typeis(lno, jl_linenumbernode_type)) {
1014+
if (!jl_typetagis(lno, jl_linenumbernode_type)) {
10151015
margs[1] = jl_new_struct(jl_linenumbernode_type, jl_box_long(0), jl_nothing);
10161016
}
10171017
margs[2] = (jl_value_t*)inmodule;

0 commit comments

Comments
 (0)