Commit Graph

104 Commits

Author SHA1 Message Date
swift-ci
f40f3be8a8 Merge remote-tracking branch 'origin/main' into rebranch 2024-07-03 18:14:58 -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
Xi Ge
736ccef626 Merge remote-tracking branch 'apple/main' into rebranch 2024-06-20 15:16:55 -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
swift-ci
a3c0c2f870 Merge remote-tracking branch 'origin/main' into rebranch 2024-06-05 14:36:10 -07:00
Alexis Laferrière
9779806a84 Serialization: Stop reading the control block if the format version doesn't match
rdar://128551774
2024-05-22 14:47:15 -07:00
swift-ci
97775b94ad Merge remote-tracking branch 'origin/main' into rebranch 2024-05-17 11:36:37 -07:00
Alexis Laferrière
074df70248 Serialization: Write the target SDK in the binary swiftmodule 2024-05-16 11:52:36 -07:00
swift-ci
1f60795e4d Merge remote-tracking branch 'origin/main' into rebranch 2024-04-22 12:53:37 -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
Ben Barham
cacfd3e3ae Rename llvm::support::endianness to llvm::endianness
LLVM is gearing up to move to `std::endianness` and as part of that has
moved `llvm::support::endianness` to `llvm::endianness`
(bbdbcd83e6702f314d147a680247058a899ba261). Rename our uses.
2024-04-08 08:58:58 -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
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
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
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
Kavon Farvardin
5f977ca763 NCGenerics: force module mismatches 2024-01-31 14:00:08 -08:00
Kavon Farvardin
ac91b7a512 [NCGenerics] hack for module mismatch 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
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
Artem Chikin
6e3f896962 [Dependency Scanning] Refactor primary scan operations into 'ModuleDependencyScanner' class
From being a scattered collection of 'static' methods in ScanDependencies.cpp
and member methods of ASTContext. This makes 'ScanDependencies.cpp' much easier
to read, and abstracts the actual scanning logic away to a place with common
state which will make it easier to reason about in the future.
2023-09-22 14:09:45 -07:00
Kuba Mracek
25eb997a28 [embedded] Add basics of module serialization, importing and validation in embedded Swift.
- Add a flag to the serialized module (IsEmbeddedSwiftModule)
- Check on import that the mode matches (don't allow importing non-embedded module in embedded mode and vice versa)
- Drop TBD support, it's not expected to work in embedded Swift for now
- Drop auto-linking backdeploy libraries, it's not expected to backdeploy embedded Swift for now
- Drop prespecializations, not expected to work in embedded Swift for now
- Use CMO to serialize everything when emitting an embedded Swift module
- Change SILLinker to deserialize/import everything when importing an embedded Swift module
- Add an IR test for importing modules
- Add a deserialization validation test
2023-09-06 20:06:36 -07:00
Allan Shortlidge
83b1b47249 NFC: Fix warning in ModuleFileSharedCore.cpp. 2023-08-15 17:13:10 -07:00
Hiroshi Yamauchi
24dfc905f5 [lldb] Capture error messages from parseASTSection to log from the caller.
This helps fix a lldb console output mixup between the lldb logging
and the llvm::dbgs() messages from parseASTSection.
2023-08-10 17:08:25 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07: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
Rintaro Ishizaki
6fa0c14dfb [Macros] Make 'PluginSearchOption' a external union
Create a 'Kind' enum so that deserialization can use the kind instead of
a string option name.
2023-06-16 11:59:19 -07:00
Rintaro Ishizaki
706985df82 [Macros] Update plugin search options serialization
Previously plugin search options were serialized for each option kind.
Instead serialize them in the order specified.
2023-06-15 17:32:59 -07:00
Alex Lorenz
ba8d4d7801 [cxx-interop] compilations that do not enable C++ interoperability should not be able to import modules that do enable C++ interoperability by default
A supplemental hidden frontend option allows advanced users to opt-out of this requirement.

Fixes https://github.com/apple/swift/issues/65833
Fixes https://github.com/apple/swift/issues/65832
2023-06-09 15:38:16 -07:00
Alexis Laferrière
421042ec7c Merge pull request #65370 from xymus/serial-macro-paths
[Macros] Serialize plugin search paths for LLDB use
2023-05-02 09:20:16 -07:00
Rintaro Ishizaki
3ef6087d32 [Macros] Serialize plugin search paths for LLDB use
rdar://107030743
2023-05-01 14:04:39 -07:00
Slava Pestov
1e26137379 Serialization: Serialize PackConformance 2023-04-19 16:41:51 -04:00
Alexis Laferrière
4327c7342f [Serialization] Attempt to load transitive impl-only dependencies on testable imports
Implementation-only dependencies may be referenced from internal decls.
When that module is imported as @testable, clients see the internal
decls and may fail accessing them if the transitive implementation-only
dependencies are not loaded.

Let's consider such transtive implementation-only dependencies as
optional for @testable imports. As such, the compiler will attempt to
load them for test targets, and won't fail if the dependency is missing.

We can make these dependencies required for non-public imports, but it
could be project breaking to do so for implementation-only dependencies.
Considering them as optional is a decent compromise.

rdar://79459263
2023-03-31 09:34:56 -07:00
Alexis Laferrière
f7f69c6ae1 [Serialization] Load non-public transitive dependencies on @testable imports
A @testable import allows a client to call internal decls which may
refer to non-public dependencies. To support such a use case, load
non-public transitive dependencies of a module when it's imported
@testable from the main module.

This replaces the previous behavior where we loaded those dependencies
for any modules built for testing. This was risky as we would load more
module for any debug build, opening the door to a different behavior
between debug and release builds. In contrast, applying this logic to
@testable clients will only change the behavior of test targets.

rdar://107329303
2023-03-29 13:59:28 -07:00
Alexis Laferrière
599346885e [Serialization] Differentiate module loading behavior for non-public imports
Differentiate `internal` and `fileprivate` imports from
implementation-only imports at the module-wide level to offer a
different module loading strategy. The main difference is for non-public
imports from a module with testing enabled to be loaded by transitive
clients.

Ideally, we would only load transitive non-public dependencies on
testable imports of the middle module. The current module loading logic
doesn't allow for this behavior easily as a module may be first loaded
for a normal import and extra dependencies would have to be loaded on
later imports. We may want to refactor the module loading logic to allow
this if needed.

rdar://106514965
2023-03-21 16:46:53 -07:00
Alexis Laferrière
d7cd65cdd6 [Serialization] Move some package-only import logic from writer to reader
Let's centralize the logic deciding if we load a transitive dependency
on the client side and have the producer write the truth in the
swiftmodule.
2023-03-21 16:45:49 -07:00
Alexis Laferrière
8aadcf464f [Serialization] Do not accept packages without a name
Realign the module loading behavior with the one of the package
access-level. If the package name is an empty string, don't accept other
modules with an empty package name as being part of the same module and
don't load package dependencies in such a case.
2023-03-20 14:03:45 -07:00
Alexis Laferrière
56e013edb9 [Serialization] Try to load transitive package dependencies in the debugger 2023-03-20 14:03:45 -07:00
Alexis Laferrière
61c0827427 [Serialization] Refactor logic deciding transitive module loading logic
Refactor and centralize the logic about how implementation-only and
package-only dependencies should be loaded.
2023-03-20 13:53:10 -07:00
Alexis Laferrière
1b86261a74 [Serialization] Exit right way on any invalid swiftmodule file
The previous behavior kept going even after we reported an invalid
swiftmodule. As such it ended up losing the precise invalid reason and
returned Malformed later on.
2023-03-07 09:55:50 -08:00
Alexis Laferrière
6980cf211b [Serialization] Intro package-only module wide information and serialize it 2023-03-03 11:43:20 -08:00
swift-ci
b08054dcc3 Merge remote-tracking branch 'origin/main' into rebranch 2023-02-14 09:38:50 -08:00
Alexis Laferrière
a5ccbf3264 [Serialization] Only remark if the last digit mismatches in precise tag check
Weaken the precise tag check at loading swiftmodule to accept binary
modules build by a compiler with a tag where only the last digit is
different. We assume that the other digit in the version should ensure
compiler and stdlib compatibility. If the last digit doesn't match,
still raise a remark.

rdar://105158258
2023-02-13 14:28:10 -08:00
Alexis Laferrière
e079db233f [Serialization] Update env var to disable precise tag check
Rename the env var to SWIFT_IGNORE_SWIFTMODULE_REVISION as it's
recommended for use outside of testing.
2023-02-13 13:51:30 -08:00
Alexis Laferrière
4579e37e61 [Serialization] Intro distinct compiler revision string for serialization 2023-02-13 13:51:30 -08:00
swift-ci
0db0a3e7a5 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-27 21:35:06 -08:00
Alexis Laferrière
39fb1c5f55 [ModuleInterface] Intro export-as for Swift modules
Introduce a new flag `-export-as` to specify a name used to identify the
target module in swiftinterfaces. This provides an analoguous feature
for Swift module as Clang's `export_as` feature.

In practice it should be used when a lower level module `MyKitCore` is
desired to be shown publicly as a downstream module `MyKit`. This should
be used in conjunction with `@_exported import MyKitCore` from `MyKit`
that allows clients to refer to all services as being part of `MyKit`,
while the new `-export-as MyKit` from `MyKitCore` will ensure that the
clients swiftinterfaces also use the `MyKit` name for all services.

In the current implementation, the export-as name is used in the
module's clients and not in the declarer's swiftinterface (e.g.
`MyKitCore`'s swiftinterface still uses the `MyKitCore` module name).
This way the module swiftinterface can be verified. In the future, we
may want a similar behavior for other modules in between `MyKitCore` and
`MyKit` as verifying a swiftinterface referencing `MyKit` without it
being imported would fail.

rdar://103888618
2023-01-26 14:27:31 -08:00
swift-ci
50fff10c87 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-19 23:54:19 -08:00
Ellie Shin
72ee150982 Add -package-name flag
De/serialize package name in module binary
Resoles rdar://103531218, rdar://103531208
2022-12-19 14:33:44 -08:00