8

I am in the process of upgrading a large project to 2.10.4 to 2.11.4. I have gotten a compiler crash, is there anyway to display the name of source file that is causing the crash? I am able to get the full trace with ' last everitt/compile:compile'

I am going to revert to erasing large chunks of the project to binary search out the cause of the crash.

Here is the trace btw:

java.lang.NullPointerException
    at scala.tools.nsc.typechecker.NamesDefaults$class.baseFunBlock$1(NamesDefaults.scala:130)
    at scala.tools.nsc.typechecker.NamesDefaults$class.transformNamedApplication(NamesDefaults.scala:375)
    at scala.tools.nsc.Global$$anon$1.transformNamedApplication(Global.scala:450)
    at scala.tools.nsc.typechecker.NamesDefaults$class.transformNamedApplication(NamesDefaults.scala:326)
    at scala.tools.nsc.Global$$anon$1.transformNamedApplication(Global.scala:450)
    at scala.tools.nsc.typechecker.Typers$Typer.tryNamesDefaults$1(Typers.scala:3298)
    at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:3367)
    at scala.tools.nsc.typechecker.Typers$Typer.tryNamesDefaults$1(Typers.scala:3353)
    at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:3367)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$tryTypedApply$1$1.apply(Typers.scala:4404)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$tryTypedApply$1$1.apply(Typers.scala:4404)
    at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:689)
    at scala.tools.nsc.typechecker.Typers$Typer.tryTypedApply$1(Typers.scala:4404)
    at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4449)
    at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4484)
    at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5242)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5259)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5295)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5322)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5269)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5273)
    at scala.tools.nsc.typechecker.Typers$Typer.typedArg(Typers.scala:3094)
    at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$class.typedArgWithFormal$1(PatternTypers.scala:112)
    at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$$anonfun$2.apply(PatternTypers.scala:115)
    at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$$anonfun$2.apply(PatternTypers.scala:115)
    at scala.runtime.Tuple2Zipped$$anonfun$map$extension$1.apply(Tuple2Zipped.scala:42)
    at scala.runtime.Tuple2Zipped$$anonfun$map$extension$1.apply(Tuple2Zipped.scala:40)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.runtime.Tuple2Zipped$.map$extension(Tuple2Zipped.scala:40)
    at scala.tools.nsc.typechecker.PatternTypers$PatternTyper$class.typedArgsForFormals(PatternTypers.scala:115)
    at scala.tools.nsc.typechecker.Typers$Typer.typedArgsForFormals(Typers.scala:107)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$handleMonomorphicCall$1(Typers.scala:3384)
    at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:3409)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$tryTypedApply$1$1.apply(Typers.scala:4404)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$tryTypedApply$1$1.apply(Typers.scala:4404)
    at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:676)
    at scala.tools.nsc.typechecker.Typers$Typer.tryTypedApply$1(Typers.scala:4404)
    at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4449)
    at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4484)
    at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5242)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5259)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5295)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5322)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5269)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5273)
    at scala.tools.nsc.typechecker.Typers$Typer.typedAssign$1(Typers.scala:4136)
    at scala.tools.nsc.typechecker.Typers$Typer.typedOutsidePatternMode$1(Typers.scala:5223)
    at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5252)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5259)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5295)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5322)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5269)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5273)
    at scala.tools.nsc.typechecker.Typers$Typer.typedBlock(Typers.scala:2341)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedOutsidePatternMode$1$1.apply(Typers.scala:5217)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$typedOutsidePatternMode$1$1.apply(Typers.scala:5217)
    at scala.tools.nsc.typechecker.Typers$Typer.typedOutsidePatternMode$1(Typers.scala:5216)
    at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5252)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5259)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5295)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5322)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5269)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5273)
    at scala.tools.nsc.typechecker.Typers$Typer.transformedOrTyped(Typers.scala:5504)
    at scala.tools.nsc.typechecker.Typers$Typer.typedDefDef(Typers.scala:2167)
    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5207)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5258)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5295)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5322)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5269)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5273)
    at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5351)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2977)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$60.apply(Typers.scala:3081)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$60.apply(Typers.scala:3081)
    at scala.collection.immutable.List.loop$1(List.scala:172)
    at scala.collection.immutable.List.mapConserve(List.scala:188)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3081)
    at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1880)
    at scala.tools.nsc.typechecker.Typers$Typer.typedClassDef(Typers.scala:1721)
    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5208)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5258)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5295)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5322)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5269)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5273)
    at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5351)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2977)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$60.apply(Typers.scala:3081)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$60.apply(Typers.scala:3081)
    at scala.collection.immutable.List.loop$1(List.scala:172)
    at scala.collection.immutable.List.mapConserve(List.scala:188)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3081)
    at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:4918)
    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5211)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5258)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5295)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5322)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5269)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5273)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5347)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:102)
    at scala.tools.nsc.Global$GlobalPhase$$anonfun$applyPhase$1.apply$mcV$sp(Global.scala:428)
    at scala.tools.nsc.Global$GlobalPhase.withCurrentUnit(Global.scala:419)
    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:428)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:94)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:93)
    at scala.collection.Iterator$class.foreach(Iterator.scala:743)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1195)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:93)
    at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1338)
    at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1325)
    at scala.tools.nsc.Global$Run.compileSources(Global.scala:1320)
    at scala.tools.nsc.Global$Run.compile(Global.scala:1418)
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:116)
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:95)
    at xsbt.CompilerInterface.run(CompilerInterface.scala:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:101)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:47)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:41)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply$mcV$sp(AggressiveCompile.scala:97)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:97)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:97)
    at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:162)
    at sbt.compiler.AggressiveCompile$$anonfun$3.compileScala$1(AggressiveCompile.scala:96)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:139)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:86)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:38)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:36)
    at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:31)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:39)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:38)
    at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:66)
    at sbt.inc.Incremental$.compile(Incremental.scala:38)
    at sbt.inc.IncrementalCompile$.apply(Compile.scala:26)
    at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:153)
    at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:70)
    at sbt.compiler.AggressiveCompile.apply(AggressiveCompile.scala:45)
    at sbt.Compiler$.apply(Compiler.scala:74)
    at sbt.Compiler$.apply(Compiler.scala:65)
    at sbt.Defaults$.sbt$Defaults$$compileTaskImpl(Defaults.scala:777)
    at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:769)
    at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:769)
    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:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    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:262)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Edit: After erasing and commenting out lots of files I simplified it to this:

case class A(x: String)
case class B(a: A, y: String)
class C(var b: B) {
  def a = b.a
  b.copy(a = a.copy())
}

Edit2: Best I can tell is that there isn't a good option for this, I am going to move on, I filed a bug report for this issue (SI-9035). If anyone knows of the option / way to do this please post an answer! In the meantime I will just continue to use the method I have been using since 2.6: erase files and comment out lines until I get it down to a minimum example and submit a bug report. Thanks for the ideas.

soc
  • 27,983
  • 20
  • 111
  • 215
BenjaminJackman
  • 1,439
  • 1
  • 10
  • 18
  • Is this a new failure? Can you try bisecting your commit history since the last known-compilable commit and then viewing the diff should indicate a changed source file that's causing it. – Daenyth Dec 08 '14 at 18:40
  • No, Unfortunately I can't take that approach because I am upgrading a very large existing project from 2.10 to 2.11, the project goes back several years. – BenjaminJackman Dec 08 '14 at 18:59
  • Does it generate any classfiles successfuly? They might help you in isolating the problem. – v6ak Dec 08 '14 at 19:28
  • I have gotten pretty far in isolating it by erasing files and commenting stuff out, I have got it down to one file at this point, I am really wondering if there is an option to scalac that will tell me what file it was processing when it threw the NPE. – BenjaminJackman Dec 08 '14 at 19:38
  • How about putting this within try / catch block? – Ashalynd Dec 08 '14 at 19:50
  • Probably adding `set scalacOptions in Compile += "-verbose"`? (assuming this is not in the test classes) – Gábor Bakos Dec 08 '14 at 19:59
  • @Ashalynd This is a compiler crash, i don't have access to the scalac compiler source – BenjaminJackman Dec 08 '14 at 20:11
  • @KingCub - Everyone has access to the scalac compiler source! It's open source. Just `git clone https://github.com/scala/scala.git`. – Rex Kerr Dec 08 '14 at 20:17
  • @RexKerr I am aware I can build the compiler from scratch, I have done so in the past, what I was trying to say is that I don't have access to the compiler source in my project. Having to recompile the entire scala compiler to track down what file it was processing when it crashed when compiling a scala file should not be necessary. – BenjaminJackman Dec 08 '14 at 20:39
  • @BenjaminJackman Fair enough, but "I don't have access to the scalac compiler source" isn't the way to express the very reasonable idea that you don't want to have to modify the source to find out which part of your code base is making the compiler crash! You wouldn't want to have to fiddle with compiler source even if it _was_ part of your project! (But unless you're programming on a smartphone, compiling the compiler isn't a big deal: set it up, go get lunch, and it'll be done long before you're back. Finding the place in the compiler's code base to change something helpful is the hard bit.) – Rex Kerr Dec 08 '14 at 21:14
  • There is a plethora of scala compiler options to print what it is doing http://paulbutcher.com/2010/04/26/scala-compiler-advanced-options/ . Have you tried any of those? – Adam Gent Dec 08 '14 at 21:23
  • possible duplicate of [How can I work around a Scala compiler crash?](http://stackoverflow.com/questions/8108127/how-can-i-work-around-a-scala-compiler-crash) – Owen Dec 08 '14 at 21:50
  • I don't think it's a duplicate - that question asks how to work around it, this one is asking how to find the source file causing the crash. – Daenyth Dec 10 '14 at 19:59

1 Answers1

2

In this case -verbose indicates it's done with phase packageobjects, and -Xshow-phases says typer is next. (Parser reports what it just parsed.)

-Ytyper-debug emits reams of generally inscrutable output, but shows what is undergoing typechecking.

That information can at least help your next search or gitter question.

Something like:

|    |    |-- b.copy(a = a.copy()) EXPRmode (site: method f in C) 
|    |    |    |-- b.copy BYVALmode-EXPRmode-FUNmode-POLYmode (silent: method f in C) 
|    |    |    |    |-- b EXPRmode-POLYmode-QUALmode (silent: method f in C) 
|    |    |    |    |    \-> nope.B
|    |    |    |    \-> (a: nope.A, y: String)nope.B
|    |    |    |-- qual$1 EXPRmode-POLYmode-QUALmode (silent: method f in C) 
|    |    |    |    \-> qual$1.type (with underlying type nope.B)
|    |    |    |-- (a: nope.A, y: String)nope.B EXPRmode-FUNmode-POLYmode-TAPPmode (silent: method f in C) 
|    |    |    |    \-> (a: nope.A, y: String)nope.B
|    |    |    |-- a = a.copy() : pt=nope.A EXPRmode (silent: method f in C) 
|    |    |    |    |-- a EXPRmode-LHSmode (silent: method f in C) 
|    |    |    |    |    \-> nope.A
|    |    |    |    |-- C.this.a_$eq(a.copy()) : pt=nope.A EXPRmode (silent: method f in C) 
|    |    |    |    |    |-- C.this.a_$eq BYVALmode-EXPRmode-FUNmode-POLYmode (silent: method f in C) 
|    |    |    |    |    |    \-> <error>
|    |    |    |    |    |-- a.copy() : pt=<error> EXPRmode (silent: method f in C) 
|    |    |    |    |    |    |-- a.copy BYVALmode-EXPRmode-FUNmode-POLYmode (silent: method f in C) 
|    |    |    |    |    |    |    |-- a EXPRmode-POLYmode-QUALmode (silent: method f in C) 
|    |    |    |    |    |    |    |    \-> nope.A
|    |    |    |    |    |    |    \-> (x: String)nope.A
|    |    |    |    |    |    |-- qual$2 EXPRmode-POLYmode-QUALmode (silent: method f in C) 
|    |    |    |    |    |    |    \-> qual$2.type (with underlying type nope.A)
|    |    |    |    |    |    |-- (x: String)nope.A EXPRmode-FUNmode-POLYmode-TAPPmode (silent: method f in C) 
|    |    |    |    |    |    |    \-> (x: String)nope.A
|    |    |    |    |    |    \-> nope.A
|    |    |    |    |    \-> <error>
|    |    |    |    \-> <error>
error: java.lang.NullPointerException
    at scala.tools.nsc.typechecker.Typers$Typer.noExpectedType$1(Typers.scala:3464)

might lead you to search for any bugs with "named arguments", such as this open bug; not your crasher, but similar players.

When the compiler "aborts", it offers more useful information than when it full-on crashes.

som-snytt
  • 39,429
  • 2
  • 47
  • 129
  • With a 200K+ LOC codebase which is where this bug occurred, reams is an understatement. In this case, the output wouldn't help me to do the first step which is trying to isolate the issue to a file. It would be very helpful if the compiler could output the file name to help narrow the search. Unfortunately it doesn't show the filename it was looking at when it crashed, which it just should do by default (should not even require an option to be enabled). – BenjaminJackman Sep 17 '15 at 23:21