Commit Graph

122 Commits

Author SHA1 Message Date
Xi Ge
d144524209 CustomAvailability: synthesized dynamic availability checking function should be private
When compiling a Swift module in incremental mode, each Swift source file is compiled into an object file
and we use linker to link them together. Because the predicate function for checking dynamic feature
availability is eagerly synthesized per compilation unit, the linker will complain about duplicated
symbols for them. Setting their visibility as private ensures that linker doesn't see them, thus addressing
the linker errors.

One workaround for this problem is to enable WMO.

rdar://164971313
2025-11-18 09:19:26 -08:00
Slava Pestov
819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Xi Ge
e31c1cc7f8 CustomAvailability: avoid exposing the synthesized function for dynamic availability checking as an API entry
For dynamic features defined from a header, we synthesize a pure Clang function to check whether the feature should
be enabled at runtime. Swift modules don't have capability to deserialize this clang predicate function, leading to
crasher as a result. This change fixes the crasher by hiding the synthesized function to be a module internal one.

rdar://164410957
2025-11-10 09:26:28 -08:00
Doug Gregor
020b69d4b6 [SE-0497] Implement @export attribute syntax
Implement the @export(implementation) and @export(interface) attributes
to replace @_alwaysEmitIntoClient and @_neverEmitIntoClient. Provide a
warning + Fix-It to start staging out the very-new
@_neverEmitIntoClient. We'll hold off on pushing folks toward
@_alwaysEmitIntoClient for a little longer.
2025-11-07 22:00:40 -08:00
Doug Gregor
34e47290f1 [C++ interop] Fix manual mangling of C++ base method thunks
When creating a C++ method that thunks from a particular C++ derived
class to call a method on one of its base classes, we do some manual
name mangling. This name mangling did not properly capture all of the
aspects of the thunk, so it was prone to collisions.

In moving to SIL asmname, we got a different set of collisions from
the ones that existed previously. Expanding the mangling to account
for small differences (const or not) as well as the base class type
eliminates these collisions. Most of the test changes account for the
new mangling, but the member-inheritance test indicates that this
change fixes an existing miscompile as well.
2025-10-29 19:35:57 -07:00
Hamish Knight
169096c233 [AST] Rename mangleDeclAsUSR -> mangleDeclWithPrefix
This is used by other things that don't necessarily want an IDE
USR.
2025-10-23 09:11:17 +01:00
Hamish Knight
73710e3eef [AST] Introduce Decl::addAttribute
Introduce a convenience entrypoint that also calls `attachToDecl` on
the attribute, and migrate all existing uses of `getAttrs().add` onto
it.
2025-10-16 11:21:54 +01:00
Egor Zhdan
f157e71ff5 [cxx-interop] Honor default expressions for unnamed arguments
We stumbled upon an old workaround that disabled the synthesis of Swift default expressions for C++ function parameters that don't have a name.

This change removes the workaround.

rdar://162310543
2025-10-10 16:06:55 +01:00
Henrik G. Olsson
5519be8b7c Move span to conditional header in libstdc++ module map
`span` is not available in all versions of libstd++, so make it a
conditional header. Also adds other missing c++20 headers.

Fixing this triggered an assert when importing a constant initialized
`wchar_t` variable, so that is also fixed. The reason is that `wchar_t`
is mapped to `Unicode.Scalar`, which cannot be directly initialized by
integer literals in Swift, triggering an assert when looking up the
protocol conformance for `_ExpressibleByBuiltinIntegerLiteral`.

rdar://162074714
2025-10-06 16:02:35 -07:00
swift-ci
2b9632fde3 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-30 07:55:22 -07:00
susmonteiro
7e14a8ea40 [cxx-interop] SWIFT_NONCOPYABLE overlooked in some cases 2025-09-30 09:28:58 +01:00
swift-ci
ef534479d5 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-22 18:21:46 -07:00
Egor Zhdan
6b4c7fcd80 Merge pull request #84343 from egorzhdan/egorzhdan/retain-release-methods
[cxx-interop] Allow retain/release operations to be methods
2025-09-22 21:53:28 +01:00
Egor Zhdan
e78ce6165f [cxx-interop] Allow retain/release operations to be methods
Some foreign reference types such as IUnknown define retain/release operations as methods of the type.

Previously Swift only supported retain/release operations as standalone functions.

