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

Better error diagnostics for cyclic references #19408

Merged
merged 3 commits into from
Jan 11, 2024

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jan 10, 2024

We now suggest to compile with -explain-cyclic, in which case we give a trace of the forcings that led to the cycle.

The reason for the separate option is that maintaining a trace is not free so we should not be doing it by default.

We now suggest to compile with -explain-cyclic, in which case we
give a trace of the forcings that led to the cycle.

The reason for the separate option is that maintaining a trace is not
free so we should not be doing it by default.
@odersky
Copy link
Contributor Author

odersky commented Jan 10, 2024

I used this for #19398, which gave this:

-- [E046] Cyclic Error: tests/new/Test.scala:1:12 ------------------------------
1 |  def test: Option[Int] = Some(1)
  |            ^
  |Cyclic reference involving trait Seq
  |
  |The error occurred while trying to complete the info of method test
  |  which required to complete the info of class Option
  |  which required to read the definition of class Option in /Users/odersky/workspace/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/Option.tasty)
  |  which required to complete the info of type IterableOnce
  |  which required to read the definition of type IterableOnce in /Users/odersky/workspace/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/package.tasty)
  |  which required to complete the info of trait IterableOnce
  |  which required to read the definition of trait IterableOnce in /Users/odersky/workspace/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/IterableOnce.tasty)
  |  which required to compute the base classes of trait Seq
  |  which required to compute the base classes of trait Iterable
  |  which required to complete the info of trait Iterable
  |  which required to read the definition of trait Iterable in /Users/odersky/workspace/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/immutable/Iterable.tasty)
  |  which required to complete the info of trait Iterable
  |  which required to read the definition of trait Iterable in /Users/odersky/workspace/dotty/scala2-library-cc-tasty/../out/bootstrap/scala2-library-cc-tasty/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala2-library-cc-tasty_3-3.4.0-RC1-bin-SNAPSHOT.jar(scala/collection/Iterable.tasty)
  |  which required to compute the base classes of trait Seq
  |
  | Run with both -explain-cyclic and -Ydebug-cyclic to see full stack trace.
  |
  | longer explanation available when compiling with `-explain`
1 error found

After I turned the stacktrace on with -Ydebug-cyclic and correlated the two pieces of info, I found the root cause: It's because we now use more self types, which are annotated types, and which create a link back from Iterable to Seq when loading Tasty. I'll try to tweak things on the cc side so that the self types are not needed.

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, LGTM

val traceCycles = CyclicReference.isTraced
try
if traceCycles then
CyclicReference.pushTrace("complete the info of ", symbol, "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"complete the info of" will be shown to users with -explain-cyclic. This terminology might not be clear to them. Maybe it should be something along the lines of "computing the signature of"

@odersky odersky merged commit 16b26ad into scala:main Jan 11, 2024
19 checks passed
@odersky odersky deleted the cylic-reporting branch January 11, 2024 22:15
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
WojciechMazur added a commit that referenced this pull request Jun 28, 2024
)

Backports #19408 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants