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

Add resource finalization to handlers #701

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

Conversation

dvdvgt
Copy link
Collaborator

@dvdvgt dvdvgt commented Nov 19, 2024

This PR aims to add resource finalization to handlers. This was already implemented under the branch feature/finalizer, however, the branch is now hilariously outdated and solving the merge conflicts almost impossible. Thus, I manually try to re-implement it.

@@ -445,7 +449,7 @@ object Transformer extends Phase[Typechecked, CoreTransformed] {
}

val body: BlockLit = BlockLit(Nil, List(promptCapt), Nil, List(promptParam),
Scope(transformedHandlers, transform(prog)))
Scope(transformedHandlers, transformedProg))

Context.bind(Reset(body))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not quite sure what the transformation is that is applied here and how to incorporate the new finalizer clauses here.

@@ -659,8 +659,17 @@ class RecursiveDescent(positions: Positions, tokens: Seq[Token], source: Source)
*/
def tryExpr(): Term =
nonterminal:
`try` ~> stmt() ~ someWhile(handler(), `with`) match {
case s ~ hs => TryHandle(s, hs)
`try` ~> stmt() ~ manyWhile(handler(), `with`) ~ finalizerClause(`suspend`, false) ~ finalizerClause(`resume`, true) ~ finalizerClause(`return`, true) ~ finalizerClause(`finally`, true) match {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For some reason, this breaks the current positions and error messages have the wrong span:

Warning:        |[warning] examples/pos/capture/regions.effekt:10:3: Handling effect Dummy, which seems not to be used by the program.
       |  try { prog() } with Dummy { resume(()) }
       |  ^
       |""".stripMargin
=> Diff (- obtained, + expected)
   try { prog() } with Dummy { resume(()) }
-  ^
+  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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.

1 participant