Commit e25d8e3e

e25d8e3e2050Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 21 files · +8 added · ~13 modified

Description

Merge pull request #1448 from OriPekelman/rfc-minimal-ractor

Ractor Milestones 3–6: spawn args, Hash/object messages, isolation, Ractor::Port

Details

Commit
e25d8e3e2050
Parent
6edcb4097963
Merge parent
82becc5d6d21

docs/RACTOR-RFC.mdmodifiedView file

@@ -1,7 +1,9 @@
11 # RFC: A Minimal Ractor for Spinel
22
3-Status: **experimental / Milestone 2** (working; ported to the C compiler in
4-`src/`). This document is both the design
3+Status: **experimental / Milestone 6** (working; ported to the C compiler in
4+`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 design
57 rationale and the record of what currently ships. It proposes whether to
68 graduate to a full implementation (see *Path forward*).
79
@@ -119,20 +121,23 @@
119121
120122 ## Deliberate divergences (where "minimal" buys simplicity)
121123
122-1. **Value codec covers immediates, Symbol, String, and Arrays** (poly + typed
123- int/float/string), deep-copied through a heap-neutral malloc'd blob
124- (`sp_ractor_serialize`/`_deserialize`, installed via a hook because the
125- rebuild allocators are static to the generated TU). Hashes, plain objects,
126- Procs, Fibers, and IO raise `Ractor::Error` at the boundary — extending the
127- codec to those (and to nested objects) is the main follow-up. Symbols travel
128- by name and are re-interned in the receiver's per-Ractor table.
124+1. **Value codec covers immediates, Symbol, String, Arrays, and Hashes** (poly
125+ + typed variants), deep-copied recursively through a heap-neutral malloc'd
126+ blob (`sp_ractor_serialize`/`_deserialize`, installed via a hook because the
127+ rebuild allocators are static to the generated TU). Plain objects, Procs,
128+ Fibers, and IO raise `Ractor::Error` at the boundary — extending the codec to
129+ user objects is the main follow-up. Symbols travel by name and are
130+ re-interned in the receiver's per-Ractor table; hashes are normalised to a
131+ poly hash on rebuild. The same codec seeds `Ractor.new(args) { |params| }`
132+ spawn arguments.
129133 2. **FIFO mailbox / outgoing queue** (mutex + condvar, grows on demand), so a
130134 Ractor may `receive` several messages and a sender need not block per slot.
131-3. **`@@cvars` / `$globals` are `__thread`** → isolated per Ractor, rather than
132- CRuby's "shared, raise on cross-Ractor mutation". Simpler and safe, but a
133- real semantic difference: a class-body cvar initializer has not run in a
134- child Ractor unless re-executed there. Programs that rely on cross-Ractor
135- cvar/gvar sharing are out of scope for this milestone.
135+3. **`@@cvars` / `$globals` accessed inside a Ractor are rejected at compile
136+ time** with `Ractor::IsolationError`, mirroring CRuby (which raises on
137+ cross-Ractor class-variable / global access). Special, thread-local or
138+ read-only globals (`$~`, `$stdout`, regex/status specials — not user-declared)
139+ are allowed. The globals themselves remain `__thread` in the runtime; the
140+ compile-time check just prevents the silent-empty-value footgun.
136141 4. **`Ractor#send` with a bare String/Symbol *literal*** is parsed as a
137142 reflective send (`recv.send("m")` → `recv.m`, a whole-program parser
138143 behaviour), so send messages via `r << v` or a local (`r.send(v)`); literals
@@ -162,9 +167,21 @@
162167
163168 ## Path forward (if this graduates)
164169
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 mailbox
167-unbounded; thread-local-ize `@@cvars`/`$globals` with a class-body initializer
168-replay on the child; add spawn args and shareable-by-value capture; and a
169-`Ractor::Port`-style multi-consumer surface. None of these change the core
170-partition above — they extend it.
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 mailbox
172+is an unbounded FIFO; `Ractor.new(args){|p|}` spawn arguments are deep-copied in
173+(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 consumers
176+on different Ractors rendezvous through it (M6). Remaining: shareable-by-value
177+frozen captures, object-graph cycles in the codec (acyclic assumed today), and
178+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*** is
183+ parsed as a reflective send (`x.send("m")` → `x.m`, a whole-program parser
184+ behaviour). Send via `x.send(var)` or an Integer literal; `x.send("lit")` is
185+ reflective.
186+- **`port << v`** can be mis-inferred as an Array push (the `<<` push-promotion
187+ heuristic types the receiver as an array). Use `port.send(v)` for ports.