Commit Graph

320 Commits

Author SHA1 Message Date
Steven Wu
7ed9a52633 [PrefixMap] Remap clang cc1 args when building swift interfaces
Fix a bug that swift clang importer is not setup correctly when prefix
map is used. There are two separate issues:
* CC1 args used to setup clang import when building swift (interface and
  sources) are not correctly remapped.
* When loading SDKInfo from SDK path, the SDKSettings.json is not
  loading from VFS, thus the file cannot be loaded from remapped path.

rdar://134458611
2024-08-23 10:32:20 -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
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
Steven Wu
da10a02231 [Macro] Fix bugs in macro dependency scanning
Fix few issues from previous implementation from explicit module build
with macros and accurate macro dependency scanning in
https://github.com/swiftlang/swift/pull/73421.

First, there is a crash when propagating the macro dependencies. It
turns out that the current macro plugin implementation doesn't need the
downstream users to know about the plugin search path from the upstream
dependencies.

Secondly, fix a bug that the swiftinterface that has macro usage won't
build because the build command doesn't inherit the plugin search path
option.

Finally, add JSON output for macro dependencies so it is easier to
debug the macro dependencies.

rdar://131214106
2024-07-09 10:37:27 -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
Steven Wu
42732c0073 [ScanDependency] Handle -Xcc options that affects module generation
Make sure the `-Xcc` options to the scanner are correctly considered
when creating ClangImporterCC1 arguments for constructed swift interface
compilation job. Under directcc1 mode, `-Xcc` options should be used to
constructed sub-invocation but should not be added to GenericArgs for
constructing interface compilation jobs.

rdar://128873665
2024-06-03 09:57:10 -07:00
artemcm
ec4e0e23aa Allow users to opt-out of implicit Cxx import with -disable-implicit-cxx-module-import 2024-05-20 11:18:45 -07:00
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