`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.
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.
* 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>
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.
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.
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.
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.
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.
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`.
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.
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.
llvm-project updated `hashExtension` in
655bea4226b401a11164f99c6344e38d8742b8e4 to use a `HashBuilder` rather
than `hash_code`. Update use in ClangImporter.