Commit Graph

1876 Commits

Author SHA1 Message Date
Egor Zhdan
418c86df66 Merge pull request #77367 from swiftlang/egorzhdan/irgen-base-subobject
[cxx-interop] Fix IRGen for C++ types that use tail padding of their bases
2024-11-06 22:41:43 +00:00
Gábor Horváth
72f49bdf1b Merge pull request #77342 from swiftlang/gaborh/import-as-unsafe-for-real
[cxx-interop] Import some C++ methods as Unsafe
2024-11-06 12:40:14 +00:00
Egor Zhdan
d3e43bbe7b [cxx-interop] Fix IRGen for C++ types that use tail padding of their bases
In C++, a field of a derived class might be placed into the tail padding of a base class. Swift was not handling this case correctly, causing an asserts-disabled compiler to run out of RAM, and an asserts-enabled compiler to fail with an assertion.

Fixes this IRGen assertion:
```
Assertion failed: (offset >= NextOffset && "adding fields out of order"), function addField, file GenStruct.cpp, line 1509.
```

rdar://138764929
2024-11-04 13:44:43 +00:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Gabor Horvath
6d24c52b80 [cxx-interop] Use the locations imported from C++
A recent PR (#77204) started to import C++ source locations into Swift.
This PR flips a switch so these locations are actually used more widely.
Now some of the diagnostic locations are changed, but they generally
improved the quality of the diagnostics, pointing out conformances
imported from Obj-C code right when they are declared.
2024-11-01 13:49:09 +00:00
Gabor Horvath
d885dec4e8 [cxx-interop] Import some C++ methods as Unsafe
ClangImporter already had some logic in place to rename certain unsafe
C++ methods to make sure their name indicates unsafety. With the recent
push for auditability, we have a new @unsafe attribute so we can
automate parts of the auditing process. This patch makes sure whenever
we rename a method as "Unsafe", we also add the @unsafe attribute.
2024-11-01 13:03:59 +00:00
fahadnayyar
f430088616 Merge pull request #76798 from fahadnayyar/frt-return-unannotated-warning
[cxx-interop] Warning unannotated C++ APIs returning SWIFT_SHARED_REF…
2024-10-31 17:40:12 -07:00
Akira Hatanaka
f73c2e51bd Revert "[SILGen] Fix the type of closure thunks that are passed const reference structs (#76903)" (#77309)
This reverts commit 9c44b79189.

The commit caused swift's deserialization code to crash.

rdar://138726860
2024-10-31 15:16:00 -07:00
Egor Zhdan
5a5b1ef7ff Merge pull request #77298 from swiftlang/egorzhdan/class-template-array-param
[cxx-interop] Disambiguate template instantiations with array type parameters
2024-10-31 17:17:58 +00:00
Egor Zhdan
aa6804a30e [cxx-interop] Disambiguate template instantiations with array type parameters
When Swift imports C++ template class instantiations, it generates a human-readable Swift name for each instantiation.

Having name collisions causes multiple Swift type with the same name, which confuses the compiler.

`MyClass<int[]>` and `MyClass<long[]>` were both being imported as `MyClass<_>` into Swift. This patch fixes that:

* `MyClass<int[]>` is now imported as `MyClass<[CInt]>`
* `MyClass<int[123]>` is now imported as `MyClass<Vector<CInt, 123>>`

rdar://138921102
2024-10-30 17:05:14 +00:00
Gabor Horvath
17ef2f66fe [cxx-interop] Make SWIFT_RETURNS_INDEPENDENT_VALUE imply immortal lifetime
The semantics of returning independent value already matches what
immortal lifetimes are within Swift. This patch makes sure this
annotation works as expected with non-escapable types.

rdar://137671642
2024-10-30 15:35:33 +00:00
fahadnayyar
e640ed637d [cxx-interop] Warning unannotated C++ APIs returning SWIFT_SHARED_REFERENCE types 2024-10-29 17:31:15 -07:00
Egor Zhdan
ffb22d7287 Merge pull request #73297 from swiftlang/egorzhdan/correct-check-for-copy-ctor
[cxx-interop] Check the presence of copy constructor correctly
2024-10-29 17:22:49 +00:00
Ben Barham
45657fe1dc Merge pull request #77269 from bnbarham/fix-windows
[cxx-interop] Fix test on Windows after LLVM update
2024-10-29 19:07:08 +10:00
Ben Barham
8055b52f37 [cxx-interop] Fix test on Windows after LLVM update 2024-10-29 13:27:19 +10:00
Ben Barham
a8916a74b2 [Test] Add missing EOF newline 2024-10-29 09:38:09 +10:00
Egor Zhdan
fbbec48c76 [cxx-interop] Check the presence of copy constructor correctly
This removes a longstanding workaround in the import logic for C++ structs:
Swift assumed that if a C++ struct has no copy constructor that is explicitly deleted, then the struct is copyable. This is not actually correct. This replaces the workaround with a proper check for the presence of a C++ copy constructor.

rdar://136838485
2024-10-28 20:05:57 +00:00
Ben Barham
f59b2f19e6 Merge branch 'main' into 2024-rebranch-to-main 2024-10-28 13:03:35 -07:00
Hiroshi Yamauchi
3c501656a1 Merge pull request #76324 from hjyamauchi/issue74866
Fix the IR gen for C++ method calls and refactor around CGFunctionInfo
2024-10-28 12:07:36 -07:00
Egor Zhdan
c854fa2c7e Merge pull request #77190 from swiftlang/egorzhdan/std-string-view
[cxx-interop] Allow creating a String from `std::string_view`
2024-10-25 01:39:01 +01:00
Hiroshi Yamauchi
fcc1f6b65e Fix the IR gen for C++ method calls and refactor around CGFunctionInfo
In GenCall, fix the IR gen for C++ method calls as under MSVC as the
calling conventions for free functions and C++ methods can be
different. This also fixes the missing inreg (on sret arguments)
issues on Windows ARM64. Also refactor to use CGFunctionInfo
returnInfo isSretAfterThis to detect when to reorder the sret and the
this arguments under MSVC.

In ClagImporter, don't drop the return type for the compound
assignment operators such as operator+= when the return value is a
reference so that the CGFunctionInfo will be correctly indicate an
indirect return for the compound assignment operators.
2024-10-24 15:40:21 -07:00
Egor Zhdan
cb486c6599 [cxx-interop] Allow creating a String from std::string_view
This adds overlay support for initializing a Swift String from C++ `std::string_view`, `std::u16string_view`, `std::u32string_view`.

rdar://138417835
2024-10-24 13:11:09 +01:00
swift-ci
2b5ffa0941 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-18 15:52:56 -07:00
Akira Hatanaka
a0b5e930b5 Disable use-std-function.swift on ubuntu-24.04 (#77101)
This fixes 9850a28ace, which was checking
for the wrong Ubuntu version.

rdar://138183421
2024-10-18 15:35:26 -07:00
swift-ci
ed4836f5b1 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-18 12:22:36 -07:00
Egor Zhdan
9c5519a74a Merge pull request #77098 from swiftlang/egorzhdan/chrono-linux-cxx23
[cxx-interop] Do not import `std::chrono::time_zone`
2024-10-18 20:52:02 +02:00
Egor Zhdan
c530d3c0db [cxx-interop] Do not import std::chrono::time_zone
This type is non-copyable and non-moveable despite having a defaulted move constructor. It cannot currently be expressed in Swift. Let's not try to import it into Swift.

rdar://138123064 / resolves https://github.com/swiftlang/swift/issues/76809
2024-10-18 15:25:50 +01:00
swift-ci
724fdbe9eb Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 16:28:22 -07:00
Akira Hatanaka
9850a28ace Disable use-std-function.swift on ubuntu-24.10 (#77002)
The test is failing because a templated constructor of std::function
with an rvalue-reference parameter is called, which isn't supported yet.

rdar://137637142
2024-10-17 16:21:25 -07:00
swift-ci
848b66dca6 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 12:15:00 -07:00
Gábor Horváth
c76f894c19 Merge pull request #77073 from swiftlang/gaborh/lifetimebound-add-diagnostics
[cxx-interop] Diagnose misuses of escapability and lifetimebound
2024-10-17 20:04:08 +01:00
swift-ci
941b45bf79 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 09:34:41 -07:00
Egor Zhdan
07c4a8fe57 Merge pull request #77071 from swiftlang/egorzhdan/explicit-operator-bool
[cxx-interop] Add test for `explicit operator bool`
2024-10-17 18:23:20 +02:00
swift-ci
1df3ffb7cb Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 09:12:58 -07:00
Gabor Horvath
e86cf185e2 [cxx-interop] Diagnose misuses of escapability and lifetimebound
When a type is explicitly annotated as escapable or non-escapable it has
requirements about the lifetime annotations. This patch introduces
diagnostics to detect that.
2024-10-17 15:35:55 +01:00
Egor Zhdan
c2cfd7500a [cxx-interop] Add test for explicit operator bool
rdar://137879510
2024-10-17 13:51:58 +01:00
Egor Zhdan
e645800edf [cxx-interop] Add test for iterator conformances with nested typedefs
Follow-up to 34f6cd3f.
2024-10-17 13:25:42 +01:00
swift-ci
f70c740512 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 04:56:35 -07:00
Egor Zhdan
04d055ad5a Merge pull request #77049 from swiftlang/egorzhdan/cxx-contiguous-fix
[cxx-interop] Conform to `UnsafeCxxContiguousIterator` based on `iterator_concept` nested type
2024-10-17 13:50:24 +02:00
swift-ci
f8ea214244 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-16 13:54:13 -07:00
John Hui
493d37e776 [cxx-interop] Fix hashable-enums test (#77053)
The hash of enum values are different from that of their underlying
rawValue due to the implementation details of Int on 64-bit platform
which are not true on 32-bit platforms. This commit removes the tests
that rely on this behavior.

rdar://138032645
2024-10-16 13:52:38 -07:00
Egor Zhdan
34f6cd3f1a [cxx-interop] Conform to UnsafeCxxContiguousIterator based on iterator_concept nested type
3a200dee has a logic bug where we tried to conform C++ iterator types to `UnsafeCxxContiguousIterator` protocol based on their nested type called `iterator_category`. The C++20 standard says we should rely on `iterator_concept` instead.

https://en.cppreference.com/w/cpp/iterator/iterator_tags#Iterator_concept

Despite what the name suggests, we are not actually using C++ concepts in this change.

rdar://137877849
2024-10-16 19:47:46 +01:00
swift-ci
b4107795e1 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-16 04:15:19 -07:00
Gábor Horváth
e4d625cbec Merge pull request #76696 from swiftlang/gaborh/lifetimebound-on-ctors
[cxx-interop] Add test for lifetimebound annotation in ctor
2024-10-16 11:57:26 +01:00
swift-ci
8956a19bd8 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-15 20:34:48 -07:00
John Hui
b58a908082 [cxx-interop] Add Hashable conformance to imported enums (#76940)
* [cxx-interop] Add Hashable conformance to imported enums

Previously, imported enums only conformed to RawRepresentable and Equatable,
so they could not be used as members of a Set or keys of a Dictionary.
This patch adds Hashable conformance to give them that ability,
as well as some test cases to clarify the expected behavior.
Existing test cases are updated to reflect this new conformance.

rdar://129713687
2024-10-15 20:24:35 -07:00
swift-ci
4ac1f2887f Merge remote-tracking branch 'origin/main' into rebranch 2024-10-15 10:16:56 -07:00
Gabor Horvath
9551e9d9ca [cxx-interop] Add test for lifetimebound annotation in ctor
There was also an off by one error in this case.
2024-10-15 16:29:31 +01:00
Egor Zhdan
3a200deee9 [cxx-interop] Add UnsafeCxxContiguousIterator & UnsafeCxxMutableContiguousIterator protocols
This adds a pair of Swift protocols that represents C++ iterator types conforming to `std::contiguous_iterator_tag` requirements. These are random access iterators that guarantee that the values are stored in consequent memory addresses.

This will be used to optimize usage of C++ containers such as `std::vector` from Swift, for instance, by providing an overload of `withContiguousStorageIfAvailable` for contiguous containers.

rdar://137877849
2024-10-15 14:30:09 +01:00
swift-ci
338452e5d0 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-14 04:35:42 -07:00