Commit Graph

103252 Commits

Author SHA1 Message Date
Alexis Laferrière
c128db77f8 AST: Support @cdecl enums without an explicit C name
Accept `@cdecl` enums without an explicit C name. The C name defaults to
the Swift one. It is printed using the `SWIFT_ENUM` macro instead of
`SWIFT_ENUM_NAMED`.
2025-07-03 14:11:27 -07:00
Alexis Laferrière
b7065585b2 SIL: Fix warning on unused variable 2025-07-03 14:11:27 -07:00
Alexis Laferrière
6750320d23 PrintAsClang: Forward reference enums when used transitively
There are two main scenarios when printing a compatibility header that
references a @cdecl enum defined in Swift code. (1) When defined in the
same module as it's used we can print the definition normally and then
reference it. (2) When used in a different mode we need to print a
forward declaration before we can reference it.

This change adds printing the forward declaration and fix an issue where
the compiler would instead print an @include of the Swift module. The
import of the Swift module would work only in a local scenario where a
compatibility header and module would be generated under the same name.
However for a distributed frameworks we do not distribute the
compatibility header so this strategy doesn't work. Relying on a forward
declaration should be more reliable in all cases but clients may need to
import the other compatibility header explicitly.
2025-07-03 14:11:27 -07:00
Alexis Laferrière
ba4cd119e7 PrintAsClang: Print @cdecl enums in the compatibility header
Print @cdecl enums in the C section of the compatibility header. Use and
extend the macros to support C compiler clients.

The macro is adapted to the features supported by the client compiler.
It uses an Objective-C style macro with raw type when available and
fallbacks to a simple typedef for C compatibility.
2025-07-03 14:11:27 -07:00
Alexis Laferrière
1c5c76f2b5 Sema: Type-check @cdecl enums
@cdecl enums are Swift enums representable in C. These enums must have
an integer raw type. They can be referenced from @cdecl functions and
@objc methods. @objc enums are still rejected from @cdecl functions.
2025-07-03 14:11:27 -07:00
Alexis Laferrière
076ae9edb3 Sema: Reject enums marked with both @cdecl and @objc 2025-07-03 14:11:27 -07:00
Alexis Laferrière
5c2efaca9a AST: Begin accepting @cdecl on enums (but not @_cdecl) 2025-07-03 14:11:27 -07:00
Alexis Laferrière
83c0667b16 Sema: Add missing range on notes about representability 2025-07-03 14:11:27 -07:00
Alexis Laferrière
3b33531ff7 ASTGen: Accept @cdecl 2025-07-03 14:11:27 -07:00
Alexis Laferrière
3a0ba5fc1c Sema: @cdecl functions C name defaults to the Swift name 2025-07-03 14:11:27 -07:00
Alexis Laferrière
22521548a7 Parser: Accept @cdecl with an indentifier for the C name
Begin accepting the attribute in the form of `@cdecl(cName)`, using an
identifier instead of a string.

For ease of landing this change we still accept the string form. We
should stop accepting it before making this feature available in
production.
2025-07-03 14:11:27 -07:00
Alexis Laferrière
596d925bc1 PrintAsClang: Print #include for headers used from @cdecl functions
Start printing `#include` for headers referenced from `@cdecl` function
signatures. This adds on top of the existing tiered imports. We already
print each module referenced from decls printed in the compatibility
header. Previously we printed mostly `@import` with an option to
fallback on a `#import`. This change adds a third fallback to `#include`
when the module is referenced from a `@cdecl` function signature. The
bridging header can also be imported in a similar way.
2025-07-03 14:11:27 -07:00
Alexis Laferrière
eedc7c2857 Sema: Update more diagnostics for @cdecl vs @objc 2025-07-03 14:11:27 -07:00
Alexis Laferrière
0600ddd2e9 Sema: Use ForeignLanguage directly in diagnostic definitions 2025-07-03 14:11:27 -07:00
Alexis Laferrière
4d7ec5853c PrintAsClang: Apply review comments to check on should print of @cdecl 2025-07-03 14:11:27 -07:00
Alexis Laferrière
372dfe4aa0 PrintAsClang: Ignore nullability attributes for C clients
In C mode we still print nullability attributes. Don't let clang warn on
them and ignore the attribute if the C compiler doesn't know them.
2025-07-03 14:11:27 -07:00
Alexis Laferrière
4b7cb77ebb PrintAsClang: Print @cdecl in their own block in compatibility headers
Add a block for C clients in the compatibility header. This block
contains only the `@cdecl` functions that are printed using only C
types.

This C block is printed above the Objective-C and C++ blocks as if we
add support for `@cdecl` types other languages should be able to
reference them in function signatures. Other languages block don't
duplicate printing the `@cdecl` functions either as they are already
accessible to them.
2025-07-03 14:11:26 -07:00
Alexis Laferrière
8d328182f6 PrintAsClang: Intro and use getKnownType for C compatibility 2025-07-03 14:11:26 -07:00
Alexis Laferrière
e38fd7f174 Sema: Simplify tracking the foreign language of an @objc decl
Apply review comments from #80744.
2025-07-03 14:11:26 -07:00
Alexis Laferrière
41f126fde6 Sema: Basic type-checking of @cdecl on global functions
This implements basic checks on the validity of the @cdecl attribute and
ensures the parameters and result types are representable in C. Many
more diagnostics will need to be updated to verify full representability
in C.
2025-07-03 14:11:26 -07:00
Artem Chikin
1d96eca733 Merge pull request #82738 from artemcm/62_DepScanFixCycleDetection
[6.2 🍒][Dependency Scanning] On cycle via overlay, fix Clang dependency path reconstruction
2025-07-03 13:56:30 -07:00
Alexis Laferrière
732918d5a5 Sema: Abstracted service for @cdecl style attributes 2025-07-03 13:45:33 -07:00
Alexis Laferrière
2647a8e150 Serialization: Read and write the underscored bit for @cdecl 2025-07-03 13:45:33 -07:00
Alexis Laferrière
3209730bac Parser: Intro @cdecl attribute and gate it behind feature flag CDecl 2025-07-03 13:45:33 -07:00
Alexis Laferrière
221a6f09f1 Sema: Requestify most checks on @_cdecl 2025-07-03 13:45:33 -07:00
Artem Chikin
716331e77a [Dependency Scanning] Add libSwiftScan API and JSON output for source import information 2025-07-03 11:12:55 -07:00
Artem Chikin
1c9b864738 [Dependency Scanning] Keep track of each imported module's access control
Adds an access control field for each imported module identified. When multiple imports of the same module are found, this keeps track of the most "open" access specifier.
2025-07-03 11:12:46 -07:00
Henrik G. Olsson
43d8b13cf1 Merge pull request #82644 from hnrklssn/cherry-pick-macro-adjustment-check
Cherry-pick "Merge pull request #81855 from hnrklssn/swiftify-availability-check-sdk"
2025-07-03 11:07:43 -07:00
Slava Pestov
0022c312f0 Merge pull request #82758 from slavapestov/fix-issue-60552-6.2
[6.2] Sema: Fix leading dot with protocol composition or parameterized protocol contextual type
2025-07-03 14:05:35 -04:00
Hamish Knight
3f2d1ddcdd [CS] Downgrade an ASSERT for 6.2 2025-07-03 17:57:42 +01:00
Hamish Knight
7e537b7f00 [CS] Ensure type variables are eliminated by Solution::simplifyType
`TypeSimplifier` may not eliminate type variables from e.g the
pattern types of pattern expansion types since they can remain
unresolved due to e.g having a placeholder count type. Make sure we
eliminate any remaining type variables along with the placeholders.
There's probably a more principled fix here, but this is a quick and
low risk fix we can hopefully take for 6.2.

rdar://154954995
2025-07-03 17:53:23 +01:00
Gábor Horváth
66d905e25a Merge pull request #82760 from Xazax-hun/reverse-interop-forward-decl-crash-on-6.2
[6.2][cxx-interop] Fix a crash when exposing @objc Swift classes
2025-07-03 17:50:34 +01:00
Artem Chikin
01e5d4433f [Dependency Scanning][C++ Interop] Do not skip lookup of 'CxxStdlib' overlay for the source module
A prior change ensured that we forego this query when looking up Swift overlays for a textual interface which was built without C++ interop. This change introduced a bug where it also caused us to skip this lookup for the main source module. This commit resolves that by preserving the fix above but also ensuring we perform the lookup for the main source module under scan.
2025-07-03 09:20:29 -07:00
Pavel Yaskevich
01404bf1ae Merge pull request #82735 from xedin/rdar-154754939-6.2
[6.2][Concurency] Allow declarations with `@isolated(any)` parameters be m…
2025-07-03 09:17:34 -07:00
Pavel Yaskevich
cf5ab749eb Merge pull request #82744 from xedin/rdar-154808850-6.2
[6.2][Concurrency] SE-0461: Extend `nonisolated(nonsending)` inference to …
2025-07-03 09:17:21 -07:00
Charles Zablit
da7764efd2 [NFC][demangling] switch to using NodePrinter::printFunctionName 2025-07-03 15:33:34 +01:00
Hamish Knight
ef8e576d23 Merge pull request #82741 from hamishknight/err-val-6.2
[6.2] [AST] Use ErrorType for invalid value generic parameter
2025-07-03 14:32:44 +01:00
Erik Eckstein
849a5e9082 MandatoryPerformanceOptimizations: don't de-virtualize a generic class method call to specialized method
This results in wrong argument/return calling conventions.
First, the method call must be specialized. Only then the call can be de-virtualized.
Usually, it's done in this order anyway, because the `class_method` instruction is located before the `apply`.
But when inlining functions, the order (in the worklist) can be the other way round.

Fixes a compiler crash.
rdar://154631438
2025-07-03 13:21:27 +02:00
Erik Eckstein
a538252a77 MoveOnlyWrappedTypeEliminator: handle EndCOWMutationAddr
fixes a compiler crash
rdar://154416511
2025-07-03 13:10:00 +02:00
Gábor Horváth
93e1c787f0 [6.2][cxx-interop] Fix a crash when exposing @objc Swift classes
Explanation: There was a null pointer dereference in reverse interop
when we wanted to expose an ObjC class written in Swift. There was a
crash during generating the scaffolding we do for Clang types. Since
the type is written in Swift, no such scaffolding is needed, this patch
skips this operation avoiding the null dereference.
Scope: Reverse C++ interop when exposing @ObjC classes written in Swift.
Issues: rdar://154252454
Original PRs: #82684
Risk: Low, the fix is narrow to the affected scenario.
Testing: Added a compiler test.
Reviewers: @egorzhdan
2025-07-03 09:25:38 +01:00
Hamish Knight
2e0b9d7f8a Merge pull request #82743 from hamishknight/diag-it-6.2 2025-07-03 09:24:25 +01:00
Slava Pestov
8e78de3a70 Sema: Fix leading dot with protocol composition or parameterized protocol contextual type
- Fixes https://github.com/swiftlang/swift/issues/60552.
- Fixes rdar://problem/99699879.
2025-07-03 00:22:31 -04:00
Slava Pestov
6fbf38f63d Merge pull request #82693 from slavapestov/fix-issue-82614-6.2
[6.2] Concurrency: Move PackExpansionType check to swift::diagnoseNonSendableTypes()
2025-07-02 22:57:00 -04:00
nate-chandler
e3f8048628 Merge pull request #82700 from nate-chandler/cherrypick/release/6.2/rdar154652254
6.2: [CSE] Fix combine of type_value.
2025-07-02 16:51:56 -07:00
Egor Zhdan
40c4f3cd9d Merge pull request #82723 from swiftlang/egorzhdan/6.2-cfoptions-block-param
🍒[cxx-interop] Fix generated header for Swift closures using `CF_OPTIONS` types
2025-07-02 23:54:40 +01:00
Pavel Yaskevich
d1a1b2fb31 [Concurrency] SE-0461: Extend nonisolated(nonsending) inference to function types
Currently only declarations would get `nonisolated(nonsending)`
inferred if the upcoming flag is enabled, this changes extend
this to apply to asynchronous nonisolated function types as well.

Resolves: rdar://154808850
(cherry picked from commit bb0cd6f0a6)
2025-07-02 14:25:02 -07:00
Hamish Knight
ce273f4527 [Sema] Downgrade an ASSERT for 6.2 2025-07-02 21:30:31 +01:00
Hamish Knight
a9d72fb695 [Sema] Avoid applying diagnostic hack to caller-side expression macros
We can't assume that type-checking the expression macro in the
parameter will also fail if it fails at the call site since e.g
name lookup may differ. Make sure we only apply this logic to simple
literals.

rdar://154771596
2025-07-02 21:29:32 +01:00
Hamish Knight
e0ed130019 Constify DiagnosticState::determineBehavior
Split out the state mutation into a new `updateFor`
function that we call for diagnostic emission, allowing
`DiagnosticTransaction::hasErrors` to query the behavior without
mutating any state.
2025-07-02 21:29:32 +01:00
Hamish Knight
4c6e06fed3 [AST] Use ErrorType for invalid value generic parameter
If we fail to resolve the value type for a value generic parameter,
previously we would have returned a null Type, causing crashes
downstream. Instead, return an ErrorType, leaving a null Type for
cases where the generic parameter isn't a value generic at all.

rdar://154856417
2025-07-02 21:19:45 +01:00