Commit Graph

34 Commits

Author SHA1 Message Date
Hamish Knight
4946c799af [AST] Remove ModuleDecl::addFile
Rather than exposing an `addFile` member on
ModuleDecl, have the `create` members take a
lambda that populates the files for the module.
Once module construction has finished, the files
are immutable.
2024-11-17 14:17:20 +00: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
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
Doug Gregor
8febd3fb32 Reimplement ModuleDecl::getSourceFileContainingLocation() using SourceManager
ModuleDecl kept track of all of the source files in the module so that it
could find the source file containing a given location, which relied on
a sorted array all of these source files. SourceManager has its own
similar data structure for a similar query mapping the locations to
buffer IDs.

Replace ModuleDecl's dats structure with a use of the SourceManager's version
with the mapping from buffer IDs to source files.
2024-09-18 07:45:50 -07:00
Artem Chikin
12e2fb63a9 [Dependency Scanning] Query package-only dependencies from adjacent binary modules when necessary
When '.package.swiftinterface' loading ('-experimental-package-interface-load') is disabled and when '-scanner-module-validation' is disabled, the scanner defaults to locating the non-package textual interface and may specify its adjacent binary module as a valid candidate binary module to use. If said candidate is up-to-date and ends up getting used, and belongs to the same package as the loading Swift source, then the source compilation may attempt to load its package-only dependencies. Since the scanner only parsed the non-package textual interface, those dependencies are not located and specified as inputs to compilation. This change causes the scanner, in such cases, to also lookup package-only dependencies in adjacent binary Swift modules of textual Swift module dependencies, if such dependency belongs to the same package as the source target being scanned.

Resolves rdar://135215789
2024-09-06 15:48:44 -07:00
Xi Ge
98f4ad840a DependenciesScanner: report user module version for textual Swift interfaces 2024-08-06 15:45:45 -07:00
Artem Chikin
a2dc674723 [Dependency Scanning] Disable validation of Swift dependency modules' existing pre-built candidate binary module files in the scanner, on a non-caching build.
As-is, this default interferes with the incremental build machinery which conservatively assumes that binary module dependencies must cause dependents to be re-built.
2024-07-29 17:16:54 -07:00
Steven Wu
2bc4080116 [ExplicitModule] Include -Xcc -D into module hash
The decision to exclude `-Xcc -D` options from swift module hash
actually doesn't help to solve the problem. It wouldn't reduce the
module variants (or the number of swiftmodule build commands) because
the command-line also encodes all the clang PCM dependencies that do get
affected by `-Xcc` flags.

To avoid the false sharing and the nondeterministic build products,
include most of the `-Xcc` flags, except include search path, into swift
module hash.

rdar://132046247
2024-07-23 14:57:44 -07:00
Steven Wu
a32dd9539b [Modules] Avoid false swift module sharing
When the swiftmodule is built with different clang importer arguments,
they can have the same module hash, causing them to be wrongly re-used even
they contains different interfaces. Add ReducedExtraArgs to the module hash to
disambiguate them.

However, some Xcc arguments, most commonly `-D` options do not affect the
swiftmodule being generated. Do not pass `-Xcc -DARGS` to swift
interface compilation to reduce the amount of module variants in the
build.

rdar://131408266
2024-07-10 14:48:12 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Steven Wu
7d85aa423d [ScanDependencies] Make sure canImport resolution agrees with import
Fix the problem that when the only module can be found is an
invalid/out-of-date swift binary module, canImport and import statement
can have different view for if the module can be imported or not.

Now canImport will evaluate to false if the only module can be found for
name is an invalid swiftmodule, with a warning with the path to the
module so users will not be surprised by such behavior.

rdar://128876895
2024-06-17 14:14:48 -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
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
9479daf29e [ScanDependency][NFC] Code clean up for testable module lookup
Cleanup testable module lookup implementation by explicitly lookup
binary module only when requested, rather than changing the scanner
module load mode.
2024-04-18 14:03:05 -07:00
Steven Wu
53ad5de6db Revert "[ScanDependency] Allow importing binary testable module when no interface"
This reverts commit 90a1586c3c.
2024-04-17 12:43:06 -07:00
Steven Wu
90a1586c3c [ScanDependency] Allow importing binary testable module when no interface
Follow-up adjustment for binary module selection in dependency scanning
time. If a testable binary module doesn't have an interface file, it
should be used even it might pull in more dependencies.
2024-04-08 10:28:25 -07:00
Steven Wu
d4c90d6eeb [DependencyScanning] Handle testable dependencies correctly
Teach scanner to pick and choose binary modules correctly based on if it
is testable import or not. Some situations that scanner need to be
careful when testable is involved:

