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

Compiler crash in icode phase with continuations and ref to val across shift in a while loop #3891

Closed
scabug opened this issue Oct 2, 2010 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Oct 2, 2010

Attempting to compile the following with 2.8.0.final or 2.8.1-RC2,

import scala.util.continuations._

object Bug {
  reset {
    while(true) {
      val v1 = 23
      shift { (k : Unit => Unit) => k() }
      val v2 = v1
    }
  }
}

results in the following stacktrace,

Exception in thread "main" java.lang.Error: symbol value v1 does not exist in Bug$$$$anonfun$$1$$$$anonfun$$while$$1$$1$$1.apply
        at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:33)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.scala$$tools$$nsc$$backend$$icode$$GenICode$$ICodePhase$$$$genLoad(GenICode.scala:843)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.scala$$tools$$nsc$$backend$$icode$$GenICode$$ICodePhase$$$$genLoad(GenICode.scala:512)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.scala$$tools$$nsc$$backend$$icode$$GenICode$$ICodePhase$$$$genStat(GenICode.scala:183)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$genStat$$1.apply(GenICode.scala:155)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$genStat$$1.apply(GenICode.scala:155)
        at scala.collection.LinearSeqOptimized$$class.foldLeft(LinearSeqOptimized.scala:123)
        at scala.collection.immutable.List.foldLeft(List.scala:45)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.genStat(GenICode.scala:155)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.scala$$tools$$nsc$$backend$$icode$$GenICode$$ICodePhase$$$$genLoad(GenICode.scala:868)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:126)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$gen$$1.apply(GenICode.scala:81)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$gen$$1.apply(GenICode.scala:81)
        at scala.collection.LinearSeqOptimized$$class.foreach(LinearSeqOptimized.scala:61)
        at scala.collection.immutable.List.foreach(List.scala:45)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:81)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:148)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:100)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$gen$$1.apply(GenICode.scala:81)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase$$$$anonfun$$gen$$1.apply(GenICode.scala:81)
        at scala.collection.LinearSeqOptimized$$class.foreach(LinearSeqOptimized.scala:61)
        at scala.collection.immutable.List.foreach(List.scala:45)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:81)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:91)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.gen(GenICode.scala:77)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.apply(GenICode.scala:73)
        at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply$$mcV$$sp(Global.scala:276)
        at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply(Global.scala:276)
        at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$applyPhase$$1.apply(Global.scala:276)
        at scala.tools.nsc.reporters.Reporter.withSource(Reporter.scala:48)
        at scala.tools.nsc.Global$$GlobalPhase.applyPhase(Global.scala:276)
        at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$run$$1.apply(Global.scala:252)
        at scala.tools.nsc.Global$$GlobalPhase$$$$anonfun$$run$$1.apply(Global.scala:252)
        at scala.collection.Iterator$$class.foreach(Iterator.scala:631)
        at scala.collection.mutable.ListBuffer$$$$anon$$1.foreach(ListBuffer.scala:304)
        at scala.tools.nsc.Global$$GlobalPhase.run(Global.scala:252)
        at scala.tools.nsc.backend.icode.GenICode$$ICodePhase.run(GenICode.scala:66)
        at scala.tools.nsc.Global$$Run.compileSources(Global.scala:733)
        at scala.tools.nsc.Global$$Run.compile(Global.scala:813)
        at scala.tools.nsc.Main$$.process(Main.scala:108)
        at scala.tools.nsc.Main$$.main(Main.scala:122)
        at scala.tools.nsc.Main.main(Main.scala)

The crash goes away if the reference to v1 is moved to before the shift.

@scabug
Copy link
Author

scabug commented Oct 2, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3891?orig=1
Reporter: @milessabin

@scabug
Copy link
Author

scabug commented Oct 2, 2010

@milessabin said:
Possibly related to SI-3501?

@scabug
Copy link
Author

scabug commented Oct 2, 2010

@paulp said:
To me this looks like an issue with cps transforms not being enforced on the synthetic desugaring. I say this because if I write a method there to do what the equivalent of the while loop, it is rejected unless I add a @cps annotation to the method return type. When the while is turned into a label it has no such annotation but this is not detected.

My general experience recently has been that while loops + other interesting construct == bug. Are they the only way to generate a LabelDef before explicitouter? I'm thinking there are some tree rewriters which need another case, although it's pretty optimistic to imagine a simple resolution.

@scabug
Copy link
Author

scabug commented Oct 10, 2010

@TiarkRompf said:
I'm not completely sure yet, but it looks indeed like the underlying issue is the same as in #3501, . I'm closing the ticket as a duplicate and adding a note about this case at #3501.

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

No branches or pull requests

2 participants