Commit Graph

145 Commits

Author SHA1 Message Date
zoecarver
f652361af3 [cxx-interop] Remove 'support' for importing C++ operators.
This does not include subscript operators.

Before this is re-enabled operators need to be re-implemented. Right now they are the source of a lot of bugs. They cause frequent crashes and mis compiles. Also, templated operators insert a lot of names into global lookup which causes problems.

They also don't work on Windows.
2022-03-30 15:39:35 -07:00
Alex
78a410c19e [cxx-interop] Add support for operator! overloading (#41434)
This patch enables operator overloading for operator! when cxx interop is enabled.
2022-03-14 09:55:03 -07:00
Ehud Adler
0056129d57 [cxx-interop] std::string::push_back is broken (#41240)
* [cxx-interop] fix  std::string::push_back by fixing mapping between clang/swift self/this type for cxx methods

* cleanup

* Fix unit test

* XFail test: operators/member-inline on linux-android

* add `C++` in expandExternalSignatureTypes comment

* Fix rebase

* Fix mapping issue in externalizeArguments

* Improve cxx_interop_ir test regex
2022-03-08 13:09:38 -05:00
zoecarver
2e0398f867 [cxx-interop] Add support for subscripts in base classes. 2022-03-01 15:13:10 -08:00
Saleem Abdulrasool
0d95706f74 test: partially enable some C++ interop tests on Windows
This enables the majority of the operator tests on Windows as these now
pass.  However, we cannot enable all of the tests, a few of them crash
due to invalid parameter ordering due to bugs in IRGen with C++ interop.
2022-01-17 08:56:51 -08:00
Saleem Abdulrasool
cb9120d060 tests: enable a couple of C++ interop tests on Windows
These should pass on Windows now, so enable them on the test suite to
prevent regressions in the future.
2022-01-16 20:54:30 -08:00
zoecarver
036361d1e4 [cxx-interop] Add SIL function representation cxx_method; Support extending C++ types.
There are three major changes here:
    1. The addition of "SILFunctionTypeRepresentation::CXXMethod".
    2. C++ methods are imported with their members *last*. Then the arguments are switched when emitting the IR for an application of the function.
    3. Clang decls are now marked as foreign witnesses.

These are all steps towards being able to have C++ protocol conformance.
2022-01-06 14:26:47 -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
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
swift-ci
886daca467 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-08 11:14:46 -07:00
Egor Zhdan
b506057fc7 C++ Interop: import caret operators
This change makes it possible to call `operator^` from Swift. It works exactly the same way as all the other arithmetic operators.
2021-09-04 16:26:15 +03:00
Arnold Schwaighofer
ee6441c4d2 Fix test/Interop/Cxx 2021-08-05 12:15:23 -07:00
Egor Zhdan
a8f126f7cd C++ Interop: import const methods as non-mutating
This change makes ClangImporter import some C++ member functions as non-mutating, given that they satisfy two requirements:
* the function itself is marked as `const`
* the parent struct doesn't contain any `mutable` members

`get` accessors of subscript operators are now also imported as non-mutating if the C++ `operator[]` satisfies the requirements above.

Fixes SR-12795.
2021-07-25 15:18:33 +03:00
Egor Zhdan
682f162f48 C++ Interop: fix subscript operator tests
C++ structs that define a non-default copy constructor should actually copy their members in the copy constructor:
Swift might copy the struct around, and if it does so after the `setValueAtIndex` call, the modification of `NonTrivialIntArrayByVal::values` won't propagate to the copied struct and these tests no longer pass:
• `Interop/Cxx/operators/member-inline.swift`
• `Interop/Cxx/operators/member-out-of-line.swift`

The tests are currently passing on the main branch despite this, but they might fail after a seemingly unrelated change (which is how I discovered this).
2021-07-12 22:22:27 +03:00
John McCall
34d4ea6b3c Fix test member-inline-silgen.swift for the stripping of [serializable] 2021-04-09 01:38:06 -04:00
Saleem Abdulrasool
68ff55a07e Merge pull request #36688 from plotfi/cxx-operator-subscript
[cxx-interop] Implement operator[] for value return types (SR-14351).
2021-04-08 19:11:27 -07:00
Slava Pestov
1e8ce52736 SIL: Strip [serialized] flag from functions even at -Onone
While the comment is correct to state that this won't enable any
new optimizations with -Onone, it does enable IRGen's lazy
function emission, which is important for 'reasync' functions,
which we don't want to emit at all even at -Onone.

This fixes debug stdlib builds with the new reasync versions
of the &&, || and ?? operators.
2021-04-08 01:47:27 -04:00
Puyan Lotfi
864b3a47e3 [cxx-interop] Implement operator[] for value return types (SR-14351).
This builds on top of the work of Egor Zhdan. It implements
`T operator[]` and does so largely by taking a path very much like the
`const T &operator[]` path.
2021-04-08 00:18:27 -04:00
Egor Zhdan
586c675286 C++ Interop: import subscript operators
This change adds support for calling `operator[]` from Swift code via a synthesized Swift subscript.

Fixes SR-12598.
2021-03-21 19:25:41 +03:00
Egor Zhdan
7141ae24cf C++ Interop: import call operators
This change adds support for calling `operator()` from Swift code.

As the C++ interop manifesto describes, `operator()` is imported into Swift as `callAsFunction`.
2021-03-02 21:13:57 +03:00
Egor Zhdan
6d5eba92b9 C++ Interop: cleanup operator tests (NFC) 2021-02-25 01:16:49 +03:00
Arnold Schwaighofer
8242ae7458 [rebranch] Fix test/Interop/Cxx/operators tests
rdar://73591415
2021-01-26 07:48:18 -08:00
Nate Chandler
20db2c0981 Merge branch 'main' into rebranch
Conflicts:
	include/swift/Basic/AnyValue.h
2021-01-12 16:30:02 -08:00
Saleem Abdulrasool
9ba7bf78db Interop: use new target-clangxx for building C++ code
This enables control over the C++ flags used during testing for the C++
interop from a single location rather than having to alter all the
tests.
2021-01-12 08:29:24 -08:00
Saleem Abdulrasool
f5a08e45bc Interop: restore -std=c++11 for a few tests
Restore the explicit C++ standard for these tests as the C++ compiler
invocation on Darwin uses the system compiler rather than the just built
clang, which may be sufficiently different to have different default
standards.

This will be cleaned up with the next change to introduce a new
`%target-clangxx` to control the C++ standard.
2021-01-11 11:01:44 -08:00
Saleem Abdulrasool
21732c9551 Interop: remove unnecessary C++ standard
Do not override the C++ standard explicitly when running the tests.
This will eventually be useful in allowing tests to run against
different C++ standards.
2021-01-11 08:57:56 -08:00
zoecarver
549189bee6 [cxx-interop] Add "nonnull" and "dereferenceable(n)" attributes to constructor params.
This reflects a change in Clang 13's codegen. Test-only fix for swift/rebranch.
2021-01-07 15:00:34 -08:00
Saleem Abdulrasool
df9d1e815f Interop/Cxx: explicitly require C++ for modules
The C++ interop modules require C++ support.  Explicitly require C++ as
a feature when building these modules.  This has no impact on the
changes as all the tests enable C++ already.
2021-01-06 16:59:42 -08:00
Zoe Carver
1f71144183 [cxx-interop] Don't crash for unkown inline-operator. (#34602)
Skip unkown or unimportable inline operators (such as deleted operator members) instead of crashing.
2020-11-06 17:13:59 -08:00
Zoe Carver
be2f85c102 [cxx-interop] [NFC] Rename MemberInline.IntBox -> LoadableIntWrapper. (#33930) 2020-09-24 20:08:19 -07:00
zoecarver
d647794ac0 [cxx-interop] Replace inline member "operator+" with "operator-".
Adding integers is a commutative operation meaning the old tests would
fail to detect an error if the arguments were passed in the wrong order.
Testing inline member operators using subtraction ensures that arguments
are passed in the correct order.
2020-09-08 21:09:43 -07:00
Michael Forster
d530e36236 Add tests for C++ out-of-line member operators (#32718) 2020-07-07 19:26:23 +02:00
Michael Forster
a443327efe Add bug reference to XFAIL operator tests 2020-07-03 11:16:06 +02:00
Michael Forster
26358c4588 Import member operator functions as static members (#32293)
This adds support to `ClangImporter` to import C++ member function operators as static methods into Swift, which is part of SR-12748.

The left-hand-side operand, which gets passed as the `this` pointer to the C++ function is represented as an additional first parameter in the Swift method. It gets mapped back in SILGen.

Two of the tests are disabled on Windows because we can't yet call member functions correctly on Windows (SR-13129).
2020-07-03 11:06:22 +02:00
zoecarver
3a23e086d2 [cxx-interop] Re-order operators.
Re-order operator case statements and tests. The order now follows the order defined in `llvm-project/clang/include/clang/Basic/OperatorKinds.def`.

Also, adds operator character(s) in parentheses.
2020-06-17 15:54:09 -07:00
zoecarver
d411f92cdd [cxx-interop] Add support for C++ comparison operators.
Adds support for C++ operators: `<`, `>`, `==`, `!=`, `<=`, and `>=`.
2020-06-17 15:54:09 -07:00
Zoe Carver
71d2c37828 [cxx-interop] Add support for percent, ampersand, and pipe operators. (#32332)
Adds support for three more basic infix operators: `%`, `&`, and `|`.

Co-authored-by: Michael Forster <forster@google.com>
2020-06-12 12:30:33 -07:00
Zoe Carver
1e52852cca [cxx-interop] Add support for C++ shift operators. (#32333)
* [cxx-interop] Add support for C++ shift operators.

Support imported C++ `<<` and `>>` operators in Swift.

* Update test names of existing operators

... to match the new ones.

Co-authored-by: Michael Forster <forster@google.com>
2020-06-12 08:40:25 -07:00
zoecarver
d4431c4883 [cxx-interop] Add support for C++ logical and/or operators.
Support imported C++ `&&` and `||` operators in Swift.
2020-06-11 17:08:12 -07:00
Michael Forster
0838a65e0d Test C++ out-of-line operator functions
Add a test to verify that C++ out-of-line operator functions are imported correctly.
Includes fixes for armv7 and arm64.

This is part of addressing SR-12748.
2020-06-05 12:32:23 +02:00
Michael Forster
e5e34fa3c9 Revert "Test C++ out-of-line operator functions (#32081)" (#32181)
This reverts commit f7473a7432.
2020-06-04 19:10:04 +02:00
Michael Forster
f7473a7432 Test C++ out-of-line operator functions (#32081)
Add tests to verify that C++ out-of-line operator functions are
imported correctly.
2020-06-03 10:37:27 +02:00
Michael Forster
c98c862e7e Start implementing C++ operator interop (#32015)
This imports the four basic arithmetic operators `+`, `-`, `*`, `/`
declared as inline non-member functions.

More to come.
2020-05-28 17:31:36 +02:00