Skip to content

[6.0 🍒][Dependency Scanning] Specify Source Locations For Missing Module Dependencies #73819

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

Merged
merged 1 commit into from
May 24, 2024

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented May 22, 2024

Cherry-pick of #73600

Explanation: This change modifies the dependency scanner to keep track of source locations of each encountered import statement, in order to be able to emit diagnostics with source locations if an import failed to resolve.

  • Keep track of each 'import' statement's source buffer, line number, and column number when adding it. The dependency scanner utilizes separate compilation instances, and therefore separate Source Managers for scanning import statements of user sources and textual interfaces of Swift dependencies. Since import resolution may happen in the main scanner compilation instance while the import itself was found by an interface-scanning sub-instance, we cannot simply hold on to the import's SourceLoc.
  • Add libSwiftScan API for diagnostics to carry above source locations to clients.

Now instead of un-locatable:

<unknown>0 error: Unable to find module dependency: 'Baz'

we will now get rich diagnostic output:

/.../test.swift:2:8: error: Unable to find module dependency: 'Baz'
 1 | import A
 2 | import Baz
   |        |- error: Unable to find module dependency: 'Baz'
   |        `- note: a dependency of main module 'test'
 3 | import C
 4 | import Baz
   |        `- note: also imported here

Risk: Low-Moderate. This only affects projects which use dependency scanning with Explicitly-Built Modules. The added locations are only used when emitting errors on already-failing compilations.

Testing: Automated tests added to the compiler and driver suite.
Reviewed By: @owenv @cachemeifyoucan @nkcsgexi

…endencies

This change modifies the dependency scanner to keep track of source locations of each encountered 'import' statement, in order to be able to emit diagnostics with source locations if an import failed to resolve.

- Keep track of each 'import' statement's source buffer, line number, and column number when adding it. The dependency scanner utilizes separate compilation instances, and therefore separate Source Managers for scanning `import` statements of user sources and textual interfaces of Swift dependencies. Since import resolution may happen in the main scanner compilation instance while the `import` itself was found by an interface-scanning sub-instance, we cannot simply hold on to the import's `SourceLoc`.
- Add libSwiftScan API for diagnostics to carry above source locations to clients.
@artemcm artemcm requested a review from a team as a code owner May 22, 2024 16:21
@artemcm
Copy link
Contributor Author

artemcm commented May 22, 2024

@artemcm artemcm requested a review from nkcsgexi May 22, 2024 17:15
Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

Thank you🎉!

@artemcm artemcm merged commit 7e434bc into swiftlang:release/6.0 May 24, 2024
5 checks passed
@artemcm artemcm deleted the 60DepScanSourceLocs branch May 24, 2024 17:55
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.

2 participants