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

Undetected escaping capability when using first class functions #50

Closed
mm0821 opened this issue May 21, 2021 · 2 comments · Fixed by #52
Closed

Undetected escaping capability when using first class functions #50

mm0821 opened this issue May 21, 2021 · 2 comments · Fixed by #52
Labels
bug Something isn't working

Comments

@mm0821
Copy link
Contributor

mm0821 commented May 21, 2021

There seems to be a problem with undetected capabilities escaping their delimiters when using first class functions closing over them, if the handler for the corresponding effect is defined in a separate function. In the following example the escaping capability for Effect2 is detected (fcfCaughtErr.txt):

effect Effect1(): Unit
effect Effect2(): Unit


def escape { prog: () => Unit / { Effect1, Effect2 } }: Unit = {
  var k: (Unit) => Unit / { escape } = fun (x: Unit) { () }
  try {
    try {
      prog()
    } with Effect1 { () =>
      k = fun (x: Unit) { resume(x) };
      resume(())
    }
  } with Effect2 { () => resume(()) }
  k(())
}

def main() = {
  escape { do Effect1(); do Effect2() }
}

However, if the handler for Effect2 is defined in the function handle2 as is done here

effect Effect1(): Unit
effect Effect2(): Unit


def handle2 { prog: () => Unit / { Effect2 } }: Unit = {
  try { prog() }
  with Effect2 { () => resume(()) }
}

def escape { prog: () => Unit / { Effect1, Effect2 } }: Unit = {
  var k: (Unit) => Unit / { escape } = fun (x: Unit) { () }
  handle2 {
    try {
      prog()
    } with Effect1 { () =>
      k = fun (x: Unit) { resume(x) };
      resume(())
    }
  }
  k(())
}

def main() = {
  escape { do Effect1(); do Effect2() }
}

this is not detected and results in a runtime error (fcfUncaughtErr.txt).

@mm0821 mm0821 added the bug Something isn't working label May 21, 2021
@b-studios
Copy link
Collaborator

Thanks for reporting! This is a soundness bug with region inference on continuations. Instead of using escape on the region, we need to use the lambda passed to handle2 as the current region. This might be overly restrictive in some cases, but would be along the lines of our current region approximation and would prevent this source of unsoundness.

@b-studios
Copy link
Collaborator

b-studios commented May 23, 2021

This really was an oversight on my sight, as can be seen in the branch fixing it. Lambdas (that is, fun() { ... }) did introduce a new region, but anonymous block arguments (like in handle2 { ... }) did not. This is clearly wrong as illustrated by your example.

jfrech added a commit that referenced this issue May 22, 2022
* Some comments

* Attempt fixing #50 by refining dynamic region

* Add new symbol kinds and document usage

* Improve LSP support by allowing reverse lookup symbol->tree for anons

* Redesign exception API using polymorphic effects

* Add draft of dom API

* Introduce Object as Keyword since we would shadow js.Object otherwise

* Fix generating mutable state within while

* Add small raytracer implementation that does not use effects

* Fix difference between JS and Chez printing of numbers

* Allow empty else branch in if

* Update stdlib

* Add some functions to the stdlib

* try making case study compatible with website

* add some more math operators to stdlib

* Update scalajs

* Move effekt sources to dedicated project folder

This commit corresponds to 2bbe521 on branch system-c-steps.

* Ignore bsp folder

* Incorporate kiama codebase as subproject

* Reorganize input sources

Backport of 4ac0904 in branch system-c-steps

* Add setTImeout to stdlib

* Add timestamp to stdlib

* Improve error messages

* Improve error messages

Backport of 00dd4b1

* Introduce abstraction of tracked params

Backport of 676b6d7

* Rename TypeAndEffect to InferredType

Backport of dd6c11a

* Try jvmopts to fix failing tests

* Reorganize libraries

* Fix chez tests

* Update dependencies and license generation

* Migrate kiama to Scala 3

* Disable native image generation for now

* export is now a keyword in Scala 3

* constructors need to be made explicit in Scala 3

* Type inference regression in Scala 3

* Disable strict warnings for now and fix exhaustivity later

* Update dependencies

* Scala 3 implicit resolution changed

* Update scala test version to work with Scala 3

* Fix Scala 3 exhaustivity checks in Typer

* Address remaining Scala 3 exhaustivity errors.

* Bump Scala version to latest release

* Fix deprecation warnings by chaning to / syntax

* Drop unused libraryDependencies

* Port most namer changes of SystemC

* Use nameFor since it automatically generates correct local/global names

* Fix missing tests

* mimicking 49edef9

* cherry-picked: Incorporate kiama codebase as subproject

* updated the now in-house `kiama` imports

* removed unnecessary `bitbucket` mentions

* Disable native image generation for now

* export is now a keyword in Scala 3

* constructors need to be made explicit in Scala 3

* Type inference regression in Scala 3

* Disable strict warnings for now and fix exhaustivity later

* Update dependencies

* Scala 3 implicit resolution changed

* Update scala test version to work with Scala 3

* Fix Scala 3 exhaustivity checks in Typer

* Address remaining Scala 3 exhaustivity errors.

* Bump Scala version to latest release

* Fix deprecation warnings by chaning to / syntax

* Drop unused libraryDependencies

* cherry-picked b-studio's Scala 3 section

commits 71d51fd to 058950e

* moved towards `eval(path: String): Unit`

* eradicated `evalLLVM`'s `mod` dependence

* hotfix

* minor refactoring: LLVM static files

* LLVM testing: always clear `out/` to avoid orphan files

* removed superfluous comment; I am no longer interested in the answer

* Port most namer changes of SystemC

* fixup: cherry-picked ef7f9e4

* Use nameFor since it automatically generates correct local/global names

* Fix missing tests

Co-authored-by: Jonathan Brachthäuser <jonathan@b-studios.de>
Co-authored-by: phischu <philipp.schuster@uni-tuebingen.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants