Skip to content

Commit 0486330

Browse files
committed
Merge branch 'master' into extrama
2 parents a2a039d + 3522661 commit 0486330

File tree

143 files changed

+3311
-17497
lines changed

Some content is hidden

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

143 files changed

+3311
-17497
lines changed

.buildkite/utilities/rr/rr_capture.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ mktempdir(temp_parent_dir) do dir
111111

112112
new_env = copy(ENV)
113113
new_env["_RR_TRACE_DIR"] = joinpath(dir, "rr_traces")
114-
new_env["RR_LOG"]="all:debug"
114+
new_env["RR_LOG"] = "all:debug"
115+
new_env["RR_UNDER_RR_LOG"] = "all:debug"
115116
new_env["RR_LOG_BUFFER"]="100000"
116117
new_env["JULIA_RR"] = capture_script_path
117118
t_start = time()

Make.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
# Set to zero to turn off extra precompile (e.g. for the REPL)
1515
JULIA_PRECOMPILE ?= 1
1616

17+
# Set FORCE_ASSERTIONS to 1 to enable assertions in the C and C++ portions
18+
# of the Julia code base. You may also want to set LLVM_ASSERTIONS to 1,
19+
# which will enable assertions in LLVM.
20+
# An "assert build" of Julia is a build that has both FORCE_ASSERTIONS=1
21+
# and LLVM_ASSERTIONS=1.
1722
FORCE_ASSERTIONS ?= 0
1823

1924
# OPENBLAS build options
@@ -330,6 +335,7 @@ INSTALL_M := $(JULIAHOME)/contrib/install.sh 755
330335

