scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Fragile initialization of runtime reflection universe, forces a large graph #10903

Open lrytz opened 6 years ago

lrytz commented 6 years ago

Diagnosis of https://github.com/scala/scala/pull/6676/files#diff-04841eeda02f00638b4cda505dbeafbeR766

Definitions.init carefully forces core types in a specific order (e.g., first load the scala package, then create synthetic members such as Nothing). See this epic comment in JavaUniverse.init().

In reality ObjectClass.initialize already forces the scala package. Object has no parent class, so the ClassfileParser / FromJavaClassCompleter use definitions.AnyClass in this case, which is defined as enterNewClass(ScalaPackageClass, tpnme.Any, Nil, ABSTRACT).

Not sure where to break the cycle. Completing the scala package needs the synthetic scala.Nothing, but adding it requires the package to be completed. Suggestions welcome.

retronym commented 6 years ago

Maybe the package loader should be responsible for adding the synthetics like Nothing to the scala package, rather than trying to do it externally.

lrytz commented 6 years ago

Here's a prototype that works, but it's pretty un-pretty... https://github.com/scala/scala/compare/2.13.x...lrytz:t10903?expand=1

Need to be really careful not to force stuff.

retronym commented 6 years ago

Seems no worse than what we’ve tried already. Would be good to make it self checking somehow, ie make it a hard failure if things are forced sooner that we expect. Not sure how to make that reality though.