Skip to content

Commit 394f15d

Browse files
committed
Merge branch 'master' of github.com:JuliaLang/julia into interactive-utils-functors
2 parents ef7727e + bac6d9a commit 394f15d

File tree

28 files changed

+274
-91
lines changed

28 files changed

+274
-91
lines changed

Compiler/src/ssair/show.jl

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ end
200200
end
201201

202202
"""
203-
Compute line number annotations for an IRCode
203+
Compute line number annotations for an IRCode or CodeInfo.
204204
205205
This functions compute three sets of annotations for each IR line. Take the following
206206
example (taken from `@code_typed sin(1.0)`):
@@ -259,7 +259,7 @@ to catch up and print the intermediate scopes. Which scope is printed is indicat
259259
by the indentation of the method name and by an increased thickness of the appropriate
260260
line for the scope.
261261
"""
262-
function compute_ir_line_annotations(code::IRCode)
262+
function compute_ir_line_annotations(code::Union{IRCode,CodeInfo})
263263
loc_annotations = String[]
264264
loc_methods = String[]
265265
loc_lineno = String[]
@@ -269,7 +269,8 @@ function compute_ir_line_annotations(code::IRCode)
269269
last_printed_depth = 0
270270
debuginfo = code.debuginfo
271271
def = :var"unknown scope"
272-
for idx in 1:length(code.stmts)
272+
n = isa(code, IRCode) ? length(code.stmts) : length(code.code)
273+
for idx in 1:n
273274
buf = IOBuffer()
274275
print(buf, "")
275276
stack = buildLineInfoNode(debuginfo, def, idx)
@@ -833,7 +834,7 @@ function new_nodes_iter(compact::IncrementalCompact)
833834
end
834835

835836
# print only line numbers on the left, some of the method names and nesting depth on the right
836-
function inline_linfo_printer(code::IRCode)
837+
function inline_linfo_printer(code::Union{IRCode,CodeInfo})
837838
loc_annotations, loc_methods, loc_lineno = compute_ir_line_annotations(code)
838839
max_loc_width = maximum(length, loc_annotations)
839840
max_lineno_width = maximum(length, loc_lineno)
@@ -902,12 +903,15 @@ function stmts_used(::IO, code::CodeInfo)
902903
return used
903904
end
904905

905-
function default_config(code::IRCode; verbose_linetable=false)
906-
return IRShowConfig(verbose_linetable ? statementidx_lineinfo_printer(code)
907-
: inline_linfo_printer(code);
908-
bb_color=:normal)
906+
function default_config(code::IRCode; debuginfo = :source_inline)
907+
return IRShowConfig(get_debuginfo_printer(code, debuginfo); bb_color=:normal)
908+
end
909+
default_config(code::CodeInfo; debuginfo = :source) = IRShowConfig(get_debuginfo_printer(code, debuginfo))
910+
function default_config(io::IO, src)
911+
debuginfo = get(io, :debuginfo, nothing)
912+
debuginfo !== nothing && return default_config(src; debuginfo)
913+
return default_config(src)
909914
end
910-
default_config(code::CodeInfo) = IRShowConfig(statementidx_lineinfo_printer(code))
911915

912916
function show_ir_stmts(io::IO, ir::Union{IRCode, CodeInfo, IncrementalCompact}, inds, config::IRShowConfig,
913917
sptypes::Vector{VarState}, used::BitSet, cfg::CFG, bb_idx::Int; pop_new_node! = Returns(nothing))
@@ -927,8 +931,7 @@ function finish_show_ir(io::IO, cfg::CFG, config::IRShowConfig)
927931
return nothing
928932
end
929933