331336
# LLVM Options
332337
LLVMROOT := $(build_prefix)
338+
# Set LLVM_ASSERTIONS to 1 to enable assertions in LLVM.
333339
LLVM_ASSERTIONS := 0
334340
LLVM_DEBUG := 0
335341
# set to 1 to get clang and compiler-rt

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ New language features
1919
* Mutable struct fields may now be annotated as `const` to prevent changing
2020
them after construction, providing for greater clarity and optimization
2121
ability of these objects ([#43305]).
22+
* Empty n-dimensional arrays can now be created using multiple semicolons inside square brackets, i.e. `[;;;]` creates a 0×0×0 `Array`. ([#41618])
2223

2324
Language changes
2425
----------------
@@ -59,6 +60,7 @@ Command-line option changes
5960
* New option `--strip-ir` to remove the compiler's IR (intermediate representation) of source
6061
code when building a system image. The resulting image will only work if `--compile=all` is
6162
used, or if all needed code is precompiled ([#42925]).
63+
* When the program file is `-` the code to be executed is read from standard in ([#43191]).
6264

6365
Multi-threading changes
6466
-----------------------
@@ -72,6 +74,7 @@ New library functions
7274
---------------------
7375

7476
* `hardlink(src, dst)` can be used to create hard links. ([#41639])
77+
* `setcpuaffinity(cmd, cpus)` can be used to set CPU affinity of sub-processes. ([#42469])
7578
* `diskstat(path=pwd())` can be used to return statistics about the disk. ([#42248])
7679

7780
New library features
@@ -152,6 +155,10 @@ Standard library changes
152155

153156
#### SparseArrays
154157

158+
* The code for SparseArrays has been moved from the Julia repo to the external
159+
repo at https://github.com/JuliaLang/SparseArrays.jl. This is only a code
160+
movement and does not impact any usage ([#43813]).
161+
155162
* New sparse concatenation functions `sparse_hcat`, `sparse_vcat`, and `sparse_hvcat` return
156163
`SparseMatrixCSC` output independent from the types of the input arguments. They make
157164
concatenation behavior available, in which the presence of some special "sparse" matrix

base/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ endif
9999
$(BUILDDIR)/version_git.jl.phony: $(SRCDIR)/version_git.sh
100100
ifneq ($(NO_GIT), 1)
101101
sh $< $(SRCDIR) > $@
102-
@# This to avoid touching git_version.jl when it is not modified,
102+
@# This to avoid touching version_git.jl when it is not modified,
103103
@# so that the system image does not need to be rebuilt.
104104
@if ! cmp -s $@ version_git.jl; then \
105105
$(call PRINT_PERL,) \

base/asyncmap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing)
236236
end
237237
catch e
238238
close(chnl)
239-
retval = e
239+
retval = capture_exception(e, catch_backtrace())
240240
end
241241
retval
242242
end

base/broadcast.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ broadcasted(::DefaultArrayStyle{1}, ::typeof(*), r::LinRange, x::Number) = LinRa
11301130
broadcasted(::DefaultArrayStyle{1}, ::typeof(*), r::OrdinalRange, x::AbstractFloat) =
11311131
Base.range_start_step_length(first(r)*x, step(r)*x, length(r))
11321132

1133+
#broadcasted(::DefaultArrayStyle{1}, ::typeof(/), r::AbstractRange, x::Number) = range(first(r)/x, last(r)/x, length=length(r))
11331134
broadcasted(::DefaultArrayStyle{1}, ::typeof(/), r::AbstractRange, x::Number) = range(first(r)/x, step=step(r)/x, length=length(r))
11341135
broadcasted(::DefaultArrayStyle{1}, ::typeof(/), r::StepRangeLen{T}, x::Number) where {T} =
11351136
StepRangeLen{typeof(T(r.ref)/x)}(r.ref/x, r.step/x, length(r), r.offset)

base/client.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ function eval_user_input(errio, @nospecialize(ast), show_value::Bool)
142142
@error "Evaluation succeeded, but an error occurred while displaying the value" typeof(value)
143143
rethrow()
144144
end
145-
println()
146145
end
147146
end
148147
break
@@ -301,7 +300,11 @@ function exec_options(opts)
301300
exit_on_sigint(true)
302301
end
303302
try
304-
include(Main, PROGRAM_FILE)
303+
if PROGRAM_FILE == "-"
304+
include_string(Main, read(stdin, String), "stdin")
305+
else
306+
include(Main, PROGRAM_FILE)
307+
end
305308
catch
306309
invokelatest(display_error, scrub_repl_backtrace(current_exceptions()))
307310
if !is_interactive::Bool

base/cmd.jl

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,31 @@ struct Cmd <: AbstractCmd
1313
flags::UInt32 # libuv process flags
1414
env::Union{Vector{String},Nothing}
1515
dir::String
16+
cpus::Union{Nothing,Vector{UInt16}}
1617
Cmd(exec::Vector{String}) =
17-
new(exec, false, 0x00, nothing, "")
18-
Cmd(cmd::Cmd, ignorestatus, flags, env, dir) =
18+
new(exec, false, 0x00, nothing, "", nothing)
19+
Cmd(cmd::Cmd, ignorestatus, flags, env, dir, cpus = nothing) =
1920
new(cmd.exec, ignorestatus, flags, env,
20-
dir === cmd.dir ? dir : cstr(dir))
21+
dir === cmd.dir ? dir : cstr(dir), cpus)
2122
function Cmd(cmd::Cmd; ignorestatus::Bool=cmd.ignorestatus, env=cmd.env, dir::AbstractString=cmd.dir,
23+
cpus::Union{Nothing,Vector{UInt16}} = cmd.cpus,
2224
detach::Bool = 0 != cmd.flags & UV_PROCESS_DETACHED,
2325
windows_verbatim::Bool = 0 != cmd.flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS,
2426
windows_hide::Bool = 0 != cmd.flags & UV_PROCESS_WINDOWS_HIDE)
2527
flags = detach * UV_PROCESS_DETACHED |
2628
windows_verbatim * UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS |
2729
windows_hide * UV_PROCESS_WINDOWS_HIDE
2830
new(cmd.exec, ignorestatus, flags, byteenv(env),
29-
dir === cmd.dir ? dir : cstr(dir))
31+
dir === cmd.dir ? dir : cstr(dir), cpus)
3032
end
3133
end
3234

3335
has_nondefault_cmd_flags(c::Cmd) =
3436
c.ignorestatus ||
3537
c.flags != 0x00 ||
3638
c.env !== nothing ||
37-
c.dir !== ""
39+
c.dir !== "" ||
40+
c.cpus !== nothing
3841

3942
"""
4043
Cmd(cmd::Cmd; ignorestatus, detach, windows_verbatim, windows_hide, env, dir)
@@ -114,6 +117,8 @@ function show(io::IO, cmd::Cmd)
114117
print_env = cmd.env !== nothing
115118
print_dir = !isempty(cmd.dir)
116119
(print_env || print_dir) && print(io, "setenv(")
120+
print_cpus = cmd.cpus !== nothing
121+
print_cpus && print(io, "setcpuaffinity(")
117122
print(io, '`')
118123
join(io, map(cmd.exec) do arg
119124
replace(sprint(context=io) do io
@@ -123,6 +128,11 @@ function show(io::IO, cmd::Cmd)
123128
end, '`' => "\\`")
124129
end, ' ')
125130
print(io, '`')
131+
if print_cpus
132+
print(io, ", ")
133+
show(io, collect(Int, cmd.cpus))
134+
print(io, ")")
135+
end
126136
print_env && (print(io, ","); show(io, cmd.env))
127137
print_dir && (print(io, "; dir="); show(io, cmd.dir))
128138
(print_dir || print_env) && print(io, ")")
@@ -294,6 +304,39 @@ function addenv(cmd::Cmd, env::Vector{<:AbstractString}; inherit::Bool = true)
294304
return addenv(cmd, Dict(k => v for (k, v) in eachsplit.(env, "=")); inherit)
295305
end
296306

307+
"""
308+
setcpuaffinity(original_command::Cmd, cpus) -> command::Cmd
309+
310+
Set the CPU affinity of the `command` by a list of CPU IDs (1-based) `cpus`. Passing
311+
`cpus = nothing` means to unset the CPU affinity if the `original_command` has any.
312+
313+
This function is supported only in Linux and Windows. It is not supported in macOS because
314+
libuv does not support affinity setting.
315+
316+
!!! compat "Julia 1.8"
317+
This function requires at least Julia 1.8.
318+
319+
# Examples
320+
321+
In Linux, the `taskset` command line program can be used to see how `setcpuaffinity` works.
322+
323+
```julia
324+
julia> run(setcpuaffinity(`sh -c 'taskset -p \$\$'`, [1, 2, 5]));
325+
pid 2273's current affinity mask: 13
326+
```
327+
328+
Note that the mask value `13` reflects that the first, second, and the fifth bits (counting
329+
from the least significant position) are turned on:
330+
331+
```julia
332+
julia> 0b010011
333+
0x13
334+
```
335+
"""
336+
function setcpuaffinity end
337+
setcpuaffinity(cmd::Cmd, ::Nothing) = Cmd(cmd; cpus = nothing)
338+
setcpuaffinity(cmd::Cmd, cpus) = Cmd(cmd; cpus = collect(UInt16, cpus))
339+
297340
(&)(left::AbstractCmd, right::AbstractCmd) = AndCmds(left, right)
298341
redir_out(src::AbstractCmd, dest::AbstractCmd) = OrCmds(src, dest)
299342
redir_err(src::AbstractCmd, dest::AbstractCmd) = ErrOrCmds(src, dest)

base/compiler/optimize.jl

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ const _PURE_BUILTINS = Any[tuple, svec, ===, typeof, nfields]
155155
# known to be effect-free if the are nothrow
156156
const _PURE_OR_ERROR_BUILTINS = [
157157
fieldtype, apply_type, isa, UnionAll,
158-
getfield, arrayref, const_arrayref, isdefined, Core.sizeof,
158+
getfield, arrayref, const_arrayref, arraysize, isdefined, Core.sizeof,
159159
Core.kwfunc, Core.ifelse, Core._typevar, (<:)
160160
]
161161

@@ -237,7 +237,7 @@ function stmt_effect_free(@nospecialize(stmt), @nospecialize(rt), src::Union{IRC
237237
end
238238
return true
239239
elseif head === :foreigncall
240-
return foreigncall_effect_free(stmt, rt, src)
240+
return foreigncall_effect_free(stmt, src)
241241
elseif head === :new_opaque_closure
242242
length(args) < 5 && return false
243243
typ = argextype(args[1], src)
@@ -262,7 +262,7 @@ function stmt_effect_free(@nospecialize(stmt), @nospecialize(rt), src::Union{IRC
262262
return true
263263
end
264264

265-
function foreigncall_effect_free(stmt::Expr, @nospecialize(rt), src::Union{IRCode,IncrementalCompact})
265+
function foreigncall_effect_free(stmt::Expr, src::Union{IRCode,IncrementalCompact})
266266
args = stmt.args
267267
name = args[1]
268268
isa(name, QuoteNode) && (name = name.value)
@@ -293,9 +293,7 @@ end
293293

294294
function alloc_array_no_throw(args::Vector{Any}, ndims::Int, src::Union{IRCode,IncrementalCompact})
295295
length(args) ndims+6 || return false
296-
atype = widenconst(argextype(args[6], src))
297-
isType(atype) || return false
298-
atype = atype.parameters[1]
296+
atype = instanceof_tfunc(argextype(args[6], src))[1]
299297
dims = Csize_t[]
300298
for i in 1:ndims
301299
dim = argextype(args[i+6], src)
@@ -309,9 +307,7 @@ end
309307

310308
function new_array_no_throw(args::Vector{Any}, src::Union{IRCode,IncrementalCompact})
311309
length(args) 7 || return false
312-
atype = widenconst(argextype(args[6], src))
313-
isType(atype) || return false
314-
atype = atype.parameters[1]
310+
atype = instanceof_tfunc(argextype(args[6], src))[1]
315311
dims = argextype(args[7], src)
316312
isa(dims, Const) || return dims === Tuple{}
317313
dimsval = dims.val
@@ -406,13 +402,14 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
406402
force_noinline = _any(@nospecialize(x) -> isexpr(x, :meta) && x.args[1] === :noinline, ir.meta)
407403

408404
# compute inlining and other related optimizations
409-
if (isa(result, Const) || isconstType(result))
405+
wresult = isa(result, InterConditional) ? widenconditional(result) : result
406+
if (isa(wresult, Const) || isconstType(wresult))
410407
proven_pure = false
411408
# must be proven pure to use constant calling convention;
412409
# otherwise we might skip throwing errors (issue #20704)
413410
# TODO: Improve this analysis; if a function is marked @pure we should really
414411
# only care about certain errors (e.g. method errors and type errors).
415-
if length(ir.stmts) < 10
412+
if length(ir.stmts) < 15
416413
proven_pure = true
417414
for i in 1:length(ir.stmts)
418415
node = ir.stmts[i]
@@ -440,14 +437,14 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
440437
# Still set pure flag to make sure `inference` tests pass
441438
# and to possibly enable more optimization in the future
442439
src.pure = true
443-
if isa(result, Const)
444-
val = result.val
440+
if isa(wresult, Const)
441+
val = wresult.val
445442
if is_inlineable_constant(val)
446443
analyzed = ConstAPI(val)
447444
end
448445
else
449-
@assert isconstType(result)
450-
analyzed = ConstAPI(result.parameters[1])
446+
@assert isconstType(wresult)
447+
analyzed = ConstAPI(wresult.parameters[1])
451448
end
452449
force_noinline || (src.inlineable = true)
453450
end
@@ -628,7 +625,8 @@ function is_pure_intrinsic_infer(f::IntrinsicFunction)
628625
end
629626

630627
# whether `f` is effect free if nothrow
631-
intrinsic_effect_free_if_nothrow(f) = f === Intrinsics.pointerref || is_pure_intrinsic_infer(f)
628+
intrinsic_effect_free_if_nothrow(f) = f === Intrinsics.pointerref ||
629+
f === Intrinsics.have_fma || is_pure_intrinsic_infer(f)
632630

633631
## Computing the cost of a function body
634632

base/compiler/ssair/ir.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,13 @@ function process_node!(compact::IncrementalCompact, result_idx::Int, inst::Instr
10071007
stmt = renumber_ssa2!(stmt, ssa_rename, used_ssas, late_fixup, result_idx, do_rename_ssa)::GotoIfNot
10081008
result[result_idx][:inst] = stmt
10091009
cond = stmt.cond
1010-
if isa(cond, Bool) && compact.fold_constant_branches
1010+
if compact.fold_constant_branches
1011+
if !isa(cond, Bool)
1012+
condT = widenconditional(argextype(cond, compact))
1013+
isa(condT, Const) || @goto bail
1014+
cond = condT.val
1015+
isa(cond, Bool) || @goto bail
1016+
end
10111017
if cond
10121018
result[result_idx][:inst] = nothing
10131019
kill_edge!(compact, active_bb, active_bb, stmt.dest)
@@ -1018,6 +1024,7 @@ function process_node!(compact::IncrementalCompact, result_idx::Int, inst::Instr
10181024
result_idx += 1
10191025
end
10201026
else
1027+
@label bail
10211028
result[result_idx][:inst] = GotoIfNot(cond, compact.bb_rename_succ[stmt.dest])
10221029
result_idx += 1
10231030
end

0 commit comments

Comments
 (0)