6 ms·
WasmFX: Effect Handlers for WebAssembly
- adhambey 3y ago[flagged]
- infogulch 3y agoI first heard of algebraic effects in a presentation about Unison recorded at Strangeloop. Realizing that exceptions, async, generators, and continuations could all be unified and implemented on top of one language feature was mind expanding. It looks like the juicy details are in the Explainer: https://github.com/WebAssembly/stack-switching/blob/main/proposals/continuations/Explainer.md https://github.com/WebAssembly/stack-switching/blob/main/pro...
- fiddlerwoaroof 3y agoAlgebraic effect and delimited continuations have equivalent power. I think, for example, GHC added delimited continuations, in part, because they made it easier to implement algebraic effects efficiently.
- duped 3y agoThe problem with abstracting control flow has always been the ease of composition within a program. I'm not sure if algebraic effects make that better, although I like the simplest form (exceptions with resume) for error handling. It's kind of like abelian groups and hyper graphs. They generalize many domains very nicely, and are an attractive abstraction. But it turns out they're too abstract for any individual domain, and don't make life easier. The PL world seems to have learned that lesson from call/cc, but I don't know if they've reached it yet with algebraic effects - although it seems looming. Control flow is sexy for PL researchers, so it makes sense why it's hot right now. Faster matrix multiplications are much more boring, no matter how much better they make society than weird control flow. Just personally, I can count on one hand the number of algorithms I've written where weird control flow was necessary to make the algorithm easier, and they were all weird shit that I expect other people to use libraries for in most cases.
- lolinder 3y ago> they were all weird shit that I expect other people to use libraries for in most cases. The theory with algebraic effects is that you'd use them to implement those libraries. Most application code won't be implementing new types of effects, but exceptions, generators, async, and who knows what else can be implemented at the library level instead of the language level. In theory it's a single abstraction that can be implemented once in the language and then all the more complicated abstractions can be swapped out as desired, rather than the current status quo where everyone has to use whatever patterns the language designers chose (which are often rather contentious).
- duped 3y agoMy point is that it's incredibly rare to actually need such abstractions.
- infogulch 3y agoMaybe it's worth investing into foundational research, instead of charging anyone who tries to do something new as frivolously chasing their own boredom.
- TeMPOraL 3y agoBut then, there is a need to make the noise generated by error handling, async, generators, etc. to disappear. Though I doubt it's doable with our current paradigm; we're pushing against the limit of working directly with plaintext, single-source-of-truth code.
- davexunit 3y agoI use delimited continuations all the time if the language exposes an interface for them. Coroutines are great to have around. I also use async/await whenever I have to write JS. Seems this proposal really covers the bases for control flow which is great.
- spankalee 3y agoWASM is used to implement all kinds of control flow in other languages, so here it makes a lot of sense to have a lower level abstraction. The languages on top of WASM will still have exceptions, generators, etc.
- phplovesong 3y agoYes! This is why im super exited about Ocaml 5.0. The ongoing work is now to add typed effects to the typesystem.
- singularity2001 3y agoDoes this approach avoid function coloring? That is: do legacy calls of functions containing yield instructions just treat these as nop?
- lapinot 3y agoThis will never happen, "legacy call" of functions manipulating the control stack in weird ways can never be meaningful. OTOH the reverse is not always true but a good system should have it: transparent recasting of pure code as effectful code. In other words, the problem that should be solvable but isn't always is that you should be able to "await" a pure function. Or more generally, transparent subtyping of less effectful code into more effectful. Subtyping isn't easy but it's also not impossible if you think about it early enough during the design.
- JaggerJo 3y agoAny chance you still know the title of the strangeloop presentation?
- meindnoch 3y agoWebAssembly is getting more complex bit by bit...
- jeffparsons 3y agoThat's okay; _using_ WebAssembly is getting easier bit by bit. Features like this one allow the high level programming language features you know and love to be implemented efficiently behind the scenes.
- charcircuit 3y agoBut they make making WASM implementations harder to make.
- phickey 3y agoUseful things are hard to make.
- kaliqt 3y agoThat's how the core has to be, like Vulkan, making the core harder allows for more control, a better foundation. Then we load up those core libraries with easy APIs that are super powerful and can do what was never thought possible. Same for WebGPU. So I think WASM is doing this exactly the right way as long as it stays powerful and flexible at the core.
- 4ad 3y agoIf you are talking about things like the garbage collection, yes, but this proposal is trivial to implement.
- davexunit 3y agoPeople said this about GC but then I implemented a WASM interpreter with GC support and it wasn't very hard to do. This FX proposal would introduce... 6 more instructions I think? Not bad. Especially compared to something like the SIMD extension which feels like it's adding a million instructions.
- chii 3y agothe monika 'fx' is often used by graphics pipelines or rendering to mean special effects, and thus often take on the connotation of being related to graphics or rendering (e.g., javaFX). I dont think wasmfx should use this monika, as it makes it sound more graphics related than it really is. Naming and connotation of a name is important, as it frames the way people think about things.
- sureglymop 3y agoDo you mean 'moniker'?
- deleted 3y ago[deleted]
- PaulDavisThe1st 3y agoAudio, too.
- Findecanor 3y agoI think that the word "effects" might be too wide a term even in the domain of programming languages. There are languages with (side-)effect annotations that have no continuation-like constructs whatsoever.
- qudat 3y agoI recently gave a talk on delimited continuations for anyone curious https://youtu.be/uRbqLGj_6mI?si=cOqlJighLJE42c-Q https://youtu.be/uRbqLGj_6mI?si=cOqlJighLJE42c-Q
- asplake 3y agoEnjoyed the linked (more detailed) explainer: https://github.com/WebAssembly/stack-switching/blob/main/proposals/continuations/Explainer.md https://github.com/WebAssembly/stack-switching/blob/main/pro...
- singularity2001 3y agocould exception handling be implemented with this? if so would that make the exception handling proposal superfluous?
- 4ad 3y ago> could exception handling be implemented with this? Yes. > if so would that make the exception handling proposal superfluous? The exception handling proposal is a subset of this proposal. This proposal doesn't replace it, it completes it.
- davexunit 3y agoThis is an exciting proposal. We have delimited continuations in Guile Hoot, a Scheme to WASM compiler, but because there's no stack switching there's more overhead than there should be.
- vanderZwan 3y agoThe moment I saw "continuations" I wondered if it was a proposal by some of the Spritely Institute people partially for the sake of Hoot! But your reply suggests it's not?
- davexunit 3y agoNope, not by us, but we are keeping our eye on it!
- jedisct1 3y agoMaybe this is actually what started that proposal, but it sounds very useful to efficiently implement @Frame when using Zig to create WebAssembly modules.