930-
function show_ir(io::IO, ir::IRCode, config::IRShowConfig=default_config(ir);
931-
pop_new_node! = new_nodes_iter(ir))
934+
function show_ir(io::IO, ir::IRCode, config::IRShowConfig=default_config(io, ir); pop_new_node! = new_nodes_iter(ir))
932935
used = stmts_used(io, ir)
933936
cfg = ir.cfg
934937
maxssaid = length(ir.stmts) + length(ir.new_nodes)
@@ -938,7 +941,7 @@ function show_ir(io::IO, ir::IRCode, config::IRShowConfig=default_config(ir);
938941
finish_show_ir(io, cfg, config)
939942
end
940943

941-
function show_ir(io::IO, ci::CodeInfo, config::IRShowConfig=default_config(ci);
944+
function show_ir(io::IO, ci::CodeInfo, config::IRShowConfig=default_config(io, ci);
942945
pop_new_node! = Returns(nothing))
943946
used = stmts_used(io, ci)
944947
cfg = compute_basic_blocks(ci.code)
@@ -952,7 +955,7 @@ function show_ir(io::IO, ci::CodeInfo, config::IRShowConfig=default_config(ci);
952955
finish_show_ir(io, cfg, config)
953956
end
954957

955-
function show_ir(io::IO, compact::IncrementalCompact, config::IRShowConfig=default_config(compact.ir))
958+
function show_ir(io::IO, compact::IncrementalCompact, config::IRShowConfig=default_config(io, compact.ir))
956959
cfg = compact.ir.cfg
957960

958961

@@ -1154,3 +1157,35 @@ const __debuginfo = Dict{Symbol, Any}(
11541157
)
11551158
const default_debuginfo = Ref{Symbol}(:none)
11561159
debuginfo(sym) = sym === :default ? default_debuginfo[] : sym
1160+
1161+
const __debuginfo = Dict{Symbol, Any}(
1162+
# :full => src -> statementidx_lineinfo_printer(src), # and add variable slot information
1163+
:source => src -> statementidx_lineinfo_printer(src),
1164+
:source_inline => src -> inline_linfo_printer(src),
1165+
# :oneliner => src -> statementidx_lineinfo_printer(PartialLineInfoPrinter, src),
1166+
:none => src -> lineinfo_disabled,
1167+
)
1168+
1169+
const debuginfo_modes = [:none, :source, :source_inline]
1170+
@assert Set(debuginfo_modes) == Set(keys(__debuginfo))
1171+
1172+
function validate_debuginfo_mode(mode::Symbol)
1173+
in(mode, debuginfo_modes) && return true
1174+
throw(ArgumentError("`debuginfo` must be one of the following: $(join([repr(mode) for mode in debuginfo_modes], ", "))"))
1175+
end
1176+
1177+
const default_debuginfo_mode = Ref{Symbol}(:none)
1178+
function expand_debuginfo_mode(mode::Symbol, default = default_debuginfo_mode[])
1179+
if mode === :default
1180+
mode = default
1181+
end
1182+
validate_debuginfo_mode(mode)
1183+
return mode
1184+
end
1185+
1186+
function get_debuginfo_printer(mode::Symbol)
1187+
mode = expand_debuginfo_mode(mode)
1188+
return __debuginfo[mode]
1189+
end
1190+
1191+
get_debuginfo_printer(src, mode::Symbol) = get_debuginfo_printer(mode)(src)

Compiler/test/AbstractInterpreter.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,4 +548,17 @@ let interp = InvokeInterp()
548548
mi = @ccall jl_method_lookup(Any[f, args...]::Ptr{Any}, (1+length(args))::Csize_t, Base.tls_world_age()::Csize_t)::Ref{Core.MethodInstance}
549549
ci = Compiler.typeinf_ext_toplevel(interp, mi, source_mode)
550550
@test invoke(f, ci, args...) == 2
551+
552+
f = error
553+
args = "test"
554+
mi = @ccall jl_method_lookup(Any[f, args...]::Ptr{Any}, (1+length(args))::Csize_t, Base.tls_world_age()::Csize_t)::Ref{Core.MethodInstance}
555+
ci = Compiler.typeinf_ext_toplevel(interp, mi, source_mode)
556+
result = nothing
557+
try
558+
invoke(f, ci, args...)
559+
catch e
560+
result = sprint(Base.show_backtrace, catch_backtrace())
561+
end
562+
@test isa(result, String)
563+
@test contains(result, "[1] error(::Char, ::Char, ::Char, ::Char)")
551564
end

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ is considered a bug fix ([#47102])
1717

1818
- The `hash` algorithm and its values have changed. Most `hash` specializations will remain correct and require no action. Types that reimplement the core hashing logic independently, such as some third-party string packages do, may require a migration to the new algorithm. ([#57509])
1919

20+
* Indexless `getindex` and `setindex!` (i.e. `A[]`) on `ReinterpretArray` now correctly throw a `BoundsError` when there is more than one element. ([#58814])
21+
2022
Compiler/Runtime improvements
2123
-----------------------------
2224

@@ -44,6 +46,7 @@ New library functions
4446

4547
* `ispositive(::Real)` and `isnegative(::Real)` are provided for performance and convenience ([#53677]).
4648
* Exporting function `fieldindex` to get the index of a struct's field ([#58119]).
49+
* `Base.donotdelete` is now public. It prevents deadcode elemination of its arguments ([#55774]).
4750

4851
New library features
4952
--------------------

base/abstractarray.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2567,16 +2567,23 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
25672567
end
25682568

25692569
# discover number of rows or columns
2570+
# d1 dimension is increased by 1 to appropriately handle 0-length arrays
25702571
for i 1:dims[d1]
25712572
outdims[d1] += cat_size(as[i], d1)
25722573
end
25732574

2575+
# adjustment to handle 0-length arrays
2576+
first_dim_zero = outdims[d1] == 0
2577+
if first_dim_zero
2578+
outdims[d1] = dims[d1]
2579+
end
2580+
25742581
currentdims = zeros(Int, N)
25752582
blockcount = 0
25762583
elementcount = 0
25772584
for i eachindex(as)
25782585
elementcount += cat_length(as[i])
2579-
currentdims[d1] += cat_size(as[i], d1)
2586+
currentdims[d1] += first_dim_zero ? 1 : cat_size(as[i], d1)
25802587
if currentdims[d1] == outdims[d1]
25812588
currentdims[d1] = 0
25822589
for d (d2, 3:N...)
@@ -2604,6 +2611,10 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
26042611
throw(DimensionMismatch("argument $i has too many elements along axis $d1"))
26052612
end
26062613
end
2614+
# restore 0-length adjustment
2615+
if first_dim_zero
2616+
outdims[d1] = 0
2617+
end
26072618

26082619
outlen = prod(outdims)
26092620
elementcount == outlen ||

base/deprecated.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,4 +557,11 @@ true
557557
"""
558558
isbindingresolved
559559

560+
# Some packages call this function
561+
function to_power_type(x::Number)
562+
T = promote_type(typeof(x), typeof(x*x))
563+
convert(T, x)
564+
end
565+
to_power_type(x) = oftype(x*x, x)
566+
560567
# END 1.12 deprecations

base/loading.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ end
184184
const slug_chars = String(['A':'Z'; 'a':'z'; '0':'9'])
185185

186186
function slug(x::UInt32, p::Int)
187-
y::UInt32 = x
188187
sprint(sizehint=p) do io
188+
y = x
189189
n = length(slug_chars)
190190
for i = 1:p
191191
y, d = divrem(y, n)
@@ -1061,6 +1061,7 @@ function explicit_manifest_uuid_path(project_file::String, pkg::PkgId)::Union{No
10611061
for (name, entries) in d
10621062
entries = entries::Vector{Any}
10631063
for entry in entries
1064+
entry = entry::Dict{String, Any}
10641065
uuid = get(entry, "uuid", nothing)::Union{Nothing, String}
10651066
extensions = get(entry, "extensions", nothing)::Union{Nothing, Dict{String, Any}}
10661067
if extensions !== nothing && haskey(extensions, pkg.name) && uuid !== nothing && uuid5(UUID(uuid), pkg.name) == pkg.uuid
@@ -4187,6 +4188,20 @@ function expand_compiler_path(tup)
41874188
end
41884189
compiler_chi(tup::Tuple) = CacheHeaderIncludes(expand_compiler_path(tup))
41894190

4191+
"""
4192+
isprecompilable(f, argtypes::Tuple{Vararg{Any}})
4193+
4194+
Check, as far as is possible without actually compiling, if the given
4195+
function `f` can be compiled for the argument tuple (of types) `argtypes`.
4196+
"""
4197+
function isprecompilable(@nospecialize(f), @nospecialize(argtypes::Tuple))
4198+
isprecompilable(Tuple{Core.Typeof(f), argtypes...})
4199+
end
4200+
4201+
function isprecompilable(@nospecialize(argt::Type))
4202+
ccall(:jl_is_compilable, Int32, (Any,), argt) != 0
4203+
end
4204+
41904205
"""
41914206
precompile(f, argtypes::Tuple{Vararg{Any}})
41924207

base/precompilation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ Base.show(io::IO, err::PkgPrecompileError) = print(io, "PkgPrecompileError: ", e
355355

356356
import Base: StaleCacheKey
357357

358-
can_fancyprint(io::IO) = io isa Base.TTY && (get(ENV, "CI", nothing) != "true")
358+
can_fancyprint(io::IO) = @something(get(io, :force_fancyprint, nothing), (io isa Base.TTY && (get(ENV, "CI", nothing) != "true")))
359359

360360
function printpkgstyle(io, header, msg; color=:green)
361361
printstyled(io, header; color, bold=true)

base/public.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,5 @@ public
125125
notnothing,
126126
runtests,
127127
text_colors,
128-
depwarn
128+
depwarn,
129+
donotdelete

base/reinterpretarray.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@ end
314314
_maybe_reshape(::IndexSCartesian2, A::ReshapedReinterpretArray, I...) = A
315315

316316
# fallbacks
317-
function _getindex(::IndexSCartesian2, A::AbstractArray{T,N}, I::Vararg{Int, N}) where {T,N}
317+
function _getindex(::IndexSCartesian2, A::AbstractArray, I::Vararg{Int, N}) where {N}
318318
@_propagate_inbounds_meta
319-
getindex(A, I...)
319+
_getindex(IndexCartesian(), A, I...)
320320
end
321-
function _setindex!(::IndexSCartesian2, A::AbstractArray{T,N}, v, I::Vararg{Int, N}) where {T,N}
321+
function _setindex!(::IndexSCartesian2, A::AbstractArray, v, I::Vararg{Int, N}) where {N}
322322
@_propagate_inbounds_meta
323-
setindex!(A, v, I...)
323+
_setindex!(IndexCartesian(), A, v, I...)
324324
end
325325
# fallbacks for array types that use "pass-through" indexing (e.g., `IndexStyle(A) = IndexStyle(parent(A))`)
326326
# but which don't handle SCartesianIndex2
@@ -391,7 +391,7 @@ check_ptr_indexable(a::Array, sz) = sizeof(eltype(a)) !== sz
391391
check_ptr_indexable(a::Memory, sz) = true
392392
check_ptr_indexable(a::AbstractArray, sz) = false
393393

394-
@propagate_inbounds getindex(a::ReinterpretArray) = a[firstindex(a)]
394+
@propagate_inbounds getindex(a::ReshapedReinterpretArray{T,0}) where {T} = a[firstindex(a)]
395395

396396
@propagate_inbounds isassigned(a::ReinterpretArray, inds::Integer...) = checkbounds(Bool, a, inds...) && (check_ptr_indexable(a) || _isassigned_ra(a, inds...))
397397
@propagate_inbounds isassigned(a::ReinterpretArray, inds::SCartesianIndex2) = isassigned(a.parent, inds.j)
@@ -412,7 +412,7 @@ end
412412
# Convert to full indices here, to avoid needing multiple conversions in
413413
# the loop in _getindex_ra
414414
inds = _to_subscript_indices(a, i)
415-
isempty(inds) ? _getindex_ra(a, 1, ()) : _getindex_ra(a, inds[1], tail(inds))
415+
isempty(inds) ? _getindex_ra(a, firstindex(a), ()) : _getindex_ra(a, inds[1], tail(inds))
416416
end
417417

418418
@propagate_inbounds function getindex(a::ReshapedReinterpretArray{T,N,S}, ind::SCartesianIndex2) where {T,N,S}
@@ -535,13 +535,13 @@ end
535535

536536
@propagate_inbounds function setindex!(a::NonReshapedReinterpretArray{T,0,S}, v) where {T,S}
537537
if isprimitivetype(S) && isprimitivetype(T)
538-
a.parent[] = reinterpret(S, v)
538+
a.parent[] = reinterpret(S, convert(T, v)::T)
539539
return a
540540
end
541541
setindex!(a, v, firstindex(a))
542542
end
543543

544-
@propagate_inbounds setindex!(a::ReinterpretArray, v) = setindex!(a, v, firstindex(a))
544+
@propagate_inbounds setindex!(a::ReshapedReinterpretArray{T,0}, v) where {T} = setindex!(a, v, firstindex(a))
545545

546546
@propagate_inbounds function setindex!(a::ReinterpretArray{T,N,S}, v, inds::Vararg{Int, N}) where {T,N,S}
547547
check_writable(a)
@@ -556,7 +556,7 @@ end
556556
return _setindex_ra!(a, v, i, ())
557557
end
558558
inds = _to_subscript_indices(a, i)
559-
_setindex_ra!(a, v, inds[1], tail(inds))
559+
isempty(inds) ? _setindex_ra!(a, v, firstindex(a), ()) : _setindex_ra!(a, v, inds[1], tail(inds))
560560
end
561561

562562
@propagate_inbounds function setindex!(a::ReshapedReinterpretArray{T,N,S}, v, ind::SCartesianIndex2) where {T,N,S}

base/stacktraces.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ end
290290

291291
# Can be extended by compiler packages to customize backtrace display of custom code instance frames
292292
function show_custom_spec_sig(io::IO, @nospecialize(owner), linfo::CodeInstance, frame::StackFrame)
293-
mi = get_ci_mi(linfo)
293+
mi = Base.get_ci_mi(linfo)
294294
return show_spec_sig(io, mi.def, mi.specTypes)
295295
end
296296

0 commit comments

Comments
 (0)