Commit Graph

125 Commits

Author SHA1 Message Date
Hiroshi Yamauchi
42fe7d90cb Merge pull request #79926 from hjyamauchi/explicit-module-build
Propagate vfs overlays and -fbuiltin-headers-in-system-modules
2025-03-28 21:58:40 -07:00
Hiroshi Yamauchi
8312f7ad9a Propagate vfs overlays and -fbuiltin-headers-in-system-modules
This fixes explicit module builds for a hello world program on Windows
as well as the ucrt import build failure as in the included test.
2025-03-27 20:57:13 -07:00
Artem Chikin
1c0caa6505 [Dependency Scanning] Carve out a special case for sdk-cache output path computation for Clang modules specifically defined in the compiler's runtime resource directory
This is, hopefully, a temporary measure while we account for why such modules are not reported as 'IsInStableDirectories'.
2025-03-19 15:37:07 -06:00
Artem Chikin
04015fef77 [Dependency Scanning] Adopt new clang scanner API to place stable modules into an SDK-specific module cache 2025-03-19 10:43:42 -06:00
Artem Chikin
88dec5199e [Dependency Scanning] Add support for placing explicitly-built SDK modules into a separate module cache
With '-sdk-module-cache-path', Swift textual interfaces found in the SDK will be built into a separate SDK-specific module cache.
Clang modules are not yet affected by this change, pending addition of the required API.
2025-03-19 09:17:04 -06:00
Cyndy Ishida
f8798ce9e6 [DependencyScanner] Update ModuleID to ModuleDeps in lookupModule calls (#80073)
This allows to read more attributes like isInSysroot.
2025-03-18 22:29:44 -07:00
Artem Chikin
0555764bb4 [Dependency Scanning] Refine cross-import overlay detection algorithm
The algorithm already performs pairwise checks on module dependencies brought into compilation per-source-file. Previously, the algorithm considered the entire sub-graph of a given source file. Actual source compiles do not consider the full transitive module dependency set for cross-import-overlay lookup, but rather only directly-imported modules in a given source file, and '@_exported import' Swift transitive dependencies.

This change adds tracking of whether a given import statement is 'exported' to the dependency scanner and then refines the cross-import overlay lookup logic to only consider transitive modules that are exported by directly-imported dependencies.
2025-02-27 15:48:11 -08:00
Saleem Abdulrasool
9c85fbc8da AST,DependencyScan,IRGen,Serialization,Tooling: track library style (#78777)
Track if the dependency is static or dynamic. This is in preparation for
helping rename the static library to differentiate it from import
libraries.
2025-02-06 13:22:56 -08:00
Steven Wu
9d59044bb1 [BrdigingHeader] Auto bridging header chaining
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.
2025-02-05 09:41:04 -08:00
Artem Chikin
477ba0dd97 [Dependency Scanning] Remove references to per-triple PCM variant compilation 2025-01-29 11:32:07 -08:00
Ian Anderson
cdb42c3535 [ClangImporter] clang's -iframework comes before builtin usr/local/include, but Swift's -Fsystem comes after
When Swift passes search paths to clang, it does so directly into the HeaderSearch. That means that those paths get ordered inconsistently compared to the equivalent clang flag, and causes inconsistencies when building clang modules with clang and with Swift. Instead of touching the HeaderSearch directly, pass Swift search paths as driver flags, just do them after the -Xcc ones.

Swift doesn't have a way to pass a search path to clang as -isystem, only as -I which usually isn't the right flag. Add an -Isystem Swift flag so that those paths can be passed to clang as -isystem.

rdar://93951328
2024-12-23 22:15:52 -08:00
Artem Chikin
d68b5b2b6e [Dependency Scan] Remove newly-introduced error failure on missing header dependency of a binary module dependency
Previous behavior had the scanner simply proceed if the header input of a binary Swift module dependency could not be resolved on the filesystem

Resolves rdar://139736789
2024-11-13 08:24:27 -08:00
Jan Svoboda
ec086e1a3c [ClangImporter] Fix build after LLVM #9573 (#77557) 2024-11-12 14:50:08 -08:00
Artem Chikin
0f50693aa5 [Dependency Scanning] Parallelize Clang module queries
This change refactors the top-level dependency scanning flow to follow the following procedure:

Scan():
1. From the source target under scan, query all imported module identifiers for a *Swift* module. Leave unresolved identifiers unresolved. Proceed transitively to build a *Swift* module dependency graph.
2. Take every unresolved import identifier in the graph from (1) and, assuming that it must be a Clang module, dispatch all of them to be queried in-parallel by the scanner's worker pool.
3. Resolve bridging header Clang module dpendencies
4. Resolve all Swift overlay dependencies, relying on all Clang modules collected in (2) and (3)
5. For the source target under scan, use all of the above discovered module dependencies to resolve all cross-import overlay dependencies
2024-10-30 11:10:10 -07:00
swift-ci
9fd863f81e Merge remote-tracking branch 'origin/main' into rebranch 2024-10-08 10:50:24 -07:00
Steven Wu
cd07d532af [CAS] Use IncludeTreeFileList instead of full CASFS for caching
Use IncludeTreeFileList instead of full feature CASFS for swift
dependency filesystem. This allows smaller CAS based VFS that is smaller
and faster. This is enabled by the CAS enabled compilation does not
need to iterate file system.

rdar://136787368
2024-09-30 16:01:33 -07:00
Ben Barham
c15bc19946 Merge remote-tracking branch 'origin/main' into main-to-rebranch
Conflicts:
  - `lib/Serialization/ModuleFileSharedCore.cpp` new headers on main
2024-09-26 16:01:56 -07:00
Steven Wu
5a6f6e1d4d [NFC][ScanDependency] Remove some ununsed code
Clean up some code that no longer used.
2024-09-24 16:29:21 -07:00
Steven Wu
b2ea889721 [ScanDependency] Use -fsyntax-only to scan clang module dependencies
Use `-fsyntax-only` action to scan clang module dependencies instead of
`-c` option. This fixes a non-deterministic output on windows from
scan-dependency output because `-c` implies it needs a temporary object
file in the cc1 arguments that makes the pcm compilation command
different every run. This can also make the `-Xcc` commands for PCM
compilation simpler and more likely to be deduplicated by build system.

rdar://135319536
2024-09-05 16:22:28 -07:00
Steven Wu
23b0d80d7c [Caching] Avoid using clang CAS options in the command-line
Avoid constructing tasks with `-Xcc` options that references clang
CASOptions. This is going to make the cache hit/miss to be dependent on
CAS location/configuraitons.

Instead, only give swift CASOptions to constructed tasks and propagate
the configurations to underlying clang importer.

rdar://132255889
2024-07-24 09:20:22 -07:00
artemcm
a89fde1898 [Dependency Scanning] Apply '-clang-scanner-module-cache-path' to header Clang module dependencies
Resolves rdar://117024665
2024-07-01 14:29:37 -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
Steven Wu
c1c0257db7 [ExplicitModule] Don't pass PCM output path in -Xcc option
There is no need to pass output path of the PCM compilation twice, once
as swift `-o` flag and other time as `-Xcc -o` flag to clang importer.
This can also cause swift caching to miss when output path is different
because `-Xcc` options are not modeled in caching model to understand
`-o` output path doesn't affect compilation output content.

rdar://128650954
2024-05-23 18:09:36 -07:00
Artem Chikin
eb1c0e71d8 [Dependency Scanning] Add required additional C++ interop overlay module queries 2024-05-20 10:23:10 -07:00
Steven Wu
7091876e64 [ScanDependencies] Fix assertion failure when failed to scan header
Fix an assertion failure when bridging header dependency scanning
failed.

rdar://127459045
2024-05-02 15:33:09 -07:00
Ben Langmuir
d178172b5c [Caching] Adopt -finclude-tree-preserve-pch-path to fix -gmodules with
This fixes -gmodules when caching by adopting the new clang -cc1 option
-finclude-tree-preserve-pch-path. -gmodules is required to make
debugging work when examining types that come from clang modules or
bridging headers, but was previously being disabled by clang's caching
support.

rdar://126370706
2024-04-12 13:20:30 -07:00
Steven Wu
471aea857a [ExplicitModuleBuild] Support -vfsoverlay swift option
Support `-vfsoverlay` swift option for explicit module build (including
caching build). Previously, if the interface file is discovered from a
location that is remapped by overlay, module cannot be built correctly.
Make sure the overlay options are passed down to all interface
compilaiton command.

For caching build, need to make sure the overlay itself is part of the CAS
file system so the downstream compilation can discover that.

rdar://123655183
2024-03-15 10:21:00 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07:00
Allan Shortlidge
109860cd96 ClangImporter: Resolve unused variable warning.
NFC.
2024-03-11 15:37:00 -07: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
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
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
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
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
Artem Chikin
aa05a5c0bd Revert "[Dependency Scanning] Use VFS-remapped paths for Clang Module Dependencies' .modulemap files" 2024-01-11 09:43:18 -08:00
Artem Chikin
6c5e884297 [Dependency Scanning] Use VFS-remapped paths for Clang Module Dependencies' .modulemap files
These files are used as an explicit input for the resulting compilation task

Resolves rdar://120554985
2024-01-09 12:46:38 -08:00
Steven Wu
ea58ef8fa5 [ClangImporter] Simply clang-importer creation flags
Currently,  `-direct-clang-cc1-module-build` and `-only-use-extra-clang-opts`
have to be passed together for clang importer creation to succeed.
Missing either will result in error. Simplified the swift-frontend flags
by removing `-only-use-extra-clang-opts` and let
`-direct-clang-cc1-module-build` to do both.
2023-12-19 12:16:20 -08:00
Steven Wu
7698d36dfb [ClangImporter] Re-write how clang-importer is created via args
Re-write and clean up how clang-importer is created from clang
arguments. Previously, it is unclear if `getClangArguments` will return
CC1 args or driver args and the logic is unnecessarily compilicated when
creating clang invocation. Now clang invocation is always created from
cc1 arguments, which can be directly provided via direct-cc1-mode or
converted from driver args.

There is no functional changes in this patch, other than
`-dump-clang-diagnostics` now will always print cc1 args, and also
driver args if that is applicable.
2023-12-19 12:16:18 -08:00
Artem Chikin
674dfb3bd4 [Dependency Scanning] Move generation of a named import path 'Identifier' out of the individual scanning workers up into the parent scanner. This operation mutates the scanner ASTContext by potentially adding new identifiers to it and is therefore not thread-safe. 2023-12-13 13:17:05 -08:00
Steven Wu
109566fb81 [Caching] Switch clang-include-tree to be default for clang modules
Switch to use clang-include-tree by default for clang module
building/caching when using a CAS. This is the default mode for clang
module and has less issues than CAS file system based implementation.
2023-11-10 11:43:32 -08:00
Jan Svoboda
8b6e58ac15 [scanner] Adopt new Clang API for build arguments (#68503) 2023-10-06 11:31:05 -07:00
Steven Wu
7b89afbb6e [DepScan] Teach dependency scanner to remap path for canonicalization
Allow DependencyScanner to canonicalize path using a prefix map. When
option `-scanner-prefix-map` option is used, dependency scanner will
remap all the input paths in following:
* all the paths in the CAS file system or clang include tree
* all the paths related to input on the command-line returned by scanner

This allows all the input paths to be canonicalized so cache key can be
computed reguardless of the exact on disk path.

The sourceFile field is not remapped so build system can track the exact
file as on the local file system.
2023-09-26 12:36:43 -07:00
Artem Chikin
6e3f896962 [Dependency Scanning] Refactor primary scan operations into 'ModuleDependencyScanner' class
From being a scattered collection of 'static' methods in ScanDependencies.cpp
and member methods of ASTContext. This makes 'ScanDependencies.cpp' much easier
to read, and abstracts the actual scanning logic away to a place with common
state which will make it easier to reason about in the future.
2023-09-22 14:09:45 -07:00
Artem Chikin
6ef79c4ba0 [Dependency Scanning] Specify Explicit Module output path to the scanner explicitly
Instead of the code querying the compiler's built-in Clang instance, refactor the
dependency scanner to explicitly keep track of module output path. It is still
set according to '-module-cache-path' as it has been prior to this change, but
now the scanner can use a different module cache for scanning PCMs, as specified
with '-clang-scanner-module-cache-path', without affecting module output path.

Resolves rdar://113222853
2023-08-10 11:11:05 -07:00
Artem Chikin
0c6f212cd5 [Dependency Scanning] Add Clang modules from scan-deps queries to the set of
"already seen" modules, to pass down to subsequent queries.
2023-08-09 09:16:46 -07:00
Steven Wu
94e8ddcf0b Merge pull request #67041 from cachemeifyoucan/eng/PR-fix-cas-depscan-edge-cases
[DepScan][CAS] Fix some cases in cas-based depscanning
2023-06-30 11:41:10 -07:00
Steven Wu
0876a3e04f Fix the command-line option from depscanner after caching option rename 2023-06-29 16:51:28 -07:00