Commit Graph

2428 Commits

Author SHA1 Message Date
Joe Groff
deab4cbf21 Merge pull request #62183 from ellishg/objc-direct-constructor
Allow Swift to call objc_direct constructors
2022-12-08 15:13:21 -08:00
zoecarver
1a0e1adee1 [cxx-interop] Don't synthesize conformance to invalid protocols. 2022-12-06 14:25:37 -08:00
zoecarver
665d3e1db4 [cxx-interop] Add diagnostics for explicit protocol conformance on the C++ side. 2022-12-02 10:04:48 -08:00
zoecarver
5eb7c7a6cf [cxx-interop] Add ability to specify protocol conformance on C++ side. 2022-11-30 17:26:15 -07:00
Egor Zhdan
cef0158a15 Merge pull request #62190 from apple/egorzhdan/clang-elaborated
[cxx-interop][rebranch] Handle clang elaborated types properly
2022-11-28 21:11:46 +00:00
Egor Zhdan
8d98f50a81 [cxx-interop][rebranch] Handle clang elaborated types properly
Clang recently started wrapping more types in `clang::ElaboratedType` after this change: https://reviews.llvm.org/D112374

This broke some assumptions in ClangImporter, specifically in enum handling logic. This change adjusts those.

Fixes these tests in rebranch:
* `Interop/Cxx/enum/anonymous-with-swift-name-module-interface.swift`
* `Interop/Cxx/enum/anonymous-with-swift-name-objc-module-interface.swift`
* `Interop/Cxx/enum/anonymous-with-swift-name.swift`
* `Interop/Cxx/enum/c-enums-NS_OPTIONS-NS_REFINED_FOR_SWIFT.swift`
* `Interop/Cxx/enum/c-enums-NS_OPTIONS.swift`
* `Interop/Cxx/enum/c-enums-withOptions-omit.swift`
* `Interop/Cxx/class/inheritance/fields-module-interface.swift`
* `Interop/Cxx/class/inheritance/fields.swift`
* `Interop/Cxx/class/inheritance/functions-module-interface.swift`
* `Interop/Cxx/class/inheritance/sub-types-module-interface.swift`
* `Interop/Cxx/class/inheritance/type-aliases-module-interface.swift`
2022-11-22 13:51:23 +00:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Ellis Hoag
693a049fe4 Allow Swift to call objc_direct constructors 2022-11-17 17:05:45 -08:00
Alex Lorenz
0312e0613d [interop][SwiftToCxxToSwift] hide reverse interop module namespaces from forward interop 2022-11-07 15:52:04 -08:00
zoecarver
bf652b6f31 Put C foreign refernece types behind a flag. 2022-11-02 17:08:31 -07:00
Doug Gregor
0cb2746c49 Keep track of source files created for macro expansions and such.
Introduce a new source file kind to describe source files for macro
expansions, and include the macro expression that they expand. This
establishes a "parent" relationship

Also track every kind of auxiliary source file---whether for macro
expansions or other reasons---that is introduced into a module, adding
an operation that allows us to find the source file that contains a
given source location.
2022-11-01 08:03:26 -07:00
Zoe Carver
777eafc0da Merge pull request #61752 from zoecarver/enable-frt-no-cxx-interop
Support foreign reference types when C++ interop is disabled.
2022-10-26 20:51:30 -07:00
zoecarver
dc581b9d58 Support foreign reference types when C++ interop is disabled. 2022-10-26 14:50:09 -07:00
zoecarver
b4abb47a65 [cxx-interop] Mark un-specialized class templates as unavailable in Swift.
They don't really work, so let's not "support" them yet.
2022-10-19 17:50:53 -07:00
Zoe Carver
4603c84f04 Merge pull request #61181 from zoecarver/lookup-operator
[cxx-interop] Fix friend operators that come from class template specializations.
2022-10-17 09:00:06 -07:00
zoecarver
492f2aaff2 [cxx-interop] Fix friend operators that come from class template specializations. 2022-10-14 13:33:06 -07:00
Hamish Knight
48ea933804 Parse an ellipsis T... for type parameter packs
In a generic parameter list, parse an ellipsis
to produce a type parameter pack. This replaces
the previous `@_typeSequence` attribute.
2022-10-14 15:40:12 +01:00
Hamish Knight
b645e63ce5 [AST] NFC: Refactor GenericTypeParamDecl construction
Add distinct overloads for the parser,
deserialization and code synthesis.
2022-10-14 15:40:12 +01:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Saleem Abdulrasool
979fa49da1 ClangImporter: simplify logic for mutability attribute
Take the spellings for the attributes as parameters for the diagnostics
to allow us to reference the ignored the attribute properly.  Use direct
pointer checks instead of an unnecessary `llvm::Optional` around a
nullable pointer.  Use `llvm::StringRef` to simplify the comparison.
This avoids re-spelling the attribute parameters which have already been
checked by `isMutabilityAttr` for the contradiction.
2022-10-07 16:40:47 -07:00
Slava Pestov
92f1361b82 Merge pull request #61429 from LucianoPAlmeida/opaque-parameters-crash
[AST] Move generic parameter logic for accessor decl from parser to GenericParamListRequest
2022-10-07 16:52:24 -04:00
Luciano Almeida
a95f60e387 [AST] Refactor generic parameter list parse logic for AccessorDecl 2022-10-07 09:43:08 -03:00
Egor Zhdan
e28605c0c9 [cxx-interop] Allow using std::map subscript
This fixes an error that occurred when trying to use the subscript on an instance `std::map`:
```
error: cannot assign through subscript: 'map' is immutable
```
This was happening even with a mutable `std::map` instance.

`std::map::operator[]` has two overloads:
* `T& operator[]( const Key& key )`
* `T& operator[]( Key&& key )`

The second one is imported with an `inout` parameter, and we picked it as an implementation of the subscript getter because it was the last of the two overloads to get imported.

Swift does not allow subscripts with `inout` parameters. This is checked at the AST level, and those checks do not run for synthesized Swift code. This caused Swift to produce a surprising error which actually indicated that the argument of the subscript, not the instance itself, must be mutable.

rdar://100529571
2022-10-03 11:18:56 +01:00
Anthony Latsis
18156d1177 Merge pull request #61347 from AnthonyLatsis/migrate-compiler-to-gh-issues
Gardening: Migrate compiler sources to GitHub issues
2022-09-30 10:48:52 +03:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Egor Zhdan
16ce2f995a [cxx-interop] Do not synthesize successor() for foreign reference types
Follow-up after `e58e2497`.

rdar://100050151
2022-09-21 12:28:40 +01:00
Egor Zhdan
e58e249788 [cxx-interop] Do not synthesize successor() for immortal types
Our current implementation of `func successor() -> MyType` relies on the ability to create a new instance of the type. For immortal foreign reference types, this wouldn't be reasonable to do.

rdar://100050151
2022-09-20 17:00:05 +01:00
zoecarver
f0d5cb9a84 [cxx-interop] Lazily instanciate var types and compute their type. 2022-09-09 17:26:22 -07:00
Slava Pestov
82bd81e127 ClangImporter: Stop calling getAllConformances() on protocols 2022-08-23 00:03:36 -04:00
Egor Zhdan
e3a321721d [cxx-interop] Synthesize conformances to CxxSequence
This makes ClangImporter automatically conform C++ sequence types to `Cxx.CxxSequence` protocol.

We consider a C++ type to be a sequence type if it defines `begin()` & `end()` methods that return iterators of the same type which conforms to `UnsafeCxxInputIterator`.
2022-08-17 16:06:37 +01:00
Zoe Carver
f018901a20 Merge pull request #60553 from zoecarver/enum-fix-for-computed-props
[cxx-interop] Fix anonymous enum issue for swift-named computed prope…
2022-08-14 20:53:12 -07:00
zoecarver
aaec49e0a5 [cxx-interop] Fix anonymous enum issue for swift-named computed properties. 2022-08-14 15:45:39 -07:00
Hamish Knight
6b9bcf3935 [AST] Change DotSyntaxCallExpr to take an Argument base
This allows us to more easily propagate inout
information to it, which will become a necessity
once InOutExpr is removed.
2022-08-08 15:11:00 +01:00
Ehud Adler
379fc1f0a4 [cxx-interop] Fix issue where multiple records in a module containing the same meth… (#60338) 2022-08-02 09:01:56 -04:00
Egor Zhdan
44f3478289 [cxx-interop] Do not try to import uninstantiatable templates
Calling `clangSema.isCompleteType` tries to instantiate a template, and if that is impossible, returns `true`. This caused Swift to try to import invalid C++ template instantiations.

This was discovered during C++ interop adoption in SwiftCompilerSources:
Several LLVM headers declare a field with a type `DenseMap<int, ForwardDeclared>` where `ForwardDeclared` is defined in an implementation file (`.cpp`) and is not visible to ClangImporter. That is valid in C++ but caused an error when importing into Swift.
2022-07-27 23:12:32 +01:00
Egor Zhdan
160b332403 Merge pull request #60262 from apple/egorzhdan/cxx-namespace-perf
[cxx-interop] Improve performance of importing C++ namespaces
2022-07-27 23:08:46 +01:00
Egor Zhdan
fbb3762c4f [cxx-interop] Improve performance of importing C++ namespaces
When ClangImporter calls Clang to import a module, Clang calls `SwiftLookupTableWriter::writeExtensionContents` for each namespace redecl, which called `addEntryToLookupTable` (a few frames omitted) which iterated over all of the namespace redecls, doing duplicate work. This caused the complexity to degrade from linear to quadratic.

`SwiftDeclConverter::VisitNamespaceDecl` is still called once per namespace, not per redecl, so we need to iterate over all the redecls there.

This dramatically improves the build time for SwiftCompilerSources when importing Clang headers in addition to LLVM headers.
2022-07-27 20:24:52 +01:00
Egor Zhdan
29b579e9d3 [cxx-interop] Do not crash when diagnosing cycles for C++ operators
C++ operator functions are `NamedDecl`s, but they don't have a trivial name, and calling `getName` results in an assertion failure.

This was discovered during C++ interop adoption in SwiftCompilerSources.

```
Assertion failed: (Name.isIdentifier() && "Name is not a simple identifier"), function getName, file Decl.h, line 277.
...
/Volumes/Projects/swift/llvm-project/clang/include/clang/AST/DependentDiagnostic.h:150:8: importing 'clang::DeclContext::ddiag_iterator::operator=='
```
2022-07-27 11:42:09 +01:00
Zoe Carver
bd003bcd7f Merge pull request #59509 from zoecarver/frt-with-ref-counting
[cxx-interop] Add support for reference counting operations on foreign reference types.
2022-07-23 20:51:39 -07:00
zoecarver
13b0a5bc37 [nfc] Clang format changes. 2022-07-21 17:34:36 -04:00
Zoe Carver
9a660e1139 Merge pull request #60180 from zoecarver/locations-for-lazy-errors
[cxx-interop] Add source locations to diagnostics for un-importable APIs.
2022-07-21 17:31:11 -04:00
Ehud Adler
0f83b65f9b [cxx-interop] Remove impl for constexpr members (#60154)
* Remove impl for constexpr members

* Readd some tets

* Only remove import of static constexpr
2022-07-21 15:41:17 -04:00
zoecarver
446b2c38ab [cxx-interop] Add source locations to diagnostics for un-importable APIs. 2022-07-21 14:59:27 -04:00
zoecarver
74d76e2888 [cxx-interop] Add diagnostics and validation for retain/release function; require all foreign reference types to provide retain release functions or be immortal. 2022-07-21 12:25:21 -04:00
zoecarver
ee2a7eeeda [nfc][cxx-interop] Add diagnostics for invalid custom reference counting operations. 2022-07-21 10:25:57 -04:00
Egor Zhdan
d85d2e9e75 [cxx-interop] Synthesize conformances to UnsafeCxxInputIterator
This teaches ClangImporter to synthesize conformances of C++ iterator types to `UnsafeCxxInputIterator` protocol from the `Cxx` module.

We consider a C++ type to be an iterator if it defines a subtype (usually a typedef or a using decl) called `iterator_category` that inherits from `std::input_iterator_tag`.

rdar://96235368
2022-07-20 11:44:25 +01:00
zoecarver
3498ff9765 [cxx-interop] Remove UnsafeLifetimeOperation record semantic kind.
This makes "owned" the default kind for records that have custom copy constructors and no pointer-members.
2022-07-18 17:15:15 -04:00
zoecarver
ca5fa9aa9b [nfc] Clang format changes. 2022-07-18 17:15:15 -04:00
zoecarver
9d1d03124b [nfc][cxx-interop] Add diagnostics when something cannot be imported. 2022-07-18 17:15:15 -04:00
zoecarver
6acffbbee6 [cxx-interop] Flip the switch: only import safe APIs. 2022-07-18 17:15:15 -04:00