Commit 6904042d
6904042dcd2cMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 21 files · ~13 modified · -8 deleted
Description
Revert "Merge pull request #1448 from OriPekelman/rfc-minimal-ractor"
This reverts commit 1d7ade7b635763eca21e74498863ec87038a5e05, reversing changes made to 789790697cbe1a529a06a36779b53b69bea7a92b.
Details
- Commit
- 6904042dcd2c
- Parent
- 4a7e0e39dcf2
docs/RACTOR-RFC.mdmodifiedView file
@@ -1,9 +1,7 @@
11
# RFC: A Minimal Ractor for Spinel22
3-
Status: **experimental / Milestone 6** (working; ported to the C compiler in4-
`src/`). Deep-copy message codec spans immediates / Symbol / String / Array /5-
Hash / user-objects; `Ractor.new` spawn arguments; compile-time `@@cvar`/`$gvar`6-
isolation; and a shared `Ractor::Port` channel. This document is both the design3+
Status: **experimental / Milestone 2** (working; ported to the C compiler in4+
`src/`). This document is both the design75
rationale and the record of what currently ships. It proposes whether to86
graduate to a full implementation (see *Path forward*).97
@@ -121,23 +119,20 @@
121119
122120
## Deliberate divergences (where "minimal" buys simplicity)123121
124-
1. **Value codec covers immediates, Symbol, String, Arrays, and Hashes** (poly125-
+ typed variants), deep-copied recursively through a heap-neutral malloc'd126-
blob (`sp_ractor_serialize`/`_deserialize`, installed via a hook because the127-
rebuild allocators are static to the generated TU). Plain objects, Procs,128-
Fibers, and IO raise `Ractor::Error` at the boundary — extending the codec to129-
user objects is the main follow-up. Symbols travel by name and are130-
re-interned in the receiver's per-Ractor table; hashes are normalised to a131-
poly hash on rebuild. The same codec seeds `Ractor.new(args) { |params| }`132-
spawn arguments.122+
1. **Value codec covers immediates, Symbol, String, and Arrays** (poly + typed123+
int/float/string), deep-copied through a heap-neutral malloc'd blob124+
(`sp_ractor_serialize`/`_deserialize`, installed via a hook because the125+
rebuild allocators are static to the generated TU). Hashes, plain objects,126+
Procs, Fibers, and IO raise `Ractor::Error` at the boundary — extending the127+
codec to those (and to nested objects) is the main follow-up. Symbols travel128+
by name and are re-interned in the receiver's per-Ractor table.133129
2. **FIFO mailbox / outgoing queue** (mutex + condvar, grows on demand), so a134130
Ractor may `receive` several messages and a sender need not block per slot.135-
3. **`@@cvars` / `$globals` accessed inside a Ractor are rejected at compile136-
time** with `Ractor::IsolationError`, mirroring CRuby (which raises on137-
cross-Ractor class-variable / global access). Special, thread-local or138-
read-only globals (`$~`, `$stdout`, regex/status specials — not user-declared)139-
are allowed. The globals themselves remain `__thread` in the runtime; the140-
compile-time check just prevents the silent-empty-value footgun.131+
3. **`@@cvars` / `$globals` are `__thread`** → isolated per Ractor, rather than132+
CRuby's "shared, raise on cross-Ractor mutation". Simpler and safe, but a133+
real semantic difference: a class-body cvar initializer has not run in a134+
child Ractor unless re-executed there. Programs that rely on cross-Ractor135+
cvar/gvar sharing are out of scope for this milestone.141136
4. **`Ractor#send` with a bare String/Symbol *literal*** is parsed as a142137
reflective send (`recv.send("m")` → `recv.m`, a whole-program parser143138
behaviour), so send messages via `r << v` or a local (`r.send(v)`); literals@@ -167,21 +162,9 @@
167162
168163
## Path forward (if this graduates)169164
170-
Done since the original RFC: the deep-copy codec now spans strings → symbols →171-
arrays → hashes → **user objects/structs** (M2/M3b/M4, recursively); the mailbox172-
is an unbounded FIFO; `Ractor.new(args){|p|}` spawn arguments are deep-copied in173-
(M3a); `@@cvar`/`$gvar` access inside a Ractor is rejected at compile time (M5);174-
and **`Ractor::Port`** provides a process-shared channel (`new`/`send`/`receive`/175-
`close`), passed across the boundary *by reference* so producers and consumers176-
on different Ractors rendezvous through it (M6). Remaining: shareable-by-value177-
frozen captures, object-graph cycles in the codec (acyclic assumed today), and178-
the Ruby-3.5 Ractor-as-Port API reshaping. None change the core partition.179-
180-
### API sharp edges (operator/method overload collisions)181-
182-
- **`Ractor#send` / `Ractor::Port#send` with a bare String/Symbol *literal*** is183-
parsed as a reflective send (`x.send("m")` → `x.m`, a whole-program parser184-
behaviour). Send via `x.send(var)` or an Integer literal; `x.send("lit")` is185-
reflective.186-
- **`port << v`** can be mis-inferred as an Array push (the `<<` push-promotion187-
heuristic types the receiver as an array). Use `port.send(v)` for ports.165+
In rough dependency order: extend `sp_deep_copy` to strings → arrays → hashes →166+
objects (symbols travel by name, re-interned on receive); make the mailbox167+
unbounded; thread-local-ize `@@cvars`/`$globals` with a class-body initializer168+
replay on the child; add spawn args and shareable-by-value capture; and a169+
`Ractor::Port`-style multi-consumer surface. None of these change the core170+
partition above — they extend it.lib/sp_gc.hmodifiedView file
Loading diff…
lib/sp_ractor.cmodifiedView file
Loading diff…
lib/sp_ractor.hmodifiedView file
Loading diff…
lib/sp_runtime.hmodifiedView file
Loading diff…
src/analyze_infer.cmodifiedView file
Loading diff…
src/analyze_pass.cmodifiedView file
Loading diff…
src/codegen.cmodifiedView file
Loading diff…
src/codegen_call.cmodifiedView file
Loading diff…
src/codegen_internal.hmodifiedView file
Loading diff…
src/codegen_util.cmodifiedView file
Loading diff…
src/types.cmodifiedView file
Loading diff…
src/types.hmodifiedView file
Loading diff…
test/ractor_hash.rbdeleted
Loading diff…
test/ractor_hash.rb.expecteddeleted
Loading diff…
test/ractor_object.rbdeleted
Loading diff…
test/ractor_object.rb.expecteddeleted
Loading diff…
test/ractor_port.rbdeleted
Loading diff…
test/ractor_port.rb.expecteddeleted
Loading diff…
test/ractor_spawn.rbdeleted
Loading diff…
test/ractor_spawn.rb.expecteddeleted
Loading diff…