scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Package objects extending traits can crash multi-stage compilation

Open WojciechMazur opened this issue 3 years ago • 2 comments

Regression reproduced based on Open CB #4757 found in vitaliihonta/scala-ql (maintainer @vitaliihonta ) In the original build all files defined in submodules or tests placed in the same package (scalaql) were failing with large amount of errors related to cyclic references.

Part of the #15949 regression tracker

Compiler version

Fails in 3.2.1-RC1 Works in 3.2.0

Minimized code

The order of files within the compilation unit is important to reproduce: Prefix ids combined with suffix unit id should allow to reproduce it in Vulpix 1st compilation unit:

// 1_syntax_1.scala
package scalaql.syntax

import scalaql.*

@forbiddenInheritance
trait ScalaqlSyntax
// 2_annotations_1.scala
package scalaql

import scala.annotation.StaticAnnotation

class forbiddenInheritance extends StaticAnnotation
// 3_package_1.scala
import scalaql.syntax.ScalaqlSyntax

package object scalaql extends ScalaqlSyntax

2nd compilation unit

// usage_2.scala
package scalaql

sealed trait Foo extends Product

Invocation:

scalac 1_syntax_1.scala 2_annotations_1.scala 3_package_1.scala 
scalac usage_2.scala 

Output

-- Error: usage_2.scala:3:25 -------------------------------------------------------------------------------------------------------------------
3 |sealed trait Foo extends Product
  |                         ^
  |                         Could not read definition of trait ScalaqlSyntax in ./scalaql/syntax/ScalaqlSyntax.class
  |                         An exception was encountered:
  |                           dotty.tools.dotc.core.CyclicReference: 
  |                         Run with -Ydebug-unpickling to see full stack trace.

Expectation

Should compile

WojciechMazur avatar Sep 06 '22 13:09 WojciechMazur

@KacperFKorban @nicolasstucki Do you think is a bisecting tool able to work with multi-stage compilation or can we adapt it. I'm worried mostly that checkouts between different commits would fail or overwrite local changes to bisect

WojciechMazur avatar Sep 06 '22 13:09 WojciechMazur

It can be reproduced without multi-stage, like so:

scalac -Ytest-pickler 1_syntax_1.scala 2_annotations_1.scala 3_package_1.scala 

So the only thing we would need is to handle scalac options in the bisect script, which should be doable. I'll try to do it this week.

KacperFKorban avatar Sep 07 '22 13:09 KacperFKorban

@KacperFKorban Any news on the bisection side?

odersky avatar Sep 25 '22 10:09 odersky

I tried bisecting it, but all I know at the moment it that:

Last good release: 3.2.1-RC1-bin-20220828-8a7c84c-NIGHTLY
First bad release: 3.2.1-RC1-bin-20220829-63344e7-NIGHTLY

So it was most likely introduced in https://github.com/lampepfl/dotty/pull/15877 But since some of the commits from that PR don't compile (most likely because of the large number of rebases) it's impossible to pinpoint the exact commit without manually fixing all of them and running the tests by hand.

KacperFKorban avatar Sep 25 '22 13:09 KacperFKorban

@KacperFKorban Thanks for getting this far! That was actually enough to figure it out.

odersky avatar Sep 25 '22 15:09 odersky