scala-native / scala-native

Your favorite language gets closer to bare metal.
http://scala-native.org
Other
4.49k stars 364 forks source link

java.util.NoSuchElementException: key not found: Local(src,0) #207

Closed Sciss closed 8 years ago

Sciss commented 8 years ago

The following test-case produces this exception when running (sbt clean run): https://github.com/Sciss/scala-native-test/tree/scala-native-issue-207

Stack trace:

java.util.NoSuchElementException: key not found: Local(src,0)
    at scala.collection.MapLike$class.default(MapLike.scala:228)
    at scala.collection.AbstractMap.default(Map.scala:58)
    at scala.collection.mutable.HashMap.apply(HashMap.scala:64)
    at scala.scalanative.compiler.analysis.UseDef$$anonfun$scala$scalanative$compiler$analysis$UseDef$$enterDeps$1$1.apply(UseDef.scala:69)
    at scala.scalanative.compiler.analysis.UseDef$$anonfun$scala$scalanative$compiler$analysis$UseDef$$enterDeps$1$1.apply(UseDef.scala:68)
    at scala.collection.mutable.UnrolledBuffer$Unrolled.foreach(UnrolledBuffer.scala:224)
    at scala.collection.mutable.UnrolledBuffer.foreach(UnrolledBuffer.scala:130)
    at scala.scalanative.compiler.analysis.UseDef$.scala$scalanative$compiler$analysis$UseDef$$enterDeps$1(UseDef.scala:68)
    at scala.scalanative.compiler.analysis.UseDef$$anonfun$apply$4$$anonfun$apply$5.apply(UseDef.scala:96)
    at scala.scalanative.compiler.analysis.UseDef$$anonfun$apply$4$$anonfun$apply$5.apply(UseDef.scala:95)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.scalanative.compiler.analysis.UseDef$$anonfun$apply$4.apply(UseDef.scala:95)
    at scala.scalanative.compiler.analysis.UseDef$$anonfun$apply$4.apply(UseDef.scala:94)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.scalanative.compiler.analysis.UseDef$.apply(UseDef.scala:94)
    at scala.scalanative.compiler.pass.DeadCodeElimination$$anonfun$preDefn$1.applyOrElse(DeadCodeElimination.scala:13)
    at scala.scalanative.compiler.pass.DeadCodeElimination$$anonfun$preDefn$1.applyOrElse(DeadCodeElimination.scala:11)
    at scala.scalanative.compiler.Pass$class.scala$scalanative$compiler$Pass$$hook(Pass.scala:36)
    at scala.scalanative.compiler.Pass$class.scala$scalanative$compiler$Pass$$txDefn(Pass.scala:49)
    at scala.scalanative.compiler.Pass$$anonfun$1.apply(Pass.scala:42)
    at scala.scalanative.compiler.Pass$$anonfun$1.apply(Pass.scala:41)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
    at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:251)
    at scala.collection.AbstractTraversable.flatMap(Traversable.scala:105)
    at scala.scalanative.compiler.Pass$class.txAssembly(Pass.scala:41)
    at scala.scalanative.compiler.Pass$class.apply(Pass.scala:194)
    at scala.scalanative.compiler.pass.DeadCodeElimination.apply(DeadCodeElimination.scala:10)
    at scala.scalanative.compiler.Compiler.loop$1(Compiler.scala:71)
    at scala.scalanative.compiler.Compiler.apply(Compiler.scala:80)
    at scala.scalanative.sbtplugin.ScalaNativePluginInternal$.scala$scalanative$sbtplugin$ScalaNativePluginInternal$$compileNir(ScalaNativePluginInternal.scala:24)
    at scala.scalanative.sbtplugin.ScalaNativePluginInternal$$anonfun$projectSettings$8.apply(ScalaNativePluginInternal.scala:114)
    at scala.scalanative.sbtplugin.ScalaNativePluginInternal$$anonfun$projectSettings$8.apply(ScalaNativePluginInternal.scala:93)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
[error] (*:nativeLink) java.util.NoSuchElementException: key not found: Local(src,0)
densh commented 8 years ago

That's a new one, a use-def analysis fails to account for something. Thanks for the report!

Milyardo commented 8 years ago

I have a project that enounters the the same problem here, I suspect use-def is failing to account for function pointers.

densh commented 8 years ago

@Milyardo Scala Native + OpenGL, looks exciting. 👍

densh commented 8 years ago

Minimal reproduction of the bug:

import scalanative.native._

object Test  {
  var foo = 1
  var funptr: FunctionPtr0[Unit] = { () =>
    foo
    ()
  }
  def main(args: Array[String]): Unit = ()
}