Commit Graph

718 Commits

Author SHA1 Message Date
Zoe Carver
41c965113f Merge pull request #42431 from zoecarver/param-types-use-enum-not-typedef
[cxx-interop] Import enum, not typedef for parameter types.
2022-04-19 08:56:53 -07:00
zoecarver
e6af2d9b49 [cxx-interop] Import enum, not typedef for parameter types.
Lookup the "anonymous" enum when importing parameter types rather than using the typedef's underlying type.
2022-04-18 19:20:19 -07:00
Zoe Carver
b8684afd80 Merge pull request #42223 from zoecarver/cxx-enum-pattern
[cxx-interop] Allow anonymous enums to be imported as non-constants.
2022-04-18 14:49:27 -07:00
zoecarver
965c7ca443 [cxx-interop] Allow anonymous enums to use the name of their base.
If an anonymous enum inherits from a typedef, it will have the typedef's name.
2022-04-18 11:05:58 -07:00
Slava Pestov
6982b90c6e Serialization: Round-trip primary associated type list 2022-04-16 22:36:29 -04:00
Becca Royal-Gordon
192c52ff17 [NFC] Integrate ImportTypeAttrs into importType() 2022-03-29 17:18:09 -07:00
Becca Royal-Gordon
8e85e1eedf [NFC] Eliminate applyParamAttributes() 2022-03-29 17:16:28 -07:00
Becca Royal-Gordon
a281feba72 [NFC] Factor out ImportTypeAttrs
Preparation for integrating the logic remaining in `applyParamAttributes()` into `importType()`.
2022-03-29 17:16:28 -07:00
Becca Royal-Gordon
6f71581b5c [NFC] Thread import diagnostics through ImportType
`ClangImporter::Implementation::importType()` and associated parts of the importer are now passed an `llvm::function_ref` they can use to emit import diagnostics on the declaration they’re importing, and the `ImportDiagnosticAdder` helper class provides a convenient way to construct such a function.