The syntax for member functions would be `SWIFT_SHARED_REFERENCE(.doRetain, .doRelease)`.

rdar://160696723
2025-09-22 12:01:17 +01:00
swift-ci
b08d731e34 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-16 19:16:11 -07:00
susmonteiro
2640c71ec0 [cxx-interop] Refactor copyability out of CxxRecordSemantics 2025-09-16 14:40:16 +01:00
Anthony Latsis
44c480e83b Mnually merge main -> rebranch
Conflicts:
* `lib/ClangImporter/ClangModuleDependencyScanner.cpp`:
  https://github.com/swiftlang/swift/commit/5e09125
*	`utils/build.ps1`: https://github.com/swiftlang/swift/pull/83523
2025-08-19 21:51:34 +01:00
Kuba (Brecka) Mracek
4ca136a9b9 Merge pull request #83791 from kubamracek/const-objcbool
[ClangImporter] Skip importing values for ObjCBool declarations
2025-08-19 07:37:19 -07:00
Kuba Mracek
7b0eff8616 [ClangImporter] Skip importing values for ObjCBool declarations 2025-08-18 10:16:51 -07:00
Gabor Horvath
66d15a1813 Reapply [cxx-interop] Avoid copies when accessing pointee
After #83289 and #82879 landed we should no longer get deserialization
failures and this feature is no longer behind a flag. This patch also
changes how we query if a function's return value depends on self.
Previously, we queried the lifetime dependencies from the Swift
declaration. Unfortunately, this is problematic as we might have not
finished fully importing the types in the function signature just yet
and the compiler might end up populating the conformance tables
prematurely. To work this around, I store functions with self-dependent
return values where lifetimes are computed in the importer for later
use.

The PR also adds a test to make sure the addressable dependency feature
will not result in deserialization errors.

rdar://155319311&154213694&112690482&128293252
2025-08-18 10:51:43 +01:00
swift-ci
5c840b6e1a Merge remote-tracking branch 'origin/main' into rebranch 2025-08-07 18:54:54 -07:00
Susana Monteiro
d237e2ea41 Merge pull request #83543 from susmonteiro/susmonteiro/overrides-of-pure-virtual-methods
[cxx-interop] Support overriding pure virtual methods from value types
2025-08-07 16:52:25 +01:00
susmonteiro
5dd038fcc0 [cxx-interop] Support overriding pure virtual methods from value types 2025-08-06 16:46:33 +01:00
swift-ci
245a6c3315 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-05 22:15:17 -07:00
Gabor Horvath
e4a120b63c [cxx-interop] Support importing subscript operators with multiple params
Previously, the compiler would crash on them.

rdar://133541125
2025-08-05 15:27:53 +01:00
swift-ci
7484d604fe Merge remote-tracking branch 'origin/main' into rebranch 2025-08-01 14:35:18 -07:00
Gabor Horvath
087793394c [cxx-interop] Fix import virtual methods with rvalue ref params
We generate forwarding calls for virutal methods. These forwarding calls
had a type error when the original parameter had an rvalue reference
type. In those scenarios we need to insert a static cast to make the
type checker happy.

rdar://154969620
2025-08-01 17:26:05 +01:00
Anthony Latsis
3f841b515c Merge remote-tracking branch 'origin/main' into jepa-rebranch 2025-07-30 14:31:33 +01:00
Doug Gregor
63135e8929 [Clang importer] Diagnose various issues with the new "destroy:"
When we cannot respect the "destroy:" annotation, mark the type as
deprecated with a message thst says why there is a problem. There are
various potential problems:

