Issue #3027: Remove the switch user-parallelism: representation per value, single-thread variant at start

Open and answer this issue on GitHub.

async, decision · opened 2026-12-01 · updated 2026-12-01 · 0 comments

Decided (owner, 2026-12-01)

Original question

Should the switch user-parallelism be removed, with each value’s representation chosen by the crossing analysis, and with a program run at user-pool = 1 running exactly the code no emits today?

The goal is the owner’s (2026-12-01): no switch, and no loss at one thread. The other aim is to carry no’s advantages over to the parallel build wherever the analysis proves that nothing crosses a thread. Neither a small measured loss nor a “close enough” loss justifies the change. This paper asks only whether this design is the direction to build in.

Where the question comes from

Today

Alternatives

0. Do nothing. The switch stays a project key.

A. A key for the root project only. Libraries are always built open, and the root decides.

B. One parallel build with cheaper primitives. Biased reference counting and biased locks: a non-atomic fast path for the owning thread, an atomic path otherwise.

C. Representation per value, plus a single-thread variant chosen at start (recommended).

  1. Per value. The crossing analysis (a_crossing_reaches, NK2501, and the sharing analysis’s union-find) already decides for each allocation class whether it can cross a thread. A class that cannot cross gets today’s no representation (plain count, RefCell, Local lock). A class that can cross keeps the atomic floor. This is ADR-037 D6’s rule (“it may only take an atomic away”) made per value instead of per build.
  2. Function variants. A function that receives values of both kinds is instantiated per kind, the way generics are, with a hidden “crosses” parameter. Libraries are source, so the whole program is visible. Mixed containers and trait objects are unified per allocation site by flow: one crossing element makes the class crossing.
  3. std specialised like user code. Today the switch reaches std only as a value its runtime is started with, and one compiled std serves both (30-nikaia-tooling.md). Under C, std’s types become generic over the mode marker. rustc then instantiates them in the program’s crate, so the compiled std in the cache is still one per machine. The rule “Nothing in std’s Nikaia half may lower differently per build option” becomes “differs only by the mode marker the analysis picks per value”. Shared and Locked can then be used in std’s Nikaia half.
  4. A single-thread variant chosen at start. The compiler also emits the whole program instantiated with crossing = false. If the runtime finds user-pool = 1 at start (nikaia-runtime.toml), it runs that variant, which is exactly the code no emits today, with the same order. This is what makes a run at one thread lossless by construction rather than by measurement.
    • In the lowered Rust this can be a mode marker type, SharedMut<T, M: Mode>, so that rustc’s monomorphisation does the duplication.
    • Cost: code size, at most 2× for the functions that touch a crossing class. Nothing is added at run time beyond one branch at start.
  5. The pool starts lazily, at the first spawn that needs it.

Measured

kind Ir per op vs. plain
Rc clone+drop ~8 —
Arc clone+drop ~8 (see caveat)
biased RC ~16 +8
RefCell borrow ~7 —
biased lock ~13 +6
Mutex lock+unlock ~25 +18

Other languages

To check before building

What changes if yes

Rough To build (one issue each, after the ADR)

  1. ADR and specification text.
  2. The emitter: a mode marker on SharedMut/Shared/Locked in the lowered Rust, chosen per allocation class from the sharing analysis.
  3. Function variants over the mode, and flow unification for mixed classes.
  4. std instantiated per mode, and the reworded rule.
  5. The runtime: choosing the variant at start, and the lazy pool.
  6. Removing the switch (CLI, manifest, env var, cache key), and the determinism probe.

Recommendation

C. It is the only alternative that removes the switch with no loss at one thread. It also carries no’s advantages into parallel runs for every value that does not cross.


Generated by Claude Code

Back to Open Issues