Commit Graph

215 Commits

Author SHA1 Message Date
swift-ci
926498e947 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-08 11:55:29 -07:00
Allan Shortlidge
1083557779 Dependency Scanning: Address -Wmissing-field-initializers warnings.
Fix warnings introduced by https://github.com/swiftlang/swift/pull/75734.
2024-08-08 08:38:25 -07:00
Egor Zhdan
059f0f97d1 [cxx-interop] Allow compiling with libc++ on Linux
This makes sure that Swift respects `-Xcc -stdlib=libc++` flags.

Clang already has existing logic to discover the system-wide libc++ installation on Linux. We rely on that logic here.

Importing a Swift module that was built with a different C++ stdlib is not supported and emits an error.

The Cxx module can be imported when compiling with any C++ stdlib. The synthesized conformances, e.g. to CxxRandomAccessCollection also work. However, CxxStdlib currently cannot be imported when compiling with libc++, since on Linux it refers to symbols from libstdc++ which have different mangled names in libc++.

rdar://118357548 / https://github.com/swiftlang/swift/issues/69825
2024-08-08 16:24:58 +01:00
swift-ci
4d726b37a8 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-06 19:55:44 -07:00
swift-ci
719a0a9889 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-06 15:54:06 -07:00
Xi Ge
98f4ad840a DependenciesScanner: report user module version for textual Swift interfaces 2024-08-06 15:45:45 -07:00
Xi Ge
b4d64bde55 DependencyScanner: report user module version in dependency scanning results for binary Swift modules 2024-08-06 11:43:53 -07:00
swift-ci
4ba49ce78f Merge remote-tracking branch 'origin/main' into rebranch 2024-07-16 09:56:11 -07:00
Steven Wu
ed936853dc [ScanDependencies] Fix a memory leak in dependency graph
Fix a memory leak from https://github.com/swiftlang/swift/pull/75134.
2024-07-15 20:41:40 -07:00
swift-ci
25be15072e Merge remote-tracking branch 'origin/main' into rebranch 2024-07-11 09:56:08 -07:00
Artem Chikin
a55beaa79d Merge pull request #75139 from artemcm/FixScanSourceLocUseAfterFree
[Dependency Scanning][NFC] Associate single-shot scanner service lifetime with the owning compilation instance's `ASTContext`
2024-07-11 09:45:34 -07:00
Artem Chikin
0d254174c6 Merge pull request #75146 from artemcm/DepScanNoGlobalLLVMOpts
[Dependency Scanning] Avoid configuration (and reset) of LLVM Options by the scanner
2024-07-11 09:45:13 -07:00
swift-ci
fffd12b39b Merge remote-tracking branch 'origin/main' into rebranch 2024-07-11 09:16:06 -07:00
Ben Barham
2715d0e9d6 Merge branch 'main' into 20240710-main-to-rebranch
Conflicts:
  - `test/Interop/Cxx/class/method/methods-this-and-indirect-return-irgen-itanium.swift`
    previously fixed on rebranch, now fixed on main (slightly differently).
2024-07-10 20:42:09 -07:00
Artem Chikin
6d0f52152a [Dependency Scanning] Avoid configuration (and reset) of LLVM Options by the scanner
The scanning action does not have any need for handling `-llvm` options, since it will never perform any code-gen. LLVM option processing relies on global option parsing structures, and the scanner has needed to carefully attempt to synchronize access to them. This change guards the configuration of LLVM options to not happen at all for dependency scanning actions, and removes calls to `llvm::cl::ResetAllOptionOccurrences()` that were previously needed.

Resolves rdar://120754696
2024-07-10 14:33:48 -07:00
Artem Chikin
613277554e [Dependency Scanning][NFC] Associate single-shot scanner service lifetime with the owning compilation instance's ASTContext
Resolves rdar://131388478
2024-07-10 13:49:14 -07:00
Artem Chikin
4b7bf3a59d [Dependency Scanning] Emit diagnostics from compilation instance initialization 2024-07-10 10:34:40 -07:00
Steven Wu
da10a02231 [Macro] Fix bugs in macro dependency scanning
Fix few issues from previous implementation from explicit module build
with macros and accurate macro dependency scanning in
https://github.com/swiftlang/swift/pull/73421.

First, there is a crash when propagating the macro dependencies. It
turns out that the current macro plugin implementation doesn't need the
downstream users to know about the plugin search path from the upstream
dependencies.

