Scala Programming Language
  1. Scala Programming Language
  2. SI-7335

scalac fails to compile its library when source files were reordered

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.11.0-M2
    • Fix Version/s: Scala 2.11.0-M3
    • Component/s: None
    • Environment:

      Gentoo Linux, 64 Bit
      java version "1.7.0_17"
      Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

      Description

      Scalac depends on order of given source files when compiling scala library. The build fails, if the sources are unordered but succeeds when sorted before.

      scalac is the current "starr" compiler. Its Bundle-Version is "2.11.0-20121228-195556-b7840d6b41".

      I found this issue, while doing some experiments of building scala with SBuild, a Scala based buildsystem (http://sbuild.tototec.de) instead of SABBUS (ant). I first used a version, were the source files are collected from the filesystem and are feeded to the compiler as-is (see attachment "scalac-args-unsorted"). I got the following error:

      /home/lefou/work/tototec/sbuild/build-foreign-project-examples/scala.git/src/library/scala/Predef.scala:72: error: illegal cyclic reference involving object Predef
      object Predef extends LowPriorityImplicits with DeprecatedPredef {
                            ^
      one error found
      

      Then, I sorted the source files alphabetically (see attachment "scalac-args-sorted"), and the error vanished.

      Note, that I can not produce the same issue with SABBUS, as it always collects the source files alphabetically sorted.

      1. scalac-args-sorted
        84 kB
        Tobias Roeser
      2. scalac-args-unsorted
        84 kB
        Tobias Roeser

        Activity

        Show
        Lukas Rytz added a comment - relevant commits https://github.com/scala/scala/commit/c5441dc https://github.com/scala/scala/commit/fa63170 https://github.com/scala/scala/pull/968
        Hide
        Jason Zaugg added a comment -

        I'm not able to reproduce:

        % java -Xmx1G -cp lib/scala-library.jar:lib/scala-reflect.jar:lib/scala-compiler.jar:lib/forkjoin.jar -Dscala.usejavacp=true scala.tools.nsc.Main @args.txt
        src/library/scala/SerialVersionUID.scala:15: warning: Implementation restriction: subclassing Classfile does not
        make your annotation visible at runtime.  If that is what
        you want, you must write the annotation class in Java.
        class SerialVersionUID(value: Long) extends scala.annotation.ClassfileAnnotation
              ^
        warning: there were 128 deprecation warnings; re-run with -deprecation for details
        warning: there were 5 feature warnings; re-run with -feature for details
        three warnings found
        
        % java -Xmx1G -cp lib/scala-library.jar:lib/scala-reflect.jar:lib/scala-compiler.jar:lib/forkjoin.jar -Dscala.usejavacp=true scala.tools.nsc.Main -version
        Scala compiler version 2.11.0-20121228-195556-b7840d6b41 -- Copyright 2002-2012, LAMP/EPFL
        
        % head -n25 args.txt
        -classpath
        target/locker/library/classes:target/forkjoin.jar:/home/lefou/.m2/repository/org/apache/ant/ant/1.8.4/ant-1.8.4.jar:target/locker/library/classes
        -d
        target/locker/library/classes
        -encoding
        UTF-8
        -target:jvm-1.6
        src/library/scala/Function3.scala
        src/library/scala/Console.scala
        src/library/scala/Product9.scala
        src/library/scala/PartialFunction.scala
        src/library/scala/Symbol.scala
        src/library/scala/Product1.scala
        src/library/scala/StringContext.scala
        src/library/scala/Product17.scala
        src/library/scala/Short.scala
        src/library/scala/Function14.scala
        src/library/scala/Product18.scala
        src/library/scala/Mutable.scala
        src/library/scala/Product10.scala
        src/library/scala/Product19.scala
        src/library/scala/Product8.scala
        src/library/scala/noinline.scala
        src/library/scala/Boolean.scala
        src/library/scala/Tuple3.scala
        
        Show
        Jason Zaugg added a comment - I'm not able to reproduce: % java -Xmx1G -cp lib/scala-library.jar:lib/scala-reflect.jar:lib/scala-compiler.jar:lib/forkjoin.jar -Dscala.usejavacp=true scala.tools.nsc.Main @args.txt src/library/scala/SerialVersionUID.scala:15: warning: Implementation restriction: subclassing Classfile does not make your annotation visible at runtime. If that is what you want, you must write the annotation class in Java. class SerialVersionUID(value: Long) extends scala.annotation.ClassfileAnnotation ^ warning: there were 128 deprecation warnings; re-run with -deprecation for details warning: there were 5 feature warnings; re-run with -feature for details three warnings found % java -Xmx1G -cp lib/scala-library.jar:lib/scala-reflect.jar:lib/scala-compiler.jar:lib/forkjoin.jar -Dscala.usejavacp=true scala.tools.nsc.Main -version Scala compiler version 2.11.0-20121228-195556-b7840d6b41 -- Copyright 2002-2012, LAMP/EPFL % head -n25 args.txt -classpath target/locker/library/classes:target/forkjoin.jar:/home/lefou/.m2/repository/org/apache/ant/ant/1.8.4/ant-1.8.4.jar:target/locker/library/classes -d target/locker/library/classes -encoding UTF-8 -target:jvm-1.6 src/library/scala/Function3.scala src/library/scala/Console.scala src/library/scala/Product9.scala src/library/scala/PartialFunction.scala src/library/scala/Symbol.scala src/library/scala/Product1.scala src/library/scala/StringContext.scala src/library/scala/Product17.scala src/library/scala/Short.scala src/library/scala/Function14.scala src/library/scala/Product18.scala src/library/scala/Mutable.scala src/library/scala/Product10.scala src/library/scala/Product19.scala src/library/scala/Product8.scala src/library/scala/noinline.scala src/library/scala/Boolean.scala src/library/scala/Tuple3.scala
        Hide
        Lukas Rytz added a comment -

        I'm quite sure the reason you cannot reproduce it is that you're using "usejavacp". The error only happens if there is no scala library on the classpath (at all) - that's why there's a "sourcepath" argument.

        Show
        Lukas Rytz added a comment - I'm quite sure the reason you cannot reproduce it is that you're using "usejavacp". The error only happens if there is no scala library on the classpath (at all) - that's why there's a "sourcepath" argument.
        Hide
        Jason Zaugg added a comment - - edited

        Gotcha. This fails:

        rm -rf target/locker/library/classes/scala &&                \
        > export LIB=build/pack/lib;                                   \
        > java -Xmx1G -cp $LIB/scala-library.jar:$LIB/scala-reflect.jar:$LIB/scala-compiler.jar:$LIB/forkjoin.jar \
        >   scala.tools.nsc.Main                                       \
        >    -classpath lib/forkjoin.jar:target/locker/library/classes \
        >    -sourcepath src/library                                   \
        >    -d target/locker/library/classes                          \
        >    src/library/scala/{Predef,LowPriorityImplicits}.scala
        src/library/scala/Predef.scala:72: error: illegal cyclic reference involving object Predef
        object Predef extends LowPriorityImplicits with DeprecatedPredef {
                              ^
        one error found
        
        Show
        Jason Zaugg added a comment - - edited Gotcha. This fails: rm -rf target/locker/library/classes/scala && \ > export LIB=build/pack/lib; \ > java -Xmx1G -cp $LIB/scala-library.jar:$LIB/scala-reflect.jar:$LIB/scala-compiler.jar:$LIB/forkjoin.jar \ > scala.tools.nsc.Main \ > -classpath lib/forkjoin.jar:target/locker/library/classes \ > -sourcepath src/library \ > -d target/locker/library/classes \ > src/library/scala/{Predef,LowPriorityImplicits}.scala src/library/scala/Predef.scala:72: error: illegal cyclic reference involving object Predef object Predef extends LowPriorityImplicits with DeprecatedPredef { ^ one error found
        Hide
        Jason Zaugg added a comment -

        It seems the correct fix here is to disable the automatic import or `scala.Predef._` in `LowPriorityImplicits.scala`, either by modifying `TreeInfo#noPredefImportForUnit`, or by simply merging the contents of that file into `Predef.scala`.

        I had thought that adding `{import scala.Predef.{_ => _}` at the top of LPI.scala would suffice, but I still hit the error.

        Show
        Jason Zaugg added a comment - It seems the correct fix here is to disable the automatic import or `scala.Predef._` in `LowPriorityImplicits.scala`, either by modifying `TreeInfo#noPredefImportForUnit`, or by simply merging the contents of that file into `Predef.scala`. I had thought that adding `{import scala.Predef.{_ => _}` at the top of LPI.scala would suffice, but I still hit the error.
        Hide
        Jason Zaugg added a comment -

        The addition of DeprecatedPredef in Predef.scala has exposed some flakiness in noPredefImportForUnit / firstDefinesClassOrObject; Predef.scala now imports Predef._.

        Assigning this ticket to myself, now i can see what's happening here.

        Show
        Jason Zaugg added a comment - The addition of DeprecatedPredef in Predef.scala has exposed some flakiness in noPredefImportForUnit / firstDefinesClassOrObject ; Predef.scala now imports Predef._ . Assigning this ticket to myself, now i can see what's happening here.
        Show
        Jason Zaugg added a comment - WIP: https://github.com/retronym/scala/compare/ticket/7335
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/2368

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Tobias Roeser
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development