Skip to content

Keep relocation site names unique for values sharing an objectid - #1117

Merged
maleadt merged 2 commits into
mainfrom
tb/unique-relocation-names
Nov 20, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/unique-relocation-names

Conversation

@maleadt

@maleadt maleadt commented Nov 19, 2026

Copy link
Copy Markdown
Member

Relocation slots and relocatable boxes are named <namespace>_<gv base>_<objectid>, and an equal name was taken to mean an equal value. Distinct values can share an objectid, though: a type only contributes its 32-bit hash, and that hash treats a free type variable as its upper bound, so W{Vector} and W{Vector{Any}} hash the same. Singletons, immutables and types built from such a pair collide, and a function referencing both fails to compile:

struct W{T} end
function f(r::Base.RefValue{Any})
    r[] = W{Vector}()
    r[] = W{Vector{Any}}()
    return
end
# ERROR: Relocation '_Z1f8RefValueI3AnyE_jl_global_ffffffff4624b7dc+0' refers to conflicting values

On device jobs the same happens for boxed isbits constants such as B{Vector}(1) and B{Vector{Any}}(1), which fail with "Interior relocation global ... is already in use". Reactant runs into this when two calls in one function are inferred as returning Vector and Vector{Any}.

The first commit makes names unique within a module by construction: the collector tracks which value each name was handed out for, and a value whose name is taken by another one gets an ordinal suffix. Globals are visited in module order instead of the order of the gv_to_value dictionary, so the suffixes are the same in every session. A box is now reused when its value is referenced through several globals, as slots already were.

I considered mixing a structural type hash into the names instead, which keeps a name a pure function of its value. It needs a reimplementation of Julia's type hashing, and still fails for immutables that hold a colliding type in a field.

The second commit corrects the documented contract for loaders. The docs promised that a name refers to the same value in every object, so that objects sharing a symbol namespace could let their weak record definitions coalesce. Names cannot guarantee that (jobs can share a namespace, and names come from hashes), and ORC coalesces weak definitions without comparing them: two objects that disagree on a name silently read each other's word. A loader that shares a namespace now has to merge the manifests it loads there with add_relocation!, which throws when slots disagree. Records stay weak_odr, because Julia's JIT before 1.14 only offers a single JITDylib; once no loader needs that they can become strong definitions, which turns a clash into a link error.

Tested on Julia 1.11, 1.12 and nightly. The new collector test fails on main with the error above.

Fixes #1116

Relocation slots and relocatable boxes are named after the `objectid`
of the value they refer to, and an equal name was taken to mean an equal
value. Distinct values can share an `objectid`, though: a type only
contributes its 32-bit hash, which does not tell `W{Vector}` from
`W{Vector{Any}}`, so singletons, immutables and types built from such a
pair collide. A function referencing both failed to compile with
"refers to conflicting values", or "is already in use" for boxes.

Track which value each name was handed out for, and give a value whose
name is taken by another one an ordinal suffix. Globals are now visited
in module order rather than that of the `gv_to_value` dictionary, so
that the suffixes are the same in every session. A box is reused when
its value is referenced through several globals, as slots already were.

Fixes #1116.
The documentation promised that a relocation name always refers to the
same value, so that a loader could put any number of objects in one
symbol namespace and let their weak record definitions coalesce. Names
cannot guarantee that across objects: jobs can share a namespace, and
the names are derived from hashes. Two objects that disagree on a name
then silently read each other's word.

Describe what does hold: names are unique within an object, and a
loader sharing a namespace has to merge the manifests it loads there
with `add_relocation!`, which throws when slots disagree. Relocatable
boxes cannot be checked that way, so objects containing them must not
share a namespace. Records stay weak for the loaders that need it;
only Julia's JIT before 1.14 forces objects into one `JITDylib`.
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.05%. Comparing base (e09998c) to head (5251a7a).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1117   +/-   ##
=======================================
  Coverage   93.04%   93.05%           
=======================================
  Files          32       32           
  Lines        8213     8222    +9     
=======================================
+ Hits         7642     7651    +9     
  Misses        571      571           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit ead724c into main Nov 20, 2026
37 checks passed
@maleadt
maleadt deleted the tb/unique-relocation-names branch November 20, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relocation slot names collide for distinct singletons with equal objectid ("refers to conflicting values")

1 participant