Commit Graph

2428 Commits

Author SHA1 Message Date
Zoe Carver
d048e0554a Merge pull request #34649 from zoecarver/cxx/no-import-no-destructor
[cxx-interop] Don't import C++ objects that we can't destroy.
2020-11-14 12:42:13 -08:00
zoecarver
bcf8733c2b [cxx-interop] Don't import C++ objects that we can't destroy.
Don't import C++ objects unless they have a public destructor that is not deleted.
2020-11-13 13:18:12 -08:00
swift_jenkins
332645899e Merge remote-tracking branch 'origin/main' into next 2020-11-10 22:43:49 -08:00
zoecarver
9c58a95755 [cxx-interop] Support function templates inside a namespace.
Thread "templateParams" through the call to find the function parameter
types when the function is in a namespace.
2020-11-10 18:49:51 -08:00
swift_jenkins
fa7aebcf67 Merge remote-tracking branch 'origin/main' into next 2020-11-05 22:33:58 -08:00
Zoe Carver
88a6f15dd2 [re-apply][cxx-interop] Support class templates containing typedefs. (#34601)
This prevents an assertion in "isOverAligned" caused class templates
that contain and use typedefs.

Re-landing 7f2b0aad2b after being reverted
in 5ef0136356.
2020-11-05 21:54:19 -08:00
swift_jenkins
95d48468e6 Merge remote-tracking branch 'origin/main' into next 2020-11-05 10:37:53 -08:00
Saleem Abdulrasool
5ef0136356 Revert "[cxx-interop] Support class templates containing typedefs." 2020-11-05 07:55:24 -08:00
swift_jenkins
ca7db980ec Merge remote-tracking branch 'origin/main' into next 2020-11-04 22:35:34 -08:00
Arnold Schwaighofer
97e5e01fe2 Merge remote-tracking branch 'origin/main' into next 2020-11-04 12:20:35 -08:00
zoecarver
7f2b0aad2b [cxx-interop] Support class templates containing typedefs.
This prevents an assertion in "isOverAligned" caused class templates
that contain and use typedefs.
2020-11-02 23:17:34 -08:00
Artem Chikin
3b545498d0 Merge pull request #34331 from artemcm/NoFoundationOnExplicitImportSoil
[Clang Importer] Do not rely on being able to always import Foundation on-demand
2020-11-02 13:02:15 -08:00
swift_jenkins
fa32dc6ba7 Merge remote-tracking branch 'origin/main' into next 2020-10-30 00:09:25 -07:00
John McCall
e35f077a9b Merge pull request #33349 from ellishg/master
[IRGen] Call objc_direct methods correctly
2020-10-30 03:03:54 -04:00
Artem Chikin
0305f20f32 [Clang Importer] Do not rely on being able to always import Foundation on-demand
When importing Clang types.
This is not an option with Explicit Module Builds. If the module being built does not (directly or transitively) depend on `Foundation`, then attempting to load it will produce an error because Implicit module loading is no longer allowed..

This change addresses a small number of cases where ClangImporter relies on being able to load `Foundation` on-demand:
- When importing a single Decl from a clang module, we check whether it has certain conformances by checking all extensions of the NominalTypeDecl of the Decl in question, to see if any of the extensions contain the conformance we are looking for, but we only check extensions whose parent module is either the original module of the NominalTypeDecl or the overlay module of the NominalTypeDecl or Foundation. It seems that we do not need to actually import `Foundation` here, just checking the module Identifier should be sufficient.
- In `maybeImportNSErrorOutParameter`, change the behavior to have an exit condition based on whether `Foundation` can be imported, before attempting to load it.
- When checking whether or not we are allowed to bridge an Objective-C type, it also looks sufficient the query whether or not `Foundation` *can* be imported, without loading it.
2020-10-28 14:47:17 -07:00
David Smith
0180aca9fc Merge branch 'main' into david/fix-merge-conflict 2020-10-27 13:05:20 -07:00
swift-ci
38d759c43a Merge pull request #34428 from zoecarver/cxx/empty-template-spec 2020-10-26 16:01:27 -07:00
swift-ci
26c962629f Merge pull request #34365 from zoecarver/cxx/bool-enum 2020-10-26 15:57:42 -07:00
zoecarver
3a87cbefad [cxx-interop] Disable importing fully specialized class templates.
Before this patch we would crash when importing a fully specialized
class template contianing a child declaration. This patch simply bails
on fully-specialized class templates instead of potentially crashing.
2020-10-25 13:06:41 -07:00
zoecarver
05faa07c48 [cxx-interop] Support bool-based enums.
This is a small fix to prevent a crash. This change simply adds another
condition for the "bool" branch that checks if "type" is associated with
a "clang::EnumDecl" with an underlying type of "bool", and if so, treats
"type" as a "Bool".
2020-10-24 23:08:59 -07:00
Ellis Hoag
3aa081c56e [IRGen] Call objc_direct methods correctly 2020-10-23 11:54:07 -05:00
Saleem Abdulrasool
4a8948373e ClangImporter: support the MS anonymous structure extension
The Microsoft extension permits the creation of structures without a
name which effectively create an anonymous inline structure.  Accommodate
that in the ClangImporter.

For more details about the extension, see:
https://docs.microsoft.com/en-us/previous-versions/a3bbz53t(v=vs.140)#anonymous-structs

Thanks to @brentdax for the suggestion of the additional check!
2020-10-22 15:43:10 -07:00
Zoe Carver
f0f2246793 [cxx-interop] Support C++ function templates in Swift. (#33053)
This patch adds rudimentary support for C++ template functions in swift.
2020-10-21 20:42:25 -07:00
zoecarver
1d3b051151 [cxx-interop] Remove logic around applying attributes.
Removes the logic around applying attributes to C++ constructor's
indirect results.

Also fixes some commenting.
2020-10-15 13:10:55 -07:00
swift_jenkins
25160da347 Merge remote-tracking branch 'origin/main' into next 2020-10-14 13:47:25 -07:00
Alexis Laferrière
e509d6883a Revert "[Sema] Fix availability checking in inlinable code" 2020-10-14 10:52:11 -07:00
swift_jenkins
8fddbcef4d Merge remote-tracking branch 'origin/main' into next 2020-10-13 09:16:15 -07:00
zoecarver
4cb337a41f [cxx-interop] Generate memberwise initializers for non-C++ types.
Previously, when we checked for `!hasUserDeclaredConstructor` rather than
`isAggregate`, we would always generate memberwise initializers for C
record types. This updates the isAggregate to be true for non-C++ types
so we will generate memberwise initializers for them as well.
2020-10-10 15:08:30 -07:00
Alexis Laferrière
429017fc7a [ClangImporter] Import unavailable decls as unavailable 2020-10-09 10:57:01 -07:00
zoecarver
5774610eaf [cxx-interop] Fix patch formatting with clang-format.
Fix all formatting of the changes made by this patch.
2020-10-09 10:42:55 -07:00
zoecarver
4364af39ee [cxx-interop] Small fixes and cleanup based on review.
* Check isAggregate instead of hasUserDeclaredConstructor.
 * Rename addEmptyArgNamesForCxxFunc ->  addEmptyArgNamesForClangFunction.
 * Other minor fixes and cleanups.
2020-10-09 10:42:54 -07:00
zoecarver
2713edb19e [cxx-interop] Fix missing APIs and tests after rebase.
* Update tests that relied on old behavior.
 * Use mangleCXXName instead of mangleCXXCtor.
 * Call VisitCXXRecordDecl not VisitRecordDecl from
 VisitClassTemplateSpecializationDecl. This allows template constructors
 to be imported and called correctly.
2020-10-09 10:42:53 -07:00
Martin Boehme
33e8c717f2 Update comment in VisitCXXRecordDecl(). 2020-10-09 10:42:51 -07:00
Martin Boehme
cb4ddda6e2 Avoid crashing if lldb imports C++ structs without enabling C++ interop. 2020-10-09 10:42:51 -07:00
Martin Boehme
bed2603944 Various changes after merging master:
- Adapt tests to changes that have happened in the meantime (e.g.
  `HasVirtualBase` is rightly no longer considered loadable)
- Don't import copy or move constructors (noticed this because
  references are now imported correctly, so copy and move constructors
  suddenly started showing up in the SIL test)
- Don't try to define an implicitly-deleted default constructor (this
  previously broke loadable-types-silgen.swift)
