Skip to content

Commit 3e88da9

Browse files
authored
Merge branch 'master' into Base_strings_StringIndexError_nospecialize
2 parents dc76a47 + 0dd78f7 commit 3e88da9

32 files changed

+647
-241
lines changed

CONTRIBUTING.md

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,40 @@ Hi! If you are new to the Julia community: welcome, and thanks for trying Julia.
44

55
If you are already familiar with Julia itself, this blog post by Katharine Hyatt on [Making your first Julia pull request](https://kshyatt.github.io/post/firstjuliapr/) is a great way to get started.
66

7-
## Learning Julia
8-
9-
[The learning page](https://julialang.org/learning) has a great list of resources for new and experienced users alike.
10-
11-
## Before filing an issue
12-
13-
- Reporting a potential bug? Please read the "[How to file a bug report](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#how-to-file-a-bug-report)" section to make sure that all necessary information is included.
147

15-
- Contributing code? Be sure to review the [contributor checklist](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#contributor-checklist) for helpful tips on the tools we use to build Julia.
8+
# Table of Contents
169

17-
- Library feature requests are generally not accepted on this issue tracker. New libraries should be developed as [packages](https://julialang.github.io/Pkg.jl/v1/creating-packages/). Discuss ideas for libraries at the [Julia Discourse forum](https://discourse.julialang.org). Doing so will often lead to pointers to existing projects and bring together collaborators with common interests.
10+
1. [Learning Julia](#learning-julia)
11+
2. [Filing an issue](#filing-an-issue)
12+
- [Before filing an issue](#before-filing-an-issue)
13+
- [How to file a bug report](#how-to-file-a-bug-report)
14+
3. [Submitting contributions](#submitting-contributions)
15+
- [Contributor Checklist](#contributor-checklist)
16+
- [Writing tests](#writing-tests)
17+
- [Improving documentation](#improving-documentation)
18+
- [Contributing to core functionality or base libraries](#contributing-to-core-functionality-or-base-libraries)
19+
- [Contributing to the standard library](#contributing-to-the-standard-library)
20+
- [Contributing to patch releases](#contributing-to-patch-releases)
21+
- [Code Formatting Guidelines](#code-formatting-guidelines)
22+
- [Git Recommendations For Pull Requests](#git-recommendations-for-pull-requests)
23+
4. [Resources](#resources)
1824

19-
## Contributor Checklist
20-
21-
* Create a [GitHub account](https://github.com/signup/free).
2225

23-
* [Fork Julia](https://github.com/JuliaLang/julia/fork).
26+
## Learning Julia
2427

25-
* Build the software and libraries (the first time takes a while, but it's fast after that). Detailed build instructions are in the [README](https://github.com/JuliaLang/julia/tree/master/README.md). Julia depends on several external packages; most are automatically downloaded and installed, but are less frequently updated than Julia itself.
28+
[The learning page](https://julialang.org/learning) has a great list of resources for new and experienced users alike.
2629

27-
* Keep Julia current. Julia is a fast-moving target, and many details of the language are still settling out. Keep the repository up-to-date and rebase work-in-progress frequently to make merges simpler.
30+
## Filing an issue
2831

29-
* Learn to use [git](https://git-scm.com), the version control system used by GitHub and the Julia project. Try a tutorial such as the one [provided by GitHub](https://try.GitHub.io/levels/1/challenges/1).
32+
### Before filing an issue
3033

31-
* Review discussions on the [Julia Discourse forum](https://discourse.julialang.org).
34+
- Reporting a potential bug? Please read the "[How to file a bug report](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#how-to-file-a-bug-report)" section to make sure that all necessary information is included.
3235

33-
* For more detailed tips, read the [submission guide](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#submitting-contributions) below.
36+
- Contributing code? Be sure to review the [contributor checklist](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#contributor-checklist) for helpful tips on the tools we use to build Julia.
3437

35-
* Relax and have fun!
38+
- Library feature requests are generally not accepted on this issue tracker. New libraries should be developed as [packages](https://julialang.github.io/Pkg.jl/v1/creating-packages/). Discuss ideas for libraries at the [Julia Discourse forum](https://discourse.julialang.org). Doing so will often lead to pointers to existing projects and bring together collaborators with common interests.
3639

37-
## How to file a bug report
40+
### How to file a bug report
3841

3942
A useful bug report filed as a GitHub issue provides information about how to reproduce the error.
4043

@@ -56,6 +59,24 @@ A useful bug report filed as a GitHub issue provides information about how to re
5659

5760
## Submitting contributions
5861

62+
### Contributor Checklist
63+
64+
* Create a [GitHub account](https://github.com/signup/free).
65+
66+
* [Fork Julia](https://github.com/JuliaLang/julia/fork).
67+
68+
* Build the software and libraries (the first time takes a while, but it's fast after that). Detailed build instructions are in the [README](https://github.com/JuliaLang/julia/tree/master/README.md). Julia depends on several external packages; most are automatically downloaded and installed, but are less frequently updated than Julia itself.
69+
70+
* Keep Julia current. Julia is a fast-moving target, and many details of the language are still settling out. Keep the repository up-to-date and rebase work-in-progress frequently to make merges simpler.
71+
72+
* Learn to use [git](https://git-scm.com), the version control system used by GitHub and the Julia project. Try a tutorial such as the one [provided by GitHub](https://try.GitHub.io/levels/1/challenges/1).
73+
74+
* Review discussions on the [Julia Discourse forum](https://discourse.julialang.org).
75+
76+
* For more detailed tips, read the [submission guide](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#submitting-contributions) below.
77+
78+
* Relax and have fun!
79+
5980
### Writing tests
6081

6182
There are never enough tests. Track [code coverage at Codecov](https://codecov.io/github/JuliaLang/julia), and help improve it.

Compiler/extras/CompilerDevTools/src/CompilerDevTools.jl

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

4848
function Compiler.optimize(interp::SplitCacheInterp, opt::Compiler.OptimizationState, caller::Compiler.InferenceResult)
4949
@invoke Compiler.optimize(interp::Compiler.AbstractInterpreter, opt::Compiler.OptimizationState, caller::Compiler.InferenceResult)
50-
ir = opt.ir::Compiler.IRCode
50+
ir = opt.result.ir::Compiler.IRCode
5151
override = GlobalRef(@__MODULE__(), :with_new_compiler)
5252
for inst in ir.stmts
5353
stmt = inst[:stmt]

Compiler/src/abstractinterpretation.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,18 +3633,20 @@ scan_partitions(query::Function, interp, g::GlobalRef, wwr::WorldWithRange) =
36333633
abstract_load_all_consistent_leaf_partitions(interp, g::GlobalRef, wwr::WorldWithRange) =
36343634
scan_leaf_partitions(abstract_eval_partition_load, interp, g, wwr)
36353635

3636+
function abstract_eval_globalref_partition(interp, binding::Core.Binding, partition::Core.BindingPartition)
3637+
# For inference purposes, we don't particularly care which global binding we end up loading, we only
3638+
# care about its type. However, we would still like to terminate the world range for the particular
3639+
# binding we end up reaching such that codegen can emit a simpler pointer load.
3640+
Pair{RTEffects, Union{Nothing, Core.Binding}}(
3641+
abstract_eval_partition_load(interp, partition),
3642+
binding_kind(partition) in (PARTITION_KIND_GLOBAL, PARTITION_KIND_DECLARED) ? binding : nothing)
3643+
end
3644+
36363645
function abstract_eval_globalref(interp, g::GlobalRef, saw_latestworld::Bool, sv::AbsIntState)
36373646
if saw_latestworld
36383647
return RTEffects(Any, Any, generic_getglobal_effects)
36393648
end
3640-
(valid_worlds, (ret, binding_if_global)) = scan_leaf_partitions(interp, g, sv.world) do interp, binding, partition
3641-
# For inference purposes, we don't particularly care which global binding we end up loading, we only
3642-
# care about its type. However, we would still like to terminate the world range for the particular
3643-
# binding we end up reaching such that codegen can emit a simpler pointer load.
3644-
Pair{RTEffects, Union{Nothing, Core.Binding}}(
3645-
abstract_eval_partition_load(interp, partition),
3646-
binding_kind(partition) in (PARTITION_KIND_GLOBAL, PARTITION_KIND_DECLARED) ? binding : nothing)
3647-
end
3649+
(valid_worlds, (ret, binding_if_global)) = scan_leaf_partitions(abstract_eval_globalref_partition, interp, g, sv.world)
36483650
update_valid_age!(sv, valid_worlds)
36493651
if ret.rt !== Union{} && ret.exct === UndefVarError && binding_if_global !== nothing && InferenceParams(interp).assume_bindings_static
36503652
if isdefined(binding_if_global, :value)

Compiler/src/optimize.jl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ is_declared_noinline(@nospecialize src::MaybeCompressed) =
129129
# return whether this src should be inlined. If so, retrieve_ir_for_inlining must return an IRCode from it
130130
function src_inlining_policy(interp::AbstractInterpreter,
131131
@nospecialize(src), @nospecialize(info::CallInfo), stmt_flag::UInt32)
132+
isa(src, OptimizationState) && (src = src.src)
132133
if isa(src, MaybeCompressed)
133134
src_inlineable = is_stmt_inline(stmt_flag) || is_inlineable(src)
134135
return src_inlineable
@@ -154,10 +155,20 @@ end
154155
# get `code_cache(::AbstractInterpreter)` from `state::InliningState`
155156
code_cache(state::InliningState) = WorldView(code_cache(state.interp), state.world)
156157

158+
mutable struct OptimizationResult
159+
ir::IRCode
160+
simplified::Bool # indicates whether the IR was processed with `cfg_simplify!`
161+
end
162+
163+
function simplify_ir!(result::OptimizationResult)
164+
result.ir = cfg_simplify!(result.ir)
165+
result.simplified = true
166+
end
167+
157168
mutable struct OptimizationState{Interp<:AbstractInterpreter}
158169
linfo::MethodInstance
159170
src::CodeInfo
160-
ir::Union{Nothing, IRCode}
171+
result::Union{Nothing, OptimizationResult}
161172
stmt_info::Vector{CallInfo}
162173
mod::Module
163174
sptypes::Vector{VarState}
@@ -226,10 +237,13 @@ include("ssair/passes.jl")
226237
include("ssair/irinterp.jl")
227238

228239
function ir_to_codeinf!(opt::OptimizationState)
229-
(; linfo, src) = opt
230-
src = ir_to_codeinf!(src, opt.ir::IRCode)
231-
src.edges = Core.svec(opt.inlining.edges...)
232-
opt.ir = nothing
240+
(; linfo, src, result) = opt
241+
if result === nothing
242+
return src
243+
end
244+
src = ir_to_codeinf!(src, result.ir)
245+
opt.result = nothing
246+
opt.src = src
233247
maybe_validate_code(linfo, src, "optimized")
234248
return src
235249
end
@@ -489,7 +503,7 @@ function finish(interp::AbstractInterpreter, opt::OptimizationState,
489503
@assert !(result isa LimitedAccuracy)
490504
result = widenslotwrapper(result)
491505

492-
opt.ir = ir
506+
opt.result = OptimizationResult(ir, false)
493507

494508
# determine and cache inlineability
495509
if !force_noinline

Compiler/src/ssair/inlining.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,14 @@ function retrieve_ir_for_inlining(mi::MethodInstance, ir::IRCode, preserve_local
975975
ir.debuginfo.def = mi
976976
return ir, spec_info, DebugInfo(ir.debuginfo, length(ir.stmts))
977977
end
978+
function retrieve_ir_for_inlining(mi::MethodInstance, opt::OptimizationState, preserve_local_sources::Bool)
979+
result = opt.result
980+
if result !== nothing
981+
!result.simplified && simplify_ir!(result)
982+
return retrieve_ir_for_inlining(mi, result.ir, preserve_local_sources)
983+
end
984+
retrieve_ir_for_inlining(mi, opt.src, preserve_local_sources)
985+
end
978986

979987
function handle_single_case!(todo::Vector{Pair{Int,Any}},
980988
ir::IRCode, idx::Int, stmt::Expr, @nospecialize(case),

Compiler/src/ssair/ir.jl

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,39 +1265,48 @@ function process_phinode_values(old_values::Vector{Any}, late_fixup::Vector{Int}
12651265
values = Vector{Any}(undef, length(old_values))
12661266
for i = 1:length(old_values)
12671267
isassigned(old_values, i) || continue
1268-
val = old_values[i]
1269-
if isa(val, SSAValue)
1270-
if do_rename_ssa
1271-
if !already_inserted(i, OldSSAValue(val.id))
1272-
push!(late_fixup, result_idx)
1273-
val = OldSSAValue(val.id)
1274-
else
1275-
val = renumber_ssa2(val, ssa_rename, used_ssas, new_new_used_ssas, do_rename_ssa, mark_refined!)
1276-
end
1277-
else
1278-
used_ssas[val.id] += 1
1279-
end
1280-
elseif isa(val, OldSSAValue)
1281-
if !already_inserted(i, val)
1268+
values[i] = process_phinode_value(old_values, i, late_fixup, already_inserted, result_idx, ssa_rename, used_ssas, new_new_used_ssas, do_rename_ssa, mark_refined!)
1269+
end
1270+
return values
1271+
end
1272+
1273+
function process_phinode_value(old_values::Vector{Any}, i::Int, late_fixup::Vector{Int},
1274+
already_inserted, result_idx::Int,
1275+
ssa_rename::Vector{Any}, used_ssas::Vector{Int},
1276+
new_new_used_ssas::Vector{Int},
1277+
do_rename_ssa::Bool,
1278+
mark_refined!::Union{Refiner, Nothing})
1279+
val = old_values[i]
1280+
if isa(val, SSAValue)
1281+
if do_rename_ssa
1282+
if !already_inserted(i, OldSSAValue(val.id))
12821283
push!(late_fixup, result_idx)
1284+
val = OldSSAValue(val.id)
12831285
else
1284-
# Always renumber these. do_rename_ssa applies only to actual SSAValues
1285-
val = renumber_ssa2(SSAValue(val.id), ssa_rename, used_ssas, new_new_used_ssas, true, mark_refined!)
1286-
end
1287-
elseif isa(val, NewSSAValue)
1288-
if val.id < 0
1289-
new_new_used_ssas[-val.id] += 1
1290-
else
1291-
@assert do_rename_ssa
1292-
val = SSAValue(val.id)
1286+
val = renumber_ssa2(val, ssa_rename, used_ssas, new_new_used_ssas, do_rename_ssa, mark_refined!)
12931287
end
1288+
else
1289+
used_ssas[val.id] += 1
12941290
end
1295-
if isa(val, NewSSAValue)
1291+
elseif isa(val, OldSSAValue)
1292+
if !already_inserted(i, val)
12961293
push!(late_fixup, result_idx)
1294+
else
1295+
# Always renumber these. do_rename_ssa applies only to actual SSAValues
1296+
val = renumber_ssa2(SSAValue(val.id), ssa_rename, used_ssas, new_new_used_ssas, true, mark_refined!)
1297+
end
1298+
elseif isa(val, NewSSAValue)
1299+
if val.id < 0
1300+
new_new_used_ssas[-val.id] += 1
1301+
else
1302+
@assert do_rename_ssa
1303+
val = SSAValue(val.id)
12971304
end
1298-
values[i] = val
12991305
end
1300-
return values
1306+
if isa(val, NewSSAValue)
1307+
push!(late_fixup, result_idx)
1308+
end
1309+
return val
13011310
end
13021311

13031312
function renumber_ssa2(val::SSAValue, ssanums::Vector{Any}, used_ssas::Vector{Int},

Compiler/src/ssair/passes.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,51 +2574,50 @@ function cfg_simplify!(ir::IRCode)
25742574
values = phi.values
25752575
(; ssa_rename, late_fixup, used_ssas, new_new_used_ssas) = compact
25762576
ssa_rename[i] = SSAValue(compact.result_idx)
2577-
already_inserted = function (i::Int, val::OldSSAValue)
2577+
already_inserted = function (branch::Int, val::OldSSAValue)
25782578
if val.id in old_bb_stmts
25792579
return val.id <= i
25802580
end
2581-
return bb_rename_pred[phi.edges[i]] < idx
2581+
return 0 < bb_rename_pred[phi.edges[branch]] < idx
25822582
end
2583-
renamed_values = process_phinode_values(values, late_fixup, already_inserted, compact.result_idx, ssa_rename, used_ssas, new_new_used_ssas, true, nothing)
25842583
edges = Int32[]
25852584
values = Any[]
2586-
sizehint!(edges, length(phi.edges)); sizehint!(values, length(renamed_values))
2585+
sizehint!(edges, length(phi.edges)); sizehint!(values, length(phi.values))
25872586
for old_index in 1:length(phi.edges)
25882587
old_edge = phi.edges[old_index]
25892588
new_edge = bb_rename_pred[old_edge]
25902589
if new_edge > 0
25912590
push!(edges, new_edge)
2592-
if isassigned(renamed_values, old_index)
2593-
push!(values, renamed_values[old_index])
2591+
if isassigned(phi.values, old_index)
2592+
val = process_phinode_value(phi.values, old_index, late_fixup, already_inserted, compact.result_idx, ssa_rename, used_ssas, new_new_used_ssas, true, nothing)
2593+
push!(values, val)
25942594
else
25952595
resize!(values, length(values)+1)
25962596
end
25972597
elseif new_edge == -1
25982598
@assert length(phi.edges) == 1
2599-
if isassigned(renamed_values, old_index)
2599+
if isassigned(phi.values, old_index)
2600+
val = process_phinode_value(phi.values, old_index, late_fixup, already_inserted, compact.result_idx, ssa_rename, used_ssas, new_new_used_ssas, true, nothing)
26002601
push!(edges, -1)
2601-
push!(values, renamed_values[old_index])
2602+
push!(values, val)
26022603
end
26032604
elseif new_edge == -3
26042605
# Multiple predecessors, we need to expand out this phi
26052606
all_new_preds = Int32[]
26062607
add_preds!(all_new_preds, bbs, bb_rename_pred, old_edge)
26072608
append!(edges, all_new_preds)
2608-
if isassigned(renamed_values, old_index)
2609-
val = renamed_values[old_index]
2610-
for _ in 1:length(all_new_preds)
2611-
push!(values, val)
2609+
np = length(all_new_preds)
2610+
if np > 0
2611+
if isassigned(phi.values, old_index)
2612+
val = process_phinode_value(phi.values, old_index, late_fixup, already_inserted, compact.result_idx, ssa_rename, used_ssas, new_new_used_ssas, true, nothing)
2613+
for p in 1:np
2614+
push!(values, val)
2615+
p > 2 && count_added_node!(compact, val)
2616+
end
2617+
else
2618+
resize!(values, length(values)+np)
26122619
end
2613-
length(all_new_preds) == 0 && kill_current_use!(compact, val)
2614-
for _ in 2:length(all_new_preds)
2615-
count_added_node!(compact, val)
2616-
end
2617-
else
2618-
resize!(values, length(values)+length(all_new_preds))
26192620
end
2620-
else
2621-
isassigned(renamed_values, old_index) && kill_current_use!(compact, renamed_values[old_index])
26222621
end
26232622
end
26242623
if length(edges) == 0 || (length(edges) == 1 && !isassigned(values, 1))

0 commit comments

Comments
 (0)