Skip to content

[Dependency Scanning] Refactor the scanner to simplify layering #82429

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 2 commits into from
Jun 25, 2025

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Jun 23, 2025

  • Refactor ModuleDependenciesCache to not hold a reference to the global SwiftDependencyScanningService
    While this made sense in the distant past where the scanning service provided backing storage for the dependency cache, it no longer does so and now makes for awkward layering where clients get at the service via the cache. Now the cache is a simple data structure while all the clients that need access to the scanning service will get it explicitly.

  • Refactor Swift Scanner loader to be standalone

    • SwiftModuleScanner will now be owned directly by the ModuleDependencyScanningWorker and will contain all the necessary custom module query logic, instead of being instantiated by the module interface loader for each query.
    • Top-level ModuleLoader no longer needs to have virtual API for this functionality.
  • Move ownership over module output path and sdk module output path directly into the scanning worker, instead of the cache.

@artemcm artemcm force-pushed the ScannerInvalidBinaryModuleRefactor branch from 0723261 to c094bb7 Compare June 23, 2025 20:32
artemcm added 2 commits June 23, 2025 13:39
- 'SwiftModuleScanner' will now be owned directly by the 'ModuleDependencyScanningWorker' and will contain all the necessary custom logic, instead of being instantiated by the module interface loader for each query
- Moves ownership over module output path and sdk module output path directly into the scanning worker, instead of the cache
…a reference to the global 'SwiftDependencyScanningService'

While this made sense in the distant past where the scanning service provided backing storage for the dependency cache, it no longer does so and now makes for awkard layering where clients get at the service via the cache. Now the cache is a simple data structure while all the clients that need access to the scanning service will get it explicitly.
@artemcm artemcm force-pushed the ScannerInvalidBinaryModuleRefactor branch from c094bb7 to 39c096c Compare June 23, 2025 20:40
@artemcm
Copy link
Contributor Author

artemcm commented Jun 23, 2025

@swift-ci test

Copy link
Contributor

@cachemeifyoucan cachemeifyoucan left a comment

Choose a reason for hiding this comment

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

LGTM with a small comment.

@@ -992,7 +992,7 @@ class SwiftDependencyScanningService {
std::shared_ptr<llvm::cas::ActionCache> ActionCache;

/// File prefix mapper.
std::unique_ptr<llvm::PrefixMapper> Mapper;
std::shared_ptr<llvm::PrefixMapper> Mapper;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be moved to worker? I feel like this should be shared, probably only here due to some unfortunate layering too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I didn't move it to the worker here is because ExplicitModuleDependencyResolver uses the prefix mapper and doesn't have access to the ModuleDependencyScanner or its associated workers, unfortunately.

Copy link
Contributor

Choose a reason for hiding this comment

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

Resolver holds an instance. We can totally rebuild the map from a CompilerInstance and we should probably do that to fully decouple the layering.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can maybe even use the CAS from the instance, if that is possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@artemcm artemcm merged commit 705b1a6 into swiftlang:main Jun 25, 2025
5 checks passed
@artemcm artemcm deleted the ScannerInvalidBinaryModuleRefactor branch June 25, 2025 16:03
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