Commit Graph

6196 Commits

Author SHA1 Message Date
Egor Zhdan
81c7fb015a [cxx-interop] Ensure that C++ structs are fully defined
Swift should never try to import C++ structs that are not fully defined. This is because Clang can't synthesize implicit members of such types, which might be necessary for Swift, e.g. a copy constructor.

This adds an assertion that makes sure that C++ structs are considered to be fully defined by Clang. This condition should already be satisfied.
2024-10-28 12:54:13 +00: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
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
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
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
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
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
Egor Zhdan
844d103f0d Merge pull request #77006 from swiftlang/egorzhdan/cxx-contiguous
[cxx-interop] Add `UnsafeCxxContiguousIterator` & `UnsafeCxxMutableContiguousIterator` protocols
2024-10-15 19:01:15 +02: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
fa5fc7948e Merge remote-tracking branch 'origin/main' into rebranch 2024-10-14 21:45:47 -07:00
Allan Shortlidge
7819dd7833 AST/Sema: Remove unnecessary ASTContext parameters from availability APIs.
Many of the methods on `AvailabilityInference` take both a `Decl` and an
`ASTContext`, which is redundant.
2024-10-14 17:46:53 -07:00
swift-ci
72676c2c4a Merge remote-tracking branch 'origin/main' into rebranch 2024-10-08 15:43:57 -07:00
Doug Gregor
f53670be08 Move _SWIFT_ATTR_SUPPORTS_MACROS to the right place 2024-10-08 11:25:46 -07:00
Doug Gregor
688dd234b4 Define __SWIFT_ATTR_SUPPORTS_MACROS when the MacrosOnImports features is available 2024-10-08 11:12:55 -07:00
Doug Gregor
ead028bb11 Support applying macros to imported-as-member declarations 2024-10-08 11:12:53 -07:00
Doug Gregor
cdcabd05bd Allow attached macros to be applied to imported C declarations
The Clang importer maps arbitrary attributes spelled with `swift_attr("...")`
over to Swift attributes, using the Swift parser to process those attributes.
Extend this mechanism to allow `swift_attr` to refer to an attached macro,
expanding that macro as needed.

When a macro is applied to an imported declaration, that declaration is
pretty-printed (from the C++ AST) to provide to the macro implementation.
There are a few games we need to place to resolve the macro, and a few more
to lazily perform pretty-printing and adjust source locations to get the
right information to the macro, but this demonstrates that we could
take this path.

As an example, we use this mechanism to add an `async` version of a C
function that delivers its result via completion handler, using the
`@AddAsync` example macro implementation from the swift-syntax
repository.
2024-10-08 11:12:50 -07:00
swift-ci
9fd863f81e Merge remote-tracking branch 'origin/main' into rebranch 2024-10-08 10:50:24 -07:00
Steven Wu
5fa12d31ae Merge pull request #76738 from cachemeifyoucan/eng/PR-136787368
[CAS] Use IncludeTreeFileList instead of full CASFS for caching
2024-10-08 10:42:24 -07:00
swift-ci
48648e95a7 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-07 04:14:40 -07:00
Egor Zhdan
168413ef61 Merge pull request #76823 from swiftlang/egorzhdan/msvc-bit-module
[cxx-interop] Modularize __msvc_bit_utils on Windows
2024-10-07 12:10:55 +01:00
Egor Zhdan
16e7cbeafa [cxx-interop] Modularize __msvc_bit_utils on Windows
`__msvc_bit_utils.hpp` was added in a recent version of MSVC, and it is causing build errors for SwiftCompilerSources:
```
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\numeric:598:12: error: function '_Select_countr_zero_impl<unsigned long long, (lambda at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\numeric:598:55)>' with deduced return type cannot be used before it is defined
    return _Select_countr_zero_impl<_Common_unsigned>([=](auto _Countr_zero_impl) {
```

This change references the `__msvc_bit_utils.hpp` header from the modulemap. Since we still need to support older versions of Visual Studio that do not provide `__msvc_bit_utils.hpp`, this also teaches ClangImporter to inject an empty header file named `__msvc_bit_utils.hpp` into the system include directory, unless it already exists.

