links icon indicating copy to clipboard operation
links copied to clipboard

CPS compilation is broken for inlined handled computations

Open dhil opened this issue 3 years ago • 1 comments

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 avatar Feb 08 '22 13:02 dhil