Skip to content

Commit

Permalink
Merge branch 'master' into stacktrace-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick authored Dec 12, 2024
2 parents 6db1238 + 9118ea7 commit b5bf60b
Show file tree
Hide file tree
Showing 64 changed files with 844 additions and 296 deletions.
1 change: 1 addition & 0 deletions Compiler/src/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ is_inaccessiblemem_or_argmemonly(effects::Effects) = effects.inaccessiblememonly

is_consistent_overlay(effects::Effects) = effects.nonoverlayed === CONSISTENT_OVERLAY

# (sync this with codegen.cpp and staticdata.c effects_foldable functions)
function encode_effects(e::Effects)
return ((e.consistent % UInt32) << 0) |
((e.effect_free % UInt32) << 3) |
Expand Down
9 changes: 4 additions & 5 deletions Compiler/test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3031,14 +3031,13 @@ end

# issue #28279
# ensure that lowering doesn't move these into statement position, which would require renumbering
using Base: +, -
function f28279(b::Bool)
@eval function f28279(b::Bool)
let i = 1
while i > b
i -= 1
while $(>)(i, b)
i = $(-)(i, 1)
end
if b end
return i + 1
return $(+)(i, 1)
end
end
code28279 = code_lowered(f28279, (Bool,))[1].code
Expand Down
2 changes: 1 addition & 1 deletion Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ ifeq (,$(findstring aarch64,$(ARCH)))
OSLIBS += -lgcc_s
endif

OSLIBS += -Wl,--export-dynamic -Wl,--undefined-version -Wl,--version-script=$(BUILDROOT)/src/julia.expmap \
OSLIBS += -Wl,--export-dynamic -Wl,--version-script=$(BUILDROOT)/src/julia.expmap \
$(NO_WHOLE_ARCHIVE)
endif

