Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasmfx #76

Merged
merged 40 commits into from
Jan 29, 2025
Merged

wasmfx #76

merged 40 commits into from
Jan 29, 2025

Conversation

butterunderflow
Copy link
Contributor

@butterunderflow butterunderflow commented Dec 11, 2024

This PR is the implementation for wasmfx effect handlers. We added a Trail in our semantics, which represents the stack of pure clauses for resume.

TODO (Dec 18):

  • Try a test case where
        val kr = (s: Stack, _: Cont[Ans], t1: Trail[Ans], m1: MCont[Ans], hs1: Handlers[Ans]) => {
          val index = trail.indexWhere { case (_, tags) => tags.contains(tagId) }
          val newTrail = if (index >= 0) trail.take(index) else trail
          kont(s ++ restStack, newTrail ++ t1, m1, hs1) // mkont lost here, and it's safe if we never modify it
        }

not dropping tags in newTrail fails

  • simplify Handler to only take in Stack
  • Remove meta-continuation for wasmfx

// FIXME: handlers are lost here
kont(s ++ restStack, List(), s1 => k1(s1, List(), m1)) // mkont lost here
val index = trail.indexWhere { case (_, tags) => tags.contains(tagId) }
Copy link
Contributor

@ahuoguo ahuoguo Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you guarantee you always find the first handler of tag_id

}
val newStack = ContV(kr) :: inputs
hs.find(_._1 == tagId) match {
case Some((_, handler)) => handler(newStack, initK[Ans], List(), mkont)
case Some((_, handler)) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally hs.find(_._1 == tagId) and tags.contains(tagId) find the same resume clause

@ahuoguo
Copy link
Contributor

ahuoguo commented Dec 13, 2024

I think this implementation is pretty mature. There's one more thing I want to test. make nested_resume a bit more nested to test whether we are handling trail correctly.

Then, we can maybe get rid of meta-continuations for wasmfx

val kr = (s: Stack, _: Cont[Ans], t1: Trail[Ans], m1: MCont[Ans], hs1: Handlers[Ans]) => {
val index = trail.indexWhere { case (_, tags) => tags.contains(tagId) }
val newTrail = if (index >= 0) trail.take(index) else trail
kont(s ++ restStack, newTrail ++ t1, m1, hs1) // mkont lost here, and it's safe if we never modify it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we replace newTrail to just trail.dropRight(1). nested-strip.wat test is the only one that will fail

@ahuoguo ahuoguo changed the base branch from fx-multi-tag-trail to main December 18, 2024 14:17
ahuoguo added a commit that referenced this pull request Jan 12, 2025
@Kraks Kraks changed the title utilize trail for wasmfx wasmfx Jan 28, 2025
@ahuoguo ahuoguo marked this pull request as ready for review January 29, 2025 15:26
@ahuoguo ahuoguo merged commit 7aebeb5 into main Jan 29, 2025
1 check failed
ahuoguo added a commit that referenced this pull request Jan 30, 2025
* implemet multi tag, found bug at suspend16 for forgetting meta-continuation

* forgor one test

* only the control flow structure for failed suspend16 test

* push wast file

* newMk doesn't work also

* push wast file

* revert nested resume

* some refactor; add test spec

* revert accidental change

* use the right remaining stack

* rebase on Dinghong's version

* check point

* refactoring

* minor refactor

* handler

* refactor eval, taking only single inst

* try catch

* rebase Dinghong's tests

* some clean up

* unify value repr for cont

* test case: throw -> resume -> throw -> no resume

* initial impl for wasmfx

* unreachable not trap

* rm redundant case

* fix call ref

* create tfp only, delete trail, simplify handlers

* simplify contV, comment on handler

* this brnach only runs tfp, not fx

* reflect fix of return_call in #76

* drafting sem for fused eval

* rm comment

* support for loop

Co-authored-by:  Jiaaaaatai <[email protected]

* first try with return_call.wast

* look at return_call.wast failure

* even odd had the same problem, ignore ASSERT_INVALID

* forgor

* rm wasmfx conflictst

* both FX and TFP in CI

---------

Co-authored-by: ahuoguo <[email protected]>
Co-authored-by: butterunderflow <[email protected]>
Co-authored-by: Alex Bai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants