Skip to content

Commit e892948

Browse files
authored
Backports release 1.12 (#57871)
2 parents aee98f8 + ea3f2ea commit e892948

File tree

25 files changed

+188
-85
lines changed

25 files changed

+188
-85
lines changed

Compiler/src/abstractinterpretation.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,6 +3283,7 @@ function abstract_eval_isdefinedglobal(interp::AbstractInterpreter, @nospecializ
32833283
exct = Union{exct, ConcurrencyViolationError}
32843284
end
32853285
end
3286+
= partialorder(typeinf_lattice(interp))
32863287
if M isa Const && s isa Const
32873288
M, s = M.val, s.val
32883289
if M isa Module && s isa Symbol

Compiler/test/codegen.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,3 +1027,8 @@ module TurnedIntoExplicit
10271027

10281028
@test !occursin("jl_apply_generic", get_llvm(f, Tuple{UInt}))
10291029
end
1030+
1031+
# Test codegen for `isdefinedglobal` of constant (#57872)
1032+
const x57872 = "Hello"
1033+
f57872() = (Core.isdefinedglobal(@__MODULE__, Base.compilerbarrier(:const, :x57872)), x57872) # Extra globalref here to force world age bounds
1034+
@test f57872() == (true, "Hello")

base/cmd.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ julia> run(cm)
504504
Process(`echo 1`, ProcessExited(0))
505505
```
506506
"""
507-
macro cmd(str)
507+
macro cmd(str::String)
508508
cmd_ex = shell_parse(str, special=shell_special, filename=String(__source__.file))[1]
509509
return :(cmd_gen($(esc(cmd_ex))))
510510
end

base/int.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,14 @@ function mod(x::T, y::T) where T<:Integer
286286
y == -1 && return T(0) # avoid potential overflow in fld
287287
return x - fld(x, y) * y
288288
end
289-
mod(x::BitSigned, y::Unsigned) = rem(y + unsigned(rem(x, y)), y)
290-
mod(x::Unsigned, y::Signed) = rem(y + signed(rem(x, y)), y)
289+
function mod(x::BitSigned, y::Unsigned)
290+
remval = rem(x, y) # correct iff remval>=0
291+
return unsigned(remval + (remval<zero(remval))*y)
292+
end
293+
function mod(x::Unsigned, y::Signed)
294+
remval = signed(rem(x, y)) #remval>0 so correct iff y>0 or remval==0
295+
return remval + (!iszero(remval) && y<zero(y))*y
296+
end
291297
mod(x::T, y::T) where {T<:Unsigned} = rem(x, y)
292298

293299
# Don't promote integers for div/rem/mod since there is no danger of overflow,

base/pcre.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ end
199199
exec(re, subject::Union{String,SubString{String}}, offset, options, match_data) =
200200
_exec(re, subject, offset, options, match_data)
201201
exec(re, subject, offset, options, match_data) =
202-
_exec(re, String(subject), offset, options, match_data)
202+
_exec(re, String(subject)::String, offset, options, match_data)
203203

204204
function _exec(re, subject, offset, options, match_data)
205205
rc = ccall((:pcre2_match_8, PCRE_LIB), Cint,

base/reflection.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,22 @@ struct CodegenParams
149149
use_jlplt::Cint
150150

151151
"""
152-
If enabled, only provably reachable code (from functions marked with `entrypoint`) is included
153-
in the output system image. Errors or warnings can be given for call sites too dynamic to handle.
154-
The option is disabled by default. (0=>disabled, 1=>safe (static errors), 2=>unsafe, 3=>unsafe plus warnings)
152+
If enabled emit LLVM IR for all functions even if wouldn't be compiled
153+
for some reason (i.e functions that return a constant value).
155154
"""
156-
trim::Cint
155+
force_emit_all::Cint
157156

158157
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
159158
prefer_specsig::Bool=false,
160159
gnu_pubnames::Bool=true, debug_info_kind::Cint = default_debug_info_kind(),
161160
debug_info_level::Cint = Cint(JLOptions().debug_level), safepoint_on_entry::Bool=true,
162-
gcstack_arg::Bool=true, use_jlplt::Bool=true, trim::Cint=Cint(0))
161+
gcstack_arg::Bool=true, use_jlplt::Bool=true, force_emit_all::Bool=false)
163162
return new(
164163
Cint(track_allocations), Cint(code_coverage),
165164
Cint(prefer_specsig),
166165
Cint(gnu_pubnames), debug_info_kind,
167166
debug_info_level, Cint(safepoint_on_entry),
168-
Cint(gcstack_arg), Cint(use_jlplt), Cint(trim))
167+
Cint(gcstack_arg), Cint(use_jlplt), Cint(force_emit_all))
169168
end
170169
end
171170

base/strings/io.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ julia> v[2]
589589
0x32
590590
```
591591
"""
592-
macro b_str(s)
592+
macro b_str(s::String)
593593
v = codeunits(unescape_string(s))
594594
QuoteNode(v)
595595
end

src/aotcompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ void *jl_emit_native_impl(jl_array_t *codeinfos, LLVMOrcThreadSafeModuleRef llvm
775775
params.tsctx, clone.getModuleUnlocked()->getDataLayout(),
776776
Triple(clone.getModuleUnlocked()->getTargetTriple()));
777777
jl_llvm_functions_t decls;
778-
if (jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr)
778+
if (!(params.params->force_emit_all) && jl_atomic_load_relaxed(&codeinst->invoke) == jl_fptr_const_return_addr)
779779
decls.functionObject = "jl_fptr_const_return";
780780
else
781781
decls = jl_emit_codeinst(result_m, codeinst, src, params);

src/cgutils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4410,7 +4410,8 @@ static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
44104410
(a->debug_info_kind == b->debug_info_kind) &&
44114411
(a->safepoint_on_entry == b->safepoint_on_entry) &&
44124412
(a->gcstack_arg == b->gcstack_arg) &&
4413-
(a->use_jlplt == b->use_jlplt);
4413+
(a->use_jlplt == b->use_jlplt) &&
4414+
(a->force_emit_all == b->force_emit_all);
44144415
}
44154416
#endif
44164417

src/codegen.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,30 +3824,29 @@ static bool emit_f_opfield(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,
38243824

38253825
static jl_cgval_t emit_isdefinedglobal(jl_codectx_t &ctx, jl_module_t *modu, jl_sym_t *name, int allow_import, enum jl_memory_order order)
38263826
{
3827-
Value *isnull = NULL;
38283827
jl_binding_t *bnd = allow_import ? jl_get_binding(modu, name) : jl_get_module_binding(modu, name, 0);
38293828
struct restriction_kind_pair rkp = { NULL, NULL, PARTITION_KIND_GUARD, 0 };
38303829
if (allow_import && jl_get_binding_leaf_partitions_restriction_kind(bnd, &rkp, ctx.min_world, ctx.max_world)) {
3831-
if (jl_bkind_is_some_constant(rkp.kind))
3832-
return mark_julia_const(ctx, rkp.restriction);
3830+
if (jl_bkind_is_some_constant(rkp.kind) && rkp.restriction)
3831+
return mark_julia_const(ctx, jl_true);
38333832
if (rkp.kind == PARTITION_KIND_GLOBAL) {
38343833
Value *bp = julia_binding_gv(ctx, rkp.binding_if_global);
38353834
bp = julia_binding_pvalue(ctx, bp);
38363835
LoadInst *v = ctx.builder.CreateAlignedLoad(ctx.types().T_prjlvalue, bp, Align(sizeof(void*)));
38373836
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_binding);
38383837
ai.decorateInst(v);
38393838
v->setOrdering(get_llvm_atomic_order(order));
3840-
isnull = ctx.builder.CreateICmpNE(v, Constant::getNullValue(ctx.types().T_prjlvalue));
3839+
Value *isnull = ctx.builder.CreateICmpNE(v, Constant::getNullValue(ctx.types().T_prjlvalue));
38413840
return mark_julia_type(ctx, isnull, false, jl_bool_type);
38423841
}
38433842
}
3844-
Value *v = ctx.builder.CreateCall(prepare_call(jlboundp_func), {
3843+
Value *isdef = ctx.builder.CreateCall(prepare_call(jlboundp_func), {
38453844
literal_pointer_val(ctx, (jl_value_t*)modu),
38463845
literal_pointer_val(ctx, (jl_value_t*)name),
38473846
ConstantInt::get(getInt32Ty(ctx.builder.getContext()), allow_import)
38483847
});
3849-
isnull = ctx.builder.CreateICmpNE(v, ConstantInt::get(getInt32Ty(ctx.builder.getContext()), 0));
3850-
return mark_julia_type(ctx, isnull, false, jl_bool_type);
3848+
isdef = ctx.builder.CreateTrunc(isdef, getInt1Ty(ctx.builder.getContext()));
3849+
return mark_julia_type(ctx, isdef, false, jl_bool_type);
38513850
}
38523851

38533852
static bool emit_f_opmemory(jl_codectx_t &ctx, jl_cgval_t *ret, jl_value_t *f,

0 commit comments

Comments
 (0)