2020-10-09 10:42:49 -07:00
Martin Boehme
b2c5a3eeed Add a constructor thunk if required to add additional constructor
arguments.

Also add more IR tests and make various other changes.
2020-10-09 10:42:48 -07:00
Martin Boehme
384854810a Revert "Only import constructors marked noexcept."
This reverts commit 29650d8c1f302708a32304d49c703c9ddbf30b75.

As discussed here, we want to import all constructors (whether they are
marked `noexcept` or not) as non-throwing initializers;

https://forums.swift.org/t/handling-c-exceptions/34823/50
2020-10-09 10:42:47 -07:00
Martin Boehme
7ad2eef265 Only import constructors marked noexcept. 2020-10-09 10:42:46 -07:00
Martin Boehme
a5e953b690 Add support for calling C++ constructors.
Because C++ constructors always take a `this` pointer to the object to
be initialized, we mark the SIL function return type with the `@out`
attribute.

On the IRGen side, we retrofit support for formal indirect return values as
well as thin metatypes.
2020-10-09 10:42:46 -07:00
Nathan Hawes
ad5b3152c0 Merge pull request #34062 from nathawes/fix-upstream-breakage-on-next
[next] Update for swiftNewTypeAttr capitalization change.
2020-09-30 12:07:28 -07:00
Nathan Hawes
40b6798d35 Update usages of 'SwiftNewtypeAttr' for the new spelling 'SwiftNewTypeAttr' 2020-09-29 10:46:13 -07:00
Doug Gregor
9b808c67fa [Concurrency] Import "did" delegate methods as @asyncHandler.
Infer @asyncHandler on a protocol methods that follow the delegate
convention of reporting that something happened via a "did" method, so
long as they also meet the constraints for an @asyncHandler method in
Swift. This enables inference of @asyncHandler for witnesses of these
methods.
2020-09-24 14:01:08 -07:00
Robert Widmann
7bee5ffc0c Remove NLOptions::NL_Known* 2020-09-21 10:37:41 -06:00
Slava Pestov
d7f4b1a1bd AST: Capture list bindings now point back to their parent CaptureListExpr
We'll need this to get the right 'selfDC' when name lookup
finds a 'self' declaration in a capture list, eg