This capability is not actually *used* in this commit—we are simply threading this function through the importer—so there is no change in behavior.
2022-03-29 17:16:28 -07:00
Puyan Lotfi
09cdd36c0a [c++-interop] For failed imports in ClangImporter, cache them regardless. (#41173)
As per SR-14137 this caches entries in ImportedDecls even when the
import failed.

Also have to mention I did this based on Thomas's PR #36747.

This should help us better handle complex templates and dependant types.
2022-03-10 10:33:04 -08:00
Zoe Carver
d3c40ef9f1 Merge pull request #41624 from zoecarver/cache-thunks-for-spec
[cxx-interop] Cache specialized function templates.
2022-03-03 14:15:44 -08:00
zoecarver
e6a99cb969 [cxx-interop] Cache specialized function templates.
This not only prevents us from creating a bunch of FuncDecls but actually is required to prevent duplicate symbol errors.
2022-03-02 11:14:09 -08:00
Omar Habra
4167e2f80d [cxx-interop] Computed properties from getters and setters (#40842)
* fixing setters

* adding tests

* Removing extras

* fixing tests

* Better naming for properties

* Cleanup

* Add tests

* Clang format it

* more refactoring and some more tests

* More tests and more fixes

* Updating tests:

fixing other tests to work with new property importing

* Fix the two asserts. Move things around. Remove createImported. Move CXXMethodBridging to it's own header.

* General updates:

Fixing tests, adding radars to follow issues that cna be a started issues on the project.
Also Factoring out MethodBridging.

* Fixing Comments left on the PR:

General formatting.

* Fixing tests, and general updates for formatting

* removing extras and passing this on swift.

Co-authored-by: Omar Habra <ohabra@apple.com>
2022-02-28 23:13:17 -08:00
zoecarver
bb00e8dcfe [cxx-interop] Rudimentary support for importing base classes.
This commit adds very basic support for importing and calling base class methods, getting and setting base class fields, and using types inside of base classes.
2022-02-18 15:59:52 -08:00
Slava Pestov
7ee83a0c22 Serialization: Round-trip the RequirementMachine's ProtocolTypeAlias records 2022-02-13 00:24:23 -05:00
Ehud Adler
18c6bdd212 [Cxx iterop] Disambiguate between methods with the same name but different constness 2022-02-09 19:49:02 -05:00
Becca Royal-Gordon
74dc00f091 Merge pull request #40677 from beccadax/sendable-to-the-whole-block
[ClangImporter] Make completion handlers Sendable
2022-02-04 14:51:21 -08:00
Nuri Amari
3762ca1fa7 Attach Lazy ClangImporter Diagnostics as Notes
Clang importer diagnostics that are produced as a result of a reference
in Swift code are attached to as notes to the Sema produced diagnostic
that indicates the declaration is unavailable.

Ex: Notes about why a C function import failed are attached to
the error explaining that the symbol could not be found in scope.
2022-01-29 14:32:42 -05:00
Becca Royal-Gordon
8c844126d4 [ClangImporter] Make completion handlers Sendable
If a method has an `async` variant, the non-`async` variant will now mark its completion handler parameter `@Sendable`. This shouldn't be a breaking change in Swift 5 code since these declarations are automatically `@_predatesConcurrency`.

Also adds:

• Support for `@_nonSendable` on parameters, which can be used to override this implicit `@Sendable`
• Support for `@Sendable` on block typedefs; it's generally going to be a good idea to mark completion block typedefs `@Sendable`.

Fixes rdar://85569247.
2022-01-25 15:49:54 -08:00
Mishal Shah
0bf1389863 Merge pull request #40907 from apple/rebranch
Update swift:main to support llvm-project:stable/20211026 changes (Rebranch merge)
2022-01-19 23:36:38 -08:00
zoecarver
76e2934c34 [cxx-interop] Re-land part of 6ba7a1e. Fix an issue with extending nested namespaces across modules.
No one should be using C++ interop yet, so this part of the change cannot break anyone.
2022-01-19 12:20:14 -08:00
swift-ci
95586e858c Merge remote-tracking branch 'origin/main' into rebranch 2022-01-04 16:00:29 -08:00
Nuri Amari
130f2de7fd Improve ClangImporter failure diagnostics
This patch introduces new diagnostics to the ClangImporter to help
explain why certain C, Objective-C or C++ declarations fail to import
into Swift. This patch includes new diagnostics for the following entities:

- C functions
- C struct fields
- Macros
- Objective-C properties
- Objective-C methods

In particular, notes are attached to indicate when any of the above
entities fail to import as a result of refering an incomplete (only
forward declared) type.

The new diangostics are hidden behind two new flags, -enable-experimental-clang-importer-diagnostics
and -enable-experimental-eager-clang-module-diagnostics. The first flag emits diagnostics lazily,
while the second eagerly imports all declarations visible from loaded Clang modules. The first
flag is intended for day to day swiftc use, the second for module linting or debugging the importer.
2022-01-02 12:43:59 -05:00
swift-ci
252ef1f43b Merge remote-tracking branch 'origin/main' into rebranch 2021-12-09 10:54:20 -08:00
Xi Ge
c5a715d4ed Revert "[cxx-interop] Fix two issues with extending nested types across modules."
This reverts commit 6ba7a1ec1e.
2021-12-08 20:00:41 -08:00
swift-ci
103ce0b560 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-08 11:38:04 -08:00
zoecarver
fc3b3a1d71 [cxx-interop] Implement foreign reference types.
This is an expiremental feature to allow an attribute, `import_as_ref`, to import a C++ record as a non-reference-counted reference type in Swift.
2021-12-08 15:35:18 +00:00
swift-ci
80507517d9 Merge remote-tracking branch 'origin/main' into rebranch 2021-12-03 21:33:52 -08:00
Doug Gregor
8b198d95be [Clang importer] Eliminate the use of lookupDirect when getting all members.
Loading of the members of a C(++) struct/class can occur while doing a
direct lookup, so triggering a second direct lookup inside there can
introduce a request-evaluator cycle. Reimplement this operation to be
more like the way we lazily populate Objective-C classes and protocols,
walking through the record members in order and importing their
variants, then adding those. This eliminates a bunch of extraneous
lookup work, keeps the members in order (see the test case change),
and eliminates the potential for cycles.
2021-12-03 15:43:57 -08:00
swift-ci
1e3397c855 Merge remote-tracking branch 'origin/main' into rebranch 2021-11-29 20:52:56 -08:00
Doug Gregor
16f32fd50a Eliminate support for @MainActor(unsafe) Clang attribute.
The `@MainActor(unsafe)` attribute could be provided for C declarations
via the Clang `swift_attr` attribute. However, this facility was never
used outside of tests, and has been superceded by `@MainActor` with the
inferred `@_predatesConcurrency`.
2021-11-29 15:05:18 -08:00
swift-ci
844c9e802c Merge remote-tracking branch 'origin/main' into rebranch 2021-11-28 21:53:03 -08:00
Becca Royal-Gordon
1695d61664 [ClangImporter] Import SwiftAttrs early
This change applies SwiftAttr attributes as soon as possible after creating an instance of a Decl, rather than waiting until the declaration is "finished". That makes sure the attributes can influence the declaration very early in its lifecycle, and in particular, before its conformance table is initialized.

Mostly NFC in this commit (other than affecting the order that attributes are printed in), but necessary for future changes in this PR.
2021-11-19 11:34:01 -08:00
Becca Royal-Gordon
d2d786a76a [NFC] Add ClangImporter header diagnostic helper 2021-11-19 11:34:01 -08:00
swift-ci
8a3731cad8 Merge remote-tracking branch 'origin/main' into rebranch 2021-11-19 09:55:20 -08:00
Saleem Abdulrasool
4d44953691 Revert "Support __available__((swift_attr("@Sendable")))" 2021-11-19 07:40:24 -08:00
swift-ci
3a5bb8b2bc Merge remote-tracking branch 'origin/main' into rebranch 2021-11-19 01:33:47 -08:00
Becca Royal-Gordon
3d2d4e1721 Merge pull request #40170 from beccadax/send-me-an-object
Support __available__((swift_attr("@Sendable")))
2021-11-19 01:26:10 -08:00
Doug Gregor
962c1148f9 Remove Clang Importer support for @_unsafeSendable/@_unsafeMainActor. 2021-11-18 09:53:54 -08:00
Ben Barham
11f28196bc Merge pull request #40168 from bnbarham/rebranch-failures
[rebranch] Fix compilation failures
2021-11-17 08:50:11 +10:00
zoecarver
6ba7a1ec1e [cxx-interop] Fix two issues with extending nested types across modules.
One fix allows extending nested records in other modules, the other fixes the same issue for namespaces.
2021-11-15 16:20:15 -08:00
Becca Royal-Gordon
de768e8fda [ClangImporter] Import SwiftAttrs early
This change applies SwiftAttr attributes as soon as possible after creating an instance of a Decl, rather than waiting until the declaration is "finished". That makes sure the attributes can influence the declaration very early in its lifecycle, and in particular, before its conformance table is initialized.

Mostly NFC in this commit (other than affecting the order that attributes are printed in), but necessary for future changes in this PR.
2021-11-12 23:12:38 -08:00
Becca Royal-Gordon
b372ff61af [NFC] Add ClangImporter header diagnostic helper 2021-11-12 23:12:38 -08:00
Ben Barham
a6f99a08c4 [rebranch][ClangImporter] Update hashExtension to use HashBuilder
llvm-project updated `hashExtension` in
655bea4226b401a11164f99c6344e38d8742b8e4 to use a `HashBuilder` rather
than `hash_code`. Update use in ClangImporter.
2021-11-13 15:33:09 +10:00
Mishal Shah
c2fd49cebb Merge pull request #39473 from apple/rebranch
Update swift:main to support llvm-project:stable/20210726 changes (Rebranch merge)
2021-10-11 09:00:51 -07:00
swift_jenkins
602f3252e8 Merge remote-tracking branch 'origin/main' into next 2021-10-06 18:21:40 -07:00
Josh Learn
f433ac2d58 Allow importing templated functions when template args do not appear
in the function signature by adding explicit metatype parameters to
the function signature.
2021-10-06 13:35:12 -07:00
swift-ci
c51550f30e Merge remote-tracking branch 'origin/main' into rebranch 2021-09-30 15:11:41 -07:00
swift_jenkins
839dc9b098 Merge remote-tracking branch 'origin/main' into next 2021-09-28 15:23:56 -07:00
Xi Ge
a4b4b1fa65 ClangImporter: don't import clang SPI attributes by default 2021-09-28 10:46:27 -07:00