Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scalac fails to compile its library when source files were reordered #7335

Closed
scabug opened this issue Apr 5, 2013 · 9 comments
Closed

scalac fails to compile its library when source files were reordered #7335

scabug opened this issue Apr 5, 2013 · 9 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Apr 5, 2013

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.

@scabug
Copy link
Author

scabug commented Apr 5, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7335?orig=1
Reporter: Tobias Roeser (lefou)
Affected Versions: 2.11.0-M2
Attachments:

@scabug
Copy link
Author

scabug commented Apr 6, 2013

@lrytz said:
relevant commits

scala/scala@c5441dc

scala/scala@fa63170

scala/scala#968

@scabug
Copy link
Author

scabug commented Apr 6, 2013

@retronym said:
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

@scabug
Copy link
Author

scabug commented Apr 6, 2013

@lrytz said:
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.

@scabug
Copy link
Author

scabug commented Apr 6, 2013

@retronym said (edited on Apr 6, 2013 9:31:08 PM UTC):
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

@scabug
Copy link
Author

scabug commented Apr 6, 2013

@retronym said:
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.

@scabug
Copy link
Author

scabug commented Apr 6, 2013

@retronym said:
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.

@scabug
Copy link
Author

scabug commented Apr 7, 2013

@scabug
Copy link
Author

scabug commented Apr 8, 2013

@retronym said:
scala/scala#2368

@scabug scabug closed this as completed Apr 16, 2013
@scabug scabug added the has PR label Apr 7, 2017
@scabug scabug added this to the 2.11.0-M3 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants