Skip to content

Commit 1c977b0

Browse files
authored
Merge pull request #34238 from JuliaLang/backports-release-1.4
Backports for 1.4-RC1
2 parents 4c58369 + 139696b commit 1c977b0

File tree

217 files changed

+453
-381
lines changed

Some content is hidden

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

217 files changed

+453
-381
lines changed

base/arrayshow.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ but it also repeated every M elements if desired.
122122
"""
123123
function print_matrix_vdots(io::IO, vdots::AbstractString,
124124
A::Vector, sep::AbstractString, M::Integer, m::Integer,
125-
pad_right::Bool)
125+
pad_right::Bool = true)
126126
for k = 1:length(A)
127127
w = A[k][1] + A[k][2]
128128
if k % M == m

base/broadcast.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ _bcsm(a::Number, b::Number) = a == b || b == 1
496496
# (We may not want to define general promotion rules between, say, OneTo and Slice, but if
497497
# we get here we know the axes are at least consistent for the purposes of broadcasting)
498498
axistype(a::T, b::T) where T = a
499+
axistype(a::OneTo, b::OneTo) = OneTo{Int}(a)
499500
axistype(a, b) = UnitRange{Int}(a)
500501

501502
## Check that all arguments are broadcast compatible with shape

base/c.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Note that the argument type tuple must be a literal tuple, and not a tuple-value
4747
(although it can include a splat expression). And that these arguments will be evaluated in global scope
4848
during compile-time (not deferred until runtime).
4949
Adding a '\\\$' in front of the function argument changes this to instead create a runtime closure
50-
over the local variable `callable`.
50+
over the local variable `callable` (this is not supported on all architectures).
5151
5252
See [manual section on ccall and cfunction usage](@ref Calling-C-and-Fortran-Code).
5353

base/compiler/ssair/passes.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
370370
end
371371
elseif isa(leaf, QuoteNode)
372372
leaf = leaf.value
373+
elseif isa(leaf, GlobalRef)
374+
mod, name = leaf.mod, leaf.name
375+
if isdefined(mod, name) && isconst(mod, name)
376+
leaf = getfield(mod, name)
377+
else
378+
return nothing
379+
end
373380
elseif isa(leaf, Union{Argument, Expr})
374381
return nothing
375382
end

base/compiler/ssair/verify.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function check_op(ir::IRCode, domtree::DomTree, @nospecialize(op), use_bb::Int,
2929
end
3030
else
3131
if !dominates(domtree, def_bb, use_bb) && !(bb_unreachable(domtree, def_bb) && bb_unreachable(domtree, use_bb))
32+
# At the moment, we allow GC preserve tokens outside the standard domination notion
3233
#@Base.show ir
3334
@verify_error "Basic Block $def_bb does not dominate block $use_bb (tried to use value $(op.id))"
3435
error()
@@ -189,10 +190,17 @@ function verify_ir(ir::IRCode)
189190
end
190191
end
191192
end
192-
if isa(stmt, Expr) && stmt.head === :(=)
193-
if stmt.args[1] isa SSAValue
194-
@verify_error "SSAValue as assignment LHS"
195-
error()
193+
if isa(stmt, Expr)
194+
if stmt.head === :(=)
195+
if stmt.args[1] isa SSAValue
196+
@verify_error "SSAValue as assignment LHS"
197+
error()
198+
end
199+
elseif stmt.head === :gc_preserve_end
200+
# We allow gc_preserve_end tokens to span across try/catch
201+
# blocks, which isn't allowed for regular SSA values, so
202+
# we skip the validation below.
203+
continue
196204
end
197205
end
198206
for op in userefs(stmt)

base/compiler/typelimits.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,6 @@ function is_derived_type(@nospecialize(t), @nospecialize(c), mindepth::Int)
5757
for p in cP
5858
is_derived_type(t, p, mindepth) && return true
5959
end
60-
if isconcretetype(c) && isbitstype(c)
61-
# see if it was extracted from a fieldtype
62-
# however, only look through types that can be inlined
63-
# to ensure monotonicity of derivation
64-
# since we know that for immutable, concrete, bits types,
65-
# the field types must have been constructed prior to the type,
66-
# it cannot have a reference cycle in the type graph
67-
cF = c.types
68-
for f in cF
69-
# often a parameter is also a field type; avoid searching twice
70-
if !contains_is(c.parameters, f)
71-
is_derived_type(t, f, mindepth) && return true
72-
end
73-
end
74-
end
7560
end
7661
return false
7762
end

base/div.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,17 @@ julia> divrem(7,3)
116116
```
117117
"""
118118
divrem(x, y) = divrem(x, y, RoundToZero)
119-
divrem(a, b, r::RoundingMode) = (div(a, b, r), rem(a, b, r))
119+
function divrem(a, b, r::RoundingMode)
120+
if r == RoundToZero
121+
# For compat. Remove in 2.0.
122+
(div(a, b), rem(a, b))
123+
elseif r === RoundDown
124+
# For compat. Remove in 2.0.
125+
(fld(a, b), mod(a, b))
126+
else
127+
(div(a, b, r), rem(a, b, r))
128+
end
129+
end
120130
function divrem(x::Integer, y::Integer, rnd::typeof(RoundNearest))
121131
(q, r) = divrem(x, y)
122132
if x >= 0

