Commit Graph

1905 Commits

Author SHA1 Message Date
Puyan Lotfi
1ae0d2aadd [cxx-interop] Fixing usage of ObjC Categories in C++-Interop mode.
In C/ObjC interop mode a Clang AST with an ObjC Category resembles:

TranslationUnitDecl
`-ObjCCategoryDecl

However in C++-Interop mode the same Category could potentially have an
extern "C" linkage specifier (guarded with #ifdef __cplusplus) and
resembles:

TranslationUnitDecl
|-LinkageSpecDecl
  `-ObjCCategoryDecl

In the latter case when the ClangImporter attempts to import the
category in swift::ClangImporter::Implementation::importDeclContextOr,
prior to this patch, would bail because it is expecting the DeclContext
above the ObjCCategoryDecl to be a TranslationUnitDecl and when it isn't
it returns nullptr.

Because of this, of course the category does not get imported as a swift
extension and therefore any fields or methods are also not imported.

In the case of UIKit, UIView has one of these categories that are
extern-"C"'ed due to UIKIT_EXTERN containing the linkage specifier in
-enable-cxx-interop mode. Since UIView is inherited by lots of other
UIKit types (UILabel etc), many of these types also have lots of missing fields
as well.

This patch checks to see if the decl about to be imported in
importDeclContextOr has a linkage specifier as it's context and makes
sure to materialize the TU from the parent of the declcontext instead of
just immediately bailing. Because of this, this patch enables
c++-interop mode to compile code that uses UIKit without hitting this
mis-compile.
2021-12-05 04:06:14 -05: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
Doug Gregor
4fccfccadf [Clang importer] Don't insert members found via lookup into the wrong context.
Discovered while investigating rdar://85840928.
2021-12-01 09:57:32 -08:00
Zoe Carver
d08ecf359d Merge pull request #40336 from zoecarver/set-lazy-complete-after-load
[nfc][cxx-interop] Mark lazy member loading complete only after members are loaded.
2021-11-30 16:34:01 -08:00
zoecarver
f3b7a40f1e [nfc][cxx-interop] Mark lazy member loading complete only after members are loaded. 2021-11-30 11:54:58 -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
Becca Royal-Gordon
ad0e7096ba Make NS_ENUM &c. Sendable even when audited
An explicit swift_attr("@_nonSendable") will override it (except for ns_error_domain where the type is embedded in another type that's forced to be Sendable), but swift_attr("@_nonSendable(_assumed)") will not.
2021-11-19 11:34:02 -08:00
Becca Royal-Gordon
b9480f12d0 Allow imported types to add a Sendable conformance
...by using `__attribute__((swift_attr("@Sendable")))`. `@_nonSendable` will "beat" `@Sendable`, while `@_nonSendable(_assumed)` will not.

This commit also checks if `SwiftAttr` supports `#pragma clang attribute` and, if it does, defines `__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS` in imported headers so they know they can apply these attributes in an auditing style.
2021-11-19 11:34:01 -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
Becca Royal-Gordon
0842795eb5 [NFC] Let SynthesizedProtocolAttrs be @unchecked
This is not yet used by anything.
2021-11-19 11:34:01 -08:00
Saleem Abdulrasool
4d44953691 Revert "Support __available__((swift_attr("@Sendable")))" 2021-11-19 07:40:24 -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
Zoe Carver
8980b8b6ec Merge pull request #40165 from zoecarver/fix-extensions-across-modules
[cxx-interop] Fix two issues with extending nested types across modules.
2021-11-16 09:08:06 -08: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
8751658f6c Make NS_ENUM &c. Sendable even when audited
An explicit swift_attr("@_nonSendable") will override it (except for ns_error_domain where the type is embedded in another type that's forced to be Sendable), but swift_attr("@_nonSendable(_assumed)") will not.
2021-11-12 23:13:29 -08:00
Becca Royal-Gordon
7549278314 Allow imported types to add a Sendable conformance
...by using `__attribute__((swift_attr("@Sendable")))`. `@_nonSendable` will "beat" `@Sendable`, while `@_nonSendable(_assumed)` will not.

This commit also checks if `SwiftAttr` supports `#pragma clang attribute` and, if it does, defines `__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS` in imported headers so they know they can apply these attributes in an auditing style.
2021-11-12 23:13:29 -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
Becca Royal-Gordon
953ffc3c8d [NFC] Let SynthesizedProtocolAttrs be @unchecked
This is not yet used by anything.
2021-11-12 23:12:38 -08:00
Zoe Carver
c6474b970d Revert "Implement ClangImporter importSourceLoc and importSourceRange (#40010)"
This reverts commit 8eb8263f81.
2021-11-11 12:09:55 -08:00
Nuri Amari
8eb8263f81 Implement ClangImporter importSourceLoc and importSourceRange (#40010)
Co-authored-by: Nuri Amari <nuriamari@fb.com>
2021-11-09 16:31:03 -08:00
Robert Widmann
22405cefea Plumb the "Is Type Sequence" Bit Through the Surface AST 2021-11-08 13:48:30 -08:00
Slava Pestov
f38f25a3de AST: Factor out AbstractGenericSignatureRequest into a new buildGenericSignature() function
This is slightly cleaner.
2021-10-30 00:35:59 -04:00
zoecarver
a5c0eb0e9c [cxx-interop] Fix lazy loading for result types.
When applying attributes, don't check the result type of the Swift function, so that we can get the benefits of lazy loading.
2021-10-25 14:40:22 -07:00
zoecarver
b8e52a7ad2 [cxx-interop] Lazily import members of Clang namespaces and records via requests.
Also adds a ClangImporter request zone and move some requests into it.
2021-10-20 14:52:43 -07:00
Zoe Carver
40422f021b Merge pull request #39664 from zoecarver/lazy-pt9-use-lookup-table
[cxx-interop] Add members to the LookupTable where possible.
2021-10-13 15:29:31 -07:00
zoecarver
eeeb27d66e [cxx-interop] Add members to the LookupTable where possible.
If possible, add imported members to the StructDecl's LookupTable rather than adding them directly as members. This will fix the issues with ordering that #39436 poorly attempted to solve during IRGen.

This also allows us to break out most of the test changes from #39436.
2021-10-13 11:53:58 -07:00
Daniel Rodríguez Troitiño
0392181c23 Merge pull request #39653 from NuriAmari/auto
NFC: Remove Decl* declarations made using auto
2021-10-12 18:11:35 -07: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
Nuri Amari
03d4d11216 Remove Decl* declarations made using auto
A non functional change replacing auto with
Decl* for some declarations using ClangImporter::Implementation::importDecl.
Increases clarity and makes subsequent planned changes easier.
2021-10-07 11:15:07 -04: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
Xi Ge
a4b4b1fa65 ClangImporter: don't import clang SPI attributes by default 2021-09-28 10:46:27 -07:00
swift-ci
0f56ea59e3 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-24 09:33:57 -07:00
Zoe Carver
3e07369ede Merge pull request #39434 from zoecarver/lazy-pt6-class-template-dce
[nfc][cxx-interop] Remove dead code in `VisitClassTemplateDecl`.
2021-09-24 12:28:30 -04:00
Zoe Carver
b159a8f969 Merge pull request #39433 from zoecarver/lazy-pt5-factor-out-validation
[nfc][cxx-interop] Factor validation logic out into lower visitors.
2021-09-24 12:28:11 -04:00
zoecarver
c0a2c7819e [nfc][cxx-interop] Remove dead code in VisitClassTemplateDecl.
This is now handled in the namespace visitor. It will eventually be handled directly in the SILModulePrinter.

Refs #38675.
2021-09-23 15:52:33 -07:00
zoecarver
62ee63d69a [nfc][cxx-interop] Factor validation logic out into lower visitors.
This just moves the same logic around. It shouldn't modify any actual functionality.

Refs #38675.
2021-09-23 15:47:55 -07:00
swift-ci
11c0f355a6 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-23 13:53:22 -07:00
zoecarver
d14281f643 [cxx-interop] Allow function templates with defaulted template type parameters to be called.
If a defaulted template type parameter is not used in the function's
signature, don't create a corresponding generic argument for that
template type. This allows us to call function templates with defaulted
template type parameters. This is very common in the standard library
for things like enable_if which is used to disable various
functions/overloads with SFINAE.

The biggest part of this change is going forward not all function
templates will be imported as generic functions in Swift. This should
work OK but we may discover there was some logic which only looked for
generic function when dealing with function templates.
2021-09-22 11:11:16 -07:00
swift-ci
a8dc9f7d6f Merge remote-tracking branch 'origin/main' into rebranch 2021-09-09 08:53:29 -07:00
Zoe Carver
f2f8bac056 Merge pull request #39134 from zoecarver/lazy-load-function-result-type
[cxx-interop] Lazily load the result of imported functions.
2021-09-09 11:44:21 -04:00
zoecarver
6e9bf50996 [cxx-interop] Lazily load the result of imported functions.
Note: we only lazily load the result if it's a record, because otherwise it's trivial to load when importing the function. Also, we still eagerly import operator's results types.
2021-09-08 17:48:39 -07:00
swift-ci
cb32b553de Merge remote-tracking branch 'origin/main' into rebranch 2021-09-04 11:32:57 -07:00
Hamish Knight
47754822c7 [CodeSynthesis] Adopt ArgumentList
Most of this should be fairly mechanical, the
changes in PlaygroundTransform are a little more
involved though.
2021-09-01 18:40:26 +01:00
swift-ci
f9db717379 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-28 14:33:15 -07:00
Xi Ge
3616872c28 Merge pull request #39068 from nkcsgexi/73902734
ClangImporter: teach clang importer to import Clang SPI symbols and model them similarly as Swift SPIs
2021-08-28 14:20:25 -07:00
Xi Ge
36f25c3130 ClangImporter: teach clang importer to import Clang SPI symbols and model them similarly as Swift SPIs
For clang symbols marked with SPI_AVAILABLE, we add SPIAccessControlAttr to them so they will be
considered as SPIs in the AST. To be able to use all these symbols, we also add an implicit SPI import
statement for all clang modules. All clang SPIs belong to the same SPI group named "OBJC_DEFUALT_SPI_GROUP" because clang
currently doesn't support custom SPI group.

rdar://73902734
2021-08-28 11:11:09 -07:00
swift-ci
5fe1881a91 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-27 21:53:32 -07:00