Commit Graph

2550 Commits

Author SHA1 Message Date
zoecarver
50ce8438c8 [cxx-interop] Don't import exit from Darwin module, use the one from _SwiftConcurrency.h. 2023-06-28 10:16:36 -07:00
zoecarver
173329ee96 [cxx-interop] only ban strstr, sin, cos, and exit on darwin where the conflict with declarations in the Darwin module; improve the test. 2023-06-28 09:40:09 -07:00
zoecarver
42bc1670a0 [cxx-interop] Re-work control flow when checking for duplicate functions.
Also add back `string.h` as a valid header and ban imports from `_SwiftConcurrencyShims`.
2023-06-27 22:19:22 -07:00
zoecarver
f07a9ffc05 [cxx-interop] check file and directory, not or. 2023-06-27 09:43:46 -07: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
zoecarver
26e30565fa [cxx-interop] Fix ambiguous 'exit' (same solution as above). 2023-06-23 12:33:23 -07:00
zoecarver
067abeb480 [cxx-interop] Pull over fix from 8e7766b and apply to strstr, sin, and cos. 2023-06-23 12:03:14 -07:00
Alex Lorenz
4590aa1ede Merge pull request #65813 from hyp/eng/passInRegs
[cxx-interop] Itanium ABI C++ records should have address-only layout when they can't be passed in registers
2023-06-16 07:47:48 -07:00
Alex Lorenz
7abd2653d9 [cxx-interop] revert back to old address-only heuristic for MSVC 2023-06-15 13:16:57 -07:00
Egor Zhdan
b459fb5fc2 [cxx-interop] Avoid linker errors when calling a defaulted constructor
When a default constructor is declared, but does not have a body because it is defaulted (`= default;`), Swift did not emit the IR for it. This was causing linker error for types such as `std::map` in libstdc++ when someone tried to initialize such types from Swift.

rdar://110638499 / resolves https://github.com/apple/swift/issues/61412
2023-06-12 20:06:49 +01:00
Holly Borla
cd752cca22 [NameLookup] Plumb source location arguments through all name lookup APIs.
This source location will be used to determine whether to add a name lookup
option to exclude macro expansions when the name lookup request is constructed.
Currently, the source location argument is unused.
2023-06-11 23:09:47 -07:00
Doug Gregor
a72fb83034 Requestify AbstractStorageDecl::hasStorage().
The `hasStorage()` computation is used in many places to determine the
signatures of other declarations. It currently needs to expand accessor
macros, which causes a number of cyclic references. Provide a
simplified request to determine `hasStorage` without expanding or
resolving macros, breaking a common pattern of cycles when using
macros.

Fixes rdar://109668383.
2023-06-10 08:28:06 -07:00
Zoe Carver
f9bd1a5623 Merge pull request #66452 from zoecarver/ns-option-as-field-take-two 2023-06-08 19:36:33 -07:00
zoecarver
3f45c172cc [cxx-interop] Correctly import fields with type NS_Option. 2023-06-08 13:12:38 -07:00
Doug Gregor
b374c099ac [Clang importer] Eliminate redundant imports of C++ fields as properties
A recent refactoring uncovered two places where we could end up
importing a C++ field declaration as a property more than once:

1. Importing the declaration context of a field in C++ mode can then
  go import all of the fields. In such a case, check that the field
  we're importing didn't happen already, and bail out early if it did.
  This is common practice in the Clang importer but wasn't happening here.
2. One caller to the function that imported a field from a C++ base
  class into its inheriting class (as a computed property) wasn't
  checking the cache, and therefore created a redundant version.

Fix both issues.
2023-06-03 10:03:10 -07:00
Egor Zhdan
25ef5d7016 Merge pull request #66220 from apple/egorzhdan/c-default-init
[cxx-interop] Synthesize a deprecated zero initializer for C++ structs
2023-06-01 11:33:46 +01:00
Egor Zhdan
fec48f9e63 [cxx-interop] Synthesize a deprecated zero initializer for C++ structs
When importing a C header in the C++ language mode, Clang/Swift treat C structs as C++ structs.

Currently Swift synthesizes a default initializer that zero-initializes the backing memory of the struct for C structs, but not for C++ structs.

This is causing issues in existing projects that use C libraries and rely on having the default initializer available in Swift. This change enables the synthesis of a default initializer for C++ structs. Since many C++ structs are not designed to be initialized this way, the initializer is marked as deprecated in Swift.

rdar://109727620
2023-05-31 13:41:25 +01:00
Nuri Amari
f676b75af0 [Swift-ObjC-Interop] Speculative cyclic lookup fix
The lookup to resolve an ObjC forward declaration
to its potential native Swift definition within
a mixed module is becoming cyclic somehow.

