Commit Graph

617 Commits

Author SHA1 Message Date
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
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
swift-ci
c49a0e84d3 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-09 10:44:16 -07:00
Meghana Gupta
4df55a12cd Merge pull request #76834 from meg-gupta/lifetimedepmultiple
Replace dependsOn with @lifetime
2024-10-09 10:17:43 -07:00
swift-ci
43530d6fb5 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-08 23:54:07 -07:00
Akira Hatanaka
9c44b79189 [SILGen] Fix the type of closure thunks that are passed const reference structs (#76903)
The thunk's parameter needs the @in_guaranteed convention if it's a
const reference parameter. However, that convention wasn't being used
because clang importer was removing the const reference from the
type and SILGen was computing the type of the parameter based on the
type without const reference.

This commit fixes the bug by passing the clang function type to
SILDeclRef so that it can be used to compute the correct thunk type.

This fixes a crash when a closure is passed to a C function taking a
pointer to a function that has a const reference struct parameter.

This recommits e074426 with fixes to
serialization/deserialization of function types. The fixes prevent clang
types of functions from being dropped during serialization.

rdar://131321096
2024-10-08 23:44:49 -07:00
Meghana Gupta
008431c3b4 Update some dependsOn tests to @lifetime 2024-10-08 15:12:13 -07:00
Meghana Gupta
f591680c2a Update SIL printing of @lifetime
Lifetime dependencies in SIL tests continue to be represented as a type modifier on the target.

As before, they are represented as a LifetimeDependentTypeRepr in the AST.
2024-10-08 15:10:59 -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
72619743bf Merge remote-tracking branch 'origin/main' into rebranch 2024-09-30 05:15:11 -07:00
Slava Pestov
9632979879 Revert "[SILGen] Fix the type of closure thunks that are passed const referen…"
This reverts commit e074426058.
2024-09-29 22:32:04 -04:00
swift-ci
327f62e576 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-27 07:15:47 -07:00
Akira Hatanaka
e074426058 [SILGen] Fix the type of closure thunks that are passed const reference structs (#75491)
The thunk's parameter needs the @in_guaranteed convention if it's a
const reference parameter. However, that convention wasn't being used
because clang importer was removing the const reference from the
type and SILGen was computing the type of the parameter based on the
type without const reference.

This commit fixes the bug by passing the clang function type to
SILDeclRef so that it can be used to compute the correct thunk type.

This fixes a crash when a closure is passed to a C function taking a
pointer to a function that has a const reference struct parameter.

rdar://131321096
2024-09-27 07:04:47 -07:00
swift-ci
59a7eb4710 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-27 06:15:16 -07:00
Gábor Horváth
89708dd15a Merge pull request #76673 from swiftlang/gaborh/structural-escapability
[cxx-interop] Add rules to recognize escapability of aggregates
2024-09-27 13:58:33 +01:00
swift-ci
0210aab197 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-25 07:55:15 -07:00
Gabor Horvath
f2911643f4 [cxx-interop] Reenable test
Additional errors were triggered due to missing availability attributes.

rdar://136620623
2024-09-25 11:38:18 +01:00
swift-ci
44e93b7140 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-24 14:54:56 -07:00
Pavel Yaskevich
f59ccb796b [Tests] NFC: Disable Interop/Cxx/class/safe-interop-mode.swift due to failures on iphonesimulator 2024-09-24 14:36:57 -07:00
swift-ci
6dc53cce15 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-24 11:14:58 -07:00
eeckstein
4285d8a87c Revert "[cxx-interop] Add test for lifetimebound annotation in ctor" 2024-09-24 20:00:37 +02:00
Gabor Horvath
cbd8cdfe95 [cxx-interop] Add rules to recognize escapability of aggregates
For now, this logic is used for importing fewer unannotated types as
unsafe. In the future, this logic will be used by escapability inference
for other (non-aggregate) types.
2024-09-24 16:41:00 +01:00
swift-ci
2bd533ccda Merge remote-tracking branch 'origin/main' into rebranch 2024-09-24 07:55:58 -07:00
Gábor Horváth
40529912a9 Merge pull request #76668 from swiftlang/gaborh/lifetimebound-off-by-one
[cxx-interop] Fix off-by-one error when importing lifetimebound attrs
2024-09-24 15:49:19 +01:00
Gábor Horváth
289a4f5e35 Merge pull request #76653 from swiftlang/gaborh/unsafe_reference
[cxx-interop] Import SWIFT_UNSAFE_REFERENCE types as @unsafe
2024-09-24 15:48:45 +01:00
Gabor Horvath
72ce39ce07 [cxx-interop] Fix off-by-one error when importing lifetimebound attrs 2024-09-24 12:01:26 +01:00
Gabor Horvath
e8aea32c95 [cxx-interop] Import SWIFT_UNSAFE_REFERENCE types as @unsafe 2024-09-23 16:51:01 +01:00
Gabor Horvath
8c3849b192 [cxx-interop] Add test for lifetimebound annotation in ctor
It looks like everything worked out of the box, no code changes
required. Added a test to avoid regressions.
2024-09-23 16:06:44 +01:00
swift-ci
df338c19a8 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-19 09:34:45 -07:00
Gabor Horvath
929c0ca7d8 [cxx-interop] Introduce a safe C++ interop mode
In this mode all C++ types are imported as unsafe by default. Users
explicitly marking types are escapable or not escapable can make them
imported as safe. In the future, we also want to import unannotated
functions as unsafe and add more logic to infer types that are actually
safe, like agregates of escapable types.
2024-09-19 12:34:07 +01:00
swift-ci
72a4f929b0 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-18 07:33:29 -07:00
Gábor Horváth
ffa1014c30 Merge pull request #76311 from swiftlang/gaborh/import-lifetimebound
[cxx-interop] Teach importer to interpret lifetimebound annotations
2024-09-18 15:24:32 +01:00
Gabor Horvath
16e012bb5e [cxx-interop] Teach importer to interpret lifetimebound annotations
The lifetimebound annotations are now imported as lifetime dependencies.
This works for basic cases but there are still some parts missing:
* Support lifeitmebound annotations on constructors
* A way to represent immortal/static lifetimes on the C++ side
2024-09-18 10:51:05 +01:00
Ben Barham
a7b50f357f Merge remote-tracking branch 'origin/main' into manual-main-merge
Conflicts:
  - `lib/Driver/ToolChains.cpp` conflicting with the `addAllArgs` rename
    for multiple options
2024-09-16 13:53:18 -07:00
Hiroshi Yamauchi
7633c00764 Merge pull request #76433 from hjyamauchi/issue74866-2
Ensure that BridgedTypeArray is indirectly returned
2024-09-16 11:46:29 -07:00
Hiroshi Yamauchi
f815e1429e Ensure that BridgedTypeArray is indirectly returned
On Windows ARM64, how a struct value type is returned is sensitive to
conditions including whether a user-defined constructor exists,
etc. See

https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?view=msvc-170#return-values

That caused a calling convention mismatch between the
non-USED_IN_CPP_SOURCE (Swift) side and the USE_IN_CPP_SOURCE (C++)
side and a crash.

Add this constructor so that the calling convention matches.

This is a fix for the OnoneSimplification crash in

https://github.com/swiftlang/swift/issues/74866#issuecomment-2319618579

and is a partial fix for

https://github.com/swiftlang/swift/issues/74866#issuecomment-2319618579
2024-09-12 10:46:55 -07:00
Akira Hatanaka
380f319371 Relax check strings (#76421)
rdar://135165028
2024-09-12 10:35:36 -07:00
Alex Lorenz
9bc2689ef1 [rebranch][cxx-interop] fix MSVC testcase check line for indirect return 2024-09-10 09:37:07 -07:00
Akira Hatanaka
7aaed1efea Pass --dump-input-filter=all to debug failing test (#76333) 2024-09-09 10:47:31 -07:00
swift-ci
93b400de6d Merge remote-tracking branch 'origin/main' into rebranch 2024-09-05 14:14:34 -07:00
Hiroshi Yamauchi
273f5fdc36 Merge pull request #76159 from hjyamauchi/issue74866
Add the inreg attribute to sreg when present.
2024-09-05 13:59:53 -07:00
Hiroshi Yamauchi
3f0de5787e Add the inreg attribute to sreg when present.
On Windows/AArch64, a different register is used between when an
arugment is both inreg and sret (X0 or X1) and when it is just sret
(X8) as the following comment indicates:

46fe36a429/llvm/lib/Target/AArch64/AArch64CallingConvention.td (L42)

```
  // In AAPCS, an SRet is passed in X8, not X0 like a normal pointer parameter.
  // However, on windows, in some circumstances, the SRet is passed in X0 or X1
  // instead.  The presence of the inreg attribute indicates that SRet is
  // passed in the alternative register (X0 or X1), not X8:
  // - X0 for non-instance methods.
  // - X1 for instance methods.

  // The "sret" attribute identifies indirect returns.
  // The "inreg" attribute identifies non-aggregate types.
  // The position of the "sret" attribute identifies instance/non-instance
  // methods.
  // "sret" on argument 0 means non-instance methods.
  // "sret" on argument 1 means instance methods.

  CCIfInReg<CCIfType<[i64],
        CCIfSRet<CCIfType<[i64], CCAssignToReg<[X0, X1]>>>>>,

  CCIfSRet<CCIfType<[i64], CCAssignToReg<[X8]>>>,
```

So missing/dropping inreg can cause a codegen bug.

This is a partial fix for #74866
2024-09-04 18:00:36 -07:00
swift-ci
8fc7ad929f Merge remote-tracking branch 'origin/main' into rebranch 2024-09-04 17:14:41 -07:00
Akira Hatanaka
f81d2e67f7 Fix a test that was failing on armv7k (#76259)
rdar://135165028
2024-09-04 17:06:20 -07:00
swift-ci
ec365a63eb Merge remote-tracking branch 'origin/main' into rebranch 2024-09-03 19:55:40 -07:00
Akira Hatanaka
7cdbb64567 Disable test on arm64e (#76229)
rdar://135165028
2024-09-03 19:51:32 -07:00
swift-ci
f1877410ef Merge remote-tracking branch 'origin/main' into rebranch 2024-09-03 02:53:13 -07:00
Gabor Horvath
738b4c6d8d [cxx-interop] Add a SWIFT_NONESCAPABLE attribute to the bridging header
This makes it easier to experiment with noescapable types in interop.
Moreover, we always wanted to have this annotation for completeness,
similar to SWIFT_NONCOPYABLE.
2024-09-02 14:51:27 +01:00
swift-ci
1b23f6a9b2 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-29 20:55:52 -07:00