* Multiple conflicting destroy functions
* Destroy functions that don't meet the pattern
* Type isn't imported as a move-only type
* Type has a non-trivial destructor (in C++)
2025-07-28 13:52:50 -07:00
swift-ci
c8477b5f42 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-23 13:17:41 -07:00
Doug Gregor
858383c71d Merge pull request #83173 from DougGregor/shared-reference-of-incomplete
[Clang importer] Import incomplete SWIFT_SHARED_REFERENCE types
2025-07-23 13:11:56 -07:00
swift-ci
4bbcafe674 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-23 10:57:03 -07:00
Kuba (Brecka) Mracek
407ef9a302 Merge pull request #83238 from kubamracek/const-cgfloat-typedef
[ClangImporter] Skip importing values for CGFloat typedefs on top of CGFloats direct
2025-07-23 10:43:24 -07:00
swift-ci
c4c8d81d28 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-23 04:37:12 -07:00
Gábor Horváth
d7bdbcb1c0 Merge pull request #83231 from Xazax-hun/addressable-params-copy-revert
Revert [cxx-interop] Avoid copies when accessing pointee
2025-07-23 12:31:14 +01:00
Doug Gregor
72be0e0851 [Clang importer] Import incomplete SWIFT_SHARED_REFERENCE types
Normally, Swift cannot import an incomplete type. However, when we are
importing a SWIFT_SHARED_REFERENCE type, we're always dealing with
pointers to the type, and there is no need for the underlying type to
be complete. This permits a common pattern in C libraries where the
actual underlying storage is opaque and all APIs traffic in the
pointer, e.g.,

    typedef struct MyTypeImpl *MyType;
    void MyTypeRetain(MyType ptr);
    void MyTypeRelease(MyType ptr);

to use SWIFT_SHARED_REFERENCE to import such types as foreign
references, rather than as OpaquePointer.

Fixes rdar://155970441.
2025-07-22 20:20:23 -07:00
Kuba Mracek
6ec280d4e1 [ClangImporter] Skip importing values for CGFloat typedefs on top of CGFloats direct 2025-07-22 10:10:15 -07:00
swift-ci
ee1864d173 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-22 08:38:56 -07:00
John Hui
4738cbbe40 [cxx-interop] Use the correct access for synthesized setterDecl (#83218)
Not setting this correctly can lead to an assertion failure in the AST verifier:

    AbstractStorageDecl's setter access is out of sync with the access actually on the setter

Fixes #82637

rdar://154685710
2025-07-22 08:26:51 -07:00
Gabor Horvath
db4b4c8abe Revert "Merge pull request #82480 from swiftlang/gaborh/addressable_params_copy"
Unfortunately, addressable parameters are viral, the whole dependency
chain needs to be consistent otherwise we get deserialization errors
when loading a module. The solution is to universally enable addressable
parameters for C++ interop but there are some blockers at the moment
that need to be solved first. Temporarily revert these changes until
those blockers are resolved.

This reverts commit b00ff4568b, reversing
changes made to 396379ecbf.
2025-07-22 14:03:24 +01:00
swift-ci
8da53334d6 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-21 04:38:05 -07:00
Egor Zhdan
f0a32d104d [cxx-interop] Prevent protocol conformance table from being prematurely populated
We've started seeing build failures where the conformance of a `std::vector` instantiation to `CxxVector` is missing. This was because the LifetimeDependenceInfoRequest triggers the protocol conformance table for the instantiation to be built before the synthesized conformance gets added.

This works around the issue by preventing LifetimeDependenceInfoRequest from running for the synthesized default argument generator function, which was the culprit of this particular failure.

rdar://155977071
2025-07-18 20:19:30 +01:00
swift-ci
cdc5561ead Merge remote-tracking branch 'origin/main' into rebranch 2025-07-10 13:17:12 -07:00
Allan Shortlidge
3d722e1919 ClangImporter: Generate and call custom availability domain predicates.
When importing custom availability domains with dynamic predicates from Clang
modules, synthesize predicate functions for `if #available` queries and call
them when generating SIL.

Resolves rdar://138441312.
2025-07-10 08:15:01 -07:00
swift-ci
5865310f70 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-03 07:55:01 -07:00
susmonteiro
b3e228845b [cxx-interop] Allow virtual methods to be renamed with swift_name 2025-07-02 16:09:02 +01:00
swift-ci
9fa89d76ef Merge remote-tracking branch 'origin/main' into rebranch 2025-07-01 05:40:30 -07:00
Gábor Horváth
11cb7e5800 Merge pull request #82333 from swiftlang/gaborh/default-arg-duplicate-symbols 2025-07-01 13:50:00 +02:00
swift-ci
7137e5b857 Merge remote-tracking branch 'origin/main' into rebranch 2025-06-30 13:15:54 -07:00
Egor Zhdan
d203591201 Merge pull request #82626 from swiftlang/egorzhdan/nfc-move-header
[cxx-interop] NFC: Move a header from `include` into `lib`
2025-06-30 20:40:04 +01:00