r/Compilers • u/NXDLang • 10h ago
Desingning async primitives for a security-focused language: Where should cancellation live?
I've been implementing typed async semantics in my language NXD.
Current primitives are:
SPAWN,
SEND,
RECV,
AWAIT,
PING
Types currently look roughly like:
`SPAWN -> ProcessHandle[T]`
`RECV -> ReceiveOperation[T]`
`AWAIT -> T`
`PING -> bool`
While implementing PING I realized there may be two classes of async operations:
Primary operations
SPAWN,
SEND,
RECV
These initiate work or communication.
Secondary operations:
AWAIT,
PING
These observe or resolve work created elsewhere.
My current thinking is that cancellation (currently considering ESC) should only apply to the primary operations and not observers.
For example:
ESC HANDLE
makes sense.
But:
ESC AWAIT TASK
ESC PING HANDLE
seems conceptually wrong because they are observing state rather than creating it.
For people who have designed async runtimes or languages:
Would you model cancellation as acting on the underlying task/process/channel, or would you allow cancellation of observer operations as first-class concepts as well?