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 backtrace in classloading for unreachable symbols #3449

Merged

Conversation

WojciechMazur
Copy link
Contributor

This change modifies the scope of reachability analysis results to limit the scope of passed data, that is never used after classloading finishes (unavailable symbols and referenced from maps). It now returns either an UnreachableSymbolsFound containing only information required to correctly point to usages of unreachble symbols, and Result containing the full information required for later stages.

This change also adds better backtraces for unreachable symbols. For example for this snippet:

object Test {
  def main(args: Array[String]): Unit = {
    class Foo(x: Long) extends java.sql.Time(x)
    trait Bar { self: java.sql.Types => }
    class Baz extends java.sql.Types with Bar
    0.until(10).foreach { _ =>
      println(Foo(1))
      println(Baz())
    }
  }
}

we would now get following output:

[error] Found 4 unreachable symbols
[error] Found unknown type java.sql.Time, referenced from:
[error]       type at Test$Foo$1(Test.scala:4)
[error]     method at Test$.main$$anonfun$1(Test.scala:8)
[error]     method at Test$$$Lambda$1.apply$mcVI$sp(Test.scala:9)
[error]     method at Test$.main(Test.scala:9)
[error]     method at Test.main(Test.scala:2)
[error] 
[error] Found unknown constructor java.sql.Types(), referenced from:
[error]     constructor at Test$Baz$1()(Test.scala:6)
[error]          method at Test$.main$$anonfun$1(Test.scala:9)
[error]          method at Test$$$Lambda$1.apply$mcVI$sp(Test.scala:9)
[error]          method at Test$.main(Test.scala:9)
[error]          method at Test.main(Test.scala:2)
[error] 
[error] Found unknown type java.sql.Types, referenced from:
[error]       type at Test$Baz$1(Test.scala:6)
[error]     method at Test$.main$$anonfun$1(Test.scala:9)
[error]     method at Test$$$Lambda$1.apply$mcVI$sp(Test.scala:9)
[error]     method at Test$.main(Test.scala:9)
[error]     method at Test.main(Test.scala:2)
[error] 
[error] Found unknown constructor java.sql.Time(long), referenced from:
[error]     constructor at Test$Foo$1(long)(Test.scala:4)
[error]          method at Test$.main$$anonfun$1(Test.scala:8)
[error]          method at Test$$$Lambda$1.apply$mcVI$sp(Test.scala:9)
[error]          method at Test$.main(Test.scala:9)
[error]          method at Test.main(Test.scala:2)
[error] 
[info] Total (1508 ms)
[error] Unreachable symbols found after classloading run. It can happen when using dependencies not cross-compiled for Scala Native or not yet ported JDK definitions.

@WojciechMazur WojciechMazur merged commit 54901f5 into scala-native:main Aug 25, 2023
48 of 50 checks passed
@WojciechMazur WojciechMazur deleted the reach/better-stacktrace branch August 25, 2023 19:52
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.

None yet

1 participant