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

Elided invocation on RHS throws compile-time exception on primitive conversion #5051

Closed
scabug opened this issue Oct 2, 2011 · 10 comments
Closed
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 2, 2011

The use case was a ??? method that would be easily @elidable, to prompt an error message from the compiler (in order to detect unimplementations). The following throws an error, apparently when generating the conversion to char. (Failing to compile is sufficient for the purpose of detecting ???. Unfortunately, it only works with primitive result types. Conversion to reference types results in ClassCastException. All this is abuse of the facility.)

package elysian

class ElysianFields {
import ElysianFields._
def run() {
//oops // OK
feature
println("Hello.")
}
//def feature: Unit = oops // OK
def feature: Char = oops // DNC

//java.lang.ClassCastException: scala.runtime.BoxedUnit cannot be cast to elysian.ElysianFields
val bugInWaiting: ElysianFields = oops // OK to elide?
}

object ElysianFields {

import annotation.elidable
import annotation.elidable._

@elidable(150)
def oops = throw new UnsupportedOperationException

def main(args: Array[String]) {
new ElysianFields().run()
}
}

$ scalac -d out -Xelide-below 1000 ./src/elysian/ElysianFields.scala
error: java.lang.ArrayIndexOutOfBoundsException: 8
at ch.epfl.lamp.fjbg.JExtendedCode.emitT2T(JExtendedCode.java:468)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genPrimitive$1(GenJVM.scala:1670)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$genBlock$1$2.apply(GenJVM.scala:1235)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$genBlock$1$2.apply(GenJVM.scala:1159)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34)
at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:38)
at scala.tools.nsc.backend.icode.BasicBlocks$BasicBlock.foreach(BasicBlocks.scala:126)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlock$1(GenJVM.scala:1159)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genBlocks$1(GenJVM.scala:1086)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genCode(GenJVM.scala:1702)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genMethod(GenJVM.scala:790)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$genClass$7.apply(GenJVM.scala:307)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$genClass$7.apply(GenJVM.scala:307)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genClass(GenJVM.scala:307)
at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
at scala.collection.Iterator$class.foreach(Iterator.scala:660)
at scala.collection.mutable.HashTable$$anon$1.foreach(HashTable.scala:157)
at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:190)
at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:43)
at scala.collection.mutable.HashMap$$anon$2.foreach(HashMap.scala:102)
at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase.run(GenJVM.scala:86)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
at scala.tools.nsc.Global$Run.compile(Global.scala:1038)
at scala.tools.nsc.Main$.process(Main.scala:106)
at scala.tools.nsc.Main$.main(Main.scala:123)
at scala.tools.nsc.Main.main(Main.scala)

@scabug
Copy link
Author

scabug commented Oct 2, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5051?orig=1
Reporter: @som-snytt
Affected Versions: 2.9.1

@scabug
Copy link
Author

scabug commented Oct 2, 2011

@som-snytt said:
As an exercise, I read the formatting help:

package elysian

class ElysianFields {
  import ElysianFields._
  def run() {
    //oops // OK
    feature
    println("Hello, "+ bugInWaiting.getClass.getName)
  }
  def feature: Char = oops // DNC
  //def feature: Unit = oops // OK

  //java.lang.ClassCastException: scala.runtime.BoxedUnit cannot be cast to elysian.ElysianFields
  //val bugInWaiting: ElysianFields = oops // OK to elide?
  val bugInWaiting: AnyRef = oops // OK 
}

object ElysianFields {

  import annotation.elidable
  import annotation.elidable._

  @elidable(150)
  def oops = throw new UnsupportedOperationException

  def main(args: Array[String]) {
    new ElysianFields().run()
  }
}

@scabug
Copy link
Author

scabug commented Feb 23, 2012

@paulp said:
As an exercise, that's funny. So is "elysian", I might have thought I was the only one who thinks that every time I see elision.

@scabug
Copy link
Author

scabug commented Feb 23, 2012

@som-snytt said:
You won't have looked at the neg test class where ElysianField becomes ElysianFailed.

I'll try to figure out how the elidable deltas broke the build. I can attest that git pull and ant test worked on my machine, but there may be interactions with later commits. I'll have to learn how to use git to fetch the commits.

@scabug
Copy link
Author

scabug commented Feb 23, 2012

@paulp said:
The tests were passing for me right up until I reverted, so part of the game is to figure out what's different. I forgot to check what happens if you compile under -optimise, which is the first place to look. Maybe jenkins builds checkin under -optimise, though I didn't think it did.

@scabug
Copy link
Author

scabug commented Feb 23, 2012

@som-snytt said:
That was my first thought too, and as a naive user, which shows how often -optimise figures on the mailing lists. Jenkins says it runs ant nightly, which is optimised.

@scabug
Copy link
Author

scabug commented Feb 23, 2012

@paulp said:
In case you're working on this, FYI I fixed it. Don't let that stop you from finding other stuff to do though, there's plenty.

@scabug
Copy link
Author

scabug commented Feb 23, 2012

@som-snytt said:
OK. I did run ant nightly and confirmed the error. Then evening came and morning came, the second day. I can see why -optimise is not the default test mode. I had to run out and pick up my daughter from pre-K, and now I'm taking her to see Olivier's Henry V. I ought to have run ant nightly before going to the cinema. Yes, I'll find something to fix that I can almost understand. Once more into the breach.

@scabug
Copy link
Author

scabug commented Feb 23, 2012

@paulp said:
If the compiler proves too difficult (or slow - one develops certain accommodations) you are still an important contributor in the witty comment department. You might take a look at 06384c052e for tips on how else one might go about this. It's what I meant elidable to do in the first place, but I was pretty green in those days.

@scabug
Copy link
Author

scabug commented Feb 23, 2012

@paulp said:
As of 98cf4014a3 expressions of type Nothing elide into a call to ???, preserving the low termination levels seen in the position's prior inhabitant.

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

No branches or pull requests

2 participants