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."))

0 commit comments

Comments
 (0)