Commit Graph

597 Commits

Author SHA1 Message Date
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Gabor Horvath
51e92d9db4 [cxx-interop] Use the new lifetime dependence language feature flag
Non-escapable types are now enabled by default. Use the new lifetime
dependence feature flag to gate interpreting lifetime annotations on the
C++ side and add tests to make sure we get the expected diagnostics when
the feaature flag is off.
2024-11-21 13:13:16 +00:00
Gábor Horváth
d3064c5fc6 Merge pull request #77678 from swiftlang/gaborh/conditional-escapability
[cxx-interop] Support nested templates for conditional escapability
2024-11-20 13:59:00 +00:00
Meghana Gupta
e8abd59da5 Update tests 2024-11-18 18:09:19 -08:00
Gabor Horvath
ad4bfef762 [cxx-interop] Support nested templates for conditional escapability
rdar://140115862
2024-11-18 14:16:40 +00:00
Egor Zhdan
004ef749be Merge pull request #77646 from swiftlang/egorzhdan/reland-copy-ctor
Re-land "[cxx-interop] Check the presence of copy constructor correctly"
2024-11-18 12:50:27 +00:00
Gábor Horváth
5b2f3b7441 Merge pull request #77588 from swiftlang/gaborh/conditional-escapability
[cxx-interop] Support conditional escapability
2024-11-15 18:26:17 +00:00
Egor Zhdan
aa584bf876 [cxx-interop] Check the presence of copy constructor correctly
This reverts commit 3066bd6919.

This re-lands a change after it got reverted because of a regression in the build of SwiftCompilerSources.

rdar://136838485
2024-11-15 15:21:55 +00:00
Gabor Horvath
558380f6f8 [cxx-interop] Support conditional escapability
This PR adds a variadic macro that builds a SwiftAttr string containing
the names of the template type parameters that need to be escapable for
the type to be considered escapable. It also adds logic to interpret
this annotation.

rdar://139065437
2024-11-15 14:27:54 +00:00
Egor Zhdan
3066bd6919 Revert "[cxx-interop] Check the presence of copy constructor correctly"
This reverts commit fbbec48c

The change was causing regressions in certain build configs that need to be investigated.

rdar://139723218
2024-11-14 16:31:27 +00:00
Egor Zhdan
6943986c71 [cxx-interop] Import private fields of C++ structs
While private and protected fields coming from C++ cannot be accessed from Swift, they can affect Swift typechecking.

For instance, the Swift typechecker mechanism that adds implicit `Sendable` conformances works by iterating over all of the struct's fields and checking whether all of them are `Sendable`. This logic was broken for C++ types with private fields, since they were never accounted for. This resulted in erroneous implicit `Sendable` confromances being added.

Same applies for `BitwiseCopyable`.

In addition to this, ClangImporter used to mistakenly mark all C++ structs that have private fields as types with unreferenceable storage, which hampered optimizations.

As a side effect of this change, we now also provide a better diagnostic when someone tries to access a private C++ field from Swift.

rdar://134430857
2024-11-12 12:47:26 +00:00
Gábor Horváth
88c2269e69 Merge pull request #77323 from swiftlang/gaborh/use-imported-locs
[cxx-interop] Use the locations imported from C++
2024-11-07 17:44:07 +00:00
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
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
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
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
8055b52f37 [cxx-interop] Fix test on Windows after LLVM update 2024-10-29 13:27:19 +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
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
848b66dca6 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-17 12:15:00 -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
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
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