Commit Graph

542 Commits

Author SHA1 Message Date
Kuba Mracek
e871cea025 [embedded] Respect float arg lowering convention under -mfloat-abi=hard 2024-06-12 11:26:02 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
swift-ci
85ae379988 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-25 15:54:05 -07:00
Hamish Knight
cfdf35ff34 [IRGen] Fix SyncCallEmission::emitCallToUnmappedExplosion crash
We cannot `dyn_cast` directly to `ClassTypeInfo` since it does not
implement `classof`, so will succeed for any `ReferenceTypeInfo`.

rdar://128735092
2024-05-25 16:47:36 +01:00
swift-ci
79df0ab8a1 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-17 09:14:02 -07:00
Akira Hatanaka
335cec0e8d [cxx-interop][IRGen] Do not pass a foreign reference type to objc_retainAutoreleasedReturnValue (#73630)
If a foreign reference type has a custom retain function, emit a call to
it instead of emitting a call to objc_retainAutoreleasedReturnValue.

rdar://117353222
2024-05-17 09:04:02 -07:00
swift-ci
5b6eadf416 Merge remote-tracking branch 'origin/main' into rebranch 2024-04-12 13:37:42 -07:00
Erik Eckstein
1b1d5ed020 IRGen: support the @sensitive attribute
Call `swift_clearSensitive` after destroying or taking "sensitive" struct types.

Also, support calling C-functions with "sensitive" parameters or return values. In SIL, sensitive types are address-only and so are sensitive parameters/return values.
Though, (small) sensitive C-structs are passed directly to/from C-functions. We need re-abstract such parameter and return values for C-functions.
2024-04-09 12:01:11 +02:00
Ben Barham
ebb8490a83 [IRGen] Add missing case for ArrayParameter
Added in 9434c083475e42f47383f3067fe2a155db5c6a30, seems to be HLSL
specific.
2024-04-08 08:58:59 -07:00
Arnold Schwaighofer
917ae2d051 LargeTypesReg2Mem: Forward the address of large formally by-val arguments and return values of C functions
rdar://47978338
2024-04-02 13:11:16 -07:00
Anton Korobeynikov
d84847ac9d Reland Allow normal function results of @yield_once coroutines (#71645)
* Allow normal function results of @yield_once coroutines

* Address review comments

* Workaround LLVM coroutine codegen problem: it assumes that unwind path never returns.
This is not true to Swift coroutines as unwind path should end with error result.
2024-03-27 13:09:02 -07:00
John McCall
0a282c044f Unify all of the task-creation builtins coming out of SILGen.
We've been building up this exponential explosion of task-creation
builtins because it's not currently possible to overload builtins.
As long as all of the operands are scalar, though, it's pretty easy
to peephole optional injections in IRGen, which means we can at
least just use a single builtin in SIL and then break it apart in
IRGen to decide which options to set.

I also eliminated the metadata argument, which can easily be recreated
from the substitutions.  I also added proper verification for the builtin,
which required (1) getting `@Sendable` right more consistently and (2)
updating a bunch of tests checking for things that are not actually
valid, like passing a function that returns an Int directly.
2024-03-06 22:21:12 -05:00
Alastair Houghton
d0c35cf2d5 [IRGen] Don't call objc_retainAutoreleasedReturnValue() without interop.
When ObjC interop is not enabled, we shouldn't be emitting calls to
`objc_retainAutoreleasedReturnValue()` as that function might not exist.

Call `swift_retain()` instead, to balance the `swift_release()` of the
returned value.

Fixes #47846, #45359.

rdar://23335318
2024-03-01 20:34:43 +00:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Akira Hatanaka
b3f302b96b [IRGen] Fix a bug where an argument wasn't annotated with sret (#71459)
Fix a bug in expandExternalSignatureTypes where it wasn't annotating a function call parameter type with sret when the result was being returned indirectly.

The bug was causing calls to ObjC methods that return their results indirectly to crash.

Additionally, fix the return type for C++ constructors computed in expandExternalSignatureTypes. Previously, the return type was always void even on targets that require constructors to return this (e.g., Apple arm64), which was causing C++ constructor thunks to be emitted needlessly.

Resolves rdar://121618707
2024-02-22 14:14:47 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Allan Shortlidge
2990c65457 NFC: Address some unused variable warnings. 2024-02-12 12:23:42 -08:00
Alastair Houghton
76f2389fd9 [IRGen][Test] Use the new availability support.
We need to only generate references to `_swift_exceptionPersonality`
if we're building for a new enough runtime.  The previous code was
good on Darwin, but would have resulted in build problems on Linux.

rdar://120952971
2024-02-06 16:21:11 +00:00
Alastair Houghton
143a473aa4 [Runtime][IRGen] Trap C++ exceptions on *throw*, not catch.
The previous approach was effectively to catch the exception and then
run a trap instruction.  That has the unfortunate feature that we end
up with a crash at the catch site, not at the throw site, which leaves
us with very little information about which exception was thrown or
where from.

(Strictly we do have the exception pointer and could obtain exception
information, but it still won't tell us what threw it.)

Instead of that, set a personality function for Swift functions that
call potentially throwing code, and have that personality function
trap the exception during phase 1 (i.e. *before* the original stack
has been unwound).

rdar://120952971
2024-02-06 16:19:17 +00:00
Arnold Schwaighofer
2f94890e5f IRGen: Remove supportsTypedPointers, getNonOpaquePointerElementType, isOpaqueOrPointeeTypeMatches
Typed pointers are no longer supported by llvm.

rdar://121083958
2024-01-17 07:33:30 -08:00
Arnold Schwaighofer
b4ef029fe6 IRGen: Add support for typed throws to thunk code generation
rdar://119725769
2023-12-15 15:39:29 -08:00
Konrad `ktoso` Malawski
828f589be4 Initial Task Executor implementation Task(on:), addTask(on:) etc. (#68793)
Co-authored-by: John McCall <rjmccall@gmail.com>
2023-12-12 17:14:24 +09:00
Arnold Schwaighofer
e3a27a13d9 IRGen: Allocate an address for the result of zero sized typed error results
rdar://118657904
2023-11-28 11:37:09 -08:00
Konrad `ktoso` Malawski
5546f4da7b Rename ExecutorRef to SerialExecutorRef 2023-11-01 18:39:44 +09:00
Mishal Shah
3594f8ecaf Merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
	test/IRGen/opaque-pointer-llvm.swift
2023-10-15 23:49:40 -07:00
Kuba (Brecka) Mracek
7e9013dd52 Merge pull request #69090 from kubamracek/embedded-actors-and-async-let
[embedded] Add support for actors and async let into the embedded Concurrency runtime
2023-10-15 13:37:35 -07:00
Arnold Schwaighofer
9482b0c86b Preliminary SIL and IRGen support for error_indirect
IRGen lowering of non-fixed-sized typed errors and the SIL support necessary to
spell out IRGen test cases.
2023-10-12 18:09:52 -07:00
swift-ci
46c67c20cf Merge remote-tracking branch 'origin/main' into rebranch 2023-10-10 02:35:18 -07:00
Kuba Mracek
90e1d2006f [embedded] Add support for actors and async let into the embedded Concurrency runtime 2023-10-09 22:43:50 -07:00
Hamish Knight
ccd32eb452 NFC: Remove ClangModuleLoader.h include from ExtInfo.h
This was unnecessarily pulling in a whole bunch
of Clang headers when all was needed was a
forward declaration.
2023-10-09 20:29:03 +01:00
swift-ci
d253b717d2 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-07 19:35:15 -07:00
Kuba Mracek
5d8c55eacb [embedded] Initial Swift Concurrency for embedded Swift 2023-10-06 20:04:03 -07:00
swift-ci
00db9cadd6 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-02 08:55:02 -07:00
Arnold Schwaighofer
6b74f511d0 Preliminary IRGen support for typed throws
Typed errors are returned indirectly in this version.
No support for non-loadable typed errors
2023-09-29 08:54:49 -07:00
Evan Wilde
700aa8aa70 Merge remote-tracking branch 'upstream/main' into rebranch
Merge conflict while removing `nocapture` from
`s21move_function_dbginfo20addressOnlyValueTestyyxAA1PRzlF`. Resolution
was to remove nocapture from the expected output in both cases:
```
// CHECK-LABEL: define swiftcc void @"$s21move_function_dbginfo20addressOnlyValueTestyyxAA1PRzlF"(ptr noalias[-nocapture-] %0, ptr %T, ptr %T.P)
```

Conflict cause: 4858cb6225
This is the same as the original change to this file. The conflict seems
to be due to the next line changing, when moving from llvm.dbg.addr to
llvm.dbg.value.

Conflicts:
  test/DebugInfo/move_function_dbginfo.swift
2023-09-26 13:36:57 -07:00
Alex Lorenz
6ecea1ac09 Merge pull request #68481 from hyp/eng/no-nocapture
[IRGen][interop] do not add 'nocapture' to not bitwise takable types
2023-09-26 07:52:05 -07:00
Alex Lorenz
4858cb6225 [IRGen][interop] do not add 'nocapture' to not bitwise takable types
The use of 'nocapture' for parameters and return values is incorrect for C++ types, as they can actually capture a pointer into its own value (e.g. std::string in libstdc++)

rdar://115062687
2023-09-25 17:43:34 -07:00
swift-ci
1b6470ca9c Merge remote-tracking branch 'origin/main' into rebranch 2023-09-20 15:07:15 -07:00
Yuta Saito
c5314bd3af Centralize KeyPath accessor calling convention logic to IRGen
KeyPath's getter/setter/hash/equals functions have their own calling
convention, which receives generic arguments and embedded indices from a
given KeyPath argument buffer.
The convention was previously implemented by:
1. Accepting an argument buffer as an UnsafeRawPointer and casting it to
   indices tuple pointer in SIL.
2. Bind generic arguments info from the given argument buffer while emitting
   prologue in IRGen by creating a new forwarding thunk.

This 2-phase lowering approach was not ideal, as it blocked KeyPath
projection optimization [^1], and also required having a target arch
specific signature lowering logic in SIL-level [^2].

This patch centralizes the KeyPath accessor calling convention logic to
IRGen, by introducing `@convention(keypath_accessor_XXX)` convention in
SIL and lowering it in IRGen. This change unblocks the KeyPath projection
optimization while capturing subscript indices, and also makes it easier
to support WebAssembly target.

[^1]: https://github.com/apple/swift/pull/28799
[^2]: https://forums.swift.org/t/wasm-support/16087/21
2023-09-20 11:25:39 -07:00
Nate Chandler
6ccd08b4e0 Merge branch 'main' into rebranch.
Resolve conflicts introduced in
https://github.com/apple/swift/pull/67944 as follows:

```
diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def
index 3c973b5884b..44cde707d17 100644
--- a/include/swift/Runtime/RuntimeFunctions.def
+++ b/include/swift/Runtime/RuntimeFunctions.def
@@ -2537,16 +2537,10 @@ FUNCTION(AutoDiffCreateLinearMapContextWithType,
          swift_autoDiffCreateLinearMapContextWithType, SwiftCC,
          DifferentiationAvailability,
          RETURNS(RefCountedPtrTy),
-<<<<<<< HEAD
-         ARGS(SizeTy),
+         ARGS(TypeMetadataPtrTy),
          ATTRS(NoUnwind),
          EFFECT(AutoDiff),
          MEMEFFECTS(ArgMemOnly))
-=======
-         ARGS(TypeMetadataPtrTy),
-         ATTRS(NoUnwind, ArgMemOnly),
-         EFFECT(AutoDiff))
->>>>>>> public-github/main

 // void *swift_autoDiffProjectTopLevelSubcontext(AutoDiffLinearMapContext *);
 FUNCTION(AutoDiffProjectTopLevelSubcontext,
@@ -2563,16 +2557,10 @@ FUNCTION(AutoDiffAllocateSubcontextWithType,
          swift_autoDiffAllocateSubcontextWithType, SwiftCC,
          DifferentiationAvailability,
          RETURNS(Int8PtrTy),
-<<<<<<< HEAD
-         ARGS(RefCountedPtrTy, SizeTy),
+         ARGS(RefCountedPtrTy, TypeMetadataPtrTy),
          ATTRS(NoUnwind),
          EFFECT(AutoDiff),
          MEMEFFECTS(ArgMemOnly))
-=======
-         ARGS(RefCountedPtrTy, TypeMetadataPtrTy),
-         ATTRS(NoUnwind, ArgMemOnly),
-         EFFECT(AutoDiff))
->>>>>>> public-github/main
```
2023-08-24 16:24:32 -07:00
Kshitij Jain
d5a3e2e630 [AutoDiff] Fixes memory leaks in autodiff linear map context allocation builtins (#67944)
When the differentiating a function containing loops, we allocate a linear map context object on the heap. This context object may store non-trivial objects, such as closures, that need to be released explicitly. Fix the autodiff linear map context allocation builtins to correctly release such objects and not just free the memory they occupy.
2023-08-24 13:57:10 -07:00
swift-ci
c5f45eb8e3 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-16 07:18:10 -07:00
Alejandro Alonso
44198d16a4 Merge pull request #67611 from Azoy/raw-types-are-cool!
[WIP] Implement dependent layouts for raw types
2023-08-16 06:55:42 -07:00
swift-ci
c1e2a8a93a Merge remote-tracking branch 'origin/main' into rebranch 2023-08-08 12:13:56 -07:00
Alex Lorenz
8d81f5e3f7 [cxx-interop][windows] Pass trivial indirect result after 'this' when invoking C++ MSVC ABI method 2023-08-07 11:15:20 -07:00
Alex Lorenz
8449b21d62 [cxx-interop][windows] additional fix for indirect return in methods for MSVC ABI
Fixes https://github.com/apple/swift/pull/67685
2023-08-03 15:07:22 -07:00
Alejandro Alonso
df17f7be90 Implement dependent layouts for raw types
Update raw_layout.swift

Allow for concrete specializations of raw layout

Make test platform agnostic
2023-08-01 14:09:23 -07:00
Evan Wilde
f4946e9718 Updating more alignment APIs
Adding a few more updates to places where the ABI Alignment functions
changed. `getABITypeAlignment` was replaced with `getABITypeAlign`,
which returns an `llvm::Align` instead of an unsigned int.
2023-07-25 12:28:28 -07:00
swift_jenkins
81614b11ec Merge remote-tracking branch 'origin/main' into next 2023-07-21 07:09:38 -07:00
Evan Wilde
bc904880d0 Handle new builtin cases: AArch64SVcount, WASMRefType
Clang and LLVM added some new builtins.

LLVM added IITDescriptor::AArch64Svcount, which I set to not be
decodable since Swift can't represent those at the moment.

Also added handling for the WASM reference type builtins in the Clang
type converter.
2023-07-17 10:55:57 -07:00