Skip to content

Commit 1a30832

Browse files
authored
Merge branch 'master' into stabilize-quicksort
2 parents 3318c34 + 6d7bc40 commit 1a30832

Some content is hidden

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

72 files changed

+934
-335
lines changed

.git-blame-ignore-revs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# .git-blame-ignore-revs
2+
# whitespace: end text files with single newlines
3+
3903fa54a638d4546ef50e56f91f0705a8ab11ef
4+
# whitespace: use only UNIX line endings (\n)
5+
e66bfa5dd32f93e76068c00ad882c1fc839c5af8
6+
# whitespace: replace non-breaking space => space
7+
100a741e7ab38c91d48cc929bb001afc8e09261f

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ New library functions
4444
---------------------
4545

4646
* `Iterators.flatmap` was added ([#44792]).
47+
* New helper `Splat(f)` which acts like `x -> f(x...)`, with pretty printing for
48+
inspecting which function `f` was originally wrapped. ([#42717])
4749

4850
Library changes
4951
---------------
@@ -120,6 +122,7 @@ Standard library changes
120122
Deprecated or removed
121123
---------------------
122124

125+
* Unexported `splat` is deprecated in favor of exported `Splat`, which has pretty printing of the wrapped function. ([#42717])
123126

124127
External dependencies
125128
---------------------

base/Enums.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ macro enum(T::Union{Symbol,Expr}, syms...)
151151
values = Vector{basetype}()
152152
seen = Set{Symbol}()
153153
namemap = Dict{basetype,Symbol}()
154-
lo = hi = 0
155-
i = zero(basetype)
154+
lo = hi = i = zero(basetype)
156155
hasexpr = false
157156

158157
if length(syms) == 1 && syms[1] isa Expr && syms[1].head === :block
@@ -193,7 +192,6 @@ macro enum(T::Union{Symbol,Expr}, syms...)
193192
if length(values) == 1
194193
lo = hi = i
195194
else
196-
lo = min(lo, i)
197195
hi = max(hi, i)
198196
end
199197
i += oneunit(i)

base/abstractarray.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,17 @@ end
914914

915915
function copyto!(dest::AbstractArray, dstart::Integer, src)
916916
i = Int(dstart)
917-
for x in src
918-
dest[i] = x
919-
i += 1
917+
if haslength(src) && length(dest) > 0
918+
@boundscheck checkbounds(dest, i:(i + length(src) - 1))
919+
for x in src
920+
@inbounds dest[i] = x
921+
i += 1
922+
end
923+
else
924+
for x in src
925+
dest[i] = x
926+
i += 1
927+
end
920928
end
921929
return dest
922930
end

base/boot.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@
111111
# module::Module
112112
# method::Symbol
113113
# file::Symbol
114-
# line::Int
115-
# inlined_at::Int
114+
# line::Int32
115+
# inlined_at::Int32
116116
#end
117117

118118
#struct GotoNode
@@ -410,7 +410,7 @@ eval(Core, quote
410410
isa(f, String) && (f = Symbol(f))
411411
return $(Expr(:new, :LineNumberNode, :l, :f))
412412
end
413-
LineInfoNode(mod::Module, @nospecialize(method), file::Symbol, line::Int, inlined_at::Int) =
413+
LineInfoNode(mod::Module, @nospecialize(method), file::Symbol, line::Int32, inlined_at::Int32) =
414414
$(Expr(:new, :LineInfoNode, :mod, :method, :file, :line, :inlined_at))
415415
GlobalRef(m::Module, s::Symbol) = $(Expr(:new, :GlobalRef, :m, :s))
416416
SlotNumber(n::Int) = $(Expr(:new, :SlotNumber, :n))

base/checked.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
# Support for checked integer arithmetic
44

5+
"""
6+
Checked
7+
8+
The Checked module provides arithmetic functions for the built-in signed and unsigned
9+
Integer types which throw an error when an overflow occurs. They are named like `checked_sub`,
10+
`checked_div`, etc. In addition, `add_with_overflow`, `sub_with_overflow`, `mul_with_overflow`
11+
return both the unchecked results and a boolean value denoting the presence of an overflow.
12+
"""
513
module Checked
614

715
export checked_neg, checked_abs, checked_add, checked_sub, checked_mul,

base/compiler/compiler.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ include("compiler/abstractinterpretation.jl")
141141
include("compiler/typeinfer.jl")
142142
include("compiler/optimize.jl") # TODO: break this up further + extract utilities
143143

144-
# required for bootstrap
145-
# TODO: find why this is needed and remove it.
144+
# required for bootstrap because sort.jl uses extrema
145+
# to decide whether to dispatch to counting sort.
146+
#
147+
# TODO: remove it.
146148
function extrema(x::Array)
147149
isempty(x) && throw(ArgumentError("collection must be non-empty"))
148150
vmin = vmax = x[1]

base/compiler/optimize.jl

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -554,29 +554,36 @@ function run_passes(ci::CodeInfo, sv::OptimizationState, caller::InferenceResult
554554
end
555555

556556
function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
557-
code = copy_exprargs(ci.code)
557+
linetable = ci.linetable
558+
if !isa(linetable, Vector{LineInfoNode})
559+
linetable = collect(LineInfoNode, linetable::Vector{Any})::Vector{LineInfoNode}
560+
end
561+
562+
# check if coverage mode is enabled
558563
coverage = coverage_enabled(sv.mod)
559-
# Go through and add an unreachable node after every
560-
# Union{} call. Then reindex labels.
561-
idx = 1
562-
oldidx = 1
563-
changemap = fill(0, length(code))
564-
prevloc = zero(eltype(ci.codelocs))
565-
stmtinfo = sv.stmt_info
566-
codelocs = ci.codelocs
567-
ssavaluetypes = ci.ssavaluetypes::Vector{Any}
568-
ssaflags = ci.ssaflags
569564
if !coverage && JLOptions().code_coverage == 3 # path-specific coverage mode
570-
for line in ci.linetable
571-
line = line::LineInfoNode
565+
for line in linetable
572566
if is_file_tracked(line.file)
573567
# if any line falls in a tracked file enable coverage for all
574568
coverage = true
575569
break
576570
end
577571
end
578572
end
579-
labelmap = coverage ? fill(0, length(code)) : changemap
573+
574+
# Go through and add an unreachable node after every
575+
# Union{} call. Then reindex labels.
576+
code = copy_exprargs(ci.code)
577+
stmtinfo = sv.stmt_info
578+
codelocs = ci.codelocs
579+
ssavaluetypes = ci.ssavaluetypes::Vector{Any}
580+
ssaflags = ci.ssaflags
581+
meta = Expr[]
582+
idx = 1
583+
oldidx = 1
584+
ssachangemap = fill(0, length(code))
585+
labelchangemap = coverage ? fill(0, length(code)) : ssachangemap
586+
prevloc = zero(eltype(ci.codelocs))
580587
while idx <= length(code)
581588
codeloc = codelocs[idx]
582589
if coverage && codeloc != prevloc && codeloc != 0
@@ -586,9 +593,9 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
586593
insert!(ssavaluetypes, idx, Nothing)
587594
insert!(stmtinfo, idx, nothing)
588595
insert!(ssaflags, idx, IR_FLAG_NULL)
589-
changemap[oldidx] += 1
590-
if oldidx < length(labelmap)
591-
labelmap[oldidx + 1] += 1
596+
ssachangemap[oldidx] += 1
597+
if oldidx < length(labelchangemap)
598+
labelchangemap[oldidx + 1] += 1
592599
end
593600
idx += 1
594601
prevloc = codeloc
@@ -601,30 +608,27 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState)
601608
insert!(ssavaluetypes, idx + 1, Union{})
602609
insert!(stmtinfo, idx + 1, nothing)
603610
insert!(ssaflags, idx + 1, ssaflags[idx])
604-
if oldidx < length(changemap)
605-
changemap[oldidx + 1] += 1
606-
coverage && (labelmap[oldidx + 1] += 1)
611+
if oldidx < length(ssachangemap)
612+
ssachangemap[oldidx + 1] += 1
613+
coverage && (labelchangemap[oldidx + 1] += 1)
607614
end
608615
idx += 1
609616
end
610617
end
611618
idx += 1
612619
oldidx += 1
613620
end
614-
renumber_ir_elements!(code, changemap, labelmap)
615621

616-
meta = Expr[]
622+
renumber_ir_elements!(code, ssachangemap, labelchangemap)
623+
617624
for i = 1:length(code)
618625
code[i] = process_meta!(meta, code[i])
619626
end
620627
strip_trailing_junk!(ci, code, stmtinfo)
621-
cfg = compute_basic_blocks(code)
622628
types = Any[]
623629
stmts = InstructionStream(code, types, stmtinfo, codelocs, ssaflags)
624-
linetable = ci.linetable
625-
isa(linetable, Vector{LineInfoNode}) || (linetable = collect(LineInfoNode, linetable::Vector{Any}))
626-
ir = IRCode(stmts, cfg, linetable, sv.slottypes, meta, sv.sptypes)
627-
return ir
630+
cfg = compute_basic_blocks(code)
631+
return IRCode(stmts, cfg, linetable, sv.slottypes, meta, sv.sptypes)
628632
end
629633

630634
function process_meta!(meta::Vector{Expr}, @nospecialize stmt)
@@ -788,31 +792,33 @@ function statement_costs!(cost::Vector{Int}, body::Vector{Any}, src::Union{CodeI
788792
return maxcost
789793
end
790794

791-
function renumber_ir_elements!(body::Vector{Any}, changemap::Vector{Int})
792-
return renumber_ir_elements!(body, changemap, changemap)
795+
function renumber_ir_elements!(body::Vector{Any}, ssachangemap::Vector{Int})
796+
return renumber_ir_elements!(body, ssachangemap, ssachangemap)
793797
end
794798

795-
function cumsum_ssamap!(ssamap::Vector{Int})
799+
function cumsum_ssamap!(ssachangemap::Vector{Int})
800+
any_change = false
796801
rel_change = 0
797-
for i = 1:length(ssamap)
798-
rel_change += ssamap[i]
799-
if ssamap[i] == -1
802+
for i = 1:length(ssachangemap)
803+
val = ssachangemap[i]
804+
any_change |= val 0
805+
rel_change += val
806+
if val == -1
800807
# Keep a marker that this statement was deleted
801-
ssamap[i] = typemin(Int)
808+
ssachangemap[i] = typemin(Int)
802809
else
803-
ssamap[i] = rel_change
810+
ssachangemap[i] = rel_change
804811
end
805812
end
813+
return any_change
806814
end
807815

808816
function renumber_ir_elements!(body::Vector{Any}, ssachangemap::Vector{Int}, labelchangemap::Vector{Int})
809-
cumsum_ssamap!(labelchangemap)
817+
any_change = cumsum_ssamap!(labelchangemap)
810818
if ssachangemap !== labelchangemap
811-
cumsum_ssamap!(ssachangemap)
812-
end
813-
if labelchangemap[end] == 0 && ssachangemap[end] == 0
814-
return
819+
any_change |= cumsum_ssamap!(ssachangemap)
815820
end
821+
any_change || return
816822
for i = 1:length(body)
817823
el = body[i]
818824
if isa(el, GotoNode)
@@ -822,7 +828,8 @@ function renumber_ir_elements!(body::Vector{Any}, ssachangemap::Vector{Int}, lab
822828
if isa(cond, SSAValue)
823829
cond = SSAValue(cond.id + ssachangemap[cond.id])
824830
end
825-
body[i] = GotoIfNot(cond, el.dest + labelchangemap[el.dest])
831+
was_deleted = labelchangemap[el.dest] == typemin(Int)
832+
body[i] = was_deleted ? cond : GotoIfNot(cond, el.dest + labelchangemap[el.dest])
826833
elseif isa(el, ReturnNode)
827834
if isdefined(el, :val)
828835
val = el.val

base/compiler/ssair/inlining.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
315315
def = item.mi.def::Method
316316
linetable_offset::Int32 = length(linetable)
317317
# Append the linetable of the inlined function to our line table
318-
inlined_at = Int(compact.result[idx][:line])
318+
inlined_at = compact.result[idx][:line]
319319
topline::Int32 = linetable_offset + Int32(1)
320320
coverage = coverage_enabled(def.module)
321321
coverage_by_path = JLOptions().code_coverage == 3
322-
push!(linetable, LineInfoNode(def.module, def.name, def.file, Int(def.line), inlined_at))
322+
push!(linetable, LineInfoNode(def.module, def.name, def.file, def.line, inlined_at))
323323
oldlinetable = spec.ir.linetable
324324
for oldline in 1:length(oldlinetable)
325325
entry = oldlinetable[oldline]

base/compiler/ssair/ir.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ function first_insert_for_bb(code, cfg::CFG, block::Int)
151151
error("any insert position isn't found")
152152
end
153153

154+
# SSA values that need renaming
155+
struct OldSSAValue
156+
id::Int
157+
end
158+
159+
# SSA values that are in `new_new_nodes` of an `IncrementalCompact` and are to
160+
# be actually inserted next time (they become `new_nodes` next time)
161+
struct NewSSAValue
162+
id::Int
163+
end
164+
165+
const AnySSAValue = Union{SSAValue, OldSSAValue, NewSSAValue}
166+
167+
154168
# SSA-indexed nodes
155169

156170
struct NewInstruction
@@ -253,6 +267,10 @@ function setindex!(is::InstructionStream, newval::Instruction, idx::Int)
253267
is.flag[idx] = newval[:flag]
254268
return is
255269
end
270+
function setindex!(is::InstructionStream, newval::AnySSAValue, idx::Int)
271+
is.inst[idx] = newval
272+
return is
273+
end
256274
function setindex!(node::Instruction, newval::Instruction)
257275
node.data[node.idx] = newval
258276
return node
@@ -312,7 +330,7 @@ function getindex(x::IRCode, s::SSAValue)
312330
end
313331
end
314332

315-
function setindex!(x::IRCode, repl::Instruction, s::SSAValue)
333+
function setindex!(x::IRCode, repl::Union{Instruction, AnySSAValue}, s::SSAValue)
316334
if s.id <= length(x.stmts)
317335
x.stmts[s.id] = repl
318336
else
@@ -321,19 +339,6 @@ function setindex!(x::IRCode, repl::Instruction, s::SSAValue)
321339
return x
322340
end
323341

324-
# SSA values that need renaming
325-
struct OldSSAValue
326-
id::Int
327-
end
328-
329-
# SSA values that are in `new_new_nodes` of an `IncrementalCompact` and are to
330-
# be actually inserted next time (they become `new_nodes` next time)
331-
struct NewSSAValue
332-
id::Int
333-
end
334-
335-
const AnySSAValue = Union{SSAValue, OldSSAValue, NewSSAValue}
336-
337342
mutable struct UseRefIterator
338343
stmt::Any
339344
relevant::Bool

0 commit comments

Comments
 (0)