Commit Graph

309 Commits

Author SHA1 Message Date
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
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
Artem Chikin
3168a914a7 Merge pull request #69527 from artemcm/FixupDepScanExtraClangArgs
[Dependency Scanning] Restore propagation of `-Xcc` flags to scanner's Swift Textual interface-reading sub-invocation
2023-10-31 08:29:14 -07:00
Artem Chikin
9eee1ec4f4 [Dependency Scanning] Restore propagation of -Xcc flags to scanner's Swift Textual interface-reading sub-invocation 2023-10-30 16:41:40 -07:00
Xi Ge
09d6944497 ModuleInterface: allow blocklist to configure module names from SDKs that we use textual interfaces exclusively 2023-10-28 14:38:11 -07:00
Steven Wu
6c3097657a [Caching] Change swift cache key computation
Update swift cache key computation mechanism from one cache key per
output, to one cache key per primary input file (for all outputs that
associated with that input).

The new schema allows fewer cache lookups while still preserving most of
the flexibility for batch mode and incremental mode.
2023-10-13 09:15:22 -07:00
Allan Shortlidge
12019c5781 Frontend: Describe all reasons a module could not be loaded.
The `unable to load compiled module` diagnostic could be incomplete because
`invalidModuleReason()` did not have a description for every serialization
status code.

Resolves rdar://115664927
2023-09-18 17:04:26 -07:00
Alexis Laferrière
52f2cc381d Serialization: allow rebuilding modules from swiftinterface in release builds
There is some special logic for loading modules from under the
resource-dir. In this case, if there's a swiftmodule next to the
swiftinterface we refuse to rebuild the module from the swiftinterface.
It was designed to catch misconfigurations, either locally if we forget
to rebuild the stdlib from source or at deployement.

It has been causing issues recently with LLDB and other tools. Let's
keep this behavior only for the local scenario by limiting it to
untagged compilers. This restriction aligns well with the strict
compiler tag check for swiftmodule compatibility.
2023-09-07 14:42:34 -07:00
Artem Chikin
626c32b890 Merge pull request #67009 from Fushj89/inherit-strict-implicit-module-context-in-sub-swiftinterface
should inherit -strict-implicit-module-context when build sub swiftinterface
2023-07-05 12:48:23 -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
fushijian
4b7b598128 should inherit -strict-implicit-module-context when build sub swiftinterface 2023-06-29 12:50:56 +08:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Steven Wu
284eb2a264 [NFC] Cleanup deprecated Optional API usage in depscan 2023-06-26 10:34:27 -07:00
Steven Wu
2b7d38dc16 [CAS] Improve swift cas options
Using the same CASOption from clang to communicate CAS configurations so
it is easier to exchange CAS configuration between them.
2023-06-26 10:34:26 -07:00
Xi Ge
f4d8761445 ModuleLoader: minor clean-up to remove dead code. NFC 2023-06-16 14:53:29 -07:00
Ben Barham
183902da47 Merge pull request #66576 from bnbarham/ignore-host-modules
[Frontend] Ignore adjacent swiftmodule in compiler host modules
2023-06-14 09:38:20 -07:00
Ben Barham
ee3a47b624 [Frontend] Ignore adjacent swiftmodule in compiler host modules
`lib/swift/host` contains modules/libraries that are built by the host
compiler. Their `.swiftmodule` will never be able to be read, ignore
them entirely.
2023-06-12 16:53:48 -07:00
Artem Chikin
92d9e61d1a [Dependency Scanning] Emit header dependencies of binary Swift module dependencies in output and provide libSwiftScan API to query it 2023-06-12 15:01:41 -04:00
Steven Wu
b1f99b8e93 [CAS] swift dependency scanning using CAS for compiler caching (#66366)
Teach swift dependency scanner to use CAS to capture the full dependencies for a build and construct build commands with immutable inputs from CAS.

This allows swift compilation caching using CAS.
2023-06-12 10:55:53 -07:00
Allan Shortlidge
0e7ad1e9a4 Frontend: Don't append -target-min-inlining-target target to implicit module builds.
When performing an implicit module build, the frontend was prepending
`-target-min-inlining-target target` to the command line. This was overriding
the implicit `-target-min-inlining-target min` argument that is implied when
`-library-level api` is specified. As a result, the wrong overload could be
picked when compiling the body of an inlinable function to SIL for emission
into the client, potentially resulting in crashes when the client of the module
is back deployed to an older OS.

Resolves rdar://109336472
2023-05-30 13:33:26 -07:00
Artem Chikin
6fcd8be072 [Dependency Scanning] Pull optional dependencies from the adjacent binary module for direct interface dependencies
For a `@Testable` import in program source, if a Swift interface dependency is discovered, and has an adjacent binary `.swiftmodule`, open up the module, and pull in its optional dependencies. If an optional dependency cannot be resolved on the filesystem, fail silently without raising a diagnostic.
2023-04-17 14:47:46 -07:00
Xi Ge
68e6b22230 ModuleInterface: pass down block list file paths to module interface building context and command lines 2023-04-08 18:29:51 -07:00
Steven Wu
09b8af86fb Virtualize swift compiler outputs (#63206)
Using a virutal output backend to capture all the outputs from
swift-frontend invocation. This allows redirecting and/or mirroring
compiler outputs to multiple location using different OutputBackend.

As an example usage for the virtual outputs, teach swift compiler to
check its output determinism by running the compiler invocation
twice and compare the hash of all its outputs.

Virtual output will be used to enable caching in the future.
2023-04-05 23:34:37 +08:00
Alexis Laferrière
109e93cb88 [Serialization] Allow rebuilding modules from the resource dir on SDK mismatch
Modules loaded from the resource dir are not usually rebuilt from the
swiftinterface as it would indicate a configuration problem. Lift that
behavior for SDK mismatch and still rebuild them.

This use case applies when a toolchain is used with a different SDK than
the one use to build the modules in the toolchain.

rdar://106101760
2023-03-07 10:00:27 -08:00
Artem Chikin
a828f14160 Update lib/Frontend/ModuleInterfaceLoader.cpp
Co-authored-by: Allan Shortlidge <tshortli@gmail.com>
2023-02-28 13:24:04 -08:00
Artem Chikin
3ea5087e2f Add Swift compilation flags to enable Clang's validate-per-build-session module behavior
Add '-validate-clang-modules-once' and '-clang-build-session-file' corresponding to Clang's '-fmodules-validate-once-per-build-session' and '-fbuild-session-file='. Ensure they are propagated to module interface build sub-invocations.

We require these to be first-class Swift options in order to ensure they are propagated to both: ClangImporter and implicit interface build compiler sub-invocations.

Compiler portion of rdar://105982120
2023-02-28 13:19:05 -08:00
Artem Chikin
1e49c3bfea Merge pull request #63735 from artemcm/PrivatePeerCandidateDiscovery
[Dependency Scanning] Detect candidate files for `.private` interface files also
2023-02-22 08:09:03 -08:00
Artem Chikin
6d59868a1d [Dependency Scanning] Detect candidate files for .private interface files also 2023-02-21 09:58:33 -08:00
Artem Chikin
8e0e51a0fd Merge pull request #63697 from artemcm/SeparateExplicitModuleInputMaps
Separate parsing out Swift and Clang modules from the explicit modulemap
2023-02-20 10:46:17 -08:00
Artem Chikin
a0b5dd4241 Separate parsing out Swift and Clang modules from the explicit module map
Since https://github.com/apple/swift/pull/63178 added support for Clang modules in the explicit module map, it is possible for there to be multiple modules with the same name: a Swift module and a Clang module. The current parsing logic just overwrites the corresponding entry module in a hashmap so we always only preserved the module that comes last, with the same name.

This change separates the parsing of the modulemap JSON file to produce a separate Swift module map and Clang module map. The Swift one is used by the 'ExplicitSwiftModuleLoader', as before, and the Clang one is only used to populate the ClangArgs with the requried -fmodule-... flags.
2023-02-17 09:03:53 -08:00
Allan Shortlidge
b11dcb985e Frontend: Add a rebuild diagnostic explaining why the adjacent swiftmodule was ignored.
In https://github.com/apple/swift/pull/42486 new behavior was introduced to ignore adjacent .swiftmodule files in the SDK. This behavior has caught a few people off guard so it seems like there should be diagnostics clarifying why a rebuild is occurring in this scenario.

Resolves rdar://105477473
2023-02-15 10:06:39 -08:00
Ben Barham
6269643b4d [Index] Prevent re-indexing system modules repeatedly
If a module was first read using the adjacent swiftmodule and then
reloaded using the swiftinterface, we would do an up to date check on
the adjacent module but write out the unit using the swiftinterface.
This would cause the same modules to be indexed repeatedly for the first
invocation using a new SDK. On the next run we would instead raad the
swiftmodule from the cache and thus the out of date check would match
up.

The impact of this varies depending on the size of the module graph in
the initial compilation and the number of jobs started at the same time.
Each SDK dependency is re-indexed *and* reloaded, which is a drain on
both CPU and memory. Thus, if many jobs are initially started and
they're all going down this path, it can cause the system to run out of
memory very quickly.

Resolves rdar://103119964.
2023-02-09 11:49:13 -08:00
Artem Chikin
c1599fede4 Add -swift-module-file frontend flag for explicit Swift module dependencies 2023-02-07 11:29:09 -07:00
Tony Allevato
dda1cda4df Allow Clang modules to be listed in the explicit module map.
This lets users of `-explicit-swift-module-map-file` use a single mapping
for all module dependencies, regardless of whether they're Swift or Clang
modules, instead of manually splitting them among this file and command
line flags.
2023-01-25 16:38:34 -08:00
Artem Chikin
c677c5533c [Module Interface Loader] Propagate '-application-extension' by configuring the generic sub-invocation 2023-01-06 14:31:05 -08:00
Artem Chikin
e790a2110d [Explicit Module Builds] Add support for versioned 'canImport' to the explicit module loader
When `canImport` query requires a moduel version, open the binary '.swiftmodule' and read out the relevant metadata.

Resolves rdar://103265511
2022-12-12 14:44:03 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Alexis Laferrière
b526205f42 Merge pull request #62044 from xymus/module-alias-disambiguate-fix
[ModuleInterface] Support loading an aliased module with an underlying module
2022-11-11 11:55:44 -08:00
Alexis Laferrière
a1270f66cc [Serialization] Support loading an aliased module with an underlying module
Importing a module using an alias (set with -module-alias) fails if the
imported module has an underlying clang module.

rdar://102217790
2022-11-10 16:30:35 -08:00
Artem Chikin
2a84d6de1b Merge pull request #61919 from artemcm/InheritExtraClangStateForInterfaceSubInvocation
Inherit parent's extra Clang arguments when creating an interface build sub-invocation.
2022-11-09 09:24:18 -08:00
Alexis Laferrière
c42bdde30a Merge pull request #61980 from xymus/index-fix-silencing-swiftinterface
[ModuleInterface] Fix silencing errors mode in swiftinterface rebuild
2022-11-08 13:17:58 -08:00
Artem Chikin
d1cbf9c8d4 Inherit parent's extra Clang arguments when creating an interface build sub-invocation.
We would like to make sure they get propagated to downstream transitive Clang module dependencies also.

Resolves rdar://101923680
2022-11-08 09:32:30 -08:00
Alexis Laferrière
4a582806dc [ModuleInterface] Fix silencing errors mode in swiftinterface rebuild
Make sure we disable forwarding diagnostics from the underlying instance
when building a swiftinterface in silencing errors mode.
2022-11-08 09:31:17 -08:00
Alexis Laferrière
1ce67099de [ModuleInterface] Support aliasing a module loaded from a swiftinterface 2022-11-04 11:10:59 -07:00
Alexis Laferrière
47b29b68db Merge pull request #61649 from xymus/index-swiftinterfaces
[Index] Force indexing of system modules to read only from swiftinterfaces
2022-10-31 14:18:45 -07:00
Alexis Laferrière
83cd432785 [Frontend] Intro global control to force loading from swiftinterface
Intro ASTContext::setIgnoreAdjacentModules to change module loading to
accept load only resilient modules from their swiftinterfaces, ignoring
the adjacent module and any silencing swiftinterfaces errors.
2022-10-31 10:58:54 -07:00
Artem Chikin
c51efbed9c Add option to suppress emission of remarks ('-suppress-remarks')
And enforce it especially in downstream contexts such as building interfaces of SDK dependencies, where the remarks are not actionable by the user.
2022-10-28 10:49:27 -07:00
Adrian Prantl
3cc2831608 Don't require a strict revision match in LLDB.
For release-management purposes during development, LLDB's embedded Swift
compiler's version number can sometimes be off-by-one in the last digit
compared to the Swift compiler.

This patch restores the old behavior from before 17183629e4.

rdar://101299168
2022-10-19 09:03:13 -07:00
Artem Chikin
625048a43f Merge pull request #61545 from artemcm/PropagateApplicationExtensionStatus
Propagate '-application-extension' to module interface loader sub-invocations.
2022-10-13 08:51:23 -07:00