Skip to content

[Explicit Module Builds] Introduce an InterModuleDependencyOracle abstraction for tracking and sharing dependency scanning results #356

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 8 commits into from
Dec 15, 2020

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Nov 11, 2020

This PR refactors the handling of inter-module dependencies to centralize their handling in a new, reference-type, oracle.

InterModuleDependencyOracle will now be responsible for responding to queries about dependencies of a given module.
The intent behind it is to abstract the actual mechanism used for tracking/computing/caching inter-module dependencies. A single oracle reference is intended to be passed around to multiple Driver invocations, corresponding to different targets, by build-system clients (e.g. SwiftPM), replacing today's use of ModuleInfoMap-based API, to communicate already-computed dependency-scan results.

As implemented, it is a simple store of ModuleInfo value objects, which a Driver invocation populates by invoking a -scan-dependencies job; not unlike passing around an accumulating ModuleInfoMap.
In the future, the oracle's internal implementation may be replaced with a direct dependency-scanner library access, without having to break the clients' API.

There will be a followup PR to cleanup some of the shims required to ensure that this does not break the API currently used by SwiftPM.

Corresponding PR to adapt this API in SwiftPM: swiftlang/swift-package-manager#3042

Resolves rdar://71209183

@artemcm
Copy link
Contributor Author

artemcm commented Nov 11, 2020

@swift-ci please test

Copy link
Contributor

@cltnschlosser cltnschlosser left a comment

Choose a reason for hiding this comment

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

Seems like a clear win for users of libSwiftDriver (SPM).

Any negative here when trying to do explicit module builds solely from the command line? Didn't seem like it, but I don't know enough about how this works to tell.

@artemcm
Copy link
Contributor Author

artemcm commented Nov 11, 2020

Thank you for taking a look, @cltnschlosser, and for your suggestions.

Any negative here when trying to do explicit module builds solely from the command line? Didn't seem like it, but I don't know enough about how this works to tell.

This does not make a difference to command line builds today; but, it does open up a possibility for the future to no longer have the driver launch -scan-dependencies jobs, instead talking to the dependency scanner directly via a library that the oracle will wrap.

@artemcm
Copy link
Contributor Author

artemcm commented Nov 11, 2020

@swift-ci please test

1 similar comment
@artemcm
Copy link
Contributor Author

artemcm commented Nov 11, 2020

@swift-ci please test

@artemcm artemcm marked this pull request as ready for review November 11, 2020 18:43
@artemcm
Copy link
Contributor Author

artemcm commented Dec 3, 2020

@swift-ci please test

@artemcm
Copy link
Contributor Author

artemcm commented Dec 10, 2020

@DougGregor @nkcsgexi ping for a review.
This PR includes a bunch of shims/adaptors to ensure that the API currently in-use by SwiftPM continues working, but it would be nice to get this in to help with the transition to:
swiftlang/swift#34786

@artemcm
Copy link
Contributor Author

artemcm commented Dec 10, 2020

@swift-ci please test

/// An abstraction of a cache and query-engine of inter-module dependencies
public class InterModuleDependencyOracle {
/// Query the ModuleInfo of a module with a given ID
@_spi(Testing) public func getModuleInfo(of moduleId: ModuleDependencyId) -> ModuleInfo? {
Copy link
Member

Choose a reason for hiding this comment

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

Should this class be made thread-safe? Clients may very well have multiple threads in which they create Driver instances that reference the same oracle...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I've added some basic thread-safety to it now, and will iterate on it as this type transitions to wrapping libSwiftScan.

…traction for tracking and sharing dependency scanning results

This PR refactors the handling of inter-module dependencies to centralize their handling in a new, reference-type, oracle.

`InterModuleDependencyOracle` will now be responsible for responding to queries about dependencies of a given module.
The intent behind it is to abstract the actual mechanism used for tracking/computing/caching inter-module dependencies. A single oracle reference is intended to be passed around to multiple Driver invocations, corresponding to different targets, by build-system clients (e.g. SwiftPM), replacing today's use of `ModuleInfoMap`-based API, to communicate already-computed dependency-scan results.

As implemented, it is a simple store of `ModuleInfo` value objects, which a `Driver` invocation populates by invoking a `-scan-dependencies` job; not unlike passing around an accumulating `ModuleInfoMap`.
In the future, the oracle's internal implementation may be replaced with a direct dependency-scanner library access, without having to break the clients' API.
… to operate on dependency graphs instead of querying the oracle
… with API currently used by SwiftPM to communicate external build artifacts
@artemcm
Copy link
Contributor Author

artemcm commented Dec 14, 2020

@swift-ci please test

@artemcm artemcm merged commit 7055a62 into swiftlang:main Dec 15, 2020
@artemcm artemcm deleted the DependencyOracle branch January 20, 2021 19:02
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