This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Compiler does not honor -Ystop option

1 reply
Oscar Forero 2
Joined: 2010-01-18,
User offline. Last seen 42 years 45 weeks ago.

Hello,

I am trying to upgrade the Scala Mojo extractor, it was fairly easy =
except for the one problem. The compiler does not appear to honor the =
stop option:

class MojoExtractorCompiler(project: MavenProject) extends =
MavenProjectTools with MojoExtractionInfo {
//Method to extract mojo description from a source file.
def extract(sourceFiles: String*): Seq[MojoDescriptor] =3D {
//helper method to initialize settings
def initialize: (Settings, Reporter) =3D {
val settings =3D new Settings();
//TODO - Set settings
settings.classpath.value =3D getCompileClasspathString(project)
// settings.stop.tryToSet(List("typer"))
settings.stop.value =3D List("typer")
println("TRACER: unparsing=3D " + settings.stop)
// settings.print.value =3D List("typer")
settings.noassertions.value =3D true
// val dirs =3D for(dir =E2=86=90 =
project.getCompileSourceRoots().asInstanceOf[java.util.List[String]]) =
yield dir
=
settings.sourcepath.tryToSet(project.getCompileSourceRoots().asInstanceOf[=
java.util.List[String]].toList)
settings.showPhases.value =3D true
val reporter =3D new ConsoleReporter(settings);
(settings, reporter)
}

//helper method to execute presentation compiler
def execute(settings: Settings, reporter: Reporter) =3D {
val compiler =3D new Global(settings, reporter) with =
MojoAnnotationExtractor {
//override def onlyPresentation =3D true
}
//Extract mojo description
def extractMojos(unit: compiler.CompilationUnit) =3D {
println("TRACER: extracting: " + unit)
for (info <- compiler.parseCompilationUnitBody(unit.body)) yield {
extractMojoDescriptor(info)
}
}

val run =3D new compiler.Run
println("TRACER: Typer phase: " + =
run.phaseNamed("parser").description)

// run.phaseNamed("parser").run
run.compile(sourceFiles.toList)
println("TRACER: Compiled up to phase: " + compiler.globalPhase)
for (unit <- run.units if !unit.isJava) yield {
extractMojos(unit)
}
}

val (settings, reporter) =3D initialize
println("TRACER: Classpath =3D " + settings.classpath)
execute(settings, reporter).toList.flatMap(x =3D> x)
}
}

setting the stop property to the typer with settings.stop.value =3D =
List("typer") results in:
[INFO] [INFO] Trace
[INFO] java.lang.AssertionError: assertion failed
[INFO] at scala.Predef$.assert(Predef.scala:79)
[INFO] at =
scala.tools.nsc.symtab.SymbolTable.phase_$eq(SymbolTable.scala:70)
[INFO] at =
scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:103)
[INFO] at =
scala.tools.nsc.Global$Run$$anonfun$scala$tools$nsc$Global$Run$$resetPacka=
geClass$1.apply(Global.scala:869)
[INFO] at =
scala.tools.nsc.Global$Run$$anonfun$scala$tools$nsc$Global$Run$$resetPacka=
geClass$1.apply(Global.scala:869)
[INFO] at =
scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:104)
[INFO] at =
scala.tools.nsc.Global$Run.scala$tools$nsc$Global$Run$$resetPackageClass(G=
lobal.scala:868)
[INFO] at =
scala.tools.nsc.Global$Run$$anonfun$compileSources$3.apply(Global.scala:77=
6)
[INFO] at =
scala.tools.nsc.Global$Run$$anonfun$compileSources$3.apply(Global.scala:77=
6)
[INFO] at scala.collection.Iterator$class.foreach(Iterator.scala:627)
[INFO] at =
scala.collection.Iterator$$anon$19.foreach(Iterator.scala:363)
[INFO] at scala.tools.nsc.Global$Run.compileSources(Global.scala:776)
[INFO] at scala.tools.nsc.Global$Run.compile(Global.scala:815)

It seems as if the phase was being set to NoPhase. Using other phases or =
the tryToSet method does not fail but when compiling it does not stop =
after the given phase and it finish in the terminal phase which is a =
problem for this code because the annotations are erased.

This was like that in 2.8.Beta1, I upgraded today to 2.8.RC1 and it has =
the same problem.

Using the option -Ystop in the compiler (through Maven) results in the =
same assertion error:

[ERROR] Caused by: java.lang.AssertionError: assertion failed
[INFO] at scala.Predef$.assert(Predef.scala:79)
[INFO] at =
scala.tools.nsc.symtab.SymbolTable.phase_$eq(SymbolTable.scala:70)
[INFO] at =
scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:103)
[INFO] at =
scala.tools.nsc.Global$Run$$anonfun$scala$tools$nsc$Global$Run$$resetPacka=
geClass$1.apply(Global.scala:869)
[INFO] at =
scala.tools.nsc.Global$Run$$anonfun$scala$tools$nsc$Global$Run$$resetPacka=
geClass$1.apply(Global.scala:869)
[INFO] at =
scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:104)
[INFO] at =
scala.tools.nsc.Global$Run.scala$tools$nsc$Global$Run$$resetPackageClass(G=
lobal.scala:868)
[INFO] at =
scala.tools.nsc.Global$Run$$anonfun$compileSources$3.apply(Global.scala:77=
6)
[INFO] at =
scala.tools.nsc.Global$Run$$anonfun$compileSources$3.apply(Global.scala:77=
6)
[INFO] at scala.collection.Iterator$class.foreach(Iterator.scala:627)
[INFO] at =
scala.collection.Iterator$$anon$19.foreach(Iterator.scala:363)
[INFO] at scala.tools.nsc.Global$Run.compileSources(Global.scala:776)
[INFO] at scala.tools.nsc.Global$Run.compile(Global.scala:815)
[INFO] at scala.tools.nsc.Main$.process(Main.scala:109)
[INFO] at scala.tools.nsc.Main$.main(Main.scala:123)
[INFO] at scala.tools.nsc.Main.main(Main.scala)

regards,

Oscar=

Oscar Forero 2
Joined: 2010-01-18,
User offline. Last seen 42 years 45 weeks ago.
Re: Compiler does not honor -Ystop option

Hello,

I found that this issue is really two different problems, one is that -Ystop is honored but it stops before the given phase not after. A possible solution will be to change the meaning of the option but I think the after version is more intuitive and it will be better to keep it.

The second problem is that if the stop is set to any phase before the typer then the line 869 in Global.scala will fail because the typer phase is not set (which is to be expected given the -Ystop option).

I created a solution for the first and a workaround? for the second, given the comment in the code that says "(not sure what this is needed for?)" I did not dare to remove it but just executed only when the typer phase has been set.

I am attaching the diff file as generated by Git, please let me know if it is worth anything. I now this is not an important issue but it was also a good way to get familiar with the code behind the magic.

Working on that I noticed that the takeWhile function from the collections was the reason of the issue, would be also practical to have one takeUntil just for symmetry?

regards,

Oscar

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland