Commit Graph

6332 Commits

Author SHA1 Message Date
Egor Zhdan
cc23c32058 [cxx-interop] Avoid trying to instantiate copy constructor of std::optional<NonCopyable>
In libc++, `std::optional` inherits from several mixin base types. Some of those base types do not declare a deleted copy constructor for non-copyable value types, which works fine because clients are not supposed to use those base types directly from C++.

Swift, however, imports all of the transitive base types when importing a C++ type. As part of this, ClangImporter will attempt to instantiate e.g. `std::__optional_copy_assign_base<NonCopyable>`, and will fail with a hard error while doing so.

rdar://152718041
2025-10-10 17:46:22 +01:00
Gabor Horvath
4af3992bb4 [cxx-interop] Restrict the uses of anonymous types
Make sure they are excluded from the reflection metadata (although in
the future we want to make sure indirect fields are included). Make sure
the users cannot refer to the anonymous field, only its members.
2025-10-10 17:46:22 +01:00
Egor Zhdan
6f0ab5dce8 Merge pull request #83914 from egorzhdan/egorzhdan/guiddef
[WinSDK] Modularize `<guiddef.h>`
2025-09-09 16:24:23 +01:00
Susana Monteiro
cd01e914fa Merge pull request #84121 from susmonteiro/susmonteiro/copy-operations-requires-clause
[cxx-interop] Check if copy constructor is eligible
2025-09-05 17:40:06 +01:00
Gábor Horváth
8cc45ddec3 Merge pull request #84105 from Xazax-hun/no-vwt-for-anon-types
[cxx-interop] Basic support for anonymous structs with non-copyable fields
2025-09-05 09:07:17 +01:00
susmonteiro
96d00189e7 [cxx-interop] Check if copy constructor is eligible 2025-09-04 22:09:42 +01:00
Gabor Horvath
0c909a8395 [cxx-interop] Basic support for anonymous structs with non-copyable fields
Anonymous structs cannot be copied or moved, these operations only can
happen to their enclosing non-anonymous types. Stop trying to emit
special member functions and value witness tables for these structs.
2025-09-04 15:20:17 +01:00
Ahmed Elrefaey
1bc96857a8 Merge pull request #82464 from a7medev/feat/full-documentation-in-code-completion
[IDE] Add full documentation to code completion result
2025-09-04 10:06:21 +01:00
Yuta Saito
3f96cef3a4 [wasm] Add support for __builtin_va_list type mapping (#84029)
Cover all va_list family of types just aliased by __builtin_va_list, including __isoc_va_list from wasi-libc. This enables proper C interop for variable argument functions on WASI targets.

Close https://github.com/swiftlang/swift/issues/72398
2025-09-02 14:36:33 +01:00
susmonteiro
1bfa16a419 [cxx-interop] Prevent crash when importing a std::optional of nonescapable 2025-09-01 17:50:49 +01:00
Egor Zhdan
28f9db7bfa [WinSDK] Modularize <guiddef.h>
This fixes modularization errors that arise when importing a C++ header that contains `#include <guiddef.h>`, which might hijack this header from the WinSDK module where it belongs.
2025-08-28 22:21:55 +01:00
fahadnayyar
720406fdd6 Diagnose unannotated C++ APIs returning SWIFT_SHARED_REFERENCE at Swift call sites (#83025)
This patch improves the warning for C++ APIs returning
`SWIFT_SHARED_REFERENCE` types but not annotated with either
`SWIFT_RETURNS_RETAINED` or `SWIFT_RETURNS_UNRETAINED` in the following
ways:

1. The warning for missing `SWIFT_RETURNS_(UN)RETAINED` annotations is
now emitted on Swift use sites, rather than while importing the API
(func/method decls).
- This logic is now implemented as a Misl Diagnostic in function
`diagnoseCxxFunctionCalls` in file lib/Sema/MiscDiagnostics.cpp.
- The warning is now triggered only when the API is actually used, which
reduces noise in large C++ headers.
- These warnings are still gated behind experimental-feature-flag `WarnUnannotatedReturnOfCxxFrt`

rdar://150800115
2025-08-25 14:44:25 -07:00
Egor Zhdan
d89333f85c Merge pull request #83825 from egorzhdan/egorzhdan/constexpr-in-namespace
[cxx-interop] Import constexpr globals in a namespace
2025-08-21 12:19:21 +01:00
Egor Zhdan
7c9bd160c1 Merge pull request #83813 from egorzhdan/egorzhdan/partial-spec-var
[cxx-interop] Do not import partial specializations of variables
2025-08-20 15:55:04 +01:00
Egor Zhdan
6bdd44e78e [cxx-interop] Import constexpr globals in a namespace
rdar://150756970 / resolves https://github.com/swiftlang/swift/issues/81327
2025-08-20 12:57:58 +01:00
Egor Zhdan
77975524be [cxx-interop] Do not import partial specializations of variables
They do not get imported correctly and trigger linker errors.

rdar://149232900 / resolves https://github.com/swiftlang/swift/issues/80802
2025-08-19 18:41:07 +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
Egor Zhdan
5a6219cbf7 Merge pull request #83793 from egorzhdan/egorzhdan/c-frt-validation
[cxx-interop] Validate C foreign reference types
2025-08-19 15:05:35 +01:00
Egor Zhdan
c73f528b82 [cxx-interop] Validate C foreign reference types
Swift validates the retain/release operations for foreign reference types to check for obvious errors, e.g. a wrong parameter type or return type.

That logic was only running for C++ foreign reference types. This patch enables it for C foreign reference types as well.

rdar://158609723
2025-08-18 19:18:18 +01:00
Kuba Mracek
7b0eff8616 [ClangImporter] Skip importing values for ObjCBool declarations 2025-08-18 10:16:51 -07:00
Artem Chikin
89b43dccf3 Merge pull request #83600 from artemcm/NoRedundantClangDepBridging
[Dependency Scanning] Bridge Clang dependency scanner results on-demand
2025-08-18 09:36:27 -07:00
Gábor Horváth
d2691dcb61 Merge pull request #83370 from Xazax-hun/addressable-param-copy-reapply
Reapply [cxx-interop] Avoid copies when accessing pointee
2025-08-18 16:41:27 +01:00
Egor Zhdan
d8edd86cfb Merge pull request #83753 from egorzhdan/egorzhdan/retain-release-unsigned
[cxx-interop] Allow retain/release operations to return an unsigned integer
2025-08-18 11:52:33 +01: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
Egor Zhdan
299f17395c Merge pull request #83761 from egorzhdan/egorzhdan/tilde-operator
[cxx-interop] Import tilde operators
2025-08-18 08:25:52 +01:00
Gábor Horváth
16fbfec493 Merge pull request #83754 from Xazax-hun/reenable-addressable-params 2025-08-16 09:17:46 +01:00
Allan Shortlidge
678b0934d6 AST: Request-ify getting the AvailabilityDomain from a ValueDecl.
Cache the result of turning a `ValueDecl` into an `AvailabilityDomain`. Use
split caching to make the common case of the decl not representing an
availability domain efficient.

NFC.
2025-08-15 16:15:36 -07:00
Artem Chikin
5015ba683a [Dependency Scanning] Bridge Clang dependency scanner results on-demand
Instead of always bridging all of the discovered modules of all of the queries, only do so for modules which are not already cached
2025-08-15 14:55:42 -07:00
Egor Zhdan
f96a5e5b2b Merge pull request #83589 from egorzhdan/egorzhdan/reland-extern-namespace
Revert "Revert "[cxx-interop] Import decls in extern blocks within namespaces""
2025-08-15 18:30:51 +01:00
Egor Zhdan
582357bf76 [cxx-interop] Import tilde operators
This teaches ClangImporter to import the bitwise not operator (`~`).

rdar://158366946 / resolves https://github.com/swiftlang/swift/issues/83740
2025-08-15 18:06:36 +01:00
Egor Zhdan
3887ed0637 [cxx-interop] Allow retain/release operations to return an unsigned integer
Release/retain functions for C++ foreign reference types might return a reference count as an integer value.

Swift previously emitted an error for such functions, saying that the retain/release functions need to return void or a reference to the value.

rdar://157853183
2025-08-15 17:30:53 +01:00
Gabor Horvath
2a9f6f89e3 Revert "Merge pull request #83483 from Xazax-hun/turn-off-addressable"
Afteri #83712 landed, let's make another try enabling addressable
parameters by default.

This reverts commit 61d60eb6ad, reversing
changes made to 670f69eadc.
2025-08-15 15:28:20 +01:00
Allan Shortlidge
0bba9bbc26 AST: Make the decl associated with an AvailabilityDomain a ValueDecl.
A decl that represents an `AvailabilityDomain` should always be a `ValueDecl`.
2025-08-14 11:35:00 -07:00
Gabor Horvath
f6d5e50f89 [cxx-interop] Do not define inherited copy/move operations
When inheriting constructors, we define the inherited ctors in the
derived class. We should not do that for copy and move operations as
these operations can never be invoked (the implicit/defined/deleted ctor
in the derived class always takes precedence). This fixes an issue where
the lifetime parameters are not getting inferred for these spurious
constructor definitions. This should also save us from doing some
redundant work in the importer. Fixes #82183.

rdar://153081347
2025-08-13 15:34:00 +01:00
Egor Zhdan
ab5fc57f66 Merge pull request #83568 from egorzhdan/egorzhdan/nsfunctionkeys-workaround
[cxx-interop] Allow old spelling of AppKit constants
2025-08-12 15:57:27 +01:00
Egor Zhdan
8e71509108 [cxx-interop] Do not look into extern blocks in libc++'s std_private_random_binomial_distribution
rdar://139067788
2025-08-08 18:47:28 +01:00
Gábor Horváth
35b5c817b2 Merge pull request #83520 from Xazax-hun/check-safety-function-types 2025-08-08 06:39:39 +01: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
Egor Zhdan
a5b4975204 Revert "Revert "[cxx-interop] Import decls in extern blocks within namespaces""
This reverts commit 8f60840551.
2025-08-07 15:03:08 +01:00
Gábor Horváth
91b4fabca1 Merge pull request #83542 from Xazax-hun/simd-is-escapable
[cxx-interop] Handle vector types in escapability analysis
2025-08-07 12:40:40 +01: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
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
Gábor Horváth
035ede372d Merge pull request #83487 from Xazax-hun/multiple-param-subscript 2025-08-06 06:05:41 +01: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
Gabor Horvath
c8f8e863f9 [cxx-interop] Handle vector types in escapability analysis
Whenever we have a vector type, the escpability depends on the
escapability of the element type. This will enable us to consider more
types like std::vector<simd::float3> as safe by default.

rdar://157141552
2025-08-05 14:55:33 +01:00
Gabor Horvath
402ad33463 [StrictMemorySafety] Check the safety of return types of calls
Previously, we skipped checking the return type of a function for safety
as we expected to warn at the use of the returned value:

  let x = returnsUnsafe()
  usesUnsafe(x) // warn here

Unfortunately, this resulted in missing some unsafe constructs that can
introduce memory safety issues when the use of the return value had a
different shape resulting in false negatives for cases like:

  return returnsUnsafe()

or

  usesUnsafe(returnsUnsafe())

This PR changes the analysis to always take return types of function
calls into account.

rdar://157237301
2025-08-05 12:16:44 +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