Commit Graph

406 Commits

Author SHA1 Message Date
Ben Barham
e0b976d150 [CxxInterop] Change C++ interop header ordering
Consider the case of a toolchain that includes clang is being used to
compile Swift. With the current ordering, the header will be found
relative to that toolchain, which could be out of date as compared to
tip. This is the case today if eg. a 5.7 toolchain is used to build
main/5.9 as the shim header is missing a definition.
2023-08-17 09:46:28 -07:00
Alex Lorenz
f623683185 [interop][SwiftToCxx] do not emit direct returns/passes when Swift's value type ABI is not yet supported 2023-08-01 18:43:13 -07:00
Alex Lorenz
0727d04c9a [interop][SwiftToCxx] correctly emit names for anonymous structs that use a typedef when emitting a Clang type reference in the generated header 2023-08-01 18:43:12 -07:00
Becca Royal-Gordon
1318bf5bf5 [NFC] Begin adopting new diagnostics features 2023-07-19 13:06:51 -07:00
Alex Lorenz
85a431eedf [interop][SwiftToCxx] ensure swift::Int and swift::UInt are usable in generic context
Fixes https://github.com/apple/swift/issues/63452
2023-07-12 12:47:49 -07:00
Erik Eckstein
6b1697eb06 use new llvm::Optional APIs to fix deprecation warnings 2023-06-28 14:28:38 +02: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
Alex Lorenz
de10b4155e [interop][SwiftToCxx] support copy-assignment operation for Swift value types and prohibit move assignment explicitly
Fixes https://github.com/apple/swift/issues/66324

Note: move semantics for Swift value types are not yet supported in C++
2023-06-06 15:55:30 -07:00
Slava Pestov
b2bc2c72ec AST: Introduce PackElementType 2023-05-25 11:17:30 -04:00
Ethan Smith
d9dcf06b64 Desugar ElabroatedType in isNSUInteger if present.
Re-enable PrintAsObjC/availability-real-sdk and PrintAsObjC/override, they are now passing.
2023-05-18 15:53:47 -07:00
Alex Lorenz
39d86bc701 [interop][SwiftToCxx] the not yet implemented move constructor for Swift value types should lead to link error when a move is used in Swift, not runtime error 2023-05-07 08:55:28 -07:00
Alex Lorenz
16b1fe173f [interop][SwiftToCxx] moving a Swift class in C++ performs a copy
C++ does not have a consuming move, so fallback to copy instead

Resolves https://github.com/apple/swift/issues/64702
2023-05-07 08:55:20 -07:00
Alex Lorenz
a1dc63ec46 Merge pull request #65728 from hyp/eng/safe-overloads-and-unavailable-unemitted-decls-in-cxx
[interop][SwiftToCxx] avoid emitting ambiguous C++ overloads and emit unavailable type stubs for top level types that could not be emitted in the C++ section of the generated header
2023-05-07 06:25:03 -07:00
Alex Lorenz
82ef9d35e7 [interop][SwiftToCxx] do not emit unavaialble stubs for internal/private decls
only emit them for public ones
2023-05-06 14:51:18 -07:00
Alex Lorenz
ace328af62 Merge pull request #65683 from hyp/swift-string-from-literal
[interop][SwiftToCxx] add swift::String overlay constructor for const…
2023-05-06 09:41:13 -07:00
Alex Lorenz
c7836e3a8e [interop][SwiftToCxx] avoid emitting ambiguous C++ overloads
Just do an arity check for now
2023-05-05 17:07:43 -07:00
Alex Lorenz
aff3568a12 [interop][SwiftToCxx] emit unavailable type stubs for top level types that could not be emitted in the C++ section of the generated header 2023-05-05 17:03:26 -07:00
Alex Lorenz
42bd9d0e64 Merge pull request #65680 from hyp/eng/cxx-warning-nomore-in-stdlib-from-gen-hdr
[interop][SwiftToCxx] avoid importing C++ stdlib in C++ section of ge…
2023-05-05 14:22:23 -07:00
Alex Lorenz
c41774188c [interop][SwiftToCxx] add swift::String overlay constructor for constructing it directly from a C string literal
resolves https://github.com/apple/swift/issues/63448
2023-05-05 06:29:59 -07:00
Alex Lorenz
f4f6f7a408 [interop][SwiftToCxx] avoid importing C++ stdlib in C++ section of generated header inside of 'pragma clang attribute' block 2023-05-04 17:01:39 -07:00
Alex Lorenz
228078f074 [interop][SwiftToCxx] remove extraneous semicolon when emitting 'pragma clang module import'
The semicolon actually causes a compiler error in that case
2023-05-04 14:56:55 -07:00
Alex Lorenz
82eb493aa0 Merge pull request #65401 from hyp/eng/varfnnameassert
[interop][SwiftToCxx] do not assert when emitting a public var and fu…
2023-04-28 07:21:00 -07:00
Alex Lorenz
601802820e [interop][SwiftToCxx] do not assert when emitting a public var and function with the same C++ name 2023-04-24 14:03:46 -07:00
Alex Lorenz
7efae9a74c [interop][SwiftToCxx] add additional type representation emission check for associated enum element types
This ensures that we do not try to emit enums whose associated values come from dependent modules that don't have a C++ representation
2023-04-24 12:31:30 -07:00
Alex Lorenz
0be1ad1a02 Merge pull request #65339 from hyp/eng/opaque-layout-ok-struct
[interop][SwiftToCxx] do not assert when emitting non-resilient struc…
2023-04-21 09:30:18 -07:00
Alex Lorenz
e6e43c6b80 [interop][SwiftToCxx] do not assert when emitting non-resilient structs with opaque layout 2023-04-20 18:46:07 -07:00
Dave Lee
39bb7bfe44 [AST] Convert ASTContext::getSwiftName to a free function
The only state `getSwiftName` uses is its argument, and can be made a free function. Of
note the inverse operation, `getKnownFoundationEntity`, is also a free function. This
removes the requirement that callers have an `ASTContext` instance.

(cherry-picked from commit fb524c0b86)
2023-04-14 11:43:13 -06:00
Augusto Noronha
cfb3e5abae Reintroduce alwaysinline and nodebug as fallbacks to SWIFT_INLINE_THUNK_ATTRIBUTES
If the C++ compiler doesn't support the transparent_stepping attribute,
fallback to annotating inline thunks with the alwaysinline and nodebug
attributes.
2023-04-04 10:42:02 -07:00
Augusto Noronha
7c8523cfec Use "transparent_stepping" attribute in C++ compiler generated interop
Use transparent_stepping instead of nodebug and alwaysinline in compiler
generated C++ code from Swift. This attribute allow for annotated
functions to be used in expression evaluation, which is an advantage
over the former two.
2023-03-31 12:53:14 -07:00
Alex Lorenz
a854550fa2 [interop] fix test failure after c4cc9e8e42
rdar://107445101
2023-03-30 16:34:50 -07:00
Alex Lorenz
c4cc9e8e42 [interop][SwiftToCxx] do not error out on -Wnon-modular-include-in-framework-module clang diagnostic when importing the generated header as part of a framework back into C++ via a Clang module 2023-03-30 08:40:40 -07:00
Alex Lorenz
580dd22c49 [interop] NFC, bump up the experimental version in the JSON file 2023-03-20 19:58:21 -07:00
Alex Lorenz
ce9648476d [interop][SwiftToCxx] ensure all emitted 'swift' namespaces are marked as swift_private 2023-03-18 17:50:57 -07:00
Alex Lorenz
70b982f9ca Merge pull request #64468 from hyp/eng/limit-stdlib-exposure
[interop][SwiftToCxx] ensure we always expose limited set of APIs fro…
2023-03-18 12:14:44 -07:00
Alex Lorenz
5ca0b5a0c5 [interop][SwiftToCxx] ensure we always expose limited set of APIs from Swift's standard library to C++
Fixes https://github.com/apple/swift/issues/64340
2023-03-17 18:24:38 -07:00
Alex Lorenz
90d1c24674 [interop] 'conforms_to' attribute should be qualified with module name
Also, improve the diagnostics for 'conforms_to'
2023-03-17 15:09:27 -07:00
Alex Lorenz
94c1de7611 [interop][SwiftToCxx] use 'SWIFT_INLINE_PRIVATE_HELPER' macro for static returnNewValue functions to ensure attribute(used) isn't applied to them 2023-03-15 09:13:38 -07:00
Alex Lorenz
30f1912cf8 [interop][SwiftToCxx] use unconditional noexcept for C++ collection overlay
accessing collection in noexcept is wrong
2023-03-14 11:41:39 -07:00
Alex Lorenz
6f4feebd34 [interop] bump up experimental version 2023-03-12 11:49:14 -07:00
Alex Lorenz
3cce09e769 [interop][SwiftToCxx] annotate several value members types as 'noexcept'
C++/clang is more strict about requiring noexcept in templates so we need some explicit annotations
2023-03-12 11:49:14 -07:00
Alex Lorenz
0b265c725c [interop][SwiftToCxx] CollectionIterator in the stdlib overlay should have 'noexcept' annotations 2023-03-12 11:49:14 -07:00
Alex Lorenz
c7873490d2 Merge pull request #64290 from hyp/eng/fix-interop-xmodule-imports
[interop][SwiftToCxx] do not expose APIs with imported declarations w…
2023-03-11 06:08:40 -08:00
John McCall
ee0e38a5a0 Merge pull request #64273 from rjmccall/variadic-generic-type-metadata
Omnibus fixes to IRGen for variadic generic type metadata
2023-03-11 00:10:56 -05:00
Alex Lorenz
4fda7f4a9a [interop][SwiftToCxx] do not expose APIs with imported declarations whose modules do not have a generated header as specified by the user
The frontend option '-clang-header-expose-module' allows the user to specify that APIs from an imported module have been exposed in another generated header, and thus APIs that depend on them can be safely exposed in the current generated header.
2023-03-10 12:34:02 -08:00
John McCall
0e932329c3 Fix fulfillments for type metadata and witness table packs
A lot of the fixes here are adjustments to compensate in the
fulfillment and metadata-path subsystems for the recent pack
substitutions representation change.  I think these adjustments
really make the case for why the change was the right one to make:
the code was clearly not considering the possibility of packs
in these positions, and the need to handle packs makes everything
work out much more cleanly.

There's still some work that needs to happen around type packs;
in particular, we're not caching them or fulfilling them as a
whole, and we do have the setup to do that properly now.
2023-03-10 12:52:37 -05:00
Alex Lorenz
75fd11cffc [interop][SwiftToCxx] hide swift::Error APIs by default in C++ Swift stdlib overlay
They're still experimental
2023-03-10 08:34:45 -08:00
Alex Lorenz
910174dcda Merge pull request #64263 from hyp/eng/bumpupv13
[interop] bump up the experimental version in JSON file
2023-03-10 06:40:42 -08:00
Alex Lorenz
0dc90d38c1 [interop][SwiftToCxx] emit Swift's stdlib inside of 'swift' namespace 2023-03-09 17:32:43 -08:00
Alex Lorenz
e174e59af2 [interop] bump up the experimental version in JSON file 2023-03-09 16:52:49 -08:00