Skip to content

Commit

Permalink
Merge branch 'master' into patch-15
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick authored Mar 11, 2024
2 parents 8149008 + f882c00 commit d194d0c
Show file tree
Hide file tree
Showing 66 changed files with 1,369 additions and 704 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ julia-debug julia-release : julia-% : julia-sysimg-% julia-src-% julia-symlink j
julia-libccalllazyfoo julia-libccalllazybar julia-libllvmcalltest julia-base-cache

stdlibs-cache-release stdlibs-cache-debug : stdlibs-cache-% : julia-%
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT) -f pkgimage.mk all-$*
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT) -f pkgimage.mk $*

debug release : % : julia-% stdlibs-cache-%

Expand Down Expand Up @@ -588,6 +588,7 @@ clean: | $(CLEAN_TARGETS)
@-$(MAKE) -C $(BUILDROOT)/cli clean
@-$(MAKE) -C $(BUILDROOT)/test clean
@-$(MAKE) -C $(BUILDROOT)/stdlib clean
@-$(MAKE) -C $(BUILDROOT) -f pkgimage.mk clean
-rm -f $(BUILDROOT)/julia
-rm -f $(BUILDROOT)/*.tar.gz
-rm -f $(build_depsbindir)/stringreplace \
Expand Down
55 changes: 0 additions & 55 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -568,61 +568,6 @@ end_base_include = time_ns()
const _sysimage_modules = PkgId[]
in_sysimage(pkgid::PkgId) = pkgid in _sysimage_modules

# Precompiles for Revise and other packages
# TODO: move these to contrib/generate_precompile.jl
# The problem is they don't work there
for match = _methods(+, (Int, Int), -1, get_world_counter())
m = match.method
delete!(push!(Set{Method}(), m), m)
copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(match), typemax(UInt)))

empty!(Set())
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
(setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
(setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
Dict(Base => [:(1+1)])[Base]
Dict(:one => [1])[:one]
Dict("abc" => Set())["abc"]
pushfirst!([], sum)
get(Base.pkgorigins, Base.PkgId(Base), nothing)
sort!([1,2,3])
unique!([1,2,3])
cumsum([1,2,3])
append!(Int[], BitSet())
isempty(BitSet())
delete!(BitSet([1,2]), 3)
deleteat!(Int32[1,2,3], [1,3])
deleteat!(Any[1,2,3], [1,3])
Core.svec(1, 2) == Core.svec(3, 4)
any(t->t[1].line > 1, [(LineNumberNode(2,:none), :(1+1))])

# Code loading uses this
sortperm(mtime.(readdir(".")), rev=true)
# JLLWrappers uses these
Dict{UUID,Set{String}}()[UUID("692b3bcd-3c85-4b1f-b108-f13ce0eb3210")] = Set{String}()
get!(Set{String}, Dict{UUID,Set{String}}(), UUID("692b3bcd-3c85-4b1f-b108-f13ce0eb3210"))
eachindex(IndexLinear(), Expr[])
push!(Expr[], Expr(:return, false))
vcat(String[], String[])
k, v = (:hello => nothing)
precompile(indexed_iterate, (Pair{Symbol, Union{Nothing, String}}, Int))
precompile(indexed_iterate, (Pair{Symbol, Union{Nothing, String}}, Int, Int))
# Preferences uses these
precompile(get_preferences, (UUID,))
precompile(record_compiletime_preference, (UUID, String))
get(Dict{String,Any}(), "missing", nothing)
delete!(Dict{String,Any}(), "missing")
for (k, v) in Dict{String,Any}()
println(k)
end

break # only actually need to do this once
end

if is_primary_base_module

# Profiling helper
Expand Down
1 change: 1 addition & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,7 @@ end
copymutable(itr) = collect(itr)

zero(x::AbstractArray{T}) where {T<:Number} = fill!(similar(x, typeof(zero(T))), zero(T))
zero(x::AbstractArray{S}) where {S<:Union{Missing, Number}} = fill!(similar(x, typeof(zero(S))), zero(S))
zero(x::AbstractArray) = map(zero, x)

## iteration support for arrays by iterating over `eachindex` in the array ##
Expand Down
4 changes: 2 additions & 2 deletions base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ eval(Core, :(NamedTuple{names}(args::Tuple) where {names} =

using .Intrinsics: sle_int, add_int

eval(Core, :(NamedTuple{names,T}(args::T) where {names, T <: Tuple} =
$(Expr(:splatnew, :(NamedTuple{names,T}), :args))))
eval(Core, :((NT::Type{NamedTuple{names,T}})(args::T) where {names, T <: Tuple} =
$(Expr(:splatnew, :NT, :args))))

# constructors for built-in types

Expand Down
6 changes: 5 additions & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ function edge_matches_sv(interp::AbstractInterpreter, frame::AbsIntState,
if callee_method2 !== inf_method2
return false
end
if isa(frame, InferenceState) && cache_owner(frame.interp) !== cache_owner(interp)
# Don't assume that frames in different interpreters are the same
return false
end
if !hardlimit || InferenceParams(interp).ignore_recursion_hardlimit
# if this is a soft limit,
# also inspect the parent of this edge,
Expand Down Expand Up @@ -2691,7 +2695,7 @@ function refine_partial_type(@nospecialize t)
# if the first/second parameter of `NamedTuple` is known to be empty,
# the second/first argument should also be empty tuple type,
# so refine it here
return Const(NamedTuple())
return Const((;))
end
return t
end
Expand Down
17 changes: 14 additions & 3 deletions base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mutable struct LazyCFGReachability
end
function get!(x::LazyCFGReachability)
isdefined(x, :reachability) && return x.reachability
domtree = construct_domtree(x.ir.cfg.blocks)
domtree = construct_domtree(x.ir)
return x.reachability = CFGReachability(x.ir.cfg, domtree)
end

Expand All @@ -189,8 +189,8 @@ end
function get!(x::LazyGenericDomtree{IsPostDom}) where {IsPostDom}
isdefined(x, :domtree) && return x.domtree
return @timeit "domtree 2" x.domtree = IsPostDom ?
construct_postdomtree(x.ir.cfg.blocks) :
construct_domtree(x.ir.cfg.blocks)
construct_postdomtree(x.ir) :
construct_domtree(x.ir)
end

const LazyDomtree = LazyGenericDomtree{false}
Expand Down Expand Up @@ -731,7 +731,16 @@ function empty_backedges!(frame::InferenceState, currpc::Int=frame.currpc)
end

function print_callstack(sv::InferenceState)
print("=================== Callstack: ==================\n")
idx = 0
while sv !== nothing
print("[")
print(idx)
if !isa(sv.interp, NativeInterpreter)
print(", ")
print(typeof(sv.interp))
end
print("] ")
print(sv.linfo)
is_cached(sv) || print(" [uncached]")
println()
Expand All @@ -740,7 +749,9 @@ function print_callstack(sv::InferenceState)
println()
end
sv = sv.parent
idx += 1
end
print("================= End callstack ==================\n")
end

function narguments(sv::InferenceState, include_va::Bool=true)
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ function get!(lazyagdomtree::LazyAugmentedDomtree)
cfg_insert_edge!(cfg, bb, length(cfg.blocks))
end
end
domtree = construct_domtree(cfg.blocks)
domtree = construct_domtree(cfg)
return lazyagdomtree.agdomtree = AugmentedDomtree(cfg, domtree)
end

Expand Down Expand Up @@ -1180,7 +1180,7 @@ function slot2reg(ir::IRCode, ci::CodeInfo, sv::OptimizationState)
# need `ci` for the slot metadata, IR for the code
svdef = sv.linfo.def
nargs = isa(svdef, Method) ? Int(svdef.nargs) : 0
@timeit "domtree 1" domtree = construct_domtree(ir.cfg.blocks)
@timeit "domtree 1" domtree = construct_domtree(ir)
defuse_insts = scan_slot_def_use(nargs, ci, ir.stmts.stmt)
𝕃ₒ = optimizer_lattice(sv.inlining.interp)
@timeit "construct_ssa" ir = construct_ssa!(ci, ir, sv, domtree, defuse_insts, 𝕃ₒ) # consumes `ir`
Expand Down
23 changes: 12 additions & 11 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1331,11 +1331,11 @@ function handle_any_const_result!(cases::Vector{InliningCase},
@nospecialize(info::CallInfo), flag::UInt32, state::InliningState;
allow_abstract::Bool, allow_typevars::Bool)
if isa(result, ConcreteResult)
return handle_concrete_result!(cases, result, info, state)
return handle_concrete_result!(cases, result, match, info, state)
elseif isa(result, SemiConcreteResult)
return handle_semi_concrete_result!(cases, result, info, flag, state; allow_abstract)
return handle_semi_concrete_result!(cases, result, match, info, flag, state; allow_abstract)
elseif isa(result, ConstPropResult)
return handle_const_prop_result!(cases, result, info, flag, state; allow_abstract, allow_typevars)
return handle_const_prop_result!(cases, result, match, info, flag, state; allow_abstract, allow_typevars)
else
@assert result === nothing || result isa VolatileInferenceResult
return handle_match!(cases, match, argtypes, info, flag, state; allow_abstract, allow_typevars, volatile_inf_result = result)
Expand Down Expand Up @@ -1481,11 +1481,11 @@ function handle_match!(cases::Vector{InliningCase},
return true
end

function handle_const_prop_result!(cases::Vector{InliningCase},
result::ConstPropResult, @nospecialize(info::CallInfo), flag::UInt32, state::InliningState;
function handle_const_prop_result!(cases::Vector{InliningCase}, result::ConstPropResult,
match::MethodMatch, @nospecialize(info::CallInfo), flag::UInt32, state::InliningState;
allow_abstract::Bool, allow_typevars::Bool)
mi = result.result.linfo
spec_types = mi.specTypes
spec_types = match.spec_types
allow_abstract || isdispatchtuple(spec_types) || return false
if !validate_sparams(mi.sparam_vals)
(allow_typevars && !may_have_fcalls(mi.def::Method)) || return false
Expand Down Expand Up @@ -1520,10 +1520,10 @@ function semiconcrete_result_item(result::SemiConcreteResult,
end

function handle_semi_concrete_result!(cases::Vector{InliningCase}, result::SemiConcreteResult,
@nospecialize(info::CallInfo), flag::UInt32, state::InliningState;
allow_abstract::Bool)
match::MethodMatch, @nospecialize(info::CallInfo), flag::UInt32, state::InliningState;
allow_abstract::Bool)
mi = result.mi
spec_types = mi.specTypes
spec_types = match.spec_types
allow_abstract || isdispatchtuple(spec_types) || return false
validate_sparams(mi.sparam_vals) || return false
item = semiconcrete_result_item(result, info, flag, state)
Expand All @@ -1532,10 +1532,11 @@ function handle_semi_concrete_result!(cases::Vector{InliningCase}, result::SemiC
return true
end

function handle_concrete_result!(cases::Vector{InliningCase}, result::ConcreteResult, @nospecialize(info::CallInfo), state::InliningState)
function handle_concrete_result!(cases::Vector{InliningCase}, result::ConcreteResult,
match::MethodMatch, @nospecialize(info::CallInfo), state::InliningState)
case = concrete_result_item(result, info, state)
case === nothing && return false
push!(cases, InliningCase(result.mi.specTypes, case))
push!(cases, InliningCase(match.spec_types, case))
return true
end

Expand Down
6 changes: 6 additions & 0 deletions base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ function IRCode()
return ir
end

construct_domtree(ir::IRCode) = construct_domtree(ir.cfg)
construct_domtree(cfg::CFG) = construct_domtree(cfg.blocks)

construct_postdomtree(ir::IRCode) = construct_postdomtree(ir.cfg)
construct_postdomtree(cfg::CFG) = construct_postdomtree(cfg.blocks)

function block_for_inst(ir::IRCode, inst::Int)
if inst > length(ir.stmts)
inst = ir.new_nodes.info[inst - length(ir.stmts)].pos
Expand Down
17 changes: 14 additions & 3 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1225,10 +1225,21 @@ function sroa_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
bb = compact.active_result_bb - 1
bbs = scope_mapping[bb]
if isexpr(stmt, :leave) && bbs != SSAValue(0)
update_scope_mapping!(scope_mapping, bb+1, scope_mapping[block_for_inst(compact, bbs)])
else
update_scope_mapping!(scope_mapping, bb+1, bbs)
# Here we want to count the number of scopes that we're leaving,
# which is the same as the number of EnterNodes being referenced
# by `stmt.args`. Which have :scope set. In practice, the frontend
# does emit these in order, so we could simply go to the last one,
# but we want to avoid making that semantic assumption.
for i = 1:length(stmt.args)
scope = stmt.args[i]
scope === nothing && continue
enter = compact[scope][:inst]
@assert isa(enter, EnterNode)
isdefined(enter, :scope) || continue
bbs = scope_mapping[block_for_inst(compact, bbs)]
end
end
update_scope_mapping!(scope_mapping, bb+1, bbs)
end
# check whether this statement is `getfield` / `setfield!` (or other "interesting" statement)
is_setfield = is_isdefined = is_finalizer = is_keyvalue_get = false
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ function merge_call_chain!(interp::AbstractInterpreter, parent::InferenceState,
end

function is_same_frame(interp::AbstractInterpreter, mi::MethodInstance, frame::InferenceState)
return mi === frame_instance(frame)
return mi === frame_instance(frame) && cache_owner(interp) === cache_owner(frame.interp)
end

function poison_callstack!(infstate::InferenceState, topmost::InferenceState)
Expand Down
9 changes: 6 additions & 3 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ kw"export"
public

`public` is used within modules to tell Julia which names are part of the
public API of the module . For example: `public foo` indicates that the name
`foo` is public, without making it available when [`using`](@ref)
the module. See the [manual section about modules](@ref modules) for details.
public API of the module. For example: `public foo` indicates that the name
`foo` is public, without making it available when [`using`](@ref) the module.

As [`export`](@ref) already indicates that a name is public, it is
unnecessary and an error to declare a name both as `public` and as `export`ed.
See the [manual section about modules](@ref modules) for details.

!!! compat "Julia 1.11"
The public keyword was added in Julia 1.11. Prior to this the notion
Expand Down
50 changes: 46 additions & 4 deletions base/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,57 @@ first(S::IdentityUnitRange) = first(S.indices)
last(S::IdentityUnitRange) = last(S.indices)
size(S::IdentityUnitRange) = (length(S.indices),)
length(S::IdentityUnitRange) = length(S.indices)
getindex(S::IdentityUnitRange, i::Int) = (@inline; @boundscheck checkbounds(S, i); i)
getindex(S::IdentityUnitRange, i::AbstractUnitRange{<:Integer}) = (@inline; @boundscheck checkbounds(S, i); i)
getindex(S::IdentityUnitRange, i::StepRange{<:Integer}) = (@inline; @boundscheck checkbounds(S, i); i)
unsafe_length(S::IdentityUnitRange) = unsafe_length(S.indices)
getindex(S::IdentityUnitRange, i::Integer) = (@inline; @boundscheck checkbounds(S, i); convert(eltype(S), i))
getindex(S::IdentityUnitRange, i::Bool) = throw(ArgumentError("invalid index: $i of type Bool"))
function getindex(S::IdentityUnitRange, i::AbstractUnitRange{<:Integer})
@inline
@boundscheck checkbounds(S, i)
return convert(AbstractUnitRange{eltype(S)}, i)
end
function getindex(S::IdentityUnitRange, i::AbstractUnitRange{Bool})
@inline
@boundscheck checkbounds(S, i)
range(first(i) ? first(S) : last(S), length = last(i))
end
function getindex(S::IdentityUnitRange, i::StepRange{<:Integer})
@inline
@boundscheck checkbounds(S, i)
return convert(AbstractRange{eltype(S)}, i)
end
function getindex(S::IdentityUnitRange, i::StepRange{Bool})
@inline
@boundscheck checkbounds(S, i)
range(first(i) ? first(S) : last(S), length = last(i), step = Int(step(i)))
end
# Indexing with offset ranges should preserve the axes of the indices
# however, this is only really possible in general with OffsetArrays.
# In some cases, though, we may obtain correct results using Base ranges
# the following methods are added to allow OffsetArrays to dispatch on the first argument without ambiguities
function getindex(S::IdentityUnitRange{<:AbstractUnitRange{<:Integer}},
i::IdentityUnitRange{<:AbstractUnitRange{<:Integer}})
@inline
@boundscheck checkbounds(S, i)
return i
end
function getindex(S::Slice{<:AbstractUnitRange{<:Integer}},
i::IdentityUnitRange{<:AbstractUnitRange{<:Integer}})
@inline
@boundscheck checkbounds(S, i)
return i
end
show(io::IO, r::IdentityUnitRange) = print(io, "Base.IdentityUnitRange(", r.indices, ")")
iterate(S::IdentityUnitRange, s...) = iterate(S.indices, s...)

# For OneTo, the values and indices of the values are identical, so this may be defined in Base.
# In general such an indexing operation would produce offset ranges
getindex(S::OneTo, I::IdentityUnitRange{<:AbstractUnitRange{<:Integer}}) = (@inline; @boundscheck checkbounds(S, I); I)
# This should also ideally return an AbstractUnitRange{eltype(S)}, but currently
# we're restricted to eltype(::IdentityUnitRange) == Int by definition
function getindex(S::OneTo, I::IdentityUnitRange{<:AbstractUnitRange{<:Integer}})
@inline
@boundscheck checkbounds(S, I)
return I
end

"""
LinearIndices(A::AbstractArray)
Expand Down
Loading

0 comments on commit d194d0c

Please sign in to comment.