Commit Graph

2682 Commits

Author SHA1 Message Date
swift-ci
e50230f935 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-06 22:35:25 -07:00
Allan Shortlidge
8f60840551 Revert "[cxx-interop] Import decls in extern blocks within namespaces"
This reverts commit 844787fddb.
2025-08-06 21:50:55 -07:00
susmonteiro
5dd038fcc0 [cxx-interop] Support overriding pure virtual methods from value types 2025-08-06 16:46:33 +01:00
Egor Zhdan
37c418275c [cxx-interop] Allow old spelling of AppKit constants
AppKit defines certain constants in Objective-C, and then renames them into different constants in Swift, e.g. `NSUpArrowFunctionKey` is renamed into `NSEvent.SpecialKey.upArrow.rawValue`.

In addition to that, AppKit also re-defines these constants in pure-Swift, which isn't the intended mechanism for renaming such constants.

Prior to https://github.com/llvm/llvm-project/pull/145947, Clang was silently dropping the `SwiftName` API Notes attributes on these constants due to a bug in the name validation mechanism. Clients of AppKit relied on that behavior and continued to use the old spelling in Swift. To preserve source compatibility and avoid a deprecation error, let's continue dropping the `SwiftName` attribute on select constants from AppKit.

rdar://157485334
2025-08-06 16:28:15 +01:00
swift-ci
43b83de02e Merge remote-tracking branch 'origin/main' into rebranch 2025-08-06 04:34:26 -07:00
Egor Zhdan
4adccbdd90 Merge pull request #83516 from egorzhdan/egorzhdan/extern-within-namespace
[cxx-interop] Import decls in extern blocks within namespaces
2025-08-06 12:27:45 +01:00
swift-ci
245a6c3315 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-05 22:15:17 -07:00
Gábor Horváth
035ede372d Merge pull request #83487 from Xazax-hun/multiple-param-subscript 2025-08-06 06:05:41 +01:00
swift-ci
df94a20e4d Merge remote-tracking branch 'origin/main' into rebranch 2025-08-05 13:55:28 -07:00
Gabor Horvath
9b0acdb885 [cxx-interop] Diagnose missing type witness instead of crashing
rdar://157473792
2025-08-05 16:29:45 +01: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
Egor Zhdan
844787fddb [cxx-interop] Import decls in extern blocks within namespaces
This teaches ClangImporter to import C++ decls that are declared within `extern "C" { ... }`/`extern "C++" { ... }` blocks which are nested in namespaces.

rdar://139067788
2025-08-04 19:42:43 +01:00
swift-ci
beb62408ed Merge remote-tracking branch 'origin/main' into rebranch 2025-08-04 07:13:30 -07:00
Gábor Horváth
330326a227 Merge pull request #83461 from Xazax-hun/default-associated-type
[cxx-interop] Support conforming to protocols with default assoc types
2025-08-04 14:58:06 +01:00
swift-ci
4838c6e954 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-01 23:15:28 -07:00
Gabor Horvath
a97d3304b6 [cxx-interop] Move back addressability behind a flag
There was another crash found by the bootstrap build bots.

This reverts commit 37ae8a22f4, reversing
changes made to 6c8da764e2.
2025-08-01 16:24:32 +01:00
swift-ci
406ad9ecdb Merge remote-tracking branch 'origin/main' into rebranch 2025-08-01 01:55:36 -07:00
Gábor Horváth
37ae8a22f4 Merge pull request #83430 from Xazax-hun/revert-addressable-flag
Revert "[cxx-interop] Move addressable parameters in interop behind a flag"
2025-08-01 08:37:25 +01:00
Gabor Horvath
922c30386d [cxx-interop] Support conforming to protocols with default assoc types
In case the type does not define a type alias with the same name fall
back to the default type of the associated type in the protocol.
Previously, the compiler crashed.

Unfortunately, we are still crashing when we do not find the right
conformance. In a follow-up PR I plan to add more graceful handling of
the case when the lookup fails.

rdar://154098495
2025-07-31 16:17:56 +01:00
swift-ci
3998a187f9 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-30 09:36:41 -07:00
Anthony Latsis
bbd84429a0 Merge pull request #83400 from swiftlang/jepa-main
Address `llvm::PointerUnion::{is,get}` deprecations
2025-07-30 17:19:58 +01:00
Gabor Horvath
254f72fdb4 Revert "[cxx-interop] Move addressable parameters in interop behind a flag"
This reverts commit f270e36aa5.
2025-07-30 15:24:45 +01:00
Anthony Latsis
3f841b515c Merge remote-tracking branch 'origin/main' into jepa-rebranch 2025-07-30 14:31:33 +01:00
Egor Zhdan
9bc16e3dc0 Merge pull request #83402 from egorzhdan/egorzhdan/honor-non-copyable-attr
[cxx-interop] Avoid trying to instantiate copy constructors of explicitly non-copyable structs
2025-07-30 12:16:54 +01:00
Doug Gregor
9194fa0ab7 Merge pull request #83364 from DougGregor/noncopyable-imported-c-struct-destroy
[Clang importer] Allow noncopyable C structs to define "destroy" operation
2025-07-29 18:16:05 -07:00
Egor Zhdan
a07da0fe44 [cxx-interop] Avoid trying to instantiate copy constructors of explicitly non-copyable structs
If a C++ struct is annotated with `__attribute__((swift_attr("~Copyable")))`, Swift should not try to instantiate the copy constructor of the struct. This provides an escape hatch for C++ types that are designed to be non-copyable, but do not explicitly define a deleted copy constructor, and instead trigger complex template instantiation failures when a copy is attempted.

