Skip to content

Commit b574c7d

Browse files
authored
Merge pull request #39146 from JuliaLang/backports-release-1.6
Backports release 1.6-beta1
2 parents c981a57 + 38f3b1e commit b574c7d

File tree

13 files changed

+150
-22
lines changed

13 files changed

+150
-22
lines changed

base/array.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,20 @@ function _collect_indices(indsA, A)
624624
copyto!(B, CartesianIndices(axes(B)), A, CartesianIndices(indsA))
625625
end
626626

627+
# NOTE: this function is not meant to be called, only inferred, for the
628+
# purpose of bounding the types of values generated by an iterator.
629+
function _iterator_upper_bound(itr)
630+
x = iterate(itr)
631+
while x !== nothing
632+
val = getfield(x, 1)
633+
if inferencebarrier(nothing)
634+
return val
635+
end
636+
x = iterate(itr, getfield(x, 2))
637+
end
638+
throw(nothing)
639+
end
640+
627641
# define this as a macro so that the call to Core.Compiler
628642
# gets inlined into the caller before recursion detection
629643
# gets a chance to see it, so that recursive calls to the caller
@@ -635,7 +649,7 @@ if isdefined(Core, :Compiler)
635649
if $I isa Generator && ($I).f isa Type
636650
($I).f
637651
else
638-
Core.Compiler.return_type(first, Tuple{typeof($I)})
652+
Core.Compiler.return_type(_iterator_upper_bound, Tuple{typeof($I)})
639653
end
640654
end
641655
end

base/cmd.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,19 @@ setenv(cmd::Cmd, env::Pair{<:AbstractString}...; dir="") =
246246
setenv(cmd::Cmd; dir="") = Cmd(cmd; dir=dir)
247247

248248
"""
249-
addenv(command::Cmd, env...)
249+
addenv(command::Cmd, env...; inherit::Bool = true)
250250
251251
Merge new environment mappings into the given `Cmd` object, returning a new `Cmd` object.
252-
Duplicate keys are replaced.
252+
Duplicate keys are replaced. If `command` does not contain any environment values set already,
253+
it inherits the current environment at time of `addenv()` call if `inherit` is `true`.
253254
"""
254-
function addenv(cmd::Cmd, env::Dict)
255+
function addenv(cmd::Cmd, env::Dict; inherit::Bool = true)
255256
new_env = Dict{String,String}()
256-
if cmd.env !== nothing
257+
if cmd.env === nothing
258+
if inherit
259+
merge!(new_env, ENV)
260+
end
261+
else
257262
for (k, v) in split.(cmd.env, "=")
258263
new_env[string(k)::String] = string(v)::String
259264
end
@@ -264,12 +269,12 @@ function addenv(cmd::Cmd, env::Dict)
264269
return setenv(cmd, new_env)
265270
end
266271

267-
function addenv(cmd::Cmd, pairs::Pair{<:AbstractString}...)
268-
return addenv(cmd, Dict(k => v for (k, v) in pairs))
272+
function addenv(cmd::Cmd, pairs::Pair{<:AbstractString}...; inherit::Bool = true)
273+
return addenv(cmd, Dict(k => v for (k, v) in pairs); inherit)
269274
end
270275

271-
function addenv(cmd::Cmd, env::Vector{<:AbstractString})
272-
return addenv(cmd, Dict(k => v for (k, v) in split.(env, "=")))
276+
function addenv(cmd::Cmd, env::Vector{<:AbstractString}; inherit::Bool = true)
277+
return addenv(cmd, Dict(k => v for (k, v) in split.(env, "=")); inherit)
273278
end
274279

275280
(&)(left::AbstractCmd, right::AbstractCmd) = AndCmds(left, right)

base/compiler/ssair/passes.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@ function getfield_elim_pass!(ir::IRCode)
637637
isa(field, Union{Int, Symbol}) || continue
638638

639639
struct_typ = unwrap_unionall(widenconst(compact_exprtype(compact, stmt.args[2])))
640+
if isa(struct_typ, Union) && struct_typ <: Tuple
641+
struct_typ = unswitchtupleunion(struct_typ)
642+
end
640643
isa(struct_typ, DataType) || continue
641644

642645
def, typeconstraint = stmt.args[2], struct_typ

base/compiler/typeutils.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,21 @@ function improvable_via_constant_propagation(@nospecialize(t))
206206
end
207207
return false
208208
end
209+
210+
# convert a Union of Tuple types to a Tuple of Unions
211+
function unswitchtupleunion(u::Union)
212+
ts = uniontypes(u)
213+
n = -1
214+
for t in ts
215+
if t isa DataType && t.name === Tuple.name && !isvarargtype(t.parameters[end])
216+
if n == -1
217+
n = length(t.parameters)
218+
elseif n != length(t.parameters)
219+
return u
220+
end
221+
else
222+
return u
223+
end
224+
end
225+
Tuple{Any[ Union{Any[t.parameters[i] for t in ts]...} for i in 1:n ]...}
226+
end

base/timing.jl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,9 @@ macro time(ex)
203203
local stats = gc_num()
204204
local compile_elapsedtime = cumulative_compile_time_ns_before()
205205
local elapsedtime = time_ns()
206-
local val = try
207-
$(esc(ex))
208-
finally
209-
elapsedtime = time_ns() - elapsedtime
210-
compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime
211-
end
206+
local val = $(esc(ex))
207+
elapsedtime = time_ns() - elapsedtime
208+
compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime
212209
local diff = GC_Diff(gc_num(), stats)
213210
time_print(elapsedtime, diff.allocd, diff.total_time, gc_alloc_count(diff), compile_elapsedtime, true)
214211
val
@@ -252,12 +249,9 @@ macro timev(ex)
252249
local stats = gc_num()
253250
local compile_elapsedtime = cumulative_compile_time_ns_before()
254251
local elapsedtime = time_ns()
255-
local val = try
256-
$(esc(ex))
257-
finally
258-
elapsedtime = time_ns() - elapsedtime
259-
compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime
260-
end
252+
local val = $(esc(ex))
253+
elapsedtime = time_ns() - elapsedtime
254+
compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime
261255
local diff = GC_Diff(gc_num(), stats)
262256
timev_print(elapsedtime, diff, compile_elapsedtime)
263257
val

src/llvm-alloc-opt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static bool hasObjref(Type *ty)
6666
return ptrty->getAddressSpace() == AddressSpace::Tracked;
6767
#if JL_LLVM_VERSION >= 110000
6868
if (isa<ArrayType>(ty) || isa<VectorType>(ty))
69-
return GetElementPtrInst::getTypeAtIndex(ty, (uint64_t)0);
69+
return hasObjref(GetElementPtrInst::getTypeAtIndex(ty, (uint64_t)0));
7070
#else
7171
if (auto seqty = dyn_cast<SequentialType>(ty))
7272
return hasObjref(seqty->getElementType());

src/task.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ static void JL_NORETURN throw_internal(jl_value_t *exception JL_MAYBE_UNROOTED)
587587
{
588588
jl_ptls_t ptls = jl_get_ptls_states();
589589
ptls->io_wait = 0;
590+
// @time needs its compile timer disabled on error,
591+
// and cannot use a try-finally as it would break scope for assignments
592+
jl_measure_compile_time[ptls->tid] = 0;
590593
if (ptls->safe_restore)
591594
jl_longjmp(*ptls->safe_restore, 1);
592595
// During startup

test/compiler/irpasses.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,20 @@ let code = code_typed(pi_on_argument, Tuple{Any})[1].first.code,
342342
@test nisa == 1
343343
@test found_pi
344344
end
345+
346+
# issue #38936
347+
# check that getfield elim can handle unions of tuple types
348+
mutable struct S38936{T} content::T end
349+
struct PrintAll{T} <: Function
350+
parts::T
351+
end
352+
function (f::PrintAll)(io::IO)
353+
for x in f.parts
354+
print(io, x)
355+
end
356+
end
357+
let f = PrintAll((S38936("<span>"), "data", S38936("</span")))
358+
@test !any(code_typed(f, (IOBuffer,))[1][1].code) do stmt
359+
stmt isa Expr && stmt.head === :call && stmt.args[1] === GlobalRef(Core, :tuple)
360+
end
361+
end

test/core.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5080,6 +5080,19 @@ end
50805080
@test f17255(10000)[1]
50815081
GC.enable(true)
50825082

5083+
# PR #39133, ensure that @time evaluates in the same scope
5084+
function time_macro_scope()
5085+
@time time_macro_local_var = 1
5086+
time_macro_local_var
5087+
end
5088+
@test time_macro_scope() == 1
5089+
5090+
function timev_macro_scope()
5091+
@timev timev_macro_local_var = 1
5092+
timev_macro_local_var
5093+
end
5094+
@time timev_macro_scope() == 1
5095+
50835096
# issue #18710
50845097
bad_tvars() where {T} = 1
50855098
@test isa(which(bad_tvars, ()), Method)

test/dict.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ end
159159
d = Dict(i==1 ? (1=>2) : (2.0=>3.0) for i=1:2)
160160
@test isa(d, Dict{Real,Real})
161161
@test d == Dict{Real,Real}(2.0=>3.0, 1=>2)
162+
163+
# issue #39117
164+
@test Dict(t[1]=>t[2] for t in zip((1,"2"), (2,"2"))) == Dict{Any,Any}(1=>2, "2"=>"2")
162165
end
163166

164167
@testset "type of Dict constructed from varargs of Pairs" begin

0 commit comments

Comments
 (0)