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

CPS compilation is broken for inlined handled computations #1097

Open
dhil opened this issue Feb 8, 2022 · 1 comment
Open

CPS compilation is broken for inlined handled computations #1097

dhil opened this issue Feb 8, 2022 · 1 comment
Assignees
Labels
Milestone

Comments

@dhil
Copy link
Member

dhil commented Feb 8, 2022

The following program does not produce any output

fun run() {
  handle({
    println(intToString(do Foo(40,2)))
  }) {
    case <Foo(x,y) => resume> -> resume(x+y)
  }
}

fun mainPage(_) {
  page
   <#><button l:onclick="{run()}">Click me!</button></#>
}

fun main() {
  addRoute("/", mainPage);
  servePages()
}

main()

after hoisting the inlined computation to a thunk, the program produces the expected output

fun f() {
  println(intToString(do Foo(40,2)))
}

fun run() {
  handle(f()) {
    case <Foo(x,y) => resume> -> resume(x+y)
  }
}

fun mainPage(_) {
  page
   <#><button l:onclick="{run()}">Click me!</button></#>
}

fun main() {
  addRoute("/", mainPage);
  servePages()
}

main()

The problem seems to be that the inlined computation is being compiled with the wrong continuation.

@dhil dhil added the bug label Feb 8, 2022
@dhil dhil added this to the 0.9.6 milestone Feb 8, 2022
@dhil dhil self-assigned this Feb 8, 2022
@dhil dhil modified the milestones: 0.9.6, 0.9.7 Mar 8, 2022
@dhil dhil modified the milestones: 0.9.7, Snooze Mar 24, 2022
@dhil dhil modified the milestones: Snooze, 0.9.8, 1.0.0 Jul 22, 2022
@dhil
Copy link
Member Author

dhil commented Jul 29, 2024

I had a look at this again. The problem is that the continuation is inadvertently thrown away due to the way let bindings are compiled.

A quick fix would be to inspect the shape of the computation M during compilation to wrap it in fun() { M }() if M is a sequence of bindings.

A better solution would be to make sure the continuation is threaded correctly through the translation pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant