Commit Graph

260 Commits

Author SHA1 Message Date
Artem Chikin
bc17581ae6 [Explicit Module Builds] Propagate the C++ Interop mode to interface sub-invocations and dependency scanner 2024-05-20 10:23:10 -07:00
Steven Wu
431f097e7c [Caching] Mark -typecheck action as caching supported
This is a regression causing lots of cached diagnostics tests not
functioning since the cached diagnostics processors are not initialized
for those tests which are supposed to test diagnostics caching.

The regression is caused by the fix that the typecheck module interface
job need to run a typecheck job in the sub-invocation. Now the typecheck
module interface job is correctly setup to avoid diagnostics about
unsupported file system error.
2024-05-13 09:36:12 -07:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -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
Ben Barham
1fdda023b3 Rename StringRef::endswith references to StringRef::ends_with
Missed this when doing the `startswith` renaming. `endswith` has also
been deprecated upstream (and presumably soon to be removed).
2024-04-01 10:59:16 -07:00
Artem Chikin
d9c00d8dd6 Merge pull request #72668 from artemcm/DepScanBinaryModuleHeaderDepModuleDeps
[Explicit Module Builds] Only specify '-fmodule-map-file' for bridging header Clang module dependencies
2024-03-29 09:02:10 -07:00
Allan Shortlidge
12fccfc4e0 Frontend: Really allow any experimental feature when compiling a module interface.
The fix for https://github.com/apple/swift/pull/72632 was not sufficient
because when modules are built from textual interface that happens in a
sub-invocation which does not have typecheck-from-interface or
compile-from-interface requested action. Instead of checking a requested
action, set a language option to control whether non-production experimental
features are allowed.

Resolves rdar://125561443
2024-03-28 14:48:15 -07:00
Artem Chikin
f3816e0335 [Explicit Module Builds] Only specify '-fmodule-map-file' for bridging header Clang module dependencies
Relying on the corresponding field in the '-explicit-swift-module-map-file' provided by the driver.

Only bridging headers require a module map because that's what aids header include resolution. With lazy module loading today, '.modulemap' parsing which happens when instantiating Clang is responsible for associating headers with modules. Then upon encountering a header include inside the bridging header the compiler knows which module corresponds to said header and is then able to load explicitly-provided PCM for that module. For all other module dependencies, they are only ever queried by-name from Swift, so '.modulemap' parsing is not necessary.
2024-03-28 13:47:13 -07:00
Steven Wu
3a341eaf16 Merge pull request #72498 from cachemeifyoucan/eng/PR-125194535
[ScanDependencies] Do not inherit driver options in direct-cc1 mode
2024-03-22 10:09:16 -07:00
Steven Wu
aad00e60cf [ScanDependencies] Do not inherit driver options in direct-cc1 mode
When direct-cc1 scanning mode is enabled, do not inherit -Xcc options
from the commandline as those are driver flags and clang importer
already handle the conversion.

rdar://125194535
2024-03-21 20:48:00 -07:00
Steven Wu
e99a93b068 [Caching] Give swiftmodule loaded from CAS a path identifier
Assign the path returned from dependency scanner for the module to the
buffer identifier when loading modules from CAS. This fixes a warning in
module trace file generation about invariant violation and also an
assertion when generating swiftdeps file.

rdar://122905379
2024-03-19 13:34:33 -07:00
Kavon Farvardin
76c6510519 Merge pull request #72276 from kavon/ncgenerics-xfails-3 2024-03-16 04:18:35 -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
Kavon Farvardin
149c052ec5 use new noncopyable types infrastructure
The infrastructure underpinning the new feature NoncopyableGenerics is
mature enough to be used.
2024-03-14 23:10:44 -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
Alexis Laferrière
c13a4c57ee Merge pull request #71617 from xymus/swiftinterface-by-default-mode
ModuleInterface: Setup logic to load distributed swiftinterfaces over swiftmodules by default
2024-03-12 07:52:15 -07:00
Steven Wu
177bbe64d4 Merge pull request #71118 from cachemeifyoucan/eng/PR-119275464
[Caching] Create clang importer from cc1 args directly
2024-03-11 13:50:34 -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
9f736811f0 [swiftinterface] Improve target overwrite for the swiftinterface
In certain cases (e.g. using arm64e interface to build arm64 target),
the target needs to be updated when building swiftinterface. Push the
target overwrite as early as possible to swiftinterface parsing by
providing a preferred target to relevant functions. In such cases, the
wrong target is never observed by other functions to avoid errors like
the sub-invocation was partially setup for the wrong target.
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
Slava Pestov
af8c8f1671 Sema: Remove non-experimental associated type inference 2024-03-07 17:30:17 -05:00
Alexis Laferrière
7edd23a627 Serialization: allow different channels to share a module cache location 2024-03-01 10:54:29 -08:00
Alexis Laferrière
1e4fe67f40 Serialization: restrict swiftmodules to distribution channels
There are scenarios where different compilers are distributed with
compatible serialization format versions and the same tag. Distinguish
swiftmodules in such a case by assigning them to different distribution
channels. A compiler expecting a specific channel will only read
swiftmodules from the same channel. The channels should be defined by
downstream code as it is by definition vendor specific.

For development, a no-channel compiler loads or defining the env var
SWIFT_IGNORE_SWIFTMODULE_REVISION skips this new check.

rdar://123731777
2024-03-01 10:52:44 -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
Alexis Laferrière
4945cfcad1 ModuleInterface: Setup logic to load swiftinterfaces by default
The Swift compiler can load either the binary swiftmodule file or the
textual swiftinterface file when importing a module. It currently picks
the swiftmodule over the swiftinterface, unless there’s an exception. We
should flip the default for distributed modules, prefer the
swiftinterface over the swiftmodule unless there’s an exception.

rdar://122955640
2024-02-27 10:26:31 -08:00
Artem Chikin
1c652ef2fe Merge pull request #71901 from artemcm/InterfaceVerifyUseXccFix
[Explicit Module Builds] Explicit interface verification sub-invocations must always inherit `-Xcc` flags from the parent instance.
2024-02-27 09:12:14 -08:00
Artem Chikin
b9d7ead714 [Explicit Module Builds] Explicit interface verification sub-invocations must always inherit -Xcc flags from the parent instance.
Otherwise they may be unable to use the explicit module dependencies which were built in the same driver invocation using those `-Xcc` flags.

Resolves rdar://123648621
2024-02-26 14:27:14 -08:00
Steven Wu
be80b95e42 [ModuleInterfaceLoader] Save a parseArg in subInvocation
Avoid parseArg twice with the same compiler invocation with minimal flag
differences. NFC.
2024-02-26 11:10:13 -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
2ded8badf7 Merge pull request #71586 from cachemeifyoucan/eng/PR-122814823
[Caching] Do not mix swift modules built from CAS vs. from FileSystem
2024-02-16 10:50:40 -08:00
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
8fd0f73ff9 [Caching] Do not mix swift modules built from CAS vs. from FileSystem
Use a different context hash for modules built from caching using CAS
vs. normal swift modules. They should not be mixed since those cannot be
loaded as a dependencies for a module which is setup to build with a
different method.

rdar://122814823
2024-02-13 11:27:59 -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