// `@remote` functions (ADR 0072): entry points another node spawns, by // key, with one argument that crosses hosts. The name used as a value is // a `Remote`; called, it is a function. import std/dist/remote.{type Remote} import std/ffi.{type Resource} import std/io import std/list import std/process.{type Dynamic, type Pid, type Subject, type proc} import std/time.{type clock} import std/wire.{type Arg} pub type Job { Job(id: Int, words: List, reply: Subject) } @thread_safe type Handle { Handle } // Accepted: a record, a list, a subject, nothing. @remote fn worker :: job: Job -> () / { process.send job.reply (show job.id) } @remote fn sum :: numbers: List -> () / { io.println (show numbers) } @remote fn notify :: to: Subject -> () / { process.send to (process.self ()) let _ = time.now () } @remote fn ping :: -> () { () } // A reference is a `Remote`, whatever reads it. fn reference :: -> Remote { worker } //~ TYPE reference: fn() -> Remote fn inferred :: { (sum, notify, ping) } //~ TYPE inferred: fn() -> (Remote>, Remote>, Remote<()>) // Called, it is a function like any other. fn called :: reply: Subject -> () / { worker Job(1, [], reply) } // A reference is not a closure: wrap it in a lambda to pass one. fn as_closure :: jobs: List -> () / { list.each jobs worker //~^ ERROR E0202 `worker` is `@remote`: its name, not called, is a reference list.each jobs fn job { worker job } } // The dispatcher's argument pairs a value with its own type's // descriptor: a program cannot pair it with another. fn forged :: d: Dynamic -> Arg { wire.Arg("u", d) //~^ ERROR E0117 `Arg` is opaque outside `std/wire` } fn not_wire :: f: fn() -> () -> Arg { wire.arg f //~^ ERROR E0706 cannot cross hosts } // Refused: generic, ... @remote fn generic :: x: a -> () //~^ ERROR E0707 `@remote` function `generic` cannot be generic { () } @remote fn polymorphic :: x: Int -> () / //~^ ERROR E0707 cannot be generic { () } // ... not one argument, a result, ... @remote fn two :: a: Int b: Int -> () //~^ ERROR E0707 `@remote` function `two` takes 2 arguments { () } @remote fn answers :: x: Int -> Int //~^ ERROR E0707 returns `Int`; it returns `()` { x } // ... an effect nothing handles around an actor, ... effect ask { fn ask :: -> Int } @remote fn asks :: x: Int -> () / //~^ ERROR E0707 performs `ask`, which nothing handles { let _ = ask () () } // ... an argument that cannot cross hosts. @remote fn callback :: f: fn() -> () -> () //~^ ERROR E0706 a function's code { () } @remote fn resource :: r: Resource -> () //~^ ERROR E0706 a `Resource` is a handle to foreign state { () } @remote fn dynamic :: d: Dynamic -> () //~^ ERROR E0706 a `Dynamic` value's type is known only { () } // A signature is required, and a body. @remote fn unannotated :: x //~^ ERROR E0107 `@remote` function `unannotated` needs a type //~^^^ ERROR E0107 `@remote` function `unannotated` needs a return type { () } @remote @extern c "foreign" fn foreign :: x: Int -> () //~^ ERROR E0114 `@remote` function `foreign` needs a body // Only on top-level functions. // The attribute's error is on its line. @remote //~^ ERROR E0114 `@remote` does not apply to a type type Message { Message } trait Run { @remote //~^ ERROR E0114 `@remote` does not apply to a method fn run :: x: a -> () }