-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[BridgingHeader] Auto bridging header chaining #78623
base: main
Are you sure you want to change the base?
[BridgingHeader] Auto bridging header chaining #78623
Conversation
Please test with following PR; @swift-ci please smoke test |
c58fd27
to
4e03c48
Compare
Please test with following PR: @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.
Formalizing the distinction of .h
vs .pch
input in the compiler is really nice, thank you.
since the new chained header is written into CAS directly without the need to serialization.
I'm keen to have this be available to all Explicitly-Built Modules builds, for which we will need a way to have the scanner relay the contents of the generated chained header to the driver.
The driver would then have to serialize the chained .h
to the filesystem and either use it directly on compile jobs, or feed it to the PCH generation task. We can probably have this be a simple libSwiftScan
API that communicates the contents of the header to the driver.
// consistant ordering. | ||
std::map<std::string, std::string> bridgingHeadersContent; | ||
auto FS = ScanASTContext.SourceMgr.getFileSystem(); | ||
for (const auto &moduleID: allSwiftModules) { |
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.
Could we run into trouble if the ordering of allSwiftModules
is not what we expect? My intuition is that the order in which we plop contents of bridging headers into the chained header matters and that it should be topological. e.g. If A -> B -> C and B and C are binary modules with bridging headers, we should include B's first and then C's.
It looks like resolveSwiftModuleDependencies
builds an array that looks like it may already satisfy this, but it's worth making sure this requirement is captured here.
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 don't think allSwiftModules is topo logically sorted yet, just enforcing a deterministic order for now in this PR.
Note the current import ordering is not really following what you suggest as well, since clang importer will including current bridging header/PCH first, then pulling in additional content as swiftmodule is imported.
This actually comes as a side effect that we need to embed the original bridging header path from command-line in swiftmodule, not the generated header that actually used during compilation. I am still working on the
I reuse an old PR that intended to unify the actions on the clang side for both getting module deps and TU deps. The original intent was that I can scan for each clang importer during swift compilation as well (where it imports clang modules + bridging header) but that might be an overkill here if we intended for using PCH for bridging header. |
Yes, that is the plan. Any suggestions for how to generate the header? How to control where the header is written to (maybe |
The header should be generated by the driver, with the scanner communicating its contents to the driver, either via
|
This is also in the mist of all the dependency scanning tasks. If driver wants to control, it needs to register a callback or just register the path beforehand. |
If the driver is in charge of placing the header, I don't see a problem with the driver also communicating the path to the scanner, but I am not sure I follow the requirement? |
4e03c48
to
e483ac9
Compare
@swift-ci please smoke test |
This is almost there. The only gap I need to close is the embedded header in the swift binary module is the chained header, rather than the original header. This is only not ok in very corner cases which current build also doesn't work well and need to pass extra information from scanner to swift-frontend. There is no need for a new scanner API and it should work for non caching build too. |
e483ac9
to
67e03df
Compare
@swift-ci please smoke test |
17b692c
to
b769acf
Compare
@swift-ci please smoke test |
@@ -369,6 +375,9 @@ class FrontendOptions { | |||
/// Emit remarks indicating use of the serialized module dependency scanning cache. | |||
bool EmitDependencyScannerCacheRemarks = false; | |||
|
|||
/// The patch at which the dependency scanner can write generated files. | |||
std::string ScannerOutputDir; |
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.
Hmm, I don't think the scanner should be writing out any generated files. Rather, it should communicate any files that need generating to the client, i.e. SwiftDriver, and then have the client do the required IO.
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.
Given that for CAS purposes we do need to have the scanner have the information of where the chained bridging header will ultimately be serialized to, we could add an option for this specifically: -chained-bridging-header-output-path
that the build system client can provide.
b769acf
to
5a7e139
Compare
@swift-ci please smoke test |
c0812fb
to
6e2dbfb
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
6e2dbfb
to
055cccd
Compare
@swift-ci please smoke test |
055cccd
to
28fd1af
Compare
@swift-ci please smoke test |
28fd1af
to
57c20e4
Compare
@swift-ci please smoke test |
57c20e4
to
d90ff24
Compare
Please test with following PR: @swift-ci please smoke test |
d90ff24
to
1527762
Compare
Please test with following PR: @swift-ci please smoke test |
1527762
to
e4a3e4c
Compare
Please test with following PR: @swift-ci please smoke test |
@artemcm This is ready to be reviewed. |
e4a3e4c
to
bd41955
Compare
Please test with following PR: @swift-ci please smoke test |
Add ability to automatically chaining the bridging headers discovered from all dependencies module when doing swift caching build. This will eliminate all implicit bridging header imports from the build and make the bridging header importing behavior much more reliable, while keep the compatibility at maximum. For example, if the current module A depends on module B and C, and both B and C are binary modules that uses bridging header, when building module A, dependency scanner will construct a new header that chains three bridging headers together with the option to build a PCH from it. This will make all importing errors more obvious while improving the performance.
bd41955
to
8b2df4f
Compare
Please test with following PR: @swift-ci please smoke test |
Add ability to automatically chaining the bridging headers discovered from all dependencies module when doing swift caching build. This will eliminate all implicit bridging header imports from the build and make the bridging header importing behavior much more reliable, while keep the compatibility at maximum.
For example, if the current module
A
depends on moduleB
andC
and bothB
andC
are binary modules that uses bridging header, when building module A, dependency scanner will construct a new header that chains three bridging headers together with the option to build a PCH from it. This will make all importing errors more obvious while improving the performance.