-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Caching] Create clang importer from cc1 args directly #71118
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
[Caching] Create clang importer from cc1 args directly #71118
Conversation
@swift-ci please smoke test |
Currently, only enable the new code path when caching is enabled since it is quite a big behavior change. Caching build requires the change since its restricted file system will definitely alter the behavior for clang importer. For normal explicit module build, this will still help with less lookup during the actual compilation, but we can enable that later. |
c33cc0f
to
2212c98
Compare
@swift-ci please smoke test |
2212c98
to
c5a2b7a
Compare
@swift-ci please smoke test |
c5a2b7a
to
28e3c46
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
c0dd08c
to
544ae88
Compare
@swift-ci please smoke test |
Rebase to resolve conflict. After some extensive testing, I feel pretty confident to turn this on for caching only. Ready to be reviewed. @artemcm @DougGregor @benlangmuir @beccadax Since this is a pretty big behavior change, do you have any concern turn on this for all explicit module build? Will run a separate qualification for that. |
Given sufficient qualification I don't have a concern with enabling this for all Explicit Module Builds. But it would be good to have that enablement be a separate change after this one that we hold off merging until we're able to get enough confidence/validation, or land behind a flag temporarily which we can use to do testing with. |
Doing this for all explicit builds seems best to me. Not only this reduces the differences in behaviour for caching, but it also means that clang modules used by swift will behave more like clang modules used by clang -- clang's dependency scanner has been using -cc1 for explicit module builds for a while now.
Flag seems like a good idea to me to make it easier to control until we're ready to flip the default for non-caching. |
Add a flag to turn on this new behavior for non-caching build. Add some nice to have swift-driver support here: swiftlang/swift-driver#1550 |
@swift-ci please smoke test |
@swift-ci please smoke test linux platform |
a331583
to
3d06d49
Compare
@swift-ci please smoke test |
Rebase to resolve merge conflict. Still waiting for review :) |
HSOpts.ImplicitModuleMaps = 0; | ||
HSOpts.VFSOverlayFiles.clear(); | ||
HSOpts.UserEntries.clear(); | ||
HSOpts.SystemHeaderPrefixes.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we switch this to use tooling::dependencies::configureInvocationForCaching
by passing in the include-tree root ID to this function (optionally, if caching is enabled)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is the eventual goal. But note following for current setup. This is creating a ClangImporter that is not using include-tree even when caching is enabled, but a regular translation unit that imports modules that are built with include tree. It needs a different set of options from an include tree build, thus it has a customized option clearing function and may need some other tweaking.
In the future, we should run a dependency scanning of the clang importer instance then let clang scanner return the arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can't move completely to configureInvocationForCaching
, would it make sense to take a similar approach to that function for how to handle HeaderSearchOptions
? In clang we clear the whole HSOpts, and only preserve a few specific settings. That makes it much easier to know what is intentionally being kept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense if we have depscanning. Right now, it is matching the behavior in
ClangImporterOptions::getReducedExtraArgsForSwiftModuleDependency
, just in a more elegant way.
3d06d49
to
e5b43f7
Compare
@swift-ci please smoke test |
ping~ |
HSOpts.ImplicitModuleMaps = 0; | ||
HSOpts.VFSOverlayFiles.clear(); | ||
HSOpts.UserEntries.clear(); | ||
HSOpts.SystemHeaderPrefixes.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can't move completely to configureInvocationForCaching
, would it make sense to take a similar approach to that function for how to handle HeaderSearchOptions
? In clang we clear the whole HSOpts, and only preserve a few specific settings. That makes it much easier to know what is intentionally being kept.
e5b43f7
to
d7a1b41
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but probably deserves review from @artemcm as well
@swift-ci please smoke test |
When caching build is enabled, teach dependency scanner to report command-lines with `-direct-clang-cc1-module-build` so the later compilation can instantiate clang importer with cc1 args directly. This avoids running clang driver code, which might involve file system lookups, which are the file deps that are not captured and might result in different compilation mode. rdar://119275464
In certain cases (e.g. using arm64e interface to build arm64 target), the target needs to be updated when building swiftinterface. Push the target overwrite as early as possible to swiftinterface parsing by providing a preferred target to relevant functions. In such cases, the wrong target is never observed by other functions to avoid errors like the sub-invocation was partially setup for the wrong target.
Model indexing output as an optional output from the swift compiler as the build system has no knowledge about them and they can be regenerated by indexer. Make sure the indexing store output is produced when cache hit so the compilation is done for the module. If cache hit, no indexing data is produced since no compilation is done. rdar://123331335
Add an experimental option to tell dependency scanner to report clang cc1 args should be used to construct clang importer in all constructed swift-frontend tasks.
d7a1b41
to
cb17ea8
Compare
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. Thank you @cachemeifyoucan
I am trying to find the reason for an internal failure in a Linux system. For it to work, we need to provide Clang with Is there a way of still using the Clang driver or is that completely gone? Is there a good place to filter then non-cc1 arguments somehow? I am not sure that removing |
The new option is supposed to be only used for explicit module build, which requires dependency scanning. The There is a follow-up PR in swift-driver to tell it not to forward |
When caching build is enabled, teach dependency scanner to report command-lines with
-direct-clang-cc1-module-build
so the later compilation can instantiate clang importer with cc1 args directly. This avoids running clang driver code, which might involve file system lookups, which are the file deps that are not captured and might result in different compilation mode.rdar://119275464