Skip to content

Mistranslation of recursively forwarded effects in JS backend #1358

@marzipankaiser

Description

@marzipankaiser

When running the following program in the JavaScript backend, it runs forever producing < on the console, until it stack-overflows:

effect stacktrace(): Unit

def withStacktrace{ body: => Unit / stacktrace }: Unit / { stacktrace } = {
  def st() = do stacktrace()
  try body()
  with stacktrace { () => println("<"); st(); resume(()) }
}
def allowStacktrace{ body: => Unit / stacktrace }: Unit = {
  try body()
  with stacktrace { () => resume(()) }
}

def foo(n: Int): Unit / stacktrace = withStacktrace {
  if (n > 0) {
    foo( n - 1 )
  } else { do stacktrace() }
}

def main() = allowStacktrace {
  foo(2)
}

(no playground link, since the playground just hangs...)

This is not the case in LLVM, Chez (also CPS), and also should not be the case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:jsbugSomething isn't working

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions