I spend two days on trying to fix it or find workaround, but I don't have enough experience with scala native yet. It's blocking me with many tasks. I'm calling for help.
I simplified the code and it still crashes if I put it in nativelib folder:
import scala.scalanative.native._
object CallbackFail {
def runCallback(callId:CInt):Unit = {
println(s"Callback #$callId")
}
// compiler crash: (GenICode.scala:740) function's symbol is null
val runCallBackPtr:CFunctionPtr1[CInt, Unit] = CFunctionPtr.fromFunction1(runCallback _)
}
Compilation command is:
;nativelib/clean;nativelib/compile
Error is:
[error] (nativelib/compile:compileIncremental) java.lang.NullPointerException
Callstack is:
java.lang.NullPointerException
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadApply6$1(GenICode.scala:740)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:809)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:123)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:71)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:148)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:98)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:71)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:89)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:71)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:89)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:67)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:63)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$applyPhase$1.apply$mcV$sp(Global.scala:467)
at scala.tools.nsc.Global$GlobalPhase.withCurrentUnit(Global.scala:458)
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:467)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:425)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:425)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:425)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:55)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1528)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1513)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1508)
at scala.tools.nsc.Global$Run.compile(Global.scala:1609)
at xsbt.CachedCompiler0.run(CompilerInterface.scala:116)
at xsbt.CachedCompiler0.run(CompilerInterface.scala:95)
at xsbt.CompilerInterface.run(CompilerInterface.scala:26)
at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:107)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:53)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:47)
at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply$mcV$sp(MixedAnalyzingCompiler.scala:50)
at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:50)
at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:50)
at sbt.compiler.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:74)
at sbt.compiler.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:49)
at sbt.compiler.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:64)
at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:66)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:64)
at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:32)
at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:72)
at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:71)
at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:99)
at sbt.inc.Incremental$.compile(Incremental.scala:71)
at sbt.inc.IncrementalCompile$.apply(Compile.scala:54)
at sbt.compiler.IC$.compileInternal(IncrementalCompiler.scala:160)
at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:138)
at sbt.Compiler$.compile(Compiler.scala:155)
at sbt.Compiler$.compile(Compiler.scala:141)
at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:879)
at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:870)
at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:868)
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)
Thanks for the bug report!
Minimized:
object CallbackFail {
scala.scalanative.native.CFunctionPtr.fromFunction0(() => ())
}
More digging, if one removes:
It does compile. It seems like our redefinition of boxed unit confuses the JVM backend.
In Scala.js, our redefinition of BoxedUnit is part of library-aux, a tiny project with "special" redefinitions that tend to otherwise crash scalac. Those are compiled in a separate run from the reset of the scalalib and everything else.
@sjrd This must be the solution for this, thanks!
@densh I've tried to delete nativelib/src/main/scala/scala/scalanative/runtime/BoxedUnit.scala but it still crashes the compiler
Most helpful comment
In Scala.js, our redefinition of
BoxedUnitis part oflibrary-aux, a tiny project with "special" redefinitions that tend to otherwise crash scalac. Those are compiled in a separate run from the reset of the scalalib and everything else.