* When it is a regular import, it should not import binary modules that
  are built with -enable-testing, it should prefer interfaces if that is
  available.
* When testable import, it should only load binary module and it should
  make sure the internal imports from binary modules are actually
  required for testable import to work.

If a testable import only find a regular binary module, dependency
scanner currently will just preceed with such module and leave the
diagnostics to swift-frontend, because the alternative (failed to find
module) can be confusing to users.

rdar://125914165
2024-04-05 07:52:16 -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
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
cb17ea8e66 [ScanDependency] Add -experimental-clang-importer-direct-cc1-scan
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.
2024-03-07 14:40:00 -08: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
Steven Wu
3e903688a2 [ScanDependency] Do not use public/private swiftinterface in the same package
When scanning finds a dependency in the same package, do not load
public/private swiftinterface since they do not have the package level
decl to compile the current module. Always prefer package module (if
enabled), or use binary module, unless it is building a public/private
swiftinterface file in which case the interface file is preferred.

This also does some clean up to sync up the code path between implicit
and explicit module finding path.

rdar://122356964
2024-02-28 17:34:03 -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
26ac2e0dbd [ExplicitModule] Change how @testable imports are handled
Always prefer binary module when using @testable imports because the
swiftmodule rebuilt from interface cannot be imported as testable.

rdar://123120159
2024-02-19 16:22:49 -08:00
Alexis Laferrière
86ea594f21 Serialization: apply the SDK build version as part of the cache hash
The SDK build version is a decent heuristic for expected changes in the
SDK. Any change in SDK, to clang headers in particular, can break
references from cached swiftmodules.

Track the SDK build version as part of the swiftmodule cache hash. This
will ensure we rebuild from swiftinterfaces on SDK updates.

rdar://122655978
2024-02-12 12:35:03 -08:00
Kavon Farvardin
483b569bc8 [NCGenerics] trigger module mismatch
A swiftmodule can only be correctly ingested by a compiler
that has a matching state of using or not-using
NoncopyableGenerics.

The reason for this is fundamental: the absence of a Copyable
conformance in the swiftmodule indicates that a type is
noncopyable. Thus, if a compiler with NoncopyableGenerics
reads a swiftmodule that was not compiled with that feature,
it will think every type in that module is noncopyable.

Similarly, if a compiler with NoncopyableGenerics produces a
swiftmodule, there will be Copyable requirements on each
generic parameter that the compiler without the feature will
become confused about.

The solution here is to trigger a module mismatch, so that
the compiler re-generates the swiftmodule file using the
swiftinterface, which has been kept compatible with the compiler
regardless of whether the feature is enabled.
2024-01-23 22:42:37 -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
Ellie Shin
fbdc16d69a Add a check for an empty package interface path
Update diags
2023-11-14 01:10:02 -08:00
Ellie Shin
e5ca8e5c0b Allow loading package interface if in same package.
Add a new flag to enable package interface loading.
Use the last value of package-name in case of dupes.
Rename PrintInterfaceContentMode as InterfaceMode.
Update diagnostics.
Test package interface loading with various scenarios.
Test duplicate package-name.
2023-11-09 18:44:06 -08:00
Ellie Shin
aba3b6c24e Introduce a package interface.
It has an extension .package.swiftinterface and contains package decls
as well as SPIs and public/inlinable decls. When a module is loaded
from interface, it now looks up the package-name in the interface
and checks if the importer is in the same package. If so, it uses
that package interface found to load the module. If not, uses the existing
logic to load modules.

Resolves rdar://104617854
2023-11-08 14:56:20 -08: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
b4dfb6baa1 [Dependency Scanning] Implement parallel imported module resolution
'ModuleDependencyScanner' maintains a Thread Pool along with a pool of workers
which are capable of executing a filesystem lookup of a named module dependency.
When resolving imports of a given Swift module, each import's resolution
operation can be issued asunchronously.
2023-09-22 14:11:26 -07:00