Secondly, fix a bug that the swiftinterface that has macro usage won't
build because the build command doesn't inherit the plugin search path
option.

Finally, add JSON output for macro dependencies so it is easier to
debug the macro dependencies.

rdar://131214106
2024-07-09 10:37:27 -07:00
Ben Barham
aa7a3a8268 Cleanup std includes
Remove `deque` from files it isn't actually used in. Add it and `stack`
to files that it is - presumably they were previously transitively found
through other includes.
2024-07-02 16:13:49 -07:00
Steven Wu
4125e8c3cd [ScanDependencies] Get accurate macro dependency
Build an accurate macro dependency for swift caching. Specifically, do
not include not used macro plugins into the dependency, which might
cause false negatives for cache hits.

This also builds the foundation for future improvement when dependency
scanning will determine the macro plugin to load and swift-frontend do
not need to redo the work.

rdar://127116512
2024-06-27 10:45:14 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
artemcm
d70863501e [Dependency Scanning] Collect and report each module dependency's Link Libraries 2024-06-05 10:59:41 -07:00
artemcm
60af9b8b93 [Dependency Scanning] Add forgotten '-Xcc' qualifier to modulemap dependency flags
Resolves rdar://128945712
2024-05-30 12:14:11 -07:00
Steven Wu
47598bbe8f [ScanDependency] Respect working directory set inside invocation
Teach scanner to respect the working directory set in the invocation
through scanner C API.

Also add test infrastructure to testing scanner from C API. Break up
DependencyScan lib into two so the swift-scan-test and remain small
without understanding swift AST.

rdar://127626011
2024-05-22 11:04:45 -07:00
artemcm
9aeadd0507 [Dependency Scanning] Specify Source Locations For Missing Module Dependencies
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.
2024-05-21 13:12:09 -07:00
Steven Wu
0e12f2042e [ScanDependency] Move binary module validation into scanner
Improve swift dependency scanner by validating and selecting dependency
module into scanner. This provides benefits that:
* Build system does not need to schedule interface compilation task if
  the candidate module is picked, it can just use the candidate module
  directly.
* There is no need for forwarding module in the explicit module build.
  Since the build system is coordinating the build, there is no need for
  the forwarding module in the module cache to avoid duplicated work,
* This also correctly supports all the module loading modes in the
  dependency scanner.

This is achieved by only adding validate and up-to-date binary module as
the candidate module for swift interface module dependency. This allows
caching build to construct the correct dependency in the CAS. If there
is a candidate module for the interface module, dependency scanner will
return a binary module dependency in the dependency graph.

The legacy behavior is mostly preserved with a hidden frontend flag
`-no-scanner-module-validation`, while the scanner output is mostly
interchangeable with new scanner behavior with `prefer-interface` module
loading mode except the candidate module will not be returned.

rdar://123711823
2024-04-05 07:52:14 -07:00
Artem Chikin
a4ac419c12 Merge pull request #72699 from artemcm/SourcesAreDependenciesToo
[DependencyScanning] Treat main source module as a Swift dependency node in cycle resolution graph
2024-03-29 16:47:33 -07:00
Artem Chikin
6d30bdfe66 [DependencyScanning] Treat main source module as a Swift dependency node in cycle resoltion graph 2024-03-29 10:38:14 -07:00
Artem Chikin
4a2b178944 Merge pull request #72599 from artemcm/NoModuleMapsOnSwiftDepsExplicit
[Dependency Scanning] By-default do not specify '-fmodule-map-file' inputs on Swift interface dependency compilation jobs
2024-03-29 09:02:18 -07:00
Artem Chikin
e489a1e03a [Dependency Scanning] Specify explicit '.modulemap' inputs for dependencies of bridging headers, direct or transitive
On all '.swiftinterface' command-line recipes, ensure we specify '-fmodule-map-file=' argument for each module which is a dependency of a header input of all swift binary module dependnecies, direct and transitive
2024-03-27 15:11:16 -07:00
Artem Chikin
2564fff913 [Dependency Scanning] Do not specify '-fmodule-map-file' inputs on Swift interface dependency compilation jobs
Swift interfaces will only ever query module inputs by-name, so parsing modulemap files to resolve their headers is not necessary.
2024-03-26 15:20:20 -07:00
Steven Wu
f71cce15cb [ScanDependency] Set context hash for source module
Set context hash for source module so swift-driver can use the hash to
compute output path if needed.

