Skip to content

Commit

Permalink
Merge pull request JuliaLang#44675 from JuliaLang/backports-release-1.8
Browse files Browse the repository at this point in the history
More backports for julia 1.8-beta2
  • Loading branch information
KristofferC committed Mar 21, 2022
2 parents e191c6e + a00e1f1 commit b655b2c
Show file tree
Hide file tree
Showing 34 changed files with 595 additions and 511 deletions.
4 changes: 2 additions & 2 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ ifeq ($(OS),FreeBSD)
ifneq (,$(findstring gfortran,$(FC)))

# First let's figure out what version of GCC we're dealing with
_GCCMAJOR := $(shell $(FC) -dumpversion | cut -d'.' -f1)
_GCCMINOR := $(shell $(FC) -dumpversion | cut -d'.' -f2)
_GCCMAJOR := $(shell $(FC) -dumpversion 2>/dev/null | cut -d'.' -f1)
_GCCMINOR := $(shell $(FC) -dumpversion 2>/dev/null | cut -d'.' -f2)

# The ports system uses major and minor for GCC < 5 (e.g. gcc49 for GCC 4.9), otherwise major only
ifeq ($(_GCCMAJOR),4)
Expand Down
4 changes: 2 additions & 2 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ eval(Core, quote
function CodeInstance(
mi::MethodInstance, @nospecialize(rettype), @nospecialize(inferred_const),
@nospecialize(inferred), const_flags::Int32, min_world::UInt, max_world::UInt,
ipo_effects::UInt8, effects::UInt8, @nospecialize(argescapes#=::Union{Nothing,Vector{ArgEscapeInfo}}=#),
ipo_effects::UInt32, effects::UInt32, @nospecialize(argescapes#=::Union{Nothing,Vector{ArgEscapeInfo}}=#),
relocatability::UInt8)
return ccall(:jl_new_codeinst, Ref{CodeInstance},
(Any, Any, Any, Any, Int32, UInt, UInt, UInt8, UInt8, Any, UInt8),
(Any, Any, Any, Any, Int32, UInt, UInt, UInt32, UInt32, Any, UInt8),
mi, rettype, inferred_const, inferred, const_flags, min_world, max_world,
ipo_effects, effects, argescapes,
relocatability)
Expand Down
6 changes: 3 additions & 3 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -973,14 +973,14 @@ end
destc = dest.chunks
cind = 1
bc′ = preprocess(dest, bc)
for P in Iterators.partition(eachindex(bc′), bitcache_size)
@inbounds for P in Iterators.partition(eachindex(bc′), bitcache_size)
ind = 1
@simd for I in P
@inbounds tmp[ind] = bc′[I]
tmp[ind] = bc′[I]
ind += 1
end
@simd for i in ind:bitcache_size
@inbounds tmp[i] = false
tmp[i] = false
end
dumpbitcache(destc, cind, tmp)
cind += bitcache_chunks
Expand Down
3 changes: 3 additions & 0 deletions base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ include("operators.jl")
include("pointer.jl")
include("refvalue.jl")

# the same constructor as defined in float.jl, but with a different name to avoid redefinition
_Bool(x::Real) = x==0 ? false : x==1 ? true : throw(InexactError(:Bool, Bool, x))

# checked arithmetic
const checked_add = +
const checked_sub = -
Expand Down
11 changes: 10 additions & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,21 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
idx = 1
oldidx = 1
changemap = fill(0, length(code))
labelmap = coverage ? fill(0, length(code)) : changemap
prevloc = zero(eltype(ci.codelocs))
stmtinfo = sv.stmt_info
codelocs = ci.codelocs
ssavaluetypes = ci.ssavaluetypes::Vector{Any}
ssaflags = ci.ssaflags
if !coverage && JLOptions().code_coverage == 3 # path-specific coverage mode
for line in ci.linetable
if is_file_tracked(line.file)
# if any line falls in a tracked file enable coverage for all
coverage = true
break
end
end
end
labelmap = coverage ? fill(0, length(code)) : changemap
while idx <= length(code)
codeloc = codelocs[idx]
if coverage && codeloc != prevloc && codeloc != 0
Expand Down
5 changes: 5 additions & 0 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,15 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
inlined_at = Int(compact.result[idx][:line])
topline::Int32 = linetable_offset + Int32(1)
coverage = coverage_enabled(def.module)
coverage_by_path = JLOptions().code_coverage == 3
push!(linetable, LineInfoNode(def.module, def.name, def.file, Int(def.line), inlined_at))
oldlinetable = spec.ir.linetable
for oldline in 1:length(oldlinetable)
entry = oldlinetable[oldline]
if !coverage && coverage_by_path && is_file_tracked(entry.file)
# include topline coverage entry if in path-specific coverage mode, and any file falls under path
coverage = true
end
newentry = LineInfoNode(entry.module, entry.method, entry.file, entry.line,
(entry.inlined_at > 0 ? entry.inlined_at + linetable_offset + (oldline == 1) : inlined_at))
if oldline == 1
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ function finish(me::InferenceState, interp::AbstractInterpreter)
ipo_effects = Effects(ipo_effects; terminates=ALWAYS_TRUE)
end
end
me.result.ipo_effects = ipo_effects
me.ipo_effects = me.result.ipo_effects = ipo_effects
validate_code_in_debug_mode(me.linfo, me.src, "inferred")
nothing
end
Expand Down
42 changes: 0 additions & 42 deletions base/compiler/typelattice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -467,45 +467,3 @@ function stupdate1!(state::VarTable, change::StateUpdate)
end
return false
end

# compute typeintersect over the extended inference lattice,
# as precisely as we can,
# where v is in the extended lattice, and t is a Type.
function tmeet(@nospecialize(v), @nospecialize(t))
if isa(v, Const)
if !has_free_typevars(t) && !isa(v.val, t)
return Bottom
end
return v
elseif isa(v, PartialStruct)
has_free_typevars(t) && return v
widev = widenconst(v)
if widev <: t
return v
end
ti = typeintersect(widev, t)
valid_as_lattice(ti) || return Bottom
@assert widev <: Tuple
new_fields = Vector{Any}(undef, length(v.fields))
for i = 1:length(new_fields)
vfi = v.fields[i]
if isvarargtype(vfi)
new_fields[i] = vfi
else
new_fields[i] = tmeet(vfi, widenconst(getfield_tfunc(t, Const(i))))
if new_fields[i] === Bottom
return Bottom
end
end
end
return tuple_tfunc(new_fields)
elseif isa(v, Conditional)
if !(Bool <: t)
return Bottom
end
return v
end
ti = typeintersect(widenconst(v), t)
valid_as_lattice(ti) || return Bottom
return ti
end
28 changes: 15 additions & 13 deletions base/compiler/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,33 @@ function Effects(e::Effects = EFFECTS_UNKNOWN;
end

is_total_or_error(effects::Effects) =
effects.consistent === ALWAYS_TRUE && effects.effect_free === ALWAYS_TRUE &&
effects.consistent === ALWAYS_TRUE &&
effects.effect_free === ALWAYS_TRUE &&
effects.terminates === ALWAYS_TRUE

is_total(effects::Effects) =
is_total_or_error(effects) && effects.nothrow === ALWAYS_TRUE
is_total_or_error(effects) &&
effects.nothrow === ALWAYS_TRUE

is_removable_if_unused(effects::Effects) =
effects.effect_free === ALWAYS_TRUE &&
effects.terminates === ALWAYS_TRUE &&
effects.nothrow === ALWAYS_TRUE

function encode_effects(e::Effects)
return (e.consistent.state << 1) |
(e.effect_free.state << 3) |
(e.nothrow.state << 5) |
(e.terminates.state << 7) |
(e.overlayed)
return (e.consistent.state << 0) |
(e.effect_free.state << 2) |
(e.nothrow.state << 4) |
(e.terminates.state << 6) |
(UInt32(e.overlayed) << 8)
end
function decode_effects(e::UInt8)
function decode_effects(e::UInt32)
return Effects(
TriState((e >> 1) & 0x03),
TriState((e >> 3) & 0x03),
TriState((e >> 5) & 0x03),
TriState((e >> 7) & 0x03),
e & 0x01 0x00,
TriState((e >> 0) & 0x03),
TriState((e >> 2) & 0x03),
TriState((e >> 4) & 0x03),
TriState((e >> 6) & 0x03),
_Bool( (e >> 8) & 0x01),
false)
end

Expand Down
4 changes: 2 additions & 2 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ inlining_enabled() = (JLOptions().can_inline == 1)
function coverage_enabled(m::Module)
ccall(:jl_generating_output, Cint, ()) == 0 || return false # don't alter caches
cov = JLOptions().code_coverage
if cov == 1
if cov == 1 # user
m = moduleroot(m)
m === Core && return false
isdefined(Main, :Base) && m === Main.Base && return false
return true
elseif cov == 2
elseif cov == 2 # all
return true
end
return false
Expand Down
6 changes: 6 additions & 0 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ floor(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,round(x, RoundDo
ceil(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,round(x, RoundUp))
round(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,round(x, RoundNearest))

# Bool
trunc(::Type{Bool}, x::AbstractFloat) = (-1 < x < 2) ? 1 <= x : throw(InexactError(:trunc, Bool, x))
floor(::Type{Bool}, x::AbstractFloat) = (0 <= x < 2) ? 1 <= x : throw(InexactError(:floor, Bool, x))
ceil(::Type{Bool}, x::AbstractFloat) = (-1 < x <= 1) ? 0 < x : throw(InexactError(:ceil, Bool, x))
round(::Type{Bool}, x::AbstractFloat) = (-0.5 <= x < 1.5) ? 0.5 < x : throw(InexactError(:round, Bool, x))

round(x::IEEEFloat, r::RoundingMode{:ToZero}) = trunc_llvm(x)
round(x::IEEEFloat, r::RoundingMode{:Down}) = floor_llvm(x)
round(x::IEEEFloat, r::RoundingMode{:Up}) = ceil_llvm(x)
Expand Down
64 changes: 37 additions & 27 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,8 @@ module IteratorsMD
simd_inner_length(iter::CartesianIndices, I::CartesianIndex) = Base.length(iter.indices[1])

simd_index(iter::CartesianIndices{0}, ::CartesianIndex, I1::Int) = first(iter)
@propagate_inbounds function simd_index(iter::CartesianIndices, Ilast::CartesianIndex, I1::Int)
CartesianIndex(getindex(iter.indices[1], I1+first(Base.axes1(iter.indices[1]))), Ilast.I...)
end
@propagate_inbounds simd_index(iter::CartesianIndices, Ilast::CartesianIndex, I1::Int) =
CartesianIndex(iter.indices[1][I1+firstindex(iter.indices[1])], Ilast)

# Split out the first N elements of a tuple
@inline function split(t, V::Val)
Expand Down Expand Up @@ -585,7 +584,7 @@ module IteratorsMD
CartesianIndices(intersect.(a.indices, b.indices))

# Views of reshaped CartesianIndices are used for partitions — ensure these are fast
const CartesianPartition{T<:CartesianIndex, P<:CartesianIndices, R<:ReshapedArray{T,1,P}} = SubArray{T,1,R,Tuple{UnitRange{Int}},false}
const CartesianPartition{T<:CartesianIndex, P<:CartesianIndices, R<:ReshapedArray{T,1,P}} = SubArray{T,1,R,<:Tuple{AbstractUnitRange{Int}},false}
eltype(::Type{PartitionIterator{T}}) where {T<:ReshapedArrayLF} = SubArray{eltype(T), 1, T, Tuple{UnitRange{Int}}, true}
eltype(::Type{PartitionIterator{T}}) where {T<:ReshapedArray} = SubArray{eltype(T), 1, T, Tuple{UnitRange{Int}}, false}
Iterators.IteratorEltype(::Type{<:PartitionIterator{T}}) where {T<:ReshapedArray} = Iterators.IteratorEltype(T)
Expand All @@ -594,7 +593,6 @@ module IteratorsMD
eltype(::Type{PartitionIterator{T}}) where {T<:Union{UnitRange, StepRange, StepRangeLen, LinRange}} = T
Iterators.IteratorEltype(::Type{<:PartitionIterator{T}}) where {T<:Union{OneTo, UnitRange, StepRange, StepRangeLen, LinRange}} = Iterators.IteratorEltype(T)


@inline function iterate(iter::CartesianPartition)
isempty(iter) && return nothing
f = first(iter)
Expand All @@ -610,33 +608,45 @@ module IteratorsMD
# In general, the Cartesian Partition might start and stop in the middle of the outer
# dimensions — thus the outer range of a CartesianPartition is itself a
# CartesianPartition.
t = tail(iter.parent.parent.indices)
ci = CartesianIndices(t)
li = LinearIndices(t)
return @inbounds view(ci, li[tail(iter[1].I)...]:li[tail(iter[end].I)...])
mi = iter.parent.mi
ci = iter.parent.parent
ax, ax1 = axes(ci), Base.axes1(ci)
subs = Base.ind2sub_rs(ax, mi, first(iter.indices[1]))
vl, fl = Base._sub2ind(tail(ax), tail(subs)...), subs[1]
vr, fr = divrem(last(iter.indices[1]) - 1, mi[end]) .+ (1, first(ax1))
oci = CartesianIndices(tail(ci.indices))
# A fake CartesianPartition to reuse the outer iterate fallback
outer = @inbounds view(ReshapedArray(oci, (length(oci),), mi), vl:vr)
init = @inbounds dec(oci[tail(subs)...].I, oci.indices) # real init state
# Use Generator to make inner loop branchless
@inline function skip_len_I(i::Int, I::CartesianIndex)
l = i == 1 ? fl : first(ax1)
r = i == length(outer) ? fr : last(ax1)
l - first(ax1), r - l + 1, I
end
(skip_len_I(i, I) for (i, I) in Iterators.enumerate(Iterators.rest(outer, (init, 0))))
end
function simd_outer_range(iter::CartesianPartition{CartesianIndex{2}})
@inline function simd_outer_range(iter::CartesianPartition{CartesianIndex{2}})
# But for two-dimensional Partitions the above is just a simple one-dimensional range
# over the second dimension; we don't need to worry about non-rectangular staggers in
# higher dimensions.
return @inbounds CartesianIndices((iter[1][2]:iter[end][2],))
end
@inline function simd_inner_length(iter::CartesianPartition, I::CartesianIndex)
inner = iter.parent.parent.indices[1]
@inbounds fi = iter[1].I
@inbounds li = iter[end].I
inner_start = I.I == tail(fi) ? fi[1] : first(inner)
inner_end = I.I == tail(li) ? li[1] : last(inner)
return inner_end - inner_start + 1
end
@inline function simd_index(iter::CartesianPartition, Ilast::CartesianIndex, I1::Int)
# I1 is the 0-based distance from the first dimension's offest
offset = first(iter.parent.parent.indices[1]) # (this is 1 for 1-based arrays)
# In the first column we need to also add in the iter's starting point (branchlessly)
f = @inbounds iter[1]
startoffset = (Ilast.I == tail(f.I))*(f[1] - 1)
CartesianIndex((I1 + offset + startoffset, Ilast.I...))
mi = iter.parent.mi
ci = iter.parent.parent
ax, ax1 = axes(ci), Base.axes1(ci)
fl, vl = Base.ind2sub_rs(ax, mi, first(iter.indices[1]))
fr, vr = Base.ind2sub_rs(ax, mi, last(iter.indices[1]))
outer = @inbounds CartesianIndices((ci.indices[2][vl:vr],))
# Use Generator to make inner loop branchless
@inline function skip_len_I(I::CartesianIndex{1})
l = I == first(outer) ? fl : first(ax1)
r = I == last(outer) ? fr : last(ax1)
l - first(ax1), r - l + 1, I
end
(skip_len_I(I) for I in outer)
end
@inline simd_inner_length(iter::CartesianPartition, (_, len, _)::Tuple{Int,Int,CartesianIndex}) = len
@propagate_inbounds simd_index(iter::CartesianPartition, (skip, _, I)::Tuple{Int,Int,CartesianIndex}, n::Int) =
simd_index(iter.parent.parent, I, n + skip)
end # IteratorsMD


Expand Down
4 changes: 4 additions & 0 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ function unsafe_load_commands(v::Ptr{Ptr{UInt8}})
end
return cmds
end

function is_file_tracked(file::Symbol)
return ccall(:jl_is_file_tracked, Cint, (Any,), file) == 1
end
2 changes: 1 addition & 1 deletion deps/Versions.make
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ OBJCONV_JLL_NAME := Objconv
OBJCONV_JLL_VER := 2.49.1+0

# blastrampoline
BLASTRAMPOLINE_VER := 5.0.1
BLASTRAMPOLINE_VER := 5.1.0
BLASTRAMPOLINE_JLL_NAME := libblastrampoline

# OpenBLAS
Expand Down
Loading

0 comments on commit b655b2c

Please sign in to comment.