// Messages must be sendable to another actor (ADR 0004, Revision 6): no // `Ref`, and resources only of `@thread_safe` kinds. `process.send` // requires `Send`, so generic code says `where Send`. import std/ffi.{type Resource} import std/process.{type Subject, type proc} import std/ref.{type Ref} type Counter { Counter(count: Ref) } type Handle { Handle } // A resource that is not `@thread_safe` is pinned to its actor, inside a // user type too. type Pinned { Pinned(Resource) } @thread_safe type SharedHandle { SharedHandle } fn send_a_ref :: -> () / { region { let mine = process.subject () process.send mine (ref.new 1) //~ ERROR E0704 `Ref< } } fn send_a_holder :: -> () / { region { let mine = process.subject () process.send mine Counter(ref.new 0) //~ ERROR E0704 `Counter< } } fn send_an_optional_ref :: -> () / { region { let mine = process.subject () process.send mine Some(ref.new 0) //~ ERROR E0704 `Option> h: Resource -> () / { process.send to h //~ ERROR E0704 `Resource` } fn send_a_pinned_holder :: to: Subject h: Resource -> () / { process.send to Pinned(h) //~ ERROR E0704 `Pinned` cannot be sent } // Sendable: values, thread-safe resources, functions, bounded generics. fn fine :: numbers: Subject> shared: Subject> h: Resource callbacks: Subject Int> -> () / { process.send numbers [1, 2] process.send shared h process.send callbacks fn { 1 } } fn relay :: to: Subject message: a -> () / where Send { process.send to message } fn unbounded_relay :: to: Subject message: a -> () / { process.send to message //~ ERROR E0402 `a` is not known to implement `Send` } // An inferred function requires what it sends, and its callers are checked. fn inferred_relay :: to message { process.send to message } fn relay_a_ref :: -> () / { region { inferred_relay (process.subject ()) (ref.new 1) //~ ERROR E0704 `Ref< } }