Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8277cc5
RAI: Add 'RAI' as the build part of the semantic version
rbvermaa Nov 19, 2026
febeef8
Add GitHub template and workflows needed on the default branch (#135)
Drvi Mar 19, 2024
859da72
RAI: Track blocks and bytes allocated for GC pools
d-netto Jan 6, 2025
0f27c33
RAI: Change task ordering behavior to prioritize older tasks
kpamnany Aug 9, 2023
4a4d9e3
RAI: Disable huge pages for all mmap'ed memory
kpamnany Aug 21, 2023
b816b50
RAI: Never use MADV_FREE
kuszmaul Aug 22, 2023
320903e
RAI: Prepend "thread (%d) " to output from `jl_print_task_backtraces()`
kpamnany Oct 9, 2023
2a273fd
RAI: Add heartbeat capability
kpamnany Oct 7, 2023
a7bb404
RAI: --safe-crash-log-file flag
d-netto Mar 22, 2024
c6f1eac
RAI: Write heartbeat thread output to safe crash log
kpamnany May 27, 2024
55916bb
RAI: fix string interpolation on OPENBLAS_BUILD_OPTS
d-netto Jan 6, 2025
fd4209c
RAI: Prepend signal number and thread ID on backtraces
kpamnany Nov 10, 2026
5a29d8a
RAI: do not prepend thread ID to backtraces from signal handler context
kpamnany Nov 10, 2026
c72d42a
RAI: Don't dereference a NULL task in jl_inside_signal_handler
rbvermaa Nov 10, 2026
bb24355
RAI: Keep the signal prefix on backtraces when there is no current task
rbvermaa Nov 10, 2026
728522e
RAI: Wake thread 0 when the heartbeat thread leaves the running count
rbvermaa Nov 16, 2026
06bfda9
idset: find the insertion slot by galloping instead of a linear scan …
KristofferC Oct 8, 2026
c98ad78
gf: hash missing-method backedges by signature per typename
rbvermaa Nov 16, 2026
dab1a34
runtime: Probe hash tables to the first empty slot, and grow them by …
vtjnash Nov 15, 2026
703cc13
Revert "[1.13] Compiler: Store no backedges for limited results (#639…
rbvermaa Nov 20, 2026
3214009
Compiler: don't double-count deleted SROA intermediaries
rbvermaa Nov 10, 2026
ca87326
Compiler: don't expand long tuples in lift_apply_args!
rbvermaa Nov 11, 2026
f501898
Compiler: add callees to the JIT before their callers
rbvermaa Nov 13, 2026
83c72d3
jltypes: cap the probe limit of type caches at 64
rbvermaa Nov 16, 2026
02ae548
gf: index every specialization by the type cache hash of its signature
rbvermaa Nov 15, 2026
b37372a
gf: never move specializations entries, only append to their index
rbvermaa Nov 18, 2026
5c685d8
Add an image format version and bump it for the specializations layout
rbvermaa Nov 17, 2026
7353f05
reinfer: share method lookups between edges while the world is unchanged
rbvermaa Nov 15, 2026
1c37ab1
gc: add --heap-target-increment-per-thread
rbvermaa Nov 16, 2026
bcdc0e4
jitlayers: never destroy the maps of ThreadSafeModules
rbvermaa Nov 16, 2026
55e7875
init: skip C and C++ teardown after the atexit hook
rbvermaa Nov 16, 2026
666337d
RAI: Turn off libuv's io_uring on Linux unless UV_USE_IO_URING is set
rbvermaa Nov 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# See https://github.com/actions/labeler
port-to-master: '**'
port-to-v1.10: '**'
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!---
PRs to RelationalAI/julia must be opened to the correct branch (see
https://github.com/RelationalAI/raicode/blob/master/nix/julia-version.json).
-->
## PR Description

_What does this PR do?_

## Checklist

Requirements for merging:
- [ ] I have opened an issue or PR upstream on JuliaLang/julia: <link to JuliaLang/julia>
- [ ] I have removed the `port-to-*` labels that don't apply.
- [ ] I have opened a PR on raicode to test these changes: <link to raicode>
17 changes: 17 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://github.com/actions/labeler
name: "Pull Request Labeler"
on:
pull_request_target:
types:
- opened

jobs:
triage:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v4
with:
dot: true
16 changes: 16 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Close stale PRs"
on:
schedule:
- cron: "0 0 * * *" # every night at midnight

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v8
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Comment or remove stale label, or this PR will be closed in 5 days.'
days-before-stale: 30
days-before-close: 5
stale-pr-label: 'stale'
28 changes: 28 additions & 0 deletions .github/workflows/update-upstream-branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Update upstream branches"
on:
schedule:
- cron: "0 0 * * *" # every night at midnight
workflow_dispatch:

jobs:
PullUpstream:
runs-on: ubuntu-latest
strategy:
fail-fast: false # run all jobs in the matrix even if one fails
matrix:
branch:
- "master"
- "backports-release-1.10"
steps:
- name: Checkout RAI/julia
uses: actions/checkout@v3
with:
ref: ${{ matrix.branch }}
- name: Update ${{ matrix.branch }}
run: |
git config --global user.email "julia-engineering@relational.ai"
git config --global user.name "RAI CI (GitHub Action Automation)"

git remote add upstream https://github.com/JuliaLang/julia
git pull upstream ${{ matrix.branch }}
git push origin ${{ matrix.branch }}
47 changes: 46 additions & 1 deletion Compiler/src/reinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ struct VerifyMethodResultState
result_maxworld::UInt
end

# The result of `_methods_by_ftype(sig, nothing, lim, world, ...)` for one signature
struct VerifyCallLookup
lim::Int
world::UInt
result::Union{Nothing,Vector{Any}}
minworld::UInt
maxworld::UInt
end

# Container for all the work arrays
struct VerifyMethodWorkspace
# Arrays of different state categories
Expand All @@ -50,6 +59,28 @@ struct VerifyMethodWorkspace
end
end

# The lookups stay valid for as long as no method is added or deleted, that is, while the world
# counter does not change. Then they can be shared between the images loaded in that time.
# Checked on every use. A cache that was saved into a system image is dropped on its first use
# in a process. Image loading is serialized (the require lock), which this relies on.
const VERIFY_CALL_CACHE = IdDict{Any,VerifyCallLookup}()
const VERIFY_CALL_CACHE_WORLD = RefValue{UInt}(0)
function verify_call_cache()
world = get_world_counter()
first_use = ccall(:jl_reinfer_cache_first_use, Cint, ()) != 0
if first_use || VERIFY_CALL_CACHE_WORLD[] != world
empty!(VERIFY_CALL_CACHE)
VERIFY_CALL_CACHE_WORLD[] = world
end
return VERIFY_CALL_CACHE
end

# Frees the cache, for callers that know they are done loading images for now.
function empty_verify_call_cache!()
empty!(VERIFY_CALL_CACHE)
return nothing
end

# Helper functions to create default states
function VerifyMethodInitialState(codeinst::CodeInstance)
mi = get_ci_mi(codeinst)
Expand Down Expand Up @@ -573,7 +604,21 @@ function verify_call(@nospecialize(sig), expecteds::Core.SimpleVector, i::Int, n
minworld = RefValue{UInt}(1)
maxworld = RefValue{UInt}(typemax(UInt))
has_ambig = RefValue{Int32}(0)
result = _methods_by_ftype(sig, nothing, lim, world, #=ambig=#false, minworld, maxworld, has_ambig)
# Without invalidation logging the lookup result is only read below, so it can be shared
# between the edges with this signature.
use_cache = _jl_debug_method_invalidation[] === nothing
call_cache = verify_call_cache()
cached = use_cache ? get(call_cache, sig, nothing) : nothing
if cached !== nothing && cached.lim == lim && cached.world == world
result = cached.result
minworld[] = cached.minworld
maxworld[] = cached.maxworld
else
result = _methods_by_ftype(sig, nothing, lim, world, #=ambig=#false, minworld, maxworld, has_ambig)
if use_cache
call_cache[sig] = VerifyCallLookup(lim, world, result, minworld[], maxworld[])
end
end
if result === nothing
empty!(matches)
maxworld[] = 0
Expand Down
14 changes: 12 additions & 2 deletions Compiler/src/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,8 @@ function perform_lifting!(compact::IncrementalCompact,
return Pair{Any, PhiNest}(stmt_val, PhiNest(visited_philikes, lifted_philikes, lifted_leaves, reverse_mapping, walker_callback))
end

const MAX_LIFTED_APPLY_TUPLE_LENGTH = 32 # same as the default `max_tuple_splat`

# Handle _apply_iterate calls: convert arguments to use `Core.svec`.
# The behavior of `Core.svec` (with boxing) better matches the ABI of codegen.
function lift_apply_args!(compact::IncrementalCompact, idx::Int, stmt::Expr)
Expand All @@ -898,7 +900,10 @@ function lift_apply_args!(compact::IncrementalCompact, idx::Int, stmt::Expr)
if svec_args === nothing
# Fallback path: generate getfield calls for tuple elements
tuple_length = length(arg_type.parameters)
if tuple_length > 0 && !isvarargtype(arg_type.parameters[tuple_length])
# Longer tuples were deliberately not unrolled by the inliner (`max_tuple_splat`).
# Expanding them here costs one statement per element and call.
if 0 < tuple_length <= MAX_LIFTED_APPLY_TUPLE_LENGTH &&
!isvarargtype(arg_type.parameters[tuple_length])
svec_args = Vector{Any}(undef, tuple_length + 1)
for j in 1:tuple_length
getfield_call = Expr(:call, GlobalRef(Core, :getfield), arg, j)
Expand Down Expand Up @@ -1788,10 +1793,15 @@ function sroa_mutables!(ir::IRCode, defuses::IdDict{Int,Tuple{SPCSet,SSADefUse}}
# show up in the nuses_total count.
nleaves = length(defuse.uses) + length(defuse.defs)
nuses = 0
nintermediaries = 0
for iidx in intermediaries
# An intermediary that DCE already deleted no longer contributes its own use
# to `used_ssas[defidx]`, so it must not be subtracted again below.
ir[SSAValue(iidx)][:stmt] === nothing && continue
nuses += used_ssas[iidx]
nintermediaries += 1
end
nuses_total = used_ssas[defidx] + nuses - length(intermediaries)
nuses_total = used_ssas[defidx] + nuses - nintermediaries
all_eliminated = all_forwarded = true
if nleaves ≠ nuses_total
finalizer_useidx = find_finalizer_useidx(defuse)
Expand Down
85 changes: 12 additions & 73 deletions Compiler/src/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState, validation
ci = result.ci
mi = result.linfo
# if we aren't cached, we don't need this edge
# but our caller might, so let's just make it anyways.
# A tombstoned result is the exception: each new caller infers it again, so its
# backedges would pile up. Its callers depend on its edges directly instead.
if last(result.valid_worlds) >= validation_world && !result.tombstone
# but our caller might, so let's just make it anyways
if last(result.valid_worlds) >= validation_world
# if we can record all of the backedges in the global reverse-cache,
# we can now widen our applicability in the global cache too
store_backedges(ci, edges)
Expand Down Expand Up @@ -288,7 +286,6 @@ function finish_cycle(::AbstractInterpreter, frames::Vector{AbsIntState}, cyclei
caller.time_caches = 0.0
end
empty!(opt_cache)
share_tombstoned_cycle_edges!(frames, cycleid)
cycletop = frames[cycleid]::InferenceState
time_start = cycletop.time_start
validation_world = get_world_counter()
Expand Down Expand Up @@ -316,32 +313,6 @@ function finish_cycle(::AbstractInterpreter, frames::Vector{AbsIntState}, cyclei
return nothing
end

# Members of a cycle consume each other's results through `MethodInstance` edges. A
# tombstoned member has no backedges (see `finish!`), so it and every member that consumed
# it depend on the edges of the whole cycle directly. Other members reach those through
# the backedges of the members they consumed.
function share_tombstoned_cycle_edges!(frames::Vector{AbsIntState}, cycleid::Int)
sharers = IdSet{InferenceState}()
for frameid = cycleid:length(frames)
member = frames[frameid]::InferenceState
member.result.tombstone || continue
push!(sharers, member)
for (consumer, _) in member.cycle_backedges
push!(sharers, consumer)
end
end
isempty(sharers) && return nothing
cycle_edges = Any[]
for frameid = cycleid:length(frames)
append_edges!(cycle_edges, (frames[frameid]::InferenceState).edges)
end
for sharer in sharers
# `opt.inlining.edges` is this same vector, so this also reaches optimized members
append_edges!(sharer.edges, cycle_edges)
end
return nothing
end

function adjust_cycle_frame!(sv::InferenceState, cycle_valid_worlds::WorldRange, cycle_valid_effects::Effects)
update_valid_age!(sv, cycle_valid_worlds)
sv.ipo_effects = cycle_valid_effects
Expand Down Expand Up @@ -834,45 +805,6 @@ function compute_edges!(sv::InferenceState)
nothing
end

# Number of entries of the edge record starting at `edges[i]`, see `ForwardToBackedgeIterator`
function edge_record_length(edges, i::Int)
item = edges[i]
item isa Int && return 2 + abs(item) # nmatches, atype, matches...
item isa Union{MethodInstance,CodeInstance,Core.Binding,Method} && return 1
return 2 # invokesig or atype, followed by its target or `Core.methodtable`
end

# Append the edge records of `from` that `edges` does not have yet.
function append_edges!(edges::Vector{Any}, from)
singles = IdSet{Any}()
multis = Int[]
i = 1
while i <= length(edges)
n = edge_record_length(edges, i)
n == 1 ? push!(singles, edges[i]) : push!(multis, i)
i += n
end
i = 1
while i <= length(from)
n = edge_record_length(from, i)
if n == 1
if !(from[i] in singles)
push!(singles, from[i])
push!(edges, from[i])
end
elseif !any(multis) do j
edge_record_length(edges, j) == n && all(k -> edges[j+k] === from[i+k], 0:n-1)
end
push!(multis, length(edges) + 1)
for k = 0:n-1
push!(edges, from[i+k])
end
end
i += n
end
return edges
end

function record_slot_assign!(sv::InferenceState)
# look at all assignments to slots
# and union the set of types stored there
Expand Down Expand Up @@ -1182,8 +1114,6 @@ function typeinf_edge(interp::AbstractInterpreter, method::Method, @nospecialize
push!(caller.tasks, function get_infer_result(interp, caller)
update_valid_age!(caller, frame.world.valid_worlds)
local isinferred = is_inferred(frame)
# a tombstoned callee has no backedges, see `finish!`
isinferred && result.tombstone && append_edges!(caller.edges, frame.edges)
local edge = isinferred ? edge_ci : nothing
local effects = isinferred ? frame.result.ipo_effects : # effects are adjusted already within `finish` for ipo_effects
adjust_effects(effects_for_cycle(frame.ipo_effects), method)
Expand Down Expand Up @@ -1653,6 +1583,11 @@ function add_codeinsts_to_jit!(interp::AbstractInterpreter, ci, source_mode::UIn
codegen === nothing && return ci
workqueue = CompilationQueue(; interp)
push!(workqueue, ci)
# Resolve every source first (this may run inference) and only then hand the code to the
# JIT, callees before callers. Once a caller is in the JIT, another thread that needs it
# completes it at once, and every callee that is not in the JIT yet is then called
# through a stub that boxes its arguments, for good.
toadd = Any[]
while !isempty(workqueue)
# ci_has_real_invoke(ci) && return ci # optimization: cease looping if ci happens to get compiled (not just jl_fptr_wait_for_compiled, but fully jl_is_compiled_codeinst)
callee = pop!(workqueue)
Expand Down Expand Up @@ -1691,7 +1626,11 @@ function add_codeinsts_to_jit!(interp::AbstractInterpreter, ci, source_mode::UIn
callee = cached
end
end
ccall(:jl_add_codeinst_to_jit, Cvoid, (Any, Any), callee, src)
push!(toadd, callee)
push!(toadd, src)
end
for i in length(toadd):-2:2
ccall(:jl_add_codeinst_to_jit, Cvoid, (Any, Any), toadd[i-1], toadd[i])
end
return ci
end
Expand Down
58 changes: 0 additions & 58 deletions Compiler/test/invalidation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,61 +395,3 @@ let mi = Base.method_instance(co_caller, (COBox,))
@test ci.owner === InvalidationTesterToken()
@test ci.max_world == typemax(UInt)
end

# A result with limited accuracy is never cached, and every new caller infers it again.
# Its CodeInstance must not be registered as a backedge, or each caller adds another one,
# and invalidating `inner` walks all of them recursively (issue #63933). Here the inner
# `memo` call is widened against the outer one, which limits the cycle `p` <-> `q` and the
# self-recursive `r` in between.
module LimitedResultBackedges
struct Box{T}
x::T
end
struct Holder
b::Box
end
@noinline call(f) = f()
@noinline memo(f) = call(f)
inner(b::Box) = memo(() -> b.x)
p(x::Int, h::Holder) = x < 0 ? q(x, h) : 0
q(x::Int, h::Holder) = x < -1 ? p(x, h) : inner(h.b)
r(x::Int, h::Holder) = x < -1 ? r(x + 1, h) : x < 0 ? inner(h.b) : 0
const ncallers = 20
for k in 1:ncallers
@eval $(Symbol(:pcaller, k))(h::Holder) = memo(() -> p($k, h))
@eval $(Symbol(:rcaller, k))(h::Holder) = memo(() -> r($k, h))
end
end
let M = LimitedResultBackedges
for k in 1:M.ncallers, caller in (:pcaller, :rcaller)
Base.return_types(getglobal(M, Symbol(caller, k)), (M.Holder,); interp=InvalidationTester())
end
for callee in (M.p, M.q, M.r)
mi = Base.method_instance(callee, (Int, M.Holder))
@test !isdefined(mi, :cache)
cis = filter(isdefined(mi, :backedges) ? mi.backedges : Any[]) do edge
edge isa Core.CodeInstance && edge.owner === InvalidationTesterToken()
end
@test !isempty(cis)
# only cached callers may be registered
@test all(cis) do ci
mi = Base.get_ci_mi(ci)
isdefined(mi, :cache) || return false
cached = mi.cache
while cached !== ci
isdefined(cached, :next) || return false
cached = cached.next
end
return true
end
end
callers = [Base.method_instance(getglobal(M, Symbol(caller, k)), (M.Holder,)).cache
for k in 1:M.ncallers for caller in (:pcaller, :rcaller)]
@test all(ci -> ci.owner === InvalidationTesterToken() && ci.max_world == typemax(UInt), callers)
invlog = ccall(:jl_debug_method_invalidation, Any, (Cint,), 1)
@eval M inner(b::Box) = memo(() -> b.x + 1)
ccall(:jl_debug_method_invalidation, Any, (Cint,), 0)
@test all(ci -> ci.max_world < typemax(UInt), callers)
depths = Int[x for x in invlog if x isa Int32]
@test maximum(depths) < M.ncallers
end
Loading
Loading