Commit Graph

36 Commits

Author SHA1 Message Date
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Richard Wei
51acf75cb5 Fix compiler crash when emitting objc header with C++ interop enabled
This was because `LoweredFunctionSignature::visitParameterList` has a special case for parameters with an empty LLVM representation (e.g. an empty struct) but forgot to increment the counter, which then tripped the assertion.

Resolves #70016.
2023-11-24 02:25:08 -08:00
Alex Lorenz
4e519a8d8b [interop][SwiftToCxx] consuming parameters should be passed using an additional copy
Fixes https://github.com/apple/swift/issues/69372
2023-10-27 17:29:52 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04: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
c9f9d9025b [interop][SwiftToCxx] fix offset computation for 32 bit platforms for vtable dispatch 2023-02-13 10:30:38 -08:00
Alex Lorenz
540202fed8 [interop][SwiftToCxx] dispatch virtual Swift methods using a relative offset into the vtable for classes deriving from resilient classes 2023-02-13 10:30:32 -08:00
Alex Lorenz
981e828b2a [interop][SwiftToCxx] dispatch swift class methods using signed isa and signed method pointer on arm64e 2023-02-11 14:05:59 -08:00
Alex Lorenz
9e32761578 [interop][SwiftToCxx] dispatch virtual calls via thunks for resilient classes 2023-02-10 16:32:54 -08:00
Alex Lorenz
b7007cb748 [interop][SwiftToCxx] dispatch Swift class methods correctly using the vtable 2023-02-09 20:20:53 -08:00
Nate Chandler
e9e93c1590 [Opaque Values] Address-lower TypeLowerings.
When opaque values are enabled, TypeConverter associates to an
address-only type an OpaqueValueTypeLowering.  That lowering stores a
single lowered SIL type, and its value category is "object".  So long as
the module has not yet been address-lowered, that type has the
appropriate value category.  After the module has been address-lowered,
however, that type has the wrong value category: the type is
address-only, and in an address-lowered module, its lowered type's value
category must be "address".

Code that obtains a lowered type expects the value category to reflect
the state of the module.  So somewhere, it's necessary to fixup that
single lowered type's value category.

One option would be to update all code that uses lowered types.  That
would require many changes across the codebase and all new code that
used lowered types would need to account for this.

Another option would be to update some popular conveniences that call
through to TypeConverter, for example those on SILFunction, and ensure
that all code used those conveniences.  Even if this were done
completely, it would be easy enough for new code to be added which
didn't use the conveniences.

A third option would be to update TypeLowering::getLoweredType to take
in the context necessary to determine whether the stored SILType should
be fixed up.  That would require each callsite to be changed and
potentially to carry around more context than it already had in order to
be able to pass it along.

A fourth option would be to make TypeConverter aware of the
address-loweredness, and to update its state at the end of
AddressLowering.

Updating TypeConverter's state would entail updating all cached
OpaqueValueTypeLowering instances at the end of the AddressLowering
pass.  Additionally, when TypeConverter produces new
OpaqueValueTypeLowerings, they would need to have the "address" value
category from creation.

Of all the options, the last is least invasive and least error-prone, so
it is taken here.
2022-12-01 14:18:17 -08:00
Allan Shortlidge
f5d760e613 Interop: Untangle circular dependency introduced by #59787
The changes for https://github.com/apple/swift/pull/59787 introduced a circular depenendcy between the SIL library and the SILGen library. I have undone this in the cheapest way possible as I don't have bandwidth to look into a more correct fix at the moment.
2022-10-27 13:17:38 -07:00
Alex Lorenz
b96bcb4691 [interop][SwiftToCxx] prohibit empty tuple param type 2022-09-15 11:22:22 -07:00
Alex Lorenz
07337cdaf6 [interop][SwiftToCxx] initial generic enum support 2022-09-14 11:37:50 -07:00
Alex Lorenz
0fea0c4eca [interop][SwiftToCxx] handle Swift tuples are unsupported types for now 2022-09-12 17:24:20 -07:00
Alex Lorenz
4c7015ad68 [interop][SwiftToCxx] ensure LoadableByAddress lowering is done on the SILFunction for while we're lowering the signature for
This correctly now passes self parameters for direct values that are too large to be direct
2022-09-07 17:42:50 -07:00
Alex Lorenz
661ae6bd1a [interop][SwiftToCxx] cleanup the function signature stuff 2022-09-07 14:06:28 -07:00
Alex Lorenz
e1989dd1f5 [interop][SwiftToCxx] verify that lowered function signature represented all LLVM IR params 2022-09-07 13:06:11 -07:00
Alex Lorenz
c351f3a550 [interop][SwiftToCxx] error result param should be handled by lowered function signature 2022-09-07 12:55:12 -07:00
Alex Lorenz
f4de75ae2c [interop][SwiftToCxx] 'self' param should be handled by type param visitor 2022-09-07 12:45:38 -07:00
Alex Lorenz
0592894e33 [interop][SwiftToCxx] move generic additional type parameters into lowered function signature 2022-09-07 12:22:04 -07:00
Alex Lorenz
4520c52ac6 [interop][SwiftToCxx] handle indirect result values as part of parameter list 2022-09-07 11:59:25 -07:00
Alex Lorenz
1696f94223 [interop][SwiftToCxx] reimplement function lowering to correctly distinguish between direct/indirect return values and parameters 2022-09-07 11:43:38 -07:00
Alex Lorenz
a5043c354d [interop][SwiftToCxx] add support for invoking methods in generic structs 2022-08-31 20:19:19 -07:00
Alex Lorenz
45d209fe1c [interop][SwiftToCxx] initial generic struct support 2022-08-31 14:02:15 -07:00
Tongjie Wang
ff28b56e15 [Interop][SwiftToCxx] add support for resilient enum 2022-08-08 14:37:13 -07:00
Alex Lorenz
32723f7e67 [interop][SwiftToCxx] initial generic function support: pass generic parameters
Only primitive types are supported at the moment from C++ as the type traits aren't emitted for all types yet
2022-07-28 22:52:21 +01:00
Roberto Rosmaninho
ff222acebc Setting hardcode SWIFT_NOEXCEPT and noexcept flags only to
non-throwing functions.
Activating swift-functions-errors tests
Inserting macros and additional parameters in C and C++ functions following the pattern to lowering to LLVM IR.
2022-07-14 12:34:53 -03:00
Tongjie Wang
23d60acbc2 sort cases based on their assigned tag indices before printing 2022-07-06 12:46:11 -07:00
Tongjie Wang
7ebcb7b33a [Interop][SwiftToCxx] Implement enum case switching 2022-06-30 22:41:15 -07:00
Alex Lorenz
9254c47b2c [interop][SwiftToCxx] emit swift type metadata access function declaration for structs 2022-06-13 09:16:17 -07:00
Alex Lorenz
132729906c [interop][SwiftToCxx] pass / return Swift struct values between C/C++ and Swift 2022-06-08 07:03:24 -07:00
Alex Lorenz
42c6ff63b8 [interop][SwiftToCxx] Gather initial struct layout information and emit struct stubs with storage in C++
This change extends the clang header printer to start emitting C++ classes for Swift struct types with the correct struct layout in them (size + alignment)
2022-06-01 14:06:25 -07:00