Commit 02d79dc1

02d79dc13e12Merged

Ori Pekelman <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Ractor: reject @@cvar / $gvar access inside a Ractor (Ractor::IsolationError)

CRuby raises on cross-Ractor class-variable / global access; we now reject it at compile time instead of silently giving a child Ractor an empty (__thread) copy. emit_ractor_new recursively scans the body (including nested blocks) for ClassVariable* nodes (always rejected) and GlobalVariable* nodes that resolve to a user-declared global (rejected); thread-local / read-only specials ($~, $stdout, regex/status globals — not user-declared) are allowed. Non-Ractor cvar/gvar use is unchanged.

Full suite 931 pass / 0 fail / 0 error.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
02d79dc13e12
Parent
5c35304691ba

docs/RACTOR-RFC.mdmodifiedView file

@@ -131,11 +131,12 @@
131131 spawn arguments.
132132 2. **FIFO mailbox / outgoing queue** (mutex + condvar, grows on demand), so a
133133 Ractor may `receive` several messages and a sender need not block per slot.
134-3. **`@@cvars` / `$globals` are `__thread`** → isolated per Ractor, rather than
135- CRuby's "shared, raise on cross-Ractor mutation". Simpler and safe, but a
136- real semantic difference: a class-body cvar initializer has not run in a
137- child Ractor unless re-executed there. Programs that rely on cross-Ractor
138- cvar/gvar sharing are out of scope for this milestone.
134+3. **`@@cvars` / `$globals` accessed inside a Ractor are rejected at compile
135+ time** with `Ractor::IsolationError`, mirroring CRuby (which raises on
136+ cross-Ractor class-variable / global access). Special, thread-local or
137+ read-only globals (`$~`, `$stdout`, regex/status specials — not user-declared)
138+ are allowed. The globals themselves remain `__thread` in the runtime; the
139+ compile-time check just prevents the silent-empty-value footgun.
139140 4. **`Ractor#send` with a bare String/Symbol *literal*** is parsed as a
140141 reflective send (`recv.send("m")` → `recv.m`, a whole-program parser
141142 behaviour), so send messages via `r << v` or a local (`r.send(v)`); literals