rdar://119202702
2024-03-20 10:12:17 -07:00
Steven Wu
cdd1ac91a8 [Caching] Support CrossImport modules for caching build
Add support for cross import modules by ingesting swiftoverlay files for
the cross import into CAS file system.

The long-term better fix will be just passing the cross import
information from scanner to swift-frontend so frontend doesn't need to
read overlay files again to figure out the cross import module.

rdar://123839248
2024-03-11 14:55:22 -07:00
Steven Wu
cdeef58e0f [Caching] Create clang importer from cc1 args directly
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
2024-03-07 14:40:00 -08:00
Artem Chikin
d113ea11ac Merge pull request #72067 from artemcm/FixTransitiveHeaderLookupInDependencyScan
[Dependency Scanning] Scan header inputs of binary Swift module dependencies
2024-03-06 16:05:12 -08:00
Artem Chikin
bfa8c0ee4f [Dependency Scanning] Scan header inputs of binary Swift moduel dependencies
Otherwise they may have module dependencies of their own which will not be detected by the scanner and included in the list of explicit inputs for compilation.
2024-03-06 11:02:35 -08:00
Artem Chikin
8c53fe8b63 [Dependency Scannin] Fallback on system default cache directory when no explicit cache path is specified by the user 2024-02-29 11:40:50 -08:00
Ben Langmuir
918bd3d4bb Merge pull request #71956 from benlangmuir/clang-prefix-map-consistent
[Caching] Use clang to prefix-map -fmodule-file-cache-key paths
2024-02-29 07:51:12 -08:00
Ben Langmuir
576cc8cee1 [Caching] Use clang to prefix-map -fmodule-file-cache-key paths
When prefix mapping paths that are used in clang, ensure we are
consistently using the same prefix mapper from clang. This prevents
mismatches that could cause modules to fail to load.

rdar://123324072
2024-02-28 13:44:28 -08:00
Artem Chikin
d2a8e32bc5 [Dependency Scanning] Collect emitted diagnostics per-scan-query 2024-02-27 14:51:54 -08:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Artem Chikin
a27cf55a47 Merge pull request #71763 from artemcm/DepScanMainTargetCycles
[Dependency Scanning] Detect cycles of main target module depending on an existing Swift textual or prebuilt binary module
2024-02-22 14:34:38 -08:00
Ben Barham
5637284e48 Merge pull request #71368 from bnbarham/std-optional-all-the-things
Migrate llvm::Optional to std::optional
2024-02-21 16:54:00 -08:00
Artem Chikin
8734d2eb97 [Dependency Scanning] Detect cycles of main target module depending on an existing Swift textual or prebuilt binary module
Resolves rdar://123112402
2024-02-21 13:57:14 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Steven Wu
423c482427 [Caching] Resolve BridgingHeader Module Deps correctly
Fix the bridging header dependencies calculation for explicit module
build, especially for caching which needs an accurate list of deps for
compute cache key correctly.

Previously, the bridging header deps are computed from `ModuleGraph`
from the clang dependency scanner, which can be affected by already seen
modules. It causes the dependencies to be missing for bridging header if
the module is seen by main swift source module.

Now report only the directly module dependencies from bridging header,
then compute all the transitive dependencies before calculating all the
cache keys.

rdar://123156636
2024-02-19 16:09:56 -08:00
Artem Chikin
500d2e5840 [Dependency Scanning] Only omit Clang VFS overlays from Swift dependencies if unused by Clang dependencies
We previously blanket omitted `-Xcc -vfsoverlay` flags from Swift module dependencies' command-line recipes. This is incorrect as the Swift module must have an exact matching VFS overlay that its Clang dependencies use, in order to load said Clang dependnecies successfully and resolve their headers as expected and as was done during the scan.

Resolves rdar://122667530
2024-02-16 15:36:46 -08:00
Steven Wu
9607e9dec1 Merge pull request #71497 from cachemeifyoucan/eng/PR-122423965
[Caching] Use subInvocation to verify interface
2024-02-13 09:18:40 -08:00
Steven Wu
3986937e03 [Caching][NFC] Restructure CASOption in swift. NFC
Clean up how CASOptions are kept and passed inside swift to make the
code more readable. Also avoid a copy of CAS configuration in
ClangImporter.
2024-02-11 14:08:09 -08:00