base/file.jl

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,20 +517,29 @@ function mktemp(parent::AbstractString=tempdir(); cleanup::Bool=true)
517517
return (filename, Base.open(filename, "r+"))
518518
end
519519

520+
# generate a random string from random bytes
521+
function _rand_string()
522+
nchars = 10
523+
A = Vector{UInt8}(undef, nchars)
524+
windowserror("SystemFunction036 (RtlGenRandom)", 0 == ccall(
525+
(:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Cvoid}, UInt32),
526+
A, sizeof(A)))
527+
528+
slug = Base.StringVector(10)
529+
chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
530+
for i = 1:nchars
531+
slug[i] = chars[(A[i] % length(chars)) + 1]
532+
end
533+
return name = String(slug)
534+
end
535+
520536
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true)
521537
isdir(parent) || throw(ArgumentError("$(repr(parent)) is not a directory"))
522-
seed::UInt32 = rand(UInt32)
523-
while true
524-
if (seed & typemax(UInt16)) == 0
525-
seed += 1
526-
end
527-
filename = _win_tempname(parent, seed)
528-
if !ispath(filename)
529-
cleanup && temp_cleanup_later(filename)
530-
return filename
531-
end
532-
seed += 1
533-
end
538+
name = _rand_string()
539+
filename = joinpath(parent, temp_prefix * name)
540+
@assert !ispath(filename)
541+
cleanup && temp_cleanup_later(filename)
542+
return filename
534543
end
535544

536545
else # !windows

base/gcutils.jl

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,20 @@ Module with garbage collection utilities.
4949
"""
5050
module GC
5151

52-
# @enum-like structure
53-
struct CollectionType
54-
x::Int
55-
end
56-
Base.cconvert(::Type{Cint}, collection::CollectionType) = Cint(collection.x)
57-
58-
const Auto = CollectionType(0)
59-
const Full = CollectionType(1)
60-
const Incremental = CollectionType(2)
61-
6252
"""
63-
GC.gc(full::Bool=true)
64-
GC.gc(collection::CollectionType)
53+
GC.gc()
54+
GC.gc(full::Bool)
6555
66-
Perform garbage collection. The argument `full` determines whether a full, but more costly
67-
collection is performed. Otherwise, heuristics are used to determine which type of
68-
collection is needed. For exact control, pass an argument of type `CollectionType`.
56+
Perform garbage collection. The argument `full` determines the kind of collection: A full
57+
collection scans all objects, while an incremental collection only scans so-called young
58+
objects and is much quicker. If called without an argument, heuristics are used to determine
59+
which type of collection is needed.
6960
7061
!!! warning
7162
Excessive use will likely lead to poor performance.
7263
"""
73-
gc(full::Bool=true) = ccall(:jl_gc_collect, Cvoid, (Cint,), full)
74-
gc(collection::CollectionType) = ccall(:jl_gc_collect, Cvoid, (Cint,), collection)
64+
gc() = ccall(:jl_gc_collect, Cvoid, (Cint,), 0)
65+
gc(full::Bool) = ccall(:jl_gc_collect, Cvoid, (Cint,), full ? 1 : 2)
7566

7667
"""
7768
GC.enable(on::Bool)
@@ -99,13 +90,7 @@ macro preserve(args...)
9990
for x in syms
10091
isa(x, Symbol) || error("Preserved variable must be a symbol")
10192
end
102-
s, r = gensym(), gensym()
103-
esc(quote
104-
$s = $(Expr(:gc_preserve_begin, syms...))
105-
$r = $(args[end])
106-
$(Expr(:gc_preserve_end, s))
107-
$r
108-
end)
93+
esc(Expr(:gc_preserve, args[end], syms...))
10994
end
11095

11196
"""

base/int.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ julia> signed(unsigned(-2))
155155
-2
156156
```
157157
"""
158-
unsigned(x) = convert(Unsigned, x)
158+
unsigned(x) = x % typeof(convert(Unsigned, zero(x)))
159159
unsigned(x::BitSigned) = reinterpret(typeof(convert(Unsigned, zero(x))), x)
160160

161161
"""
@@ -164,7 +164,7 @@ unsigned(x::BitSigned) = reinterpret(typeof(convert(Unsigned, zero(x))), x)
164164
Convert a number to a signed integer. If the argument is unsigned, it is reinterpreted as
165165
signed without checking for overflow.
166166
"""
167-
signed(x) = convert(Signed, x)
167+
signed(x) = x % typeof(convert(Signed, zero(x)))
168168
signed(x::BitUnsigned) = reinterpret(typeof(convert(Signed, zero(x))), x)
169169

170170
div(x::BitSigned, y::Unsigned) = flipsign(signed(div(unsigned(abs(x)), y)), x)

0 commit comments

Comments
 (0)