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

Fix #415: Report usage positions of missing definitions when linking #2069

Conversation

WojciechMazur
Copy link
Contributor

This PR adds aggregation of missing definitions with their usage positions when performing static reachability phase.
Currently, when some definition is missing, we would result in a single exception due to usage of Map.apply which does not contain any greater context.
Thanks to this PR we would get list of all missing definitions with places of their usage, eg.:

    [error] Found 2 missing definitions while linking
    [error] Not found Top(java.time.Instant$)
    [error] 	at <project_dir>/javalib/src/main/scala/java/nio/file/attribute/FileTime.scala:9
    [error] Not found Top(java.util.Locale$)
    [error] 	at <project_dir>/javalib/src/main/scala/java/lang/String.scala:11
    [error] 	at <project_dir>/javalib/src/main/scala/java/lang/String.scala:43
    [error] 	at <project_dir>/javalib/src/main/scala/java/text/DateFormatSymbols.scala:28
    [error] 	at <project_dir>/javalib/src/main/scala/java/text/DecimalFormat.scala:60
    [error] 	at <project_dir>/javalib/src/main/scala/java/util/Formatter.scala:6
    [error] 	at <project_dir>/javalib/src/main/scala/java/util/Formatter.scala:45
    [error] 	at <project_dir>/javalib/src/main/scala/java/util/Formatter.scala:53
    [error] stack trace is suppressed; run last tests / Test / nativeLink for the full output
    [error] (tests / Test / nativeLink) scala.scalanative.linker.Reach$ReachabilityFailureException: Undefined definitions found in reachability phase

Resolves #415

Copy link
Collaborator

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

This is cool :)

extends RuntimeException(msg)
with NoStackTrace
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see a reason for NoStackTrace here. NoStackTrace is useful for exceptions thrown in non-failure paths, which must therefore be fast to initialize. This is not the case here.

Perhaps you wanted to avoid the stack trace to be displayed in the sbt shell? If that's the case, then there is a better solution: the sbt plugin should catch the exception and wrap it in a MessageOnlyException.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, consider extending Exception rather than RuntimeException. Or better: don't we have a generic LinkingException somewhere? If not, maybe we should define one.

tools/src/main/scala/scala/scalanative/linker/Reach.scala Outdated Show resolved Hide resolved
tools/src/main/scala/scala/scalanative/linker/Reach.scala Outdated Show resolved Hide resolved
@sjrd sjrd changed the title Report usage positions of missing definitions when linking Fix #415: Report usage positions of missing definitions when linking Dec 17, 2020
@sjrd sjrd merged commit 199c7d5 into scala-native:master Dec 17, 2020
@WojciechMazur WojciechMazur deleted the feature/rachability_reports_missing_links_pos branch February 15, 2021 09:09
ekrich pushed a commit to ekrich/scala-native that referenced this pull request May 21, 2021
…hen linking (scala-native#2069)

This commit adds aggregation of missing definitions with their
usage positions when performing the reachability analysis.

Previously, when some definition was missing, we would result in a
single exception without any context. 

Now, we get a list of all the missing definitions, with the places
of their usage. For example:

    [error] Found 2 missing definitions while linking
    [error] Not found Top(java.time.Instant$)
    [error] 	at <project_dir>/javalib/src/main/scala/java/nio/file/attribute/FileTime.scala:9
    [error] Not found Top(java.util.Locale$)
    [error] 	at <project_dir>/javalib/src/main/scala/java/lang/String.scala:11
    [error] 	at <project_dir>/javalib/src/main/scala/java/lang/String.scala:43
    [error] 	at <project_dir>/javalib/src/main/scala/java/text/DateFormatSymbols.scala:28
    [error] 	at <project_dir>/javalib/src/main/scala/java/text/DecimalFormat.scala:60
    [error] 	at <project_dir>/javalib/src/main/scala/java/util/Formatter.scala:6
    [error] 	at <project_dir>/javalib/src/main/scala/java/util/Formatter.scala:45
    [error] 	at <project_dir>/javalib/src/main/scala/java/util/Formatter.scala:53
    [error] stack trace is suppressed; run last tests / Test / nativeLink for the full output
    [error] (tests / Test / nativeLink) scala.scalanative.linker.Reach$ReachabilityFailureException: Undefined definitions found in reachability phase
WojciechMazur added a commit to WojciechMazur/scala-native that referenced this pull request Aug 25, 2021
…hen linking (scala-native#2069)

This commit adds aggregation of missing definitions with their
usage positions when performing the reachability analysis.

Previously, when some definition was missing, we would result in a
single exception without any context. 

Now, we get a list of all the missing definitions, with the places
of their usage. For example:

    [error] Found 2 missing definitions while linking
    [error] Not found Top(java.time.Instant$)
    [error] 	at <project_dir>/javalib/src/main/scala/java/nio/file/attribute/FileTime.scala:9
    [error] Not found Top(java.util.Locale$)
    [error] 	at <project_dir>/javalib/src/main/scala/java/lang/String.scala:11
    [error] 	at <project_dir>/javalib/src/main/scala/java/lang/String.scala:43
    [error] 	at <project_dir>/javalib/src/main/scala/java/text/DateFormatSymbols.scala:28
    [error] 	at <project_dir>/javalib/src/main/scala/java/text/DecimalFormat.scala:60
    [error] 	at <project_dir>/javalib/src/main/scala/java/util/Formatter.scala:6
    [error] 	at <project_dir>/javalib/src/main/scala/java/util/Formatter.scala:45
    [error] 	at <project_dir>/javalib/src/main/scala/java/util/Formatter.scala:53
    [error] stack trace is suppressed; run last tests / Test / nativeLink for the full output
    [error] (tests / Test / nativeLink) scala.scalanative.linker.Reach$ReachabilityFailureException: Undefined definitions found in reachability phase
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.

Position of unresolved links
2 participants