Any info out there on migrating a Scala 2.9 compiler plugin to 2.10?
Asked Answered
S

1

16

I have a Scala 2.9 compiler plugin (source code) and works just fine in 2.9 but does not even compile with 2.10. There are dozens (maybe 100+) of errors all of the same kind such as:

    [scalac] C:\***.scala:31: error: illegal cyclic reference involving class Global
    [scalac]   val fileSeparator = System.getProperty("file.separator");
    [scalac]                       ^

... that eventually terminate with:

    [scalac] scala.reflect.internal.Types$TypeError: illegal cyclic reference involving class Global
    [scalac]     at scala.reflect.internal.Types$class.defineBaseClassesOfCompoundType(Types.scala:1731)
    [scalac]     at scala.reflect.internal.SymbolTable.defineBaseClassesOfCompoundType(SymbolTable.scala:12)
    [scalac]     at scala.reflect.internal.Types$CompoundType.baseClasses(Types.scala:1581)
    [scalac]     at scala.reflect.internal.Types$TypeRef.baseClasses(Types.scala:2369)
    [scalac]     at scala.reflect.internal.Types$SimpleTypeProxy$class.baseClasses(Types.scala:248)
    [scalac]     at scala.reflect.internal.Types$SingletonType.baseClasses(Types.scala:1292)
    [scalac]     at scala.reflect.internal.Types$Type.findMembers(Types.scala:1058)
    [scalac]     at scala.reflect.internal.Types$Type.membersBasedOnFlags(Types.scala:683)
    [scalac]     at scala.reflect.internal.Types$Type.implicitMembers(Types.scala:637)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.collect$1(Contexts.scala:630)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.collectImplicitImports(Contexts.scala:642)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:670)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Contexts$Context.implicitss(Contexts.scala:675)
    [scalac]     at scala.tools.nsc.typechecker.Implicits$ImplicitSearch.bestImplicit(Implicits.scala:1378)
    [scalac]     at scala.tools.nsc.typechecker.Implicits$class.inferImplicit(Implicits.scala:82)
    [scalac]     at scala.tools.nsc.Global$$anon$1.inferImplicit(Global.scala:490)
    [scalac]     at scala.tools.nsc.typechecker.Implicits$class.inferImplicit(Implicits.scala:37)
    [scalac]     at scala.tools.nsc.Global$$anon$1.inferImplicit(Global.scala:490)
    [scalac]     at scala.tools.nsc.typechecker.Typers$Typer.hasImport$1(Typers.scala:764)
    [scalac]     at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$action$1(Typers.scala:766)
    [scalac]     at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$checkFeature$1.apply$mcV$sp(Typers.scala:788)
    [scalac]     at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$apply$1.apply(Analyzer.scala:100)
    [scalac]     at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$apply$1.apply(Analyzer.scala:100)
    [scalac]     at scala.collection.immutable.List.foreach(List.scala:309)
    [scalac]     at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    [scalac]     at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
    [scalac]     at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:100)
    [scalac]     at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:461)
    [scalac]     at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:90)
    [scalac]     at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:90)
    [scalac]     at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    [scalac]     at scala.collection.AbstractIterator.foreach(Iterator.scala:1156)
    [scalac]     at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:90)
    [scalac]     at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1574)
    [scalac]     at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1548)
    [scalac]     at scala.tools.nsc.Global$Run.compileSources(Global.scala:1544)
    [scalac]     at scala.tools.nsc.Global$Run.compile(Global.scala:1654)
    [scalac]     at scala.tools.ant.Scalac.executeInternal(Scalac.scala:699)
    [scalac]     at scala.tools.ant.Scalac.execute(Scalac.scala:647)
    ...

I need some info or help as to what has changed in 2.10 or how to otherwise deal with this... I tried Googling around and looking in forums but found very little information on this subject.

Will be grateful for any help!

EDIT: Additional info. This is obviously using ant task (see stack trace). That task has been defined:

    <taskdef resource="scala/tools/ant/antlib.xml">
        <classpath>
          <pathelement location=".../scala-library.jar"   />
          <pathelement location=".../scala-reflect.jar"   />
          <pathelement location=".../scala-compiler.jar"  />
        </classpath>
    </taskdef>

EDIT 2: More additional info: I managed to get this plugin to compile (did not run it yet as other things failed) using command-line 2.10 compiler (remember - all is fine in 2.9 world) - ant-based build continues to fail the same way (bug?). I had to make two changes. First deals with varargs. There is a method such as:

    def foo(arg: String*) { ... }

There is another method which is effectively a synonym for it ad was written in 2.9 Scala as:

    def bar = foo _;

I had to change this to the following to get it to work:

    def bar(arg: String*) = foo(arg: *);

Another dealt with 'hasAssignedAnnotations' not being present in ValOrDefDef.symbol any more (I just commented that out to get it to compile, not a real fix).

Again, does anyone know of a web site or a document out there that can help me with migration - i.e. what changed from 2.9 to 2.10 in terms that I need, including compiler plugins.

Thanks!

Swansdown answered 16/1, 2013 at 20:26 Comment(4)
Just guessing, maybe there is a new shadowing of symbol System in the 2.10 compiler. In 2.10, you can also use sys.props("file.separator"), might fix that error.Galwegian
The error appears on many lines that are very different and do not seem to be related at all. The one I included here is just an example.Swansdown
Do you have a link to your sources?Galwegian
Not open source. They belong to the company I work form, can't reveal.Swansdown
L
2

I do not think there is any usable documentation. If I remember correctly Martin Odersky said in this presentation that more than 1000 files were edited. For 2.10 they have rewritten large parts of the compiler to support better reflection. As a side effect macros popped into existence. The other side effect of course is that a lot of compiler plugins stopped working.

In theory you could browse / search the git history of the scala source code, in practice this will most likely be too time consuming. Some compiler plugins have been converted to macro's, as they are a bit easier to ship. I don't know if this is an option for you.

Your best bet might be to look at the changes made to plugins that are shipped with scala. I found this commit (The new reflection - Showing 190 changed files with 9,001 additions and 6,403 deletions) of the continuations plugin that contains a lot of information and changes. I hope this is of any help.

Loaning answered 18/2, 2013 at 22:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.