Commit Graph

229 Commits

Author SHA1 Message Date
Kavon Farvardin
08b71e0136 NCGenerics: rebuild stdlib from its interface
When a NoncopyableGenericsMismatch happens between the compiler and
stdlib, allow the compiler to rebuild the stdlib from its interface
instead of exiting with an error.
2024-02-15 18:08:54 -08:00
Artem Chikin
b816a3e883 Merge pull request #71624 from artemcm/DepScanCxxInteropImportNo
[Dependency Scanning] Interface-scanning sub-invocations should not attempt to import `CxxShims`
2024-02-15 11:57:08 -08:00
Artem Chikin
bb5e20d015 [Dependency Scanning] Interface-scanning sub-invocations should not attempt to import CxxShims
Swift interfaces currently aren't meant to expose C++ in their API so we should not also bring in this C++-related module dependency which is not found when the ClangImporter is not configured for C++.
2024-02-15 09:15:22 -08:00
Doug Gregor
81ffafdc6a Merge pull request #70602 from ApolloZhu/macro/expression-as-default-argument
[Macros] Expression macro as caller-side default argument
2024-02-14 16:10:11 -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
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
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
55cc29f4cd [Explicit Module Build] Execute module interface verification in a sub-invocation context
Otherwise, with `-explicit-interface-module-build` they do not read out/inherit compiler flags written in the interface itself.

Resolves rdar://122418125
2024-02-07 08:46:25 -08:00
Apollo Zhu
512308357c Load plugin libraries when type checking swiftinterface 2024-02-06 15:02:14 -08:00
Steven Wu
1ababc0bda [Caching] Fix versioned canImport check for swift module
Fix the ExplicitCASModuleLoader check for if `canImport` works for a
specific swift module. It was mistakenly using the clang caching schema
to load the underlying module but in reality, it should only load swift
module with swift caching schema.

In future, we should let dependency scanner to report version/underlying
version for the modules it enounters so the versioned canImport check
doesn't need to load and parse the module/TBD file to figure out if the
check is successful or not.

rdar://120554271
2024-01-30 16:08:42 -08:00
Kavon Farvardin
931f47d02c [NCGenerics] require associated type inference when rebuilding module 2024-01-23 22:42:38 -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
Ben Barham
d51c58a6f9 [Basic] hasFeature should succeed for promoted language features
Merge `$<Feature>` and `hasFeature` implementations.
  - `$<Feature>` did not support upcoming language features.
  - `hasFeature` did not support promoted language features and also
    didn't take into account `Options` in `Features.def`.

Remove `Options` entirely, it was always one of three cases:
  - `true`
  - `langOpts.hasFeature`
  - `hasSwiftSwiftParser`

Since `LangOptions::hasFeature` should always be used anyway, it's no
longer necessary. `hasSwiftSwiftParser` can be special cased when adding
the default promoted language features (by removing those features).

Resolves rdar://117917456.
2024-01-05 10:26:13 -08:00
Artem Chikin
1a60dae74a Merge pull request #70335 from artemcm/DepScanSkipSwiftDependencyClangSearchPaths
[Explicit Moduele Builds] Look through forwarding modules for `canImport` version check.
2023-12-08 18:40:13 -08:00
Artem Chikin
22d39e91e7 [Explicit Moduele Builds] Look through forwarding modules for 'canImport' version check.
Otherwise we default to version 0 for all modules which get forwarded.

Resolves rdar://119346213
2023-12-08 15:20:50 -08:00
Artem Chikin
60b3a4c6a9 Merge pull request #70316 from artemcm/DepScanSkipSwiftDependencyClangSearchPaths
[Dependency Scanning] Filter out '-Xcc' search paths from Swift module compilation commands
2023-12-08 14:45:29 -08:00
Artem Chikin
f5e2b24912 [Dependency Scanning] Filter out '-Xcc' search paths from Swift module compilation commands
These search paths will not get used during Swift module compilation and can only hinder module sharing among different targets.

Resolves rdar://119217774
2023-12-08 10:38:44 -08:00
Adrian Prantl
5ef93af269 Revert "Don't require a strict revision match in LLDB."
This reverts commit 3cc2831608.

The compiler's revision check has been relaxed since the feature was introduced
and so it's nos better to reduce the number of special code paths for LLDB in
the compiler to facilitate reasoning about it.

rdar://117824367
2023-12-06 11:14:14 -08:00
Ben Barham
eba98a6367 [Frontend] Ensure constraint solving runs salvaging
When index-while-building is enabled, system modules are rebuilt from
their interface with diagnostics silenced so failures are not propagated
to the build. This is enabled via a local diagnostic engine that has no
consumers.

Typechecking uses the lack of consumers to add
`ConstraintSystemFlags::SuppressDiagnostics`, which controls whether
salvaging (and output of diagnostics) is run. There are cases today
where salvaging can find a correct solution though, so we should ensure
that it's always run.

This is a quick workaround for the indexing case - we should instead
always run salvaging, regardless of whether diagnostics are suppressed
or not.

Resolves rdar://117133297.
2023-11-30 12:01:20 -08:00
Ellie Shin
e8d43434db Merge pull request #69733 from apple/es-pkg-intf
Introduce a package interface
2023-11-15 03:53:49 -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
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