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

Multiple resumption misoptimization #861

Open
jiribenes opened this issue Mar 6, 2025 · 2 comments · May be fixed by #872
Open

Multiple resumption misoptimization #861

jiribenes opened this issue Mar 6, 2025 · 2 comments · May be fixed by #872
Labels
bug Something isn't working

Comments

@jiribenes
Copy link
Contributor

jiribenes commented Mar 6, 2025

The following program discovered by @timsueberkrueb prints something different when ran with optimisations than without:

effect flip(): Bool
effect choice(): Bool

def main() = {
  try {
    val x = do choice()
    val y = do choice()
    println(x.show ++ " " ++ y.show)
  } with choice {
    try {
      resume(do flip())
    } with flip {
      resume(true)
      resume(false)
    }
  }
}

~>

$ effekt --backend=js --no-optimize hello.effekt
true true
true false
false true
false false

$ effekt --backend=js hello.effekt
false false
@jiribenes jiribenes added the bug Something isn't working label Mar 6, 2025
@timsueberkrueb
Copy link
Contributor

The following program works as expected with and without optimizations:

effect flip(): Bool
effect choice(): Bool

def main() = {
  try {
    try {
      val x = do choice()
      val y = do choice()
      println(x.show ++ " " ++ y.show)
    } with choice {
      resume(do flip())
    }
  } with flip {
    resume(true)
    resume(false)
  }
}

The only difference here is that flip is handled in the outer scope.

@jiribenes
Copy link
Contributor Author

jiribenes commented Mar 6, 2025

The optimised IR of the program in the issue description looks like:

def main() = {
  val x: Bool = reset { {p1} => 
    shift(p1) { {k1} => 
      val _1: Unit = resume(k1) { return true };

      resume(k1) {
        return false
      }
    }
  };
  val y: Bool = reset { {p2} => 
    shift(p2) { {k2} => 
      val _2: Unit = resume(k2) { return true };

      resume(k2) {
        return false
      }
    }
  };
  val v_r_left: String = if (x) { return "true" } else { return "false" };
  val v_r_right: String = if (y) { return "true" } else { return "false" };

  let tmp = println(infixConcat(infixConcat(v_r_left, " "), v_r_right))
  return tmp
}

@b-studios b-studios linked a pull request Mar 8, 2025 that will close this issue
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