The old uncached lookup still works, so it seems
this is an issue with cache invalidation somehow.
Until the route of the issue, use the old uncached
lookup method.
2023-05-28 11:45:54 -07:00
QuietMisdreavus
34faa58b52 [ClangImporter] don't add swift_attr files to a module's auxiliary files (#65867)
rdar://107624995
2023-05-17 09:10:13 -06:00
Alex Lorenz
2c4188b8f4 [cxx-interop] mark C++ classes with trivial_abi attribute as unavailable in Swift 2023-05-09 16:23:36 -07:00
Alex Lorenz
49d7e041de [cxx-interop] C++ records should have address-only layout when they can't be passed in registers
This ensures that a C++ record with only ObjC ARC pointers with trivial other members is passed by value in SIL

Fixes https://github.com/apple/swift/issues/61929
2023-05-09 16:23:35 -07:00
Egor Zhdan
42b3973de8 [cxx-interop] Do not mix up computed properties from different records
If two different C++ structs have methods with the same name, both annotated with `SWIFT_COMPUTED_PROPERTY`, ClangImporter previously confused them when one of the structs referenced the other struct.

rdar://108990490 / resolves https://github.com/apple/swift/issues/65675
2023-05-06 17:04:08 +01:00
Alex Hoppen
053d215d55 Merge pull request #65427 from ahoppen/ahoppen/macro-attribute-completions
[CodeCompletion] Support completion for macro roles and the 'names:' argument label
2023-04-28 17:20:24 -07:00
Alex Lorenz
3282fb7bc1 Merge pull request #65437 from hyp/eng/nomathinthiscompiler
[interop] avoid importing math functions from the C++ standard library
2023-04-28 07:21:13 -07:00
Alex Hoppen
186b854721 [Parser] Pass code completion status from attribute parsing to decl parsing
This is needed to be able to perform code completion inside `@freestanding` and `@attached`.
2023-04-27 18:13:16 -07:00
Alex Lorenz
8e7766bf18 [interop] avoid importing math functions from the C++ standard library
They cause ambiguities with math functions from platform's libc
2023-04-27 10:25:51 -07:00
Alex Lorenz
0fff76915b [interop] Ensure an FRT or a pointer to struct/class gets a Swift type name for a C++ template parameter
In the follow-up, I should also expand this to cover pointers to builtin types too, but for now lets go with a miminal fix here
2023-04-26 14:48:21 -07:00
Alex Lorenz
f45d9f7662 Merge pull request #65056 from hyp/eng/no-never-ever
[interop] do not import functions whose return type is not imported
2023-04-12 08:20:04 -07:00
Alex Lorenz
380f9a7008 [interop] add availability for foreign reference types
Such types have runtime support only SwiftStdlib 5.8 and above
2023-04-11 15:28:22 -07:00
Alex Lorenz
8e0c17b274 [interop] do not import functions whose return type is not imported 2023-04-11 08:27:45 -07:00
Alex Lorenz
c2315060b6 [interop] mark C++ virtual functions as unavailable in Swift
They're not yet supported
2023-04-10 11:51:38 -07:00
zoecarver
5a20d72880 [cxx-interop] Allow specific getters/setters to be imported as computed properties.
Adds `SWIFT_COMPUTED_PROPERTY`. Refs `-cxx-interop-getters-setters-as-properties`.
2023-04-07 10:30:30 -07:00
Alex Lorenz
991d0a720d [interop] emit symbolic interfaces with method signatures with matching parameter count
We do not care about parameter's type in the symbolic method declaration, but we do care about the arity of the method.
2023-03-30 13:16:30 -07:00
Alexis Laferrière
201c4b6205 Merge pull request #64486 from xymus/import-filter-refactor
[Sema] Intro common sets of import filters to simplify calls to `getImportedModules`
2023-03-21 11:10:50 -07:00
zoecarver
9d5d624d10 [cxx-interop] Let through decls (mainly class templates) that do not have required lifetime operations when printing a module interface. 2023-03-20 15:47:23 -07:00
zoecarver
1e43ba0514 [cxx-interp] Don't select the move contstructor if it hasn't been defined. 2023-03-20 15:47:23 -07:00
zoecarver
615062d517 [cxx-interop] Fix warning; pull apart another case where record semantics relied on sema having instanciated special members. 2023-03-20 15:47:23 -07:00
zoecarver
9ee2667699 stash 2023-03-20 15:47:22 -07:00
zoecarver
a10bf21fcd [cxx-interop] 'Support' C++ move only types; fix a few bugs in the object model.
The implemented object model should now match the object model outlined in the Forward Vision document.
2023-03-20 15:47:22 -07:00
Alex Lorenz
cf0763dc87 [interop] Swift -> C++ -> Swift class type bridging 2023-03-18 19:29:55 -07:00
Alex Lorenz
953dfec62b [interop] fix swift-ide-test module interface namespace printing crash for _impl namespace in swift_private namespace 2023-03-18 17:50:57 -07:00
Alex Lorenz
0c214fe559 Merge pull request #64466 from hyp/eng/inontrivvy
[interop] C++ record should use AddressOnly type layout only when it's non-trivial for purpose of calls
2023-03-18 07:11:14 -07:00
Alex Lorenz
e26109f71e Merge pull request #64459 from hyp/eng/conforms_to++
[interop] 'conforms_to' attribute should be qualified with module name
2023-03-17 20:18:37 -07:00
Alex Lorenz
863f98755e [interop] C++ record should use AddressOnly type layout only when it's non-trivial for purpose of calls
A record that's non trivia for purpose of calls, as defined in Itanium ABI is allowed to have non-trivial copy/move assignment operators, but it most not have non-trivial constructors or destructors. This change ensures that a C++ record with a non-trivial copy assignment operator but trivial other members can be passed/returned directly by value, so that the compiler can accept the returned value correctly when calling a C++ function.
2023-03-17 17:02:14 -07:00
Alexis Laferrière
205a2edf38 [Sema] Intro set of import filters for general use
Calling getImportedModules requires to list the desired kind of imports.
With the new kind of imports this has become cumbersome. Let's simplify
it by offering common sets of imports. Advanced call sites can still
list the desired imports explicitly.
2023-03-17 16:05:44 -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
426772e920 [interop] NFC, fix an integer comparison warning in VisitClassTemplateSpecializationDecl 2023-03-17 14:43:06 -07:00
Alex Lorenz
827af150ab [interop] ensure std::pair is imported into Swift 2023-03-14 07:29:48 -07:00
Nuri Amari
a5356940d3 [NFC] Escape @class / @protocol comments causing warnings 2023-03-10 12:41:49 -08:00