Skip to content

Commit 4807a12

Browse files
committed
Merge remote-tracking branch 'origin/master' into mb/ReduceReuse♻
2 parents 3d5cfec + 32211a6 commit 4807a12

Some content is hidden

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

74 files changed

+941
-529
lines changed

Compiler/src/bootstrap.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function activate_codegen!()
1010
Core.eval(Compiler, quote
1111
let typeinf_world_age = Base.tls_world_age()
1212
@eval Core.OptimizedGenerics.CompilerPlugins.typeinf(::Nothing, mi::MethodInstance, source_mode::UInt8) =
13-
Base.invoke_in_world($(Expr(:$, :typeinf_world_age)), typeinf_ext_toplevel, mi, Base.tls_world_age(), source_mode)
13+
Base.invoke_in_world($(Expr(:$, :typeinf_world_age)), typeinf_ext_toplevel, mi, Base.tls_world_age(), source_mode, Compiler.TRIM_NO)
1414
end
1515
end)
1616
end
@@ -67,7 +67,7 @@ function bootstrap!()
6767
end
6868
mi = specialize_method(m.method, Tuple{params...}, m.sparams)
6969
#isa_compileable_sig(mi) || println(stderr, "WARNING: inferring `", mi, "` which isn't expected to be called.")
70-
typeinf_ext_toplevel(mi, world, isa_compileable_sig(mi) ? SOURCE_MODE_ABI : SOURCE_MODE_NOT_REQUIRED)
70+
typeinf_ext_toplevel(mi, world, isa_compileable_sig(mi) ? SOURCE_MODE_ABI : SOURCE_MODE_NOT_REQUIRED, TRIM_NO)
7171
end
7272
end
7373
end

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/src/ssair/verify.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
irshow_was_loaded() = invokelatest(isdefined, Compiler.IRShow, :debuginfo_firstline)
3+
irshow_was_loaded() = invokelatest(isdefinedglobal, Compiler.IRShow, :debuginfo_firstline)
44
function maybe_show_ir(ir::IRCode)
55
if irshow_was_loaded()
66
# ensure we use I/O that does not yield, as this gets called during compilation

Compiler/src/typeinfer.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,8 +1564,9 @@ function typeinf_ext_toplevel(interp::AbstractInterpreter, mi::MethodInstance, s
15641564
end
15651565

15661566
# This is a bridge for the C code calling `jl_typeinf_func()` on a single Method match
1567-
function typeinf_ext_toplevel(mi::MethodInstance, world::UInt, source_mode::UInt8)
1568-
interp = NativeInterpreter(world)
1567+
function typeinf_ext_toplevel(mi::MethodInstance, world::UInt, source_mode::UInt8, trim_mode::UInt8)
1568+
inf_params = InferenceParams(; force_enable_inference = trim_mode != TRIM_NO)
1569+
interp = NativeInterpreter(world; inf_params)
15691570
return typeinf_ext_toplevel(interp, mi, source_mode)
15701571
end
15711572

@@ -1648,11 +1649,11 @@ end
16481649

16491650
# This is a bridge for the C code calling `jl_typeinf_func()` on set of Method matches
16501651
# The trim_mode can be any of:
1651-
const TRIM_NO = 0
1652-
const TRIM_SAFE = 1
1653-
const TRIM_UNSAFE = 2
1654-
const TRIM_UNSAFE_WARN = 3
1655-
function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim_mode::Int)
1652+
const TRIM_NO = 0x0
1653+
const TRIM_SAFE = 0x1
1654+
const TRIM_UNSAFE = 0x2
1655+
const TRIM_UNSAFE_WARN = 0x3
1656+
function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim_mode::UInt8)
16561657
inf_params = InferenceParams(; force_enable_inference = trim_mode != TRIM_NO)
16571658

16581659
# Create an "invokelatest" queue to enable eager compilation of speculative

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

