Skip to content

Commit d830420

Browse files
authored
Merge branch 'master' into gb/sched-refact
2 parents ca21e01 + 34070fa commit d830420

File tree

636 files changed

+27034
-15322
lines changed

Some content is hidden

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

636 files changed

+27034
-15322
lines changed

.github/CODEOWNERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ CODEOWNERS @JuliaLang/github-actions
44

55
/.github/workflows/rerun_failed.yml @DilumAluthge
66
/.github/workflows/statuses.yml @DilumAluthge
7+
/base/special/ @oscardssmith
8+
/base/sort.jl @LilithHafner
9+
/test/sorting.jl @LilithHafner
10+
/stdlib/*_jll @giordano
11+
/base/binaryplatforms.jl @giordano
12+
/src/julia_gcext.h @fingolfin
13+
/test/gcext/gcext.c @fingolfin

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
/julia-*
1212
/source-dist.tmp
1313
/source-dist.tmp1
14+
/test/results_*.json
15+
/test/results_*.dat
1416

1517
*.expmap
1618
*.exe

CONTRIBUTING.md

Lines changed: 46 additions & 26 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.
107

11-
## Before filing an issue
8+
# Table of Contents
129

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.
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)
1424

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.
1625

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.
18-
19-
## Contributor Checklist
20-
21-
* Create a [GitHub account](https://github.com/signup/free).
22-
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.
@@ -190,7 +211,7 @@ The Julia community uses [GitHub issues](https://github.com/JuliaLang/julia/issu
190211
Issues and pull requests should have self explanatory titles such that they can be understood from the list of PRs and Issues.
191212
i.e. `Add {feature}` and `Fix {bug}` are good, `Fix #12345. Corrects the bug.` is bad.
192213
193-
You can make pull requests for incomplete features to get code review. The convention is to open these a draft PRs and prefix
214+
You can make pull requests for incomplete features to get code review. The convention is to open these as draft PRs and prefix
194215
the pull request title with "WIP:" for Work In Progress, or "RFC:" for Request for Comments when work is completed and ready
195216
for merging. This will prevent accidental merging of work that is in progress.
196217
@@ -209,6 +230,7 @@ Add new code to Julia's base libraries as follows (this is the "basic" approach;
209230
Build as usual, and do `make clean testall` to test your contribution. If your contribution includes changes to Makefiles or external dependencies, make sure you can build Julia from a clean tree using `git clean -fdx` or equivalent (be careful – this command will delete any files lying around that aren't checked into git).
210231
211232
#### Running specific tests
233+
212234
There are `make` targets for running specific tests:
213235
214236
make test-bitarray
@@ -323,13 +345,11 @@ please remove the `backport-X.Y` tag from the originating pull request for the c
323345

324346
#### General Formatting Guidelines for Julia code contributions
325347

326-
- 4 spaces per indentation level, no tabs
348+
- Follow the latest dev version of [Julia Style Guide](https://docs.julialang.org/en/v1/manual/style-guide/).
327349
- use whitespace to make the code more readable
328350
- no whitespace at the end of a line (trailing whitespace)
329351
- comments are good, especially when they explain the algorithm
330352
- try to adhere to a 92 character line length limit
331-
- use upper camel case convention for modules, type names
332-
- use lower case with underscores for method names
333353
- it is generally preferred to use ASCII operators and identifiers over
334354
Unicode equivalents whenever possible
335355
- in docstrings refer to the language as "Julia" and the executable as "`julia`"
@@ -346,8 +366,8 @@ please remove the `backport-X.Y` tag from the originating pull request for the c
346366

347367
### Git Recommendations For Pull Requests
348368

349-
- Avoid working from the `master` branch of your fork, creating a new branch will make it easier if Julia's `master` changes and you need to update your pull request.
350-
- Try to [squash](https://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) together small commits that make repeated changes to the same section of code so your pull request is easier to review. A reasonable number of separate well-factored commits is fine, especially for larger changes.
369+
- Avoid working from the `master` branch of your fork. Create a new branch as it will make it easier to update your pull request if Julia's `master` changes.
370+
- Try to [squash](https://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) together small commits that make repeated changes to the same section of code, so your pull request is easier to review. A reasonable number of separate well-factored commits is fine, especially for larger changes.
351371
- If any conflicts arise due to changes in Julia's `master`, prefer updating your pull request branch with `git rebase` versus `git merge` or `git pull`, since the latter will introduce merge commits that clutter the git history with noise that makes your changes more difficult to review.
352372
- Descriptive commit messages are good.
353373
- Using `git add -p` or `git add -i` can be useful to avoid accidentally committing unrelated changes.

Compiler/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Manifest.toml

Compiler/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Compiler"
22
uuid = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
3-
version = "0.0.3"
3+
version = "0.1.0"
44

55
[compat]
66
julia = "1.10"

Compiler/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# The `Compiler` module
2+
3+
This directory maintains the implementation of the Julia compiler.
4+
5+
Through a bootstrapping process, it is bundled into the Julia runtime as `Base.Compiler`.
6+
7+
You can also use this `Compiler` module as the `Compiler` standard library by following the steps below.
8+
9+
## How to use
10+
11+
To utilize this `Compiler.jl` standard library, you need to declare it as a dependency in
12+
your `Project.toml` as follows:
13+
> Project.toml
14+
```toml
15+
[deps]
16+
Compiler = "807dbc54-b67e-4c79-8afb-eafe4df6f2e1"
17+
18+
[compat]
19+
Compiler = "0.1"
20+
```
21+
22+
With the setup above, [the special placeholder version (v0.1.0)](https://github.com/JuliaLang/BaseCompiler.jl)
23+
will be installed by default.[^1]
24+
25+
[^1]: Currently, only version v0.1.0 is registered in the [General](https://github.com/JuliaRegistries/General) registry.
26+
27+
If needed, you can switch to a custom implementation of the `Compiler` module by running
28+
```julia-repl
29+
pkg> dev /path/to/Compiler.jl # to use a local implementation
30+
```
31+
or
32+
```julia-repl
33+
pkg> add https://url/of/Compiler/branch # to use a remote implementation
34+
```
35+
This feature is particularly useful for developing or experimenting with alternative compiler implementations.
36+
37+
> [!note]
38+
> The Compiler.jl standard library is available starting from Julia v1.10.
39+
> However, switching to a custom compiler implementation is supported only from
40+
> Julia v1.12 onwards.
41+
42+
> [!warning]
43+
> When using a custom, non-`Base` version of `Compiler` implementation, it may be necessary
44+
> to run `InteractiveUtils.@activate Compiler` to ensure proper functionality of certain
45+
> reflection utilities.

Compiler/extras/CompilerDevTools/src/CompilerDevTools.jl

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,77 @@
11
module CompilerDevTools
22

33
using Compiler
4+
using Compiler: argextype, widenconst
45
using Core.IR
6+
using Base: isexpr
7+
8+
mutable struct SplitCacheOwner end
59

6-
struct SplitCacheOwner; end
710
struct SplitCacheInterp <: Compiler.AbstractInterpreter
811
world::UInt
12+
owner::SplitCacheOwner
913
inf_params::Compiler.InferenceParams
1014
opt_params::Compiler.OptimizationParams
1115
inf_cache::Vector{Compiler.InferenceResult}
16+
codegen_cache::IdDict{CodeInstance,CodeInfo}
1217
function SplitCacheInterp(;
1318
world::UInt = Base.get_world_counter(),
19+
owner::SplitCacheOwner = SplitCacheOwner(),
1420
inf_params::Compiler.InferenceParams = Compiler.InferenceParams(),
1521
opt_params::Compiler.OptimizationParams = Compiler.OptimizationParams(),
1622
inf_cache::Vector{Compiler.InferenceResult} = Compiler.InferenceResult[])
17-
new(world, inf_params, opt_params, inf_cache)
23+
new(world, owner, inf_params, opt_params, inf_cache, IdDict{CodeInstance,CodeInfo}())
1824
end
1925
end
2026

2127
Compiler.InferenceParams(interp::SplitCacheInterp) = interp.inf_params
2228
Compiler.OptimizationParams(interp::SplitCacheInterp) = interp.opt_params
2329
Compiler.get_inference_world(interp::SplitCacheInterp) = interp.world
2430
Compiler.get_inference_cache(interp::SplitCacheInterp) = interp.inf_cache
25-
Compiler.cache_owner(::SplitCacheInterp) = SplitCacheOwner()
31+
Compiler.cache_owner(interp::SplitCacheInterp) = interp.owner
32+
Compiler.codegen_cache(interp::SplitCacheInterp) = interp.codegen_cache
2633

2734
import Core.OptimizedGenerics.CompilerPlugins: typeinf, typeinf_edge
28-
@eval @noinline typeinf(::SplitCacheOwner, mi::MethodInstance, source_mode::UInt8) =
29-
Base.invoke_in_world(which(typeinf, Tuple{SplitCacheOwner, MethodInstance, UInt8}).primary_world, Compiler.typeinf_ext, SplitCacheInterp(; world=Base.tls_world_age()), mi, source_mode)
35+
@eval @noinline typeinf(owner::SplitCacheOwner, mi::MethodInstance, source_mode::UInt8) =
36+
Base.invoke_in_world(which(typeinf, Tuple{SplitCacheOwner, MethodInstance, UInt8}).primary_world, Compiler.typeinf_ext_toplevel, SplitCacheInterp(; world=Base.tls_world_age(), owner), mi, source_mode)
3037

31-
@eval @noinline function typeinf_edge(::SplitCacheOwner, mi::MethodInstance, parent_frame::Compiler.InferenceState, world::UInt, source_mode::UInt8)
38+
@eval @noinline function typeinf_edge(owner::SplitCacheOwner, mi::MethodInstance, parent_frame::Compiler.InferenceState, world::UInt, source_mode::UInt8)
3239
# TODO: This isn't quite right, we're just sketching things for now
33-
interp = SplitCacheInterp(; world)
40+
interp = SplitCacheInterp(; world, owner)
3441
Compiler.typeinf_edge(interp, mi.def, mi.specTypes, Core.svec(), parent_frame, false, false)
3542
end
3643

37-
function with_new_compiler(f, args...)
38-
mi = @ccall jl_method_lookup(Any[f, args...]::Ptr{Any}, (1+length(args))::Csize_t, Base.tls_world_age()::Csize_t)::Ref{Core.MethodInstance}
39-
world = Base.tls_world_age()
44+
function lookup_method_instance(f, args...)
45+
@ccall jl_method_lookup(Any[f, args...]::Ptr{Any}, (1+length(args))::Csize_t, Base.tls_world_age()::Csize_t)::Ref{Core.MethodInstance}
46+
end
47+
48+
function Compiler.transform_result_for_cache(interp::SplitCacheInterp, result::Compiler.InferenceResult, edges::Compiler.SimpleVector)
49+
opt = result.src::Compiler.OptimizationState
50+
ir = opt.optresult.ir::Compiler.IRCode
51+
override = with_new_compiler
52+
for inst in ir.stmts
53+
stmt = inst[:stmt]
54+
isexpr(stmt, :call) || continue
55+
f = stmt.args[1]
56+
f === override && continue
57+
T = widenconst(argextype(f, ir))
58+
T <: Core.Builtin && continue
59+
insert!(stmt.args, 1, override)
60+
insert!(stmt.args, 3, interp.owner)
61+
end
62+
@invoke Compiler.transform_result_for_cache(interp::Compiler.AbstractInterpreter, result::Compiler.InferenceResult, edges::Compiler.SimpleVector)
63+
end
64+
65+
with_new_compiler(f, args...; owner::SplitCacheOwner = SplitCacheOwner()) = with_new_compiler(f, owner, args...)
66+
67+
function with_new_compiler(f, owner::SplitCacheOwner, args...)
68+
# We try to avoid introducing `with_new_compiler` in the first place,
69+
# but if we can't see the type, it's still possible to end up with a
70+
# builtin here - simply forward to the ordinary builtin call.
71+
isa(f, Core.Builtin) && return f(args...)
72+
mi = lookup_method_instance(f, args...)
4073
new_compiler_ci = Core.OptimizedGenerics.CompilerPlugins.typeinf(
41-
SplitCacheOwner(), mi, Compiler.SOURCE_MODE_ABI
74+
owner, mi, Compiler.SOURCE_MODE_ABI
4275
)
4376
invoke(f, new_compiler_ci, args...)
4477
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Test
2+
using Compiler: code_cache
3+
using Base: inferencebarrier
4+
using CompilerDevTools
5+
using CompilerDevTools: lookup_method_instance, SplitCacheInterp
6+
7+
@testset "CompilerDevTools" begin
8+
do_work(x, y) = x + y
9+
f1() = do_work(inferencebarrier(1), inferencebarrier(2))
10+
interp = SplitCacheInterp()
11+
cache = code_cache(interp)
12+
mi = lookup_method_instance(f1)
13+
@test !haskey(cache, mi)
14+
@test with_new_compiler(f1, interp.owner) === 3
15+
@test haskey(cache, mi)
16+
# Here `do_work` is compiled at runtime, and so must have
17+
# required extra work to be cached under the same cache owner.
18+
mi = lookup_method_instance(do_work, 1, 2)
19+
@test haskey(cache, mi)
20+
21+
# Should not error with a builtin whose type we do not know
22+
f_unknown_builtin() = Base.compilerbarrier(:type, isa)(1, Int)
23+
with_new_compiler(f_unknown_builtin, interp.owner) === true
24+
end;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using Pkg
2+
3+
Pkg.activate(dirname(@__DIR__)) do
4+
Pkg.instantiate()
5+
include("runtests.jl")
6+
end

0 commit comments

Comments
 (0)