class C {
  func bar() {}
  func foo() {
    _ = { [self] in bar() }
  }
}
2020-09-18 02:59:15 -04:00
Doug Gregor
0f18948bd5 [Concurrency] Allow @objc async methods.
Allow the declaration of @objc async methods, mapping them to a
completion-handler API in Objective-C. This covers most of the
checking and semantics within the type checker:
* Declaring @objc async methods and checking their parameter/result types
* Determining the default Objective-C selector by adding
completionHandler/WithCompletionHandler as appropriate
* Determining the type of the completion handler parameter
* Inferring @objc from protocol requirements
* Inferring @objc from an overridden method
2020-09-08 10:15:24 -07:00
Nathan Hawes
9da1d89520 Manually merge remote-tracking branch 'upstream/master' into HEAD
Conflicts:
	lib/AST/ExtInfo.cpp
2020-08-31 10:50:54 -07:00
Doug Gregor
1e5d30f5ca [Concurrency] Import Objective-C methods with completion handlers as async
When a given Objective-C method has a completion handler parameter
with an appropriate signature, import that Objective-C method as
async. For example, consider the following CloudKit API:

    - (void)fetchShareParticipantWithUserRecordID:(CKRecordID
*)userRecordID
            completionHandler:(void (^)(CKShareParticipant * _Nullable shareParticipant, NSError * _Nullable error))completionHandler;

With the experimental concurrency model, this would import as:

    func fetchShareParticipant(withUserRecordID userRecordID: CKRecord.ID) async throws -> CKShare.Participant?

The compiler will be responsible for turning the caller's continuation
into a block to pass along to the completion handler. When the error
parameter of the completion handler is non-null, the async call
will result in that error being thrown. Otherwise, the other arguments
passed to that completion handler will be returned as the result of
the async call.

async versions of methods are imported alongside their
completion-handler versions, to maintain source compatibility with
existing code that provides a completion handler.

Note that this only covers the Clang importer portion of this task.
2020-08-27 21:30:13 -07:00
swift_jenkins
b1cc1ae5ae Merge remote-tracking branch 'origin/master' into master-rebranch 2020-08-18 18:26:20 -07:00
Anthony Latsis
efa8f86193 [NFC] FuncDecl: Strip factory constructors out of TypeLocs 2020-08-19 00:09:10 +03:00
Anthony Latsis
492156c10f Remove SubscriptDecl::getBodyResultTypeLoc 2020-08-19 00:09:10 +03:00