louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#115 · main · 21 min 41 s
0Étoiles
0Forks
40Issues
| 1 | // Messages must be sendable to another actor (ADR 0004, Revision 6): no |
| 2 | // `Ref`, and resources only of `@thread_safe` kinds. `process.send` |
| 3 | // requires `Send`, so generic code says `where Send<a>`. |
| 4 | |
| 5 | import std/ffi.{type Resource} |
| 6 | import std/process.{type Subject, type proc} |
| 7 | import std/ref.{type Ref} |
| 8 | |
| 9 | type Counter<h> { Counter(count: Ref<h, Int>) } |
| 10 | |
| 11 | type Handle { Handle } |
| 12 | |
| 13 | // A resource that is not `@thread_safe` is pinned to its actor, inside a |
| 14 | // user type too. |
| 15 | type Pinned { Pinned(Resource<Handle>) } |
| 16 | |
| 17 | @thread_safe |
| 18 | type SharedHandle { SharedHandle } |
| 19 | |
| 20 | fn send_a_ref :: -> () / <proc> |
| 21 | { |
| 22 | region |
| 23 | { |
| 24 | let mine = process.subject () |
| 25 | process.send mine (ref.new 1) //~ ERROR E0704 `Ref< |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | fn send_a_holder :: -> () / <proc> |
| 30 | { |
| 31 | region |
| 32 | { |
| 33 | let mine = process.subject () |
| 34 | process.send mine Counter(ref.new 0) //~ ERROR E0704 `Counter< |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | fn send_an_optional_ref :: -> () / <proc> |
| 39 | { |
| 40 | region |
| 41 | { |
| 42 | let mine = process.subject () |
| 43 | process.send mine Some(ref.new 0) //~ ERROR E0704 `Option<Ref< |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | fn send_a_handle :: |
| 48 | to: Subject<Resource<Handle>> |
| 49 | h: Resource<Handle> |
| 50 | -> () / <proc> |
| 51 | { |
| 52 | process.send to h //~ ERROR E0704 `Resource<Handle>` |
| 53 | } |
| 54 | |
| 55 | fn send_a_pinned_holder :: |
| 56 | to: Subject<Pinned> |
| 57 | h: Resource<Handle> |
| 58 | -> () / <proc> |
| 59 | { |
| 60 | process.send to Pinned(h) //~ ERROR E0704 `Pinned` cannot be sent |
| 61 | } |
| 62 | |
| 63 | // Sendable: values, thread-safe resources, functions, bounded generics. |
| 64 | fn fine :: |
| 65 | numbers: Subject<List<Int>> |
| 66 | shared: Subject<Resource<SharedHandle>> |
| 67 | h: Resource<SharedHandle> |
| 68 | callbacks: Subject<send fn() -> Int> |
| 69 | -> () / <proc> |
| 70 | { |
| 71 | process.send numbers [1, 2] |
| 72 | process.send shared h |
| 73 | process.send callbacks fn { 1 } |
| 74 | } |
| 75 | |
| 76 | fn relay :: to: Subject<a> message: a -> () / <proc> where Send<a> |
| 77 | { |
| 78 | process.send to message |
| 79 | } |
| 80 | |
| 81 | fn unbounded_relay :: to: Subject<a> message: a -> () / <proc> |
| 82 | { |
| 83 | process.send to message //~ ERROR E0402 `a` is not known to implement `Send` |
| 84 | } |
| 85 | |
| 86 | // An inferred function requires what it sends, and its callers are checked. |
| 87 | fn inferred_relay :: to message |
| 88 | { |
| 89 | process.send to message |
| 90 | } |
| 91 | |
| 92 | fn relay_a_ref :: -> () / <proc> |
| 93 | { |
| 94 | region |
| 95 | { |
| 96 | inferred_relay (process.subject ()) (ref.new 1) //~ ERROR E0704 `Ref< |
| 97 | } |
| 98 | } |