Commit Graph

515 Commits

Author SHA1 Message Date
Steven Wu
8150fb001d [InterfaceFile] Improve flag extraction from interface file
Improve the version/flags extract from interface file by moving away
from using Regex and limiting the search to the beginning of the file.

Switch away from Regex will give 5-10% improvement in time and
instruction counts, and limiting the search lines can save a lot of time
if the swiftinterface is large. For example, the extract time for Swift
stdlib is 10x faster after the patch.

Current strategey for limiting the line to search is by only parsing the
first comment block.
2024-10-31 12:46:05 -07:00
Pavel Yaskevich
84a62fc170 [Frontend/Serialization] Narrow -swift-compiler-version to -interface-compiler-version
It might be unexpected to future users that `-swift-compiler-version`
would produce a version aligned to .swiftinterface instead of one used
to build the .swiftmodule file. To avoid this possible confusion, let's
scope down the version to `-interface-compiler-version` flag and
`SWIFT_INTERFACE_COMPILER_VERSION` option in the module.
2024-10-28 13:45:27 -07:00
Pavel Yaskevich
ab4d8f61eb [Serialization] Add -swift-compiler-version option to swiftmodules 2024-10-25 09:53:40 -07:00
Daniel Rodríguez Troitiño
4e2fbe17c3 [swiftinterface] Handle target variants the same as targets (#77156)
Based on preliminary work from @rmaz.

The compilation arguments for a swiftinterface file are preprocessed to
modify the `-target` argument to match the preferred target (which comes
from the command line) in cases in which the sub-architecture differs,
but it is compatible (for example using `arm64e` when `arm64` is being
compiled), but this was not done for the target variant, which ended up
with mismatches on the sub-architecture used by the target and target
variant, which fails an assert in assert toolchains.
2024-10-22 16:34:19 -07:00
Steven Wu
e0541b0357 [Macro][Dependencies] Properly model macro dependencies in the scanner
Add function to handle all macro dependencies kinds in the scanner,
including taking care of the macro definitions in the module interface
for its client to use. The change involves:
  * Encode the macro definition inside the binary module
  * Resolve macro modules in the dependencies scanners, including those
    declared inside the dependency modules.
  * Propagate the macro defined from the direct dependencies to track
    all the potentially available modules inside a module compilation.
2024-09-19 16:41:53 -07:00
Alexis Laferrière
8d28ed4fa9 Merge pull request #76269 from xymus/public-module-name
Diagnostics: Intro the public module name concept to hide support modules from clients
2024-09-09 16:57:12 -07:00
Artem Chikin
b70824c44d Merge pull request #76321 from artemcm/PackageOnlyAdjacentScanFix
[Dependency Scanning] Query package-only dependencies from adjacent binary modules when necessary
2024-09-09 09:53:01 -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
Alexis Laferrière
c70162c703 Merge branch 'main' into public-module-name 2024-09-05 20:02:07 -07:00
Allan Shortlidge
4c3a009c2b SILGen: Remove triplesAreValidForZippering() assert.
This assert was correctly catching the fact that `-target-variant` is not being
normalized at the same time as `-target` when building arm64e modules from
swiftinterface. That should be fixed, but at the moment it isn't causing any
concrete harm and the assertion fails when building against the SDKs included
with the latest Xcode 16 betas.

Resolves rdar://133020098.
2024-09-04 22:39:21 -07:00
Alexis Laferrière
214da85183 Sema: Keep public module name in ModuleDecl 2024-09-04 16:20:12 -07:00
Egor Zhdan
bfe72b4be9 Merge pull request #75589 from swiftlang/egorzhdan/linux-libcxx-interop
[cxx-interop] Allow compiling with libc++ on Linux
2024-08-09 13:42:29 +01:00
Egor Zhdan
059f0f97d1 [cxx-interop] Allow compiling with libc++ on Linux
This makes sure that Swift respects `-Xcc -stdlib=libc++` flags.

Clang already has existing logic to discover the system-wide libc++ installation on Linux. We rely on that logic here.

Importing a Swift module that was built with a different C++ stdlib is not supported and emits an error.

The Cxx module can be imported when compiling with any C++ stdlib. The synthesized conformances, e.g. to CxxRandomAccessCollection also work. However, CxxStdlib currently cannot be imported when compiling with libc++, since on Linux it refers to symbols from libstdc++ which have different mangled names in libc++.

rdar://118357548 / https://github.com/swiftlang/swift/issues/69825
2024-08-08 16:24:58 +01:00
Xi Ge
370bcec229 Merge pull request #75704 from swiftlang/version-number-hack
DependencyScanner: report user module version in dependency scanning results for binary Swift modules
2024-08-06 15:42:39 -07:00
Xi Ge
b4d64bde55 DependencyScanner: report user module version in dependency scanning results for binary Swift modules 2024-08-06 11:43:53 -07:00
Adrian Prantl
f0902a9163 Expose an ImportNonPublicDependencies LangOpt for LLDB (NFC).
This patch allows controlling the automatic import of private dependencies
separately from the DebuggerSupport option, which currently also triggers this
behavior. With explicit modules + precise compiler invocations LLDB is moving
towards no longer needing this behavior.

rdar://133088201
(cherry picked from commit a1ba7159e3)
2024-08-05 12:53:43 -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
Ellie Shin
5e58876b16 Update tests 2024-07-11 13:13:00 -07:00
Ellie Shin
255a0940de Correct discrepancies in the package interface file lookup.
Add a check for the client side flag which explcitly opts in to loading the package interface,
besides whether package-name is empty or in the same package.

rdar://131393508
2024-07-10 18:23:15 -07:00
Artem Chikin
2464f87f8f [Dependency Scanning] Resolve cross-import overlays relative to defining interface for prebuilt binary Swift dependencies
When the dependency scanner picks a pre-built binary module candidate for a given dependency, it needs to be able to attempt to resolve its cross-import overlays relative to the textual interface that the binary module was built from. For example, if a collection of binary modules are located in, and resolved as dependencies from, a pre-built module directory, the scanner must lookup their corresponding cross-import overlays relative to the defining interface as read out from the binary module's MODULE_INTERFACE_PATH. https://github.com/swiftlang/swift/pull/70817 ensures that binary modules serialize the path to their defining textual interface.

Resolves rdar://130778577
2024-07-03 10:05:54 -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
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
6ea604bf9f Always add an implicit import of 'Cxx' module when C++ Interop is enabled.
We cannot always rely on being able to do so only as an overlay query upon loading 'requires cplusplus' modulemap modules. The 'requires' statement only applies to submodules, and we may not be able to query language feature modulemap attributes in dependency scanning context.
2024-05-20 10:23:10 -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
10b30483dd [ScanDependency] Allow continue searching for testable module
When swift dependency scanner first finds a binary module for a testable
import, verify if the module is built for enable-testing or not. If not,
keeps searching in case there is a second testable binary module in the
search path.

Previously, the first binary module will always be accepted by scanner
and rely on the importer to provide a good diagnostics. Now the scanner
will emit a warning before continue searching, so user understands why
the binary in the search path is not taken.
2024-04-24 12:35:45 -07:00
Ellie Shin
0c0d8c0316 Merge branch 'main' into elsh/pkg-sil-verify 2024-04-18 13:34:29 -07:00
Ellie Shin
45e8454a9e Merge branch 'main' into elsh/pkg-sil-verify 2024-04-17 22:46:55 -07:00
Ellie Shin
fbb3382e21 During Package CMO, SIL cloning happens during which
SILOptions::EnableSerializePackage info is lost.

SILVerifier needs this info to determine whether resilience
can be bypassed for decls serialized in a resiliently
built module when Package CMO optimization enabled.

This PR adds SerializePackageEnabled bit to Module format
and uses that in SILVerifier.

Resolves rdar://126157356
2024-04-17 22:37:48 -07:00
Steven Wu
77fefe9a75 [ScanDependencies] Do not count optional dependencies when not needed
If a testable module is loaded from a non-testable import, ignore its
optional dependencies because the consumer should not use them. This
matches the behavior of the implicit build or the behavior how
forwarding module is created.
2024-04-17 19:10:58 -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
Artem Chikin
01d891ad99 Merge pull request #72834 from artemcm/UpstreamVisionOS
Introduce visionOS Platform
2024-04-15 09:33:49 -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
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
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
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
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
Artem Chikin
d113ea11ac Merge pull request #72067 from artemcm/FixTransitiveHeaderLookupInDependencyScan
[Dependency Scanning] Scan header inputs of binary Swift module dependencies
2024-03-06 16:05:12 -08:00
Artem Chikin
bfa8c0ee4f [Dependency Scanning] Scan header inputs of binary Swift moduel dependencies
Otherwise they may have module dependencies of their own which will not be detected by the scanner and included in the list of explicit inputs for compilation.
2024-03-06 11:02:35 -08:00
Steven Wu
698ae7b4ee Merge pull request #72091 from cachemeifyoucan/eng/PR-124056756
[PackageInterface] Reduce parsing interface file for package-name
2024-03-05 13:31:55 -08:00
Steven Wu
1081f561c4 [PackageInterface] Reduce parsing interface file for package-name
Try best to avoid parsing interface file to extract package name during
dependency discovery to improve scanning performance.

rdar://124056756
2024-03-05 09:12:37 -08:00
Ellie Shin
30669fca65 Currently when checking if resilience check can be bypassed within a package,
we only check if the loaded module is built from a package interface. This is
not enough as a binary module could just contain exportable decls if built with
experimental-skip-non-exportable-decls, essentially resulting in content equivalent
to interface content. This might be made a default behavior so this PR requires
a module to opt in to allow non-resilient access by a participating client in the
same package.

Since it affects module format, SWIFTMODULE_VERSION_MINOR is updated.

rdar://123651270
2024-03-01 15:13:58 -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
Steven Wu
aa5ef5773c Fix a use-after-free in getPackageInterfacePathIfInSamePackage
Fix a use-after-free bug in package-name extraction code, where the
BumpPtrAllcoator is destroyed before a StringRef that uses the allocated
name is used.
2024-02-26 15:55:49 -08:00