Skip to content

Commit 55922cf

Browse files
authored
Merge branch 'master' into teh/integer
2 parents 06b86f7 + b8110f8 commit 55922cf

36 files changed

+299
-75
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Standard library changes
6161
#### LinearAlgebra
6262
* New method `LinearAlgebra.issuccess(::CholeskyPivoted)` for checking whether pivoted Cholesky factorization was successful ([#36002]).
6363
* `UniformScaling` can now be indexed into using ranges to return dense matrices and vectors ([#24359]).
64+
* New function `LinearAlgebra.BLAS.get_num_threads()` for getting the number of BLAS threads. ([#36360])
6465

6566
#### Markdown
6667

base/Base.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ include("abstractarraymath.jl")
129129
include("arraymath.jl")
130130

131131
# SIMD loops
132+
@pure sizeof(s::String) = Core.sizeof(s) # needed by gensym as called from simdloop
132133
include("simdloop.jl")
133134
using .SimdLoop
134135

base/abstractarray.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ function getindex(A::AbstractArray, I...)
10601060
error_if_canonical_getindex(IndexStyle(A), A, I...)
10611061
_getindex(IndexStyle(A), A, to_indices(A, I)...)
10621062
end
1063+
# To avoid invalidations from multidimensional.jl: getindex(A::Array, i1::Union{Integer, CartesianIndex}, I::Union{Integer, CartesianIndex}...)
1064+
getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]
1065+
10631066
function unsafe_getindex(A::AbstractArray, I...)
10641067
@_inline_meta
10651068
@inbounds r = getindex(A, I...)
@@ -2163,7 +2166,7 @@ end
21632166
# map on collections
21642167
map(f, A::AbstractArray) = collect_similar(A, Generator(f,A))
21652168

2166-
mapany(f, itr) = map!(f, Vector{Any}(undef, length(itr)), itr) # convenient for Expr.args
2169+
mapany(f, itr) = map!(f, Vector{Any}(undef, length(itr)::Int), itr) # convenient for Expr.args
21672170

21682171
# default to returning an Array for `map` on general iterators
21692172
"""

base/compiler/ssair/slot2ssa.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ function fixemup!(cond, rename, ir::IRCode, ci::CodeInfo, idx::Int, @nospecializ
168168
return nothing
169169
end
170170
op[] = x
171+
elseif isa(val, GlobalRef) && !isdefined(val.mod, val.name)
172+
op[] = NewSSAValue(insert_node!(ir, idx, Any, val).id - length(ir.stmts))
171173
end
172174
end
173175
return urs[]

base/compiler/ssair/verify.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
if !isdefined(@__MODULE__, Symbol("@verify_error"))
44
macro verify_error(arg)
5-
arg isa String && return esc(:(println(stderr, $arg)))
5+
arg isa String && return esc(:(print && println(stderr, $arg)))
66
(arg isa Expr && arg.head === :string) || error("verify_error macro expected a string expression")
77
pushfirst!(arg.args, GlobalRef(Core, :stderr))
88
pushfirst!(arg.args, :println)
@@ -11,7 +11,7 @@ if !isdefined(@__MODULE__, Symbol("@verify_error"))
1111
end
1212
end
1313

14-
function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int, use_idx::Int)
14+
function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int, use_idx::Int, print::Bool)
1515
if isa(op, SSAValue)
1616
if op.id > length(ir.stmts)
1717
def_bb = block_for_inst(ir.cfg, ir.new_nodes[op.id - length(ir.stmts)].pos)
@@ -35,6 +35,11 @@ function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int,
3535
error()
3636
end
3737
end
38+
elseif isa(op, GlobalRef)
39+
if !isdefined(op.mod, op.name)
40+
@verify_error "Unbound GlobalRef not allowed in value position"
41+
error()
42+
end
3843
elseif isa(op, Union{OldSSAValue, NewSSAValue})
3944
#@Base.show ir
4045
@verify_error "Left over SSA marker"
@@ -55,7 +60,7 @@ function count_int(val::Int, arr::Vector{Int})
5560
n
5661
end
5762

58-
function verify_ir(ir::IRCode)
63+
function verify_ir(ir::IRCode, print::Bool=true)
5964
# For now require compact IR
6065
# @assert isempty(ir.new_nodes)
6166
# Verify CFG
@@ -169,7 +174,7 @@ function verify_ir(ir::IRCode)
169174
@verify_error "GlobalRefs and Exprs are not allowed as PhiNode values"
170175
error()
171176
end
172-
check_op(ir, domtree, val, edge, last(ir.cfg.blocks[stmt.edges[i]].stmts)+1)
177+
check_op(ir, domtree, val, edge, last(ir.cfg.blocks[stmt.edges[i]].stmts)+1, print)
173178
end
174179
elseif isa(stmt, PhiCNode)
175180
for i = 1:length(stmt.values)
@@ -206,17 +211,18 @@ function verify_ir(ir::IRCode)
206211
end
207212
for op in userefs(stmt)
208213
op = op[]
209-
check_op(ir, domtree, op, bb, idx)
214+
check_op(ir, domtree, op, bb, idx, print)
210215
end
211216
end
212217
end
213218
end
214219

215-
function verify_linetable(linetable::Vector{LineInfoNode})
220+
function verify_linetable(linetable::Vector{LineInfoNode}, print::Bool=true)
216221
for i in 1:length(linetable)
217222
line = linetable[i]
218223
if i <= line.inlined_at
219224
@verify_error "Misordered linetable"
225+
error()
220226
end
221227
end
222228
end

base/docs/Docs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function signature!(tv, expr::Expr)
9696
push!(sig.args[end].args, argtype(arg))
9797
end
9898
if isexpr(expr.args[1], :curly) && isempty(tv)
99-
append!(tv, mapany(tvar, expr.args[1].args[2:end]))
99+
append!(tv, mapany(tvar, (expr.args[1]::Expr).args[2:end]))
100100
end
101101
for i = length(tv):-1:1
102102
push!(sig.args, :(Tuple{$(tv[i].args[1])}))

base/essentials.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ convert(::Type{T}, x::T) where {T} = x
172172
convert(::Type{Type}, x::Type) = x # the ssair optimizer is strongly dependent on this method existing to avoid over-specialization
173173
# in the absence of inlining-enabled
174174
# (due to fields typed as `Type`, which is generally a bad idea)
175+
# These end up being called during bootstrap and then would be invalidated if not for the following:
176+
convert(::Type{String}, x::String) = x
175177

176178
"""
177179
@eval [mod,] ex

base/indices.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ not all index types are guaranteed to propagate to `Base.to_index`.
320320
"""
321321
to_indices(A, I::Tuple) = (@_inline_meta; to_indices(A, axes(A), I))
322322
to_indices(A, I::Tuple{Any}) = (@_inline_meta; to_indices(A, (eachindex(IndexLinear(), A),), I))
323+
# In simple cases, we know that we don't need to use axes(A), optimize those.
324+
# Having this here avoids invalidations from multidimensional.jl: to_indices(A, I::Tuple{Vararg{Union{Integer, CartesianIndex}}})
325+
to_indices(A, I::Tuple{}) = ()
326+
to_indices(A, I::Tuple{Vararg{Integer}}) = (@_inline_meta; to_indices(A, (), I))
323327
to_indices(A, inds, ::Tuple{}) = ()
324328
to_indices(A, inds, I::Tuple{Any, Vararg{Any}}) =
325329
(@_inline_meta; (to_index(A, I[1]), to_indices(A, _maybetail(inds), tail(I))...))

base/initdefs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ function active_project(search_load_path::Bool=true)
266266
project == "@" && continue
267267
project = load_path_expand(project)
268268
project === nothing && continue
269+
# while this seems well-inferred, nevertheless without the type annotation below
270+
# there are backedges here from abspath(::AbstractString, ::String)
271+
project = project::String
269272
if !isfile_casesensitive(project) && basename(project) project_names
270273
project = abspath(project, "Project.toml")
271274
end

base/math.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,10 @@ end
776776
ldexp(x::Float16, q::Integer) = Float16(ldexp(Float32(x), q))
777777

778778
"""
779-
exponent(x) -> Int
779+
exponent(x::AbstractFloat) -> Int
780780
781781
Get the exponent of a normalized floating-point number.
782+
Returns the largest integer `y` such that `2^y ≤ abs(x)`.
782783
"""
783784
function exponent(x::T) where T<:IEEEFloat
784785
@noinline throw1(x) = throw(DomainError(x, "Cannot be NaN or Inf."))

base/meta.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function _parse_string(text::AbstractString, filename::AbstractString,
155155
if index < 1 || index > ncodeunits(text) + 1
156156
throw(BoundsError(text, index))
157157
end
158-
ex, offset = Core._parse(text, filename, index-1, options)
158+
ex, offset::Int = Core._parse(text, filename, index-1, options)
159159
ex, offset+1
160160
end
161161

base/multidimensional.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,6 @@ ensure_indexable(I::Tuple{}) = ()
701701

702702
# In simple cases, we know that we don't need to use axes(A). Optimize those
703703
# until Julia gets smart enough to elide the call on its own:
704-
to_indices(A, I::Tuple{}) = ()
705704
@inline to_indices(A, I::Tuple{Vararg{Union{Integer, CartesianIndex}}}) = to_indices(A, (), I)
706705
# But some index types require more context spanning multiple indices
707706
# CartesianIndexes are simple; they just splat out

base/reflection.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,18 +987,22 @@ struct CodegenParams
987987

988988
lookup::Ptr{Cvoid}
989989

990+
generic_context::Any
991+
990992
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
991993
static_alloc::Bool=true, prefer_specsig::Bool=false,
992994
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
993995
module_setup=nothing, module_activation=nothing, raise_exception=nothing,
994996
emit_function=nothing, emitted_function=nothing,
995-
lookup::Ptr{Cvoid}=cglobal(:jl_rettype_inferred))
997+
lookup::Ptr{Cvoid}=cglobal(:jl_rettype_inferred),
998+
generic_context = nothing)
996999
return new(
9971000
Cint(track_allocations), Cint(code_coverage),
9981001
Cint(static_alloc), Cint(prefer_specsig),
9991002
Cint(gnu_pubnames), debug_info_kind,
10001003
module_setup, module_activation, raise_exception,
1001-
emit_function, emitted_function, lookup)
1004+
emit_function, emitted_function, lookup,
1005+
generic_context)
10021006
end
10031007
end
10041008

base/shell.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717

1818
function shell_parse(str::AbstractString, interpolate::Bool=true;
1919
special::AbstractString="")
20-
s::SubString = SubString(str, firstindex(str))
20+
s = SubString(str, firstindex(str))
2121
s = rstrip_shell(lstrip(s))
2222

2323
# N.B.: This is used by REPLCompletions
@@ -37,9 +37,9 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
3737
push!(arg, x)
3838
end
3939
end
40-
function consume_upto(j)
40+
function consume_upto(s, i, j)
4141
update_arg(s[i:prevind(s, j)::Int])
42-
i = something(peek(st), (lastindex(s)::Int+1,'\0'))[1]
42+
something(peek(st), (lastindex(s)::Int+1,'\0'))[1]
4343
end
4444
function append_arg()
4545
if isempty(arg); arg = Any["",]; end
@@ -49,7 +49,7 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
4949

5050
for (j::Int, c::AbstractChar) in st
5151
if !in_single_quotes && !in_double_quotes && isspace(c)
52-
consume_upto(j)
52+
i = consume_upto(s, i, j)
5353
append_arg()
5454
while !isempty(st)
5555
# We've made sure above that we don't end in whitespace,
@@ -59,7 +59,7 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
5959
popfirst!(st)
6060
end
6161
elseif interpolate && !in_single_quotes && c == '$'
62-
consume_upto(j)
62+
i = consume_upto(s, i, j)
6363
isempty(st) && error("\$ right before end of command")
6464
stpos, c = popfirst!(st)
6565
isspace(c) && error("space not allowed right after \$")
@@ -79,21 +79,21 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
7979
else
8080
if !in_double_quotes && c == '\''
8181
in_single_quotes = !in_single_quotes
82-
consume_upto(j)
82+
i = consume_upto(s, i, j)
8383
elseif !in_single_quotes && c == '"'
8484
in_double_quotes = !in_double_quotes
85-
consume_upto(j)
85+
i = consume_upto(s, i, j)
8686
elseif c == '\\'
8787
if in_double_quotes
8888
isempty(st) && error("unterminated double quote")
8989
k, c′ = peek(st)
9090
if c′ == '"' || c′ == '$' || c′ == '\\'
91-
consume_upto(j)
91+
i = consume_upto(s, i, j)
9292
_ = popfirst!(st)
9393
end
9494
elseif !in_single_quotes
9595
isempty(st) && error("dangling backslash")
96-
consume_upto(j)
96+
i = consume_upto(s, i, j)
9797
_ = popfirst!(st)
9898
end
9999
elseif !in_single_quotes && !in_double_quotes && c in special

base/simdloop.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function check_body!(x::Expr)
2626
if x.head === :break || x.head === :continue
2727
throw(SimdError("$(x.head) is not allowed inside a @simd loop body"))
2828
elseif x.head === :macrocall && x.args[1] === Symbol("@goto")
29-
throw(SimdError("$(x.args[1]) is not allowed inside a @simd loop body"))
29+
throw(SimdError("@goto is not allowed inside a @simd loop body"))
3030
end
3131
for arg in x.args
3232
check_body!(arg)

base/strings/string.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pointer(s::String) = unsafe_convert(Ptr{UInt8}, s)
9595
pointer(s::String, i::Integer) = pointer(s)+(i-1)
9696

9797
@pure ncodeunits(s::String) = Core.sizeof(s)
98-
@pure sizeof(s::String) = Core.sizeof(s)
9998
codeunit(s::String) = UInt8
10099

101100
@inline function codeunit(s::String, i::Integer)

base/strings/util.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ julia> lstrip(a)
224224
"""
225225
function lstrip(f, s::AbstractString)
226226
e = lastindex(s)
227-
for (i, c) in pairs(s)
227+
for (i::Int, c::AbstractChar) in pairs(s)
228228
!f(c) && return @inbounds SubString(s, i, e)
229229
end
230230
SubString(s, e+1, e)

base/util.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Printing with the color `:nothing` will print the string without modifications.
6666
"""
6767
text_colors
6868

69-
function with_output_color(f::Function, color::Union{Int, Symbol}, io::IO, args...; bold::Bool = false)
69+
function with_output_color(@nospecialize(f::Function), color::Union{Int, Symbol}, io::IO, args...; bold::Bool = false)
7070
buf = IOBuffer()
7171
iscolor = get(io, :color, false)::Bool
7272
try f(IOContext(buf, io), args...)

src/cgutils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2872,5 +2872,6 @@ static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
28722872
// hooks
28732873
(a->module_setup == b->module_setup) &&
28742874
(a->module_activation == b->module_activation) &&
2875-
(a->raise_exception == b->raise_exception);
2875+
(a->raise_exception == b->raise_exception) &&
2876+
(a->generic_context == b->generic_context);
28762877
}

src/codegen.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ extern "C" {
821821
1,
822822
#endif
823823
jl_default_debug_info_kind, NULL, NULL, NULL, NULL, NULL,
824-
jl_rettype_inferred };
824+
jl_rettype_inferred, NULL };
825825
}
826826

827827
template<typename T>
@@ -2352,7 +2352,7 @@ static Value *emit_bits_compare(jl_codectx_t &ctx, jl_cgval_t arg1, jl_cgval_t a
23522352
nroots++;
23532353
if ((gc_uses[nroots] = get_gc_root_for(arg2)))
23542354
nroots++;
2355-
OperandBundleDef OpBundle("jl_roots", gc_uses);
2355+
OperandBundleDef OpBundle("jl_roots", makeArrayRef(gc_uses, nroots));
23562356
Value *answer = ctx.builder.CreateCall(prepare_call(memcmp_func), {
23572357
ctx.builder.CreateBitCast(varg1, T_pint8),
23582358
ctx.builder.CreateBitCast(varg2, T_pint8),
@@ -3379,7 +3379,15 @@ static jl_cgval_t emit_call(jl_codectx_t &ctx, jl_expr_t *ex, jl_value_t *rt)
33793379
return emit_intrinsic(ctx, fi, args, nargs - 1);
33803380
}
33813381

3382-
jl_cgval_t *argv = (jl_cgval_t*)alloca(sizeof(jl_cgval_t) * nargs);
3382+
jl_value_t *context = ctx.params->generic_context == jl_nothing ? nullptr : ctx.params->generic_context;
3383+
size_t n_generic_args = nargs + (context ? 1 : 0);
3384+
3385+
jl_cgval_t *generic_argv = (jl_cgval_t*)alloca(sizeof(jl_cgval_t) * n_generic_args);
3386+
jl_cgval_t *argv = generic_argv;
3387+
if (context) {
3388+
generic_argv[0] = mark_julia_const(context);
3389+
argv = &generic_argv[1];
3390+
}
33833391
argv[0] = f;
33843392
for (size_t i = 1; i < nargs; ++i) {
33853393
argv[i] = emit_expr(ctx, args[i]);
@@ -3405,7 +3413,7 @@ static jl_cgval_t emit_call(jl_codectx_t &ctx, jl_expr_t *ex, jl_value_t *rt)
34053413
}
34063414

34073415
// emit function and arguments
3408-
Value *callval = emit_jlcall(ctx, jlapplygeneric_func, nullptr, argv, nargs, JLCALL_F_CC);
3416+
Value *callval = emit_jlcall(ctx, jlapplygeneric_func, nullptr, generic_argv, n_generic_args, JLCALL_F_CC);
34093417
return mark_julia_type(ctx, callval, true, rt);
34103418
}
34113419

@@ -7425,6 +7433,7 @@ extern "C" void jl_init_llvm(void)
74257433
jl_default_cgparams.raise_exception = jl_nothing;
74267434
jl_default_cgparams.emit_function = jl_nothing;
74277435
jl_default_cgparams.emitted_function = jl_nothing;
7436+
jl_default_cgparams.generic_context = jl_nothing;
74287437
jl_init_debuginfo();
74297438

74307439
InitializeNativeTarget();

src/dlload.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags,
190190
snprintf(relocated, PATHBUF, "%s%s", jl_options.julia_bindir, dl_path + 16);
191191
len = len - 16 + strlen(jl_options.julia_bindir);
192192
} else {
193-
strncpy(relocated, dl_path, len);
193+
strncpy(relocated, dl_path, PATHBUF);
194+
relocated[PATHBUF-1] = '\0';
194195
}
195196
for (i = 0; i < n_extensions; i++) {
196197
const char *ext = extensions[i];

src/dump.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ static void jl_serialize_value_(jl_serializer_state *s, jl_value_t *v, int as_li
662662
int flags = validate << 0;
663663
if (codeinst->invoke == jl_fptr_const_return)
664664
flags |= 1 << 2;
665+
if (codeinst->precompile)
666+
flags |= 1 << 3;
665667
write_uint8(s->s, flags);
666668
jl_serialize_value(s, (jl_value_t*)codeinst->def);
667669
if (validate || codeinst->min_world == 0) {
@@ -1494,6 +1496,8 @@ static jl_value_t *jl_deserialize_value_code_instance(jl_serializer_state *s, jl
14941496
jl_gc_wb(codeinst, codeinst->rettype);
14951497
if (constret)
14961498
codeinst->invoke = jl_fptr_const_return;
1499+
if ((flags >> 3) & 1)
1500+
codeinst->precompile = 1;
14971501
codeinst->next = (jl_code_instance_t*)jl_deserialize_value(s, (jl_value_t**)&codeinst->next);
14981502
jl_gc_wb(codeinst, codeinst->next);
14991503
if (validate)

0 commit comments

Comments
 (0)