Expand Down
9 changes: 8 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ New language features
- atomic set once (`@atomiconce v[3] = 2`),
- atomic swap (`x = @atomicswap v[3] = 2`), and
- atomic replace (`x = @atomicreplace v[3] 2=>5`).
- New option `--task-metrics=yes` to enable the collection of per-task timing information,
which can also be enabled/disabled at runtime with `Base.Experimental.task_metrics(::Bool)`. ([#56320])
The available metrics are:
- actual running time for the task (`Base.Experimental.task_running_time_ns`), and
- wall-time for the task (`Base.Experimental.task_wall_time_ns`).

Language changes
----------------
Expand All @@ -31,7 +36,7 @@ Language changes
may pave the way for inference to be able to intelligently re-use the old
results, once the new method is deleted. ([#53415])

- Macro expansion will no longer eagerly recurse into into `Expr(:toplevel)`
- Macro expansion will no longer eagerly recurse into `Expr(:toplevel)`
expressions returned from macros. Instead, macro expansion of `:toplevel`
expressions will be delayed until evaluation time. This allows a later
expression within a given `:toplevel` expression to make use of macros
Expand Down Expand Up @@ -105,6 +110,7 @@ New library features
* `invoke` now supports passing a Method instead of a type signature making this interface somewhat more flexible for certain uncommon use cases ([#56692]).
* `invoke` now supports passing a CodeInstance instead of a type, which can enable
certain compiler plugin workflows ([#56660]).
* `sort` now supports `NTuple`s ([#54494])

Standard library changes
------------------------
Expand Down Expand Up @@ -166,6 +172,7 @@ Standard library changes
in the REPL will now issue a warning the first time occurs. ([#54872])
- When an object is printed automatically (by being returned in the REPL), its display is now truncated after printing 20 KiB.
This does not affect manual calls to `show`, `print`, and so forth. ([#53959])
- Backslash completions now print the respective glyph or emoji next to each matching backslash shortcode. ([#54800])

#### SuiteSparse

Expand Down
26 changes: 22 additions & 4 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,33 @@
#end

#mutable struct Task
# parent::Task
# next::Any
# queue::Any
# storage::Any
# state::Symbol
# donenotify::Any
# result::Any
# exception::Any
# backtrace::Any
# scope::Any
# code::Any
# @atomic _state::UInt8
# sticky::UInt8
# priority::UInt16
# @atomic _isexception::UInt8
# pad00::UInt8
# pad01::UInt8
# pad02::UInt8
# rngState0::UInt64
# rngState1::UInt64
# rngState2::UInt64
# rngState3::UInt64
# rngState4::UInt64
# const metrics_enabled::Bool
# pad10::UInt8
# pad11::UInt8
# pad12::UInt8
# @atomic first_enqueued_at::UInt64
# @atomic last_started_running_at::UInt64
# @atomic running_time_ns::UInt64
# @atomic finished_at::UInt64
#end

export
Expand Down
2 changes: 1 addition & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Instructions for Julia Core Developers:
# 1. When making a breaking change that is known to be depnedet upon by an
# important and closely coupled package, decide on a unique `change_name`
# for your PR and add it to the list below. In general, is is better to
# for your PR and add it to the list below. In general, it is better to
# err on the side of caution and assign a `change_name` even if it is not
# clear that it is required. `change_name`s may also be assigned after the
# fact in a separate PR. (Note that this may cause packages to misbehave
Expand Down
74 changes: 74 additions & 0 deletions base/experimental.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,78 @@ usage, by eliminating the tracking of those possible invalidation.
"""
disable_new_worlds() = ccall(:jl_disable_new_worlds, Cvoid, ())

### Task metrics

"""
Base.Experimental.task_metrics(::Bool)
Enable or disable the collection of per-task metrics.
A `Task` created when `Base.Experimental.task_metrics(true)` is in effect will have
[`Base.Experimental.task_running_time_ns`](@ref) and [`Base.Experimental.task_wall_time_ns`](@ref)
timing information available.
!!! note
Task metrics can be enabled at start-up via the `--task-metrics=yes` command line option.
"""
function task_metrics(b::Bool)
if b
ccall(:jl_task_metrics_enable, Cvoid, ())
else
ccall(:jl_task_metrics_disable, Cvoid, ())
end
return nothing
end

"""
Base.Experimental.task_running_time_ns(t::Task) -> Union{UInt64, Nothing}
Return the total nanoseconds that the task `t` has spent running.
This metric is only updated when `t` yields or completes unless `t` is the current task, in
which it will be updated continuously.
See also [`Base.Experimental.task_wall_time_ns`](@ref).
Returns `nothing` if task timings are not enabled.
See [`Base.Experimental.task_metrics`](@ref).
!!! note "This metric is from the Julia scheduler"
A task may be running on an OS thread that is descheduled by the OS
scheduler, this time still counts towards the metric.
!!! compat "Julia 1.12"
This method was added in Julia 1.12.
"""
function task_running_time_ns(t::Task=current_task())
t.metrics_enabled || return nothing
if t == current_task()
# These metrics fields can't update while we're running.
# But since we're running we need to include the time since we last started running!
return t.running_time_ns + (time_ns() - t.last_started_running_at)
else
return t.running_time_ns
end
end

"""
Base.Experimental.task_wall_time_ns(t::Task) -> Union{UInt64, Nothing}
Return the total nanoseconds that the task `t` was runnable.
This is the time since the task first entered the run queue until the time at which it
completed, or until the current time if the task has not yet completed.
See also [`Base.Experimental.task_running_time_ns`](@ref).
Returns `nothing` if task timings are not enabled.
See [`Base.Experimental.task_metrics`](@ref).
!!! compat "Julia 1.12"
This method was added in Julia 1.12.
"""
function task_wall_time_ns(t::Task=current_task())
t.metrics_enabled || return nothing
start_at = t.first_enqueued_at
start_at == 0 && return UInt64(0)
end_at = t.finished_at
end_at == 0 && return time_ns() - start_at
return end_at - start_at
end

end # module
13 changes: 8 additions & 5 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,16 @@ significand_mask(::Type{Float16}) = 0x03ff
mantissa(x::T) where {T} = reinterpret(Unsigned, x) & significand_mask(T)

for T in (Float16, Float32, Float64)
@eval significand_bits(::Type{$T}) = $(trailing_ones(significand_mask(T)))
@eval exponent_bits(::Type{$T}) = $(sizeof(T)*8 - significand_bits(T) - 1)
@eval exponent_bias(::Type{$T}) = $(Int(exponent_one(T) >> significand_bits(T)))
sb = trailing_ones(significand_mask(T))
em = exponent_mask(T)
eb = Int(exponent_one(T) >> sb)
@eval significand_bits(::Type{$T}) = $(sb)
@eval exponent_bits(::Type{$T}) = $(sizeof(T)*8 - sb - 1)
@eval exponent_bias(::Type{$T}) = $(eb)
# maximum float exponent
@eval exponent_max(::Type{$T}) = $(Int(exponent_mask(T) >> significand_bits(T)) - exponent_bias(T) - 1)
@eval exponent_max(::Type{$T}) = $(Int(em >> sb) - eb - 1)
# maximum float exponent without bias
@eval exponent_raw_max(::Type{$T}) = $(Int(exponent_mask(T) >> significand_bits(T)))
@eval exponent_raw_max(::Type{$T}) = $(Int(em >> sb))
end

"""
Expand Down
5 changes: 5 additions & 0 deletions base/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,15 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any},
return x
end
if isa(x, Core.ReturnNode)
# Unreachable doesn't have val defined
if !isdefined(x, :val)
return x
else
return Core.ReturnNode(
_partially_inline!(x.val, slot_replacements, type_signature, static_param_values,
slot_offset, statement_offset, boundscheck),
)
end
end
if isa(x, Core.GotoIfNot)
return Core.GotoIfNot(
Expand Down
1 change: 1 addition & 0 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct JLOptions
heap_size_hint::UInt64
trace_compile_timing::Int8
trim::Int8
task_metrics::Int8
end

# This runs early in the sysimage != is not defined yet
Expand Down
2 changes: 1 addition & 1 deletion base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ The `unsafe` prefix on this function indicates that no validation is performed o
pointer `p` to ensure that it is valid. Like C, the programmer is responsible for ensuring
that referenced memory is not freed or garbage collected while invoking this function.
Incorrect usage may segfault your program. Unlike C, storing memory region allocated as
different type may be valid provided that that the types are compatible.
different type may be valid provided that the types are compatible.
!!! compat "Julia 1.10"
The `order` argument is available as of Julia 1.10.
Expand Down
2 changes: 1 addition & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ function _getindex(v::UnitRange{T}, i::Integer) where {T<:OverflowSafe}
end

let BitInteger64 = Union{Int8,Int16,Int32,Int64,UInt8,UInt16,UInt32,UInt64} # for bootstrapping
function checkbounds(::Type{Bool}, v::StepRange{<:BitInteger64, <:BitInteger64}, i::BitInteger64)
global function checkbounds(::Type{Bool}, v::StepRange{<:BitInteger64, <:BitInteger64}, i::BitInteger64)
res = widemul(step(v), i-oneunit(i)) + first(v)
(0 < i) & ifelse(0 < step(v), res <= last(v), res >= last(v))
end
Expand Down
43 changes: 40 additions & 3 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Sort

using Base.Order

using Base: copymutable, midpoint, require_one_based_indexing, uinttype,
using Base: copymutable, midpoint, require_one_based_indexing, uinttype, tail,
sub_with_overflow, add_with_overflow, OneTo, BitSigned, BitIntegerType, top_set_bit

import Base:
Expand Down Expand Up @@ -1482,8 +1482,9 @@ InitialOptimizations(next) = SubArrayOptimization(
`DefaultStable` is an algorithm which indicates that a fast, general purpose sorting
algorithm should be used, but does not specify exactly which algorithm.
Currently, it is composed of two parts: the [`InitialOptimizations`](@ref) and a hybrid of
Radix, Insertion, Counting, Quick sorts.
Currently, when sorting short NTuples, this is an unrolled mergesort, and otherwise it is
composed of two parts: the [`InitialOptimizations`](@ref) and a hybrid of Radix, Insertion,
Counting, Quick sorts.
We begin with MissingOptimization because it has no runtime cost when it is not
triggered and can enable other optimizations to be applied later. For example,
Expand Down Expand Up @@ -1619,6 +1620,7 @@ defalg(v::AbstractArray) = DEFAULT_STABLE
defalg(v::AbstractArray{<:Union{Number, Missing}}) = DEFAULT_UNSTABLE
defalg(v::AbstractArray{Missing}) = DEFAULT_UNSTABLE # for method disambiguation
defalg(v::AbstractArray{Union{}}) = DEFAULT_UNSTABLE # for method disambiguation
defalg(v::NTuple) = DEFAULT_STABLE

"""
sort!(v; alg::Base.Sort.Algorithm=Base.Sort.defalg(v), lt=isless, by=identity, rev::Bool=false, order::Base.Order.Ordering=Base.Order.Forward)
Expand Down Expand Up @@ -1757,6 +1759,41 @@ julia> v
"""
sort(v::AbstractVector; kws...) = sort!(copymutable(v); kws...)

function sort(x::NTuple;
alg::Algorithm=defalg(x),
lt=isless,
by=identity,
rev::Union{Bool,Nothing}=nothing,
order::Ordering=Forward,
scratch::Union{Vector, Nothing}=nothing)
# Can't do this check with type parameters because of https://github.com/JuliaLang/julia/issues/56698
scratch === nothing || eltype(x) == eltype(scratch) || throw(ArgumentError("scratch has the wrong eltype"))
_sort(x, alg, ord(lt,by,rev,order), (;scratch))::typeof(x)
end
# Folks who want to hack internals can define a new _sort(x::NTuple, ::TheirAlg, o::Ordering)
# or _sort(x::NTuple{N, TheirType}, ::DefaultStable, o::Ordering) where N
function _sort(x::NTuple, a::Union{DefaultStable, DefaultUnstable}, o::Ordering, kw)
# The unrolled tuple sort is prohibitively slow to compile for length > 9.
# See https://github.com/JuliaLang/julia/pull/46104#issuecomment-1435688502 for benchmarks
if length(x) > 9
v = copymutable(x)
_sort!(v, a, o, kw)
typeof(x)(v)
else
_mergesort(x, o)
end
end
_mergesort(x::Union{NTuple{0}, NTuple{1}}, o::Ordering) = x
function _mergesort(x::NTuple, o::Ordering)
a, b = Base.IteratorsMD.split(x, Val(length(x)>>1))
merge(_mergesort(a, o), _mergesort(b, o), o)
end
merge(x::NTuple, y::NTuple{0}, o::Ordering) = x
merge(x::NTuple{0}, y::NTuple, o::Ordering) = y
merge(x::NTuple{0}, y::NTuple{0}, o::Ordering) = x # Method ambiguity
merge(x::NTuple, y::NTuple, o::Ordering) =
(lt(o, y[1], x[1]) ? (y[1], merge(x, tail(y), o)...) : (x[1], merge(tail(x), y, o)...))

## partialsortperm: the permutation to sort the first k elements of an array ##

"""
Expand Down
2 changes: 2 additions & 0 deletions base/special/exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ end
small_part = muladd(jU, expm1b_kernel(base, r), jL) + jU

if !(abs(x) <= SUBNORM_EXP(base, T))
isnan(x) && return x
x >= MAX_EXP(base, T) && return Inf
x <= MIN_EXP(base, T) && return 0.0
if k <= -53
Expand Down Expand Up @@ -243,6 +244,7 @@ end
hi, lo = Base.canonicalize2(1.0, kern)
small_part = fma(jU, hi, muladd(jU, (lo+xlo), very_small))
if !(abs(x) <= SUBNORM_EXP(base, T))
isnan(x) && return x
x >= MAX_EXP(base, T) && return Inf
x <= MIN_EXP(base, T) && return 0.0
if k <= -53
Expand Down
4 changes: 3 additions & 1 deletion base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ print(io::IO, s::Union{String,SubString{String}}) = (write(io, s); nothing)
"""
repr(x; context=nothing)
Create a string from any value using the 2-argument `show(io, x)` function.
Create a string representation of any value using the 2-argument `show(io, x)` function,
which aims to produce a string that is parseable Julia code, where possible.
i.e. `eval(Meta.parse(repr(x))) == x` should hold true.
You should not add methods to `repr`; define a [`show`](@ref) method instead.
The optional keyword argument `context` can be set to a `:key=>value` pair, a
Expand Down
2 changes: 1 addition & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

# Can be be loaded on top of either an existing system image built from
# Can be loaded on top of either an existing system image built from
# `Base_compiler.jl` or standalone, in which case we will build it now.
let had_compiler = isdefined(Main, :Base)
if had_compiler; else
Expand Down
Loading

0 comments on commit b5bf60b

Please sign in to comment.