Compiler/test/codegen.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,3 +1069,9 @@ let io = IOBuffer()
10691069
str = String(take!(io))
10701070
@test !occursin("jtbaa_unionselbyte", str)
10711071
end
1072+
1073+
let io = IOBuffer()
1074+
code_llvm(io, (x, y) -> (@atomic x[1] = y; nothing), (AtomicMemory{Pair{Any,Any}}, Pair{Any,Any},), raw=true, optimize=false)
1075+
str = String(take!(io))
1076+
@test occursin("julia.write_barrier", str)
1077+
end

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ julia-deps: | $(DIRS) $(build_datarootdir)/julia/base $(build_datarootdir)/julia
8989
julia-stdlib: | $(DIRS) julia-deps
9090
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/stdlib
9191

92-
julia-base: julia-deps $(build_sysconfdir)/julia/startup.jl $(build_man1dir)/julia.1 $(build_datarootdir)/julia/julia-config.jl $(build_datarootdir)/julia/juliac.jl $(build_datarootdir)/julia/juliac-buildscript.jl
92+
julia-base: julia-deps $(build_sysconfdir)/julia/startup.jl $(build_man1dir)/julia.1 $(build_datarootdir)/julia/julia-config.jl $(build_datarootdir)/julia/juliac/juliac.jl $(build_datarootdir)/julia/juliac/juliac-buildscript.jl $(build_datarootdir)/julia/juliac/juliac-trim-base.jl $(build_datarootdir)/julia/juliac/juliac-trim-stdlib.jl
9393
@$(MAKE) $(QUIET_MAKE) -C $(BUILDROOT)/base
9494

9595
julia-libccalltest: julia-deps
@@ -184,6 +184,7 @@ $(build_sysconfdir)/julia/startup.jl: $(JULIAHOME)/etc/startup.jl | $(build_sysc
184184
@cp $< $@
185185

186186
$(build_datarootdir)/julia/%: $(JULIAHOME)/contrib/% | $(build_datarootdir)/julia
187+
mkdir -p $(dir $@)
187188
$(INSTALL_M) $< $(dir $@)
188189

189190
$(build_depsbindir)/stringreplace: $(JULIAHOME)/contrib/stringreplace.c | $(build_depsbindir)

NEWS.md

Lines changed: 2 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

base/abstractarray.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ function eachindex(A::AbstractArray, B::AbstractArray...)
387387
@inline
388388
eachindex(IndexStyle(A,B...), A, B...)
389389
end
390+
eachindex(::IndexLinear, A::Union{Array, Memory}) = unchecked_oneto(length(A))
390391
eachindex(::IndexLinear, A::AbstractArray) = (@inline; oneto(length(A)))
391392
eachindex(::IndexLinear, A::AbstractVector) = (@inline; axes1(A))
392393
function eachindex(::IndexLinear, A::AbstractArray, B::AbstractArray...)
@@ -1237,15 +1238,15 @@ oneunit(x::AbstractMatrix{T}) where {T} = _one(oneunit(T), x)
12371238
iterate_starting_state(A) = iterate_starting_state(A, IndexStyle(A))
12381239
iterate_starting_state(A, ::IndexLinear) = firstindex(A)
12391240
iterate_starting_state(A, ::IndexStyle) = (eachindex(A),)
1240-
iterate(A::AbstractArray, state = iterate_starting_state(A)) = _iterate(A, state)
1241-
function _iterate(A::AbstractArray, state::Tuple)
1241+
@inline iterate(A::AbstractArray, state = iterate_starting_state(A)) = _iterate(A, state)
1242+
@inline function _iterate(A::AbstractArray, state::Tuple)
12421243
y = iterate(state...)
12431244
y === nothing && return nothing
12441245
A[y[1]], (state[1], tail(y)...)
12451246
end
1246-
function _iterate(A::AbstractArray, state::Integer)
1247+
@inline function _iterate(A::AbstractArray, state::Integer)
12471248
checkbounds(Bool, A, state) || return nothing
1248-
@inbounds(A[state]), state + one(state)
1249+
A[state], state + one(state)
12491250
end
12501251

12511252
isempty(a::AbstractArray) = (length(a) == 0)

base/array.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,6 @@ function grow_to!(dest, itr, st)
902902
return dest
903903
end
904904

905-
## Iteration ##
906-
907-
iterate(A::Array, i=1) = (@inline; _iterate_array(A, i))
908-
909905
## Indexing: getindex ##
910906

911907
"""

0 commit comments

Comments
 (0)