5 ms·
> async/await contexts are not first-class values Because async/await are not values, they are ways to run/structure your code. That's why they are so infectio
by SkiFire13 1y ago
> async/await contexts are not first-class values
Because async/await are not values, they are ways to run/structure your code. That's why they are so infectious. If you don't want the division the only solution is to make everything of one kind. Languages like C make everything sync/blocking, while languages like Go make everything async.
- dwattttt 1y ago> the only solution is to make everything of one kind That's not really the case. All you really need is a way to run async code from a sync function; "keep doing this async thing until it's done" is the primitive you need, and some languages/runtimes offer this.
- SkiFire13 1y agoGoing by that reasoning then Rust solved the colored function problem too: when calling an `async` function from a sync one use `block_on`, while when calling a sync blocking function from an `async` one use `spawn_blocking`, but somehow people are not happy with this.
- dwattttt 1y agoYes, it's quite curious. Having used both block_on and spawn_blocking, and not being worried about what "colour" my function is, I am also quite confused about the fuss. On a practical note, since Rust doesn't standardise on an async runtime, it would be more accurate to say tokio solved the coloured function problem, for whatever that means. Or any and everyone else that made it easy to call one coloured function from another.
- naasking 1y ago> Because async/await are not values They are computations that produce values. Computations can be reified as values. What do you think functions and threads are? As I described above, "delimited continuations" are values that subsume async/await and many other kinds of effects. You can handle async/await like any other value if they were reified as delimited continuations, but this makes the compiler writer's life much more difficult.
- SkiFire13 1y ago> As I described above, "delimited continuations" are values that subsume async/await and many other kinds of effects. Supporting delimited continuations force some specific ways of performing computations. They are akin to making everything async, which proves my point: you have to make everything of one kind in order to solve the problem.
- naasking 1y ago> They are akin to making everything async, which proves my point: you have to make everything of one kind in order to solve the problem. You can use ordinary direct style compilation, but all references to stack values simply have to be relative offsets, then a simple implementation of shift/reset is just capturing context and copying stack fragments, which you can do using setjmp/longjmp in C (although there are better ways [1]). This is not akin to making everything async, nor is everything "of one kind", whatever that means. A delimited continuation is very much its own kind of thing, distinct from other values, and doesn't have to influence the function call/return semantics unless you're targeting a less flexible runtime like the JVM. [1] https://github.com/koka-lang/libhandle https://github.com/koka-lang/libhandle
- SkiFire13 1y ago> but all references to stack values simply have to be relative offsets Then such references are no longer pointers, and in order to have a generic reference (that can point to both stack memory and heap memory) you have to store additional data (which one of them it points to) and conditionally use the correct one any time you access it. This is a very invasive change to the memory model. > then a simple implementation of shift/reset is just capturing context and copying stack fragments, which you can do using setjmp/longjmp in C That sounds like you're just reinventing green threads then, which basically forces everything to be async once you start noticing its issues. > https://github.com/koka-lang/libhandle https://github.com/koka-lang/libhandle This returns a 404 error for me. > This is not akin to making everything async, nor is everything "of one kind", whatever that means. Sure, if everything has to be able to "wait" for the result of a continuation then you're forcing async support on everything. If instead you implement continuations as some kind of monads that users have to return from their functions then you got function coloring because you can't normally wait for the result of a continuation from a function that does not return a continuation.