Skip to content

Commit

Permalink
Merge branch 'master' into jishnub/copytristrided
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Jan 25, 2024
2 parents 28bdad5 + 14cf64f commit 9946353
Show file tree
Hide file tree
Showing 148 changed files with 2,378 additions and 1,040 deletions.
29 changes: 22 additions & 7 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ New language features
API. Symbols marked with `export` are now also treated as public API. The
difference between `public` and `export` is that `public` names do not become
available when `using` a package/module ([#50105]).
* `ScopedValue` implement dynamic scope with inheritance across tasks ([#50958]).
* `ScopedValue` implements dynamic scope with inheritance across tasks ([#50958]).
* The new macro `Base.Cartesian.@ncallkw` is analogous to `Base.Cartesian.@ncall`,
but allows to add keyword arguments to the function call ([#51501]).
* Support for Unicode 15.1 ([#51799]).
Expand All @@ -30,7 +30,7 @@ Language changes
wants to begin exiting.
* Code coverage and malloc tracking is no longer generated during the package precompilation stage.
Further, during these modes pkgimage caches are now used for packages that are not being tracked.
Meaning that coverage testing (the default for `julia-actions/julia-runtest`) will by default use
This means that coverage testing (the default for `julia-actions/julia-runtest`) will by default use
pkgimage caches for all other packages than the package being tested, likely meaning faster test
execution. ([#52123])

Expand All @@ -42,7 +42,7 @@ Compiler/Runtime improvements
* Updated GC heuristics to count allocated pages instead of individual objects ([#50144]).
* A new `LazyLibrary` type is exported from `Libdl` for use in building chained lazy library
loads, primarily to be used within JLLs ([#50074]).
* Added a support for annotating `Base.@assume_effects` on code block ([#52400]).
* Added support for annotating `Base.@assume_effects` on code blocks ([#52400]).

Command-line option changes
---------------------------
Expand All @@ -68,12 +68,11 @@ New library functions

* `in!(x, s::AbstractSet)` will return whether `x` is in `s`, and insert `x` in `s` if not.
* The new `Libc.mkfifo` function wraps the `mkfifo` C function on Unix platforms ([#34587]).
* `hardlink(src, dst)` can be used to create hard links ([#41639]).
* `diskstat(path=pwd())` can be used to return statistics about the disk ([#42248]).
* `copyuntil(out, io, delim)` and `copyline(out, io)` copy data into an `out::IO` stream ([#48273]).
* `eachrsplit(string, pattern)` iterates split substrings right to left.
* `Sys.username()` can be used to return the current user's username ([#51897]).
* `wrap(Array, m::Union{MemoryRef{T}, Memory{T}}, dims)` which is the safe counterpart to `unsafe_wrap` ([#52049]).
* `wrap(Array, m::Union{MemoryRef{T}, Memory{T}}, dims)` is the safe counterpart to `unsafe_wrap` ([#52049]).
* `GC.logging_enabled()` can be used to test whether GC logging has been enabled via `GC.enable_logging` ([#51647]).

New library features
--------------------
Expand All @@ -93,6 +92,7 @@ New library features
content is fully written, then call `closewrite` manually to avoid
data-races. Or use the callback form of `open` to have all that handled
automatically.
* `@timed` now additionally returns the elapsed compilation and recompilation time ([#52889])

Standard library changes
------------------------
Expand All @@ -108,6 +108,12 @@ Standard library changes
* The new `@styled_str` string macro provides a convenient way of creating a
`AnnotatedString` with various faces or other attributes applied ([#49586]).

#### JuliaSyntaxHighlighting

* A new standard library for applying syntax highlighting to Julia code, this
uses `JuliaSyntax` and `StyledStrings` to implement a `highlight` function
that creates an `AnnotatedString` with syntax highlighting applied.

#### Package Manager

#### LinearAlgebra
Expand Down Expand Up @@ -139,7 +145,14 @@ Standard library changes
#### REPL

* Tab complete hints now show in lighter text while typing in the repl. To disable
set `Base.active_repl.options.hint_tab_completes = false` ([#51229]).
set `Base.active_repl.options.hint_tab_completes = false` interactively, or in startup.jl:
```
if VERSION >= v"1.11.0-0"
atreplinit() do repl
repl.options.hint_tab_completes = false
end
end
``` ([#51229]).
* Meta-M with an empty prompt now toggles the contextual module between the previous non-Main
contextual module and Main so that switching back and forth is simple. ([#51616], [#52670])
Expand Down Expand Up @@ -171,6 +184,8 @@ Standard library changes
Deprecated or removed
---------------------
* `Base.map`, `Iterators.map`, and `foreach` lost their single-argument methods ([#52631]).
External dependencies
---------------------
Expand Down
9 changes: 2 additions & 7 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3108,9 +3108,8 @@ julia> foreach((x, y) -> println(x, " with ", y), tri, 'a':'z')
7 with c
```
"""
foreach(f) = (f(); nothing)
foreach(f, itr) = (for x in itr; f(x); end; nothing)
foreach(f, itrs...) = (for z in zip(itrs...); f(z...); end; nothing)
foreach(f, itr, itrs...) = (for z in zip(itr, itrs...); f(z...); end; nothing)

## map over arrays ##

Expand Down Expand Up @@ -3282,10 +3281,6 @@ end
concatenate_setindex!(R, v, I...) = (R[I...] .= (v,); R)
concatenate_setindex!(R, X::AbstractArray, I...) = (R[I...] = X)

## 0 arguments

map(f) = f()

## 1 argument

function map!(f::F, dest::AbstractArray, A::AbstractArray) where F
Expand Down Expand Up @@ -3421,7 +3416,7 @@ julia> map(+, [1 2; 3 4], [1,10,100,1000], zeros(3,1)) # iterates until 3rd is
102.0
```
"""
map(f, iters...) = collect(Generator(f, iters...))
map(f, it, iters...) = collect(Generator(f, it, iters...))

# multi-item push!, pushfirst! (built on top of type-specific 1-item version)
# (note: must not cause a dispatch loop when 1-item case is not defined)
Expand Down
9 changes: 8 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ See also [`copy!`](@ref Base.copy!), [`copyto!`](@ref), [`deepcopy`](@ref).
copy

@eval function copy(a::Array{T}) where {T}
# `jl_genericmemory_copy_slice` only throws when the size exceeds the max allocation
# size, but since we're copying an existing array, we're guaranteed that this will not happen.
@_nothrow_meta
ref = a.ref
newmem = ccall(:jl_genericmemory_copy_slice, Ref{Memory{T}}, (Any, Ptr{Cvoid}, Int), ref.mem, ref.ptr_or_offset, length(a))
return $(Expr(:new, :(typeof(a)), :(Core.memoryref(newmem)), :(a.size)))
Expand Down Expand Up @@ -1040,6 +1043,7 @@ end
array_new_memory(mem::Memory, newlen::Int) = typeof(mem)(undef, newlen) # when implemented, this should attempt to first expand mem

function _growbeg!(a::Vector, delta::Integer)
@_noub_meta
delta = Int(delta)
delta == 0 && return # avoid attempting to index off the end
delta >= 0 || throw(ArgumentError("grow requires delta >= 0"))
Expand Down Expand Up @@ -1077,6 +1081,7 @@ function _growbeg!(a::Vector, delta::Integer)
end

function _growend!(a::Vector, delta::Integer)
@_noub_meta
delta = Int(delta)
delta >= 0 || throw(ArgumentError("grow requires delta >= 0"))
ref = a.ref
Expand Down Expand Up @@ -1113,6 +1118,7 @@ function _growend!(a::Vector, delta::Integer)
end

function _growat!(a::Vector, i::Integer, delta::Integer)
@_terminates_globally_noub_meta
delta = Int(delta)
i = Int(i)
i == 1 && return _growbeg!(a, delta)
Expand Down Expand Up @@ -1715,10 +1721,11 @@ julia> insert!(Any[1:6;], 3, "here")
```
"""
function insert!(a::Array{T,1}, i::Integer, item) where T
@_noub_meta
# Throw convert error before changing the shape of the array
_item = item isa T ? item : convert(T, item)::T
_growat!(a, i, 1)
# _growat! already did bound check
# :noub, because _growat! already did bound check
@inbounds a[i] = _item
return a
end
Expand Down
76 changes: 38 additions & 38 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,6 @@ const RECURSION_MSG_HARDLIMIT = "Bounded recursion detected under hardlimit. Cal
function abstract_call_method(interp::AbstractInterpreter,
method::Method, @nospecialize(sig), sparams::SimpleVector,
hardlimit::Bool, si::StmtInfo, sv::AbsIntState)
if method.name === :depwarn && isdefined(Main, :Base) && method.module === Main.Base
add_remark!(interp, sv, "Refusing to infer into `depwarn`")
return MethodCallResult(Any, Any, false, false, nothing, Effects())
end
sigtuple = unwrap_unionall(sig)
sigtuple isa DataType ||
return MethodCallResult(Any, Any, false, false, nothing, Effects())
Expand Down Expand Up @@ -814,12 +810,7 @@ end
function abstract_call_method_with_const_args(interp::AbstractInterpreter,
result::MethodCallResult, @nospecialize(f), arginfo::ArgInfo, si::StmtInfo,
match::MethodMatch, sv::AbsIntState, invokecall::Union{Nothing,InvokeCall}=nothing)

if !const_prop_enabled(interp, sv, match)
return nothing
end
if bail_out_const_call(interp, result, si)
add_remark!(interp, sv, "[constprop] No more information to be gained")
if bail_out_const_call(interp, result, si, match, sv)
return nothing
end
eligibility = concrete_eval_eligible(interp, f, result, arginfo, sv)
Expand Down Expand Up @@ -852,30 +843,33 @@ function abstract_call_method_with_const_args(interp::AbstractInterpreter,
return const_prop_call(interp, mi, result, arginfo, sv, concrete_eval_result)
end

function const_prop_enabled(interp::AbstractInterpreter, sv::AbsIntState, match::MethodMatch)
function bail_out_const_call(interp::AbstractInterpreter, result::MethodCallResult,
si::StmtInfo, match::MethodMatch, sv::AbsIntState)
if !InferenceParams(interp).ipo_constant_propagation
add_remark!(interp, sv, "[constprop] Disabled by parameter")
return false
return true
end
if is_no_constprop(match.method)
add_remark!(interp, sv, "[constprop] Disabled by method parameter")
return false
return true
end
return true
end

function bail_out_const_call(interp::AbstractInterpreter, result::MethodCallResult, si::StmtInfo)
if is_removable_if_unused(result.effects)
if isa(result.rt, Const) || call_result_unused(si)
if isa(result.rt, Const)
add_remark!(interp, sv, "[constprop] No more information to be gained (const)")
return true
elseif call_result_unused(si)
add_remark!(interp, sv, "[constprop] No more information to be gained (unused result)")
return true
end
elseif result.rt === Bottom
end
if result.rt === Bottom
if is_terminates(result.effects) && is_effect_free(result.effects)
# In the future, we may want to add `&& isa(result.exct, Const)` to
# the list of conditions here, but currently, our effect system isn't
# precise enough to let us determine :consistency of `exct`, so we
# would have to force constprop just to determine this, which is too
# expensive.
add_remark!(interp, sv, "[constprop] No more information to be gained (bottom)")
return true
end
end
Expand Down Expand Up @@ -974,7 +968,10 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter,
match::MethodMatch, sv::AbsIntState)
method = match.method
force = force_const_prop(interp, f, method)
force || const_prop_entry_heuristic(interp, result, si, sv) || return nothing
if !const_prop_entry_heuristic(interp, result, si, sv, force)
# N.B. remarks are emitted within `const_prop_entry_heuristic`
return nothing
end
nargs::Int = method.nargs
method.isva && (nargs -= 1)
length(arginfo.argtypes) < nargs && return nothing
Expand All @@ -1001,8 +998,17 @@ function maybe_get_const_prop_profitable(interp::AbstractInterpreter,
return mi
end

function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodCallResult, si::StmtInfo, sv::AbsIntState)
if call_result_unused(si) && result.edgecycle
function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodCallResult,
si::StmtInfo, sv::AbsIntState, force::Bool)
if result.rt isa LimitedAccuracy
# optimizations like inlining are disabled for limited frames,
# thus there won't be much benefit in constant-prop' here
# N.B. don't allow forced constprop' for safety (xref #52763)
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (limited accuracy)")
return false
elseif force
return true
elseif call_result_unused(si) && result.edgecycle
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (edgecycle with unused result)")
return false
end
Expand All @@ -1015,27 +1021,21 @@ function const_prop_entry_heuristic(interp::AbstractInterpreter, result::MethodC
if rt === Bottom
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (erroneous result)")
return false
else
return true
end
return true
elseif isa(rt, PartialStruct) || isa(rt, InterConditional) || isa(rt, InterMustAlias)
# could be improved to `Const` or a more precise wrapper
return true
elseif isa(rt, LimitedAccuracy)
# optimizations like inlining are disabled for limited frames,
# thus there won't be much benefit in constant-prop' here
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (limited accuracy)")
return false
else
if isa(rt, Const)
if !is_nothrow(result.effects)
# Could still be improved to Bottom (or at least could see the effects improved)
return true
end
elseif isa(rt, Const)
if is_nothrow(result.effects)
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (nothrow const)")
return false
end
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (unimprovable result)")
return false
# Could still be improved to Bottom (or at least could see the effects improved)
return true
end
add_remark!(interp, sv, "[constprop] Disabled by entry heuristic (unimprovable result)")
return false
end

# determines heuristically whether if constant propagation can be worthwhile
Expand Down Expand Up @@ -2722,7 +2722,7 @@ end
function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e), vtypes::VarTable, sv::InferenceState)
if !isa(e, Expr)
if isa(e, PhiNode)
add_curr_ssaflag!(sv, IR_FLAG_EFFECT_FREE | IR_FLAG_NOTHROW)
add_curr_ssaflag!(sv, IR_FLAGS_REMOVABLE)
return RTEffects(abstract_eval_phi(interp, e, vtypes, sv), Union{}, EFFECTS_TOTAL)
end
(; rt, exct, effects) = abstract_eval_special_value(interp, e, vtypes, sv)
Expand Down
1 change: 1 addition & 0 deletions base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ include("compiler/validation.jl")
include("compiler/ssair/basicblock.jl")
include("compiler/ssair/domtree.jl")
include("compiler/ssair/ir.jl")
include("compiler/ssair/tarjan.jl")

include("compiler/abstractlattice.jl")
include("compiler/inferenceresult.jl")
Expand Down
17 changes: 14 additions & 3 deletions base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ function getindex(tpdum::TwoPhaseDefUseMap, idx::Int)
return TwoPhaseVectorView(tpdum.data, nelems, range)
end

mutable struct LazyCFGReachability
ir::IRCode
reachability::CFGReachability
LazyCFGReachability(ir::IRCode) = new(ir)
end
function get!(x::LazyCFGReachability)
isdefined(x, :reachability) && return x.reachability
domtree = construct_domtree(x.ir.cfg.blocks)
return x.reachability = CFGReachability(x.ir.cfg, domtree)
end

mutable struct LazyGenericDomtree{IsPostDom}
ir::IRCode
domtree::GenericDomTree{IsPostDom}
Expand Down Expand Up @@ -744,7 +755,7 @@ mutable struct IRInterpretationState
const sptypes::Vector{VarState}
const tpdum::TwoPhaseDefUseMap
const ssa_refined::BitSet
const lazydomtree::LazyDomtree
const lazyreachability::LazyCFGReachability
valid_worlds::WorldRange
const edges::Vector{Any}
parent # ::Union{Nothing,AbsIntState}
Expand All @@ -764,12 +775,12 @@ mutable struct IRInterpretationState
append!(ir.argtypes, given_argtypes)
tpdum = TwoPhaseDefUseMap(length(ir.stmts))
ssa_refined = BitSet()
lazydomtree = LazyDomtree(ir)
lazyreachability = LazyCFGReachability(ir)
valid_worlds = WorldRange(min_world, max_world == typemax(UInt) ? get_world_counter() : max_world)
edges = Any[]
parent = nothing
return new(method_info, ir, mi, world, curridx, argtypes_refined, ir.sptypes, tpdum,
ssa_refined, lazydomtree, valid_worlds, edges, parent)
ssa_refined, lazyreachability, valid_worlds, edges, parent)
end
end

Expand Down
Loading

0 comments on commit 9946353

Please sign in to comment.