rdar://157034491
2025-07-29 19:03:04 +01:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Gabor Horvath
f270e36aa5 [cxx-interop] Move addressable parameters in interop behind a flag
This unblocks the CI while we figure out some SILGen issues. We cannot
reuse AddressableParameters because that is already used in some
projects and consuming modules where the AddressableParameters flag was not
propagated to results in deserialization errors.
2025-07-28 23:29:22 +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
Doug Gregor
6ba560fb4b [Clang importer] Allow noncopyable C structs to define "destroy" operation
A C struct can be imported as noncopyable, but C doesn't have
destructors, so there is no way to provide user-defined logic to
perform the destruction. Introduce a new swift_attr that applies to
imported noncopyable types and which provides such a "destroy"
operation. It can be used like this:

    typedef struct __attribute__((swift_attr("~Copyable")))
                   __attribute__((swift_attr("destroy:wgpuAdapterInfoFreeMembers")))
      WGPUAdapterInfo { /*...*/ } WGPUAdapterInfo;

    void wgpuAdapterInfoFreeMembers(WGPUAdapterInfo adapterInfo);

This will bring the WGPUAdapterInfo struct in as a noncopyable type
that will be cleaned up by calling wgpuAdapterInfoFreeMembers once it
is no longer in use.

Implements rdar://156889370.
2025-07-28 00:02:31 -07:00
Allan Shortlidge
c4e242e7db Merge pull request #83349 from tshortli/check-custom-domain-availability-for-conformances
Sema: Check custom domain availability during conformance checking
2025-07-26 11:54:17 -07:00
Gabor Horvath
9525aeec18 [cxx-interop] Enable addressable-self unconditionally
This was behind a feature flag. Unfortunately, this flag is viral, if
the module we consume and the consuming module had inconsistent settings
that could lead to deserialization errors. To avoid this, we need to
move this out of the flag and apply the attribute unconditionally. This
PR moves addressable-self out of the experimental flag and addresses a
couple of the fallouts:
* This attribute should not be applied to types with reference semantics
  like foreign reference types or Obj-C classes.
* There was a SILGen assertion failure which is solved by pealing off
  the @lvalue specifier from the type behind a load expression.

This fixes part of rdar://155971658
2025-07-26 08:37:03 +01:00
Allan Shortlidge
aa199aaf81 Correct misspelling of "availability" in a few places. 2025-07-25 21:30:53 -07:00
John Hui
9b95242ac4 [cxx-interop] Import const-qualified indirect fields with private setters (#83219)
We already make imported computed properties' setters private in
VisitFieldDecl(), but not in VisitIndirectFieldDecl(), which handles
things like the members of an anonymous union in another struct.
2025-07-24 19:04:58 -07:00
Artem Chikin
b60bc39ee5 [APINotes] Add support for handling Clang modules carrying all versions of APINotes
Controlled from Swift with '-version-independent-apinotes', which, for the underlying Clang invocation enables '-fswift-version-independent-apinotes', results in PCMs which aggregate all versioned APINotes wrapped in a 'SwiftVersionedAttr', with the intent to have the client pick and apply only those that match its current Swift version, discarding the rest.

This change introduces the configuration flags for this mode as well as the corresponding logic at the beginning of `importDeclImpl` to canonicalize versioned attributes, i.e. select the appropriate attributes for the current target and discard the rest.
2025-07-24 09:08:31 -07:00
swift-ci
199e8095b3 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-23 15:56:58 -07:00
Doug Gregor
49febcd468 Merge pull request #83252 from DougGregor/import-conforms-to-newtype
[Clang importer] Handle Swift conformances on typedefs and C types
2025-07-23 15:38:01 -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
swift-ci
367f0082fc Merge remote-tracking branch 'origin/main' into rebranch 2025-07-22 22:17:45 -07:00
Doug Gregor
c5db5cced5 [Clang importer] Handle Swift conformances on typedefs and C types
The code for handling Swift conforms_to attributes was specific to
C++ record types. Generalize it to work on typedefs imported as
nominal types, also in C.

Fixes rdar://156290361.
2025-07-22 20:20:23 -07: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
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
Anthony Latsis
2920ea84d1 Address llvm::(Mutable)ArrayRef ctor deprecations
See:
- https://github.com/llvm/llvm-project/pull/146113
- https://github.com/llvm/llvm-project/pull/146011
2025-07-21 12:36:53 +01:00
swift-ci
b02a3ab4c2 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-18 04:17:04 -07:00