rdar://137066642
2024-10-04 13:15:20 +01:00
Steven Wu
ab219d246e [ClangImporter] Update the error condition when delayed inputs are used
Return error only when no inputs are available, instead of relying on
checking no errors occured in diagnostics.
2024-10-03 11:23:16 -07:00
swift-ci
7a9a95d9f5 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-03 09:14:49 -07:00
Akira Hatanaka
90e4a98a46 [cxx-interop] Use the name of the typedef when an unnamed class is used as a template argument (#76844)
This fixes a bug where IRGen would try to use the same name for two
different protocol witness methods.

rdar://134149098
2024-10-03 08:58:29 -07:00
swift-ci
fa8b276b48 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-03 07:54:56 -07:00
Egor Zhdan
c874e6f84c Merge pull request #76119 from finagolfin/droid
[test] Check that the C/C++ module maps are looked for in `-resource-dir` before `-sdk`
2024-10-03 15:36:35 +01:00
swift-ci
cd956f3b28 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-03 04:53:49 -07:00
Egor Zhdan
9169d81bd5 Merge pull request #76830 from swiftlang/egorzhdan/cxx-set-array-literal
[cxx-interop] Conform `std::set` to `ExpressibleByArrayLiteral`
2024-10-03 12:44:07 +01:00
swift-ci
b8a5d2d6d7 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-03 01:35:42 -07:00
Konrad `ktoso` Malawski
dea3b59331 Merge pull request #76250 from ktoso/wip-experimental-isolated-deinit 2024-10-03 17:19:10 +09:00
Egor Zhdan
f37f42fc7e [cxx-interop] Conform std::set to ExpressibleByArrayLiteral
Swift's own `Set` conforms to `ExpressibleByArrayLiteral`. This change conforms instantiations of C++ `std::set` to `ExpressibleByArrayLiteral` as well.

This makes it possible to pass an array literal as an argument to a function that takes a `std::set` as parameter.

rdar://137126325
2024-10-02 19:27:51 +01:00
swift-ci
61d5b48a52 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-02 08:15:55 -07:00
Egor Zhdan
7f597c63ae Merge pull request #76726 from swiftlang/egorzhdan/char8_t
[cxx-interop] Support `char8_t` C++20 type
2024-10-02 16:10:17 +01:00
Steven Wu
8d2d92a96f [ClangImporter][CAS] Add delay init CAS inputs in clang importer
Handle the special clang instance usage in clang importer to make sure
the inputs from CAS are initialized before perform frontend actions.
2024-10-01 11:33:43 -07:00
swift-ci
c4877a5680 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-01 10:54:18 -07:00
Alastair Houghton
ac750a6aec Merge pull request #76545 from al45tair/eng/PR-115918181
[ClangImporter][ModuleWrap] Turn off libc warnings.
2024-10-01 18:46:06 +01:00
Steven Wu
cd07d532af [CAS] Use IncludeTreeFileList instead of full CASFS for caching
Use IncludeTreeFileList instead of full feature CASFS for swift
dependency filesystem. This allows smaller CAS based VFS that is smaller
and faster. This is enabled by the CAS enabled compilation does not
need to iterate file system.

rdar://136787368
2024-09-30 16:01:33 -07:00
Alastair Houghton
bace89ffbd [ClangImporter] Just turn off the warning, not the actual overlays.
We should still try adding the overlays, even if we're asked not to
generate a diagnostic while doing so.  That's slightly safer because
it means that we're less likely to find ourselves in a situation
where `swift-modulewrap` wants to use types from the C/C++ library
and can't.

rdar://115918181
2024-09-30 17:02:41 +01:00
Konrad `ktoso` Malawski
45b97f146b Merge branch 'main' into wip-experimental-isolated-deinit 2024-09-30 13:47:39 +09:00
swift-ci
21ca39540e Merge remote-tracking branch 'origin/main' into rebranch 2024-09-27 22:54:31 -07:00