Commit Graph

576 Commits

Author SHA1 Message Date
John McCall
98711fd628 Revise the continuation ABI.
The immediate desire is to minimize the set of ABI dependencies
on the layout of an ExecutorRef.  In addition to that, however,
I wanted to generally reduce the code size impact of an unsafe
continuation since it now requires accessing thread-local state,
and I wanted resumption to not have to create unnecessary type
metadata for the value type just to do the initialization.

Therefore, I've introduced a swift_continuation_init function
which handles the default initialization of a continuation
and returns a reference to the current task.  I've also moved
the initialization of the normal continuation result into the
caller (out of the runtime), and I've moved the resumption-side
cmpxchg into the runtime (and prior to the task being enqueued).
2021-03-28 12:58:16 -04:00
swift_jenkins
701ce71a72 Merge remote-tracking branch 'origin/main' into next 2021-03-18 22:22:44 -07:00
Arnold Schwaighofer
ec2d78677e Merge pull request #36490 from aschwaighofer/remove_unused_resume_parent_executor
Remove unused resume parent executor
2021-03-18 18:30:22 -07:00
swift_jenkins
86915442f9 Merge remote-tracking branch 'origin/main' into next 2021-03-18 18:22:19 -07:00
Arnold Schwaighofer
4bffcac39e Merge pull request #36496 from aschwaighofer/revert_ptrauth-returns_workaround
Revert "arm64e: Workaround ptrauth-returns failure for swifttailcc"
2021-03-18 16:35:40 -07:00
swift_jenkins
aa49b315c6 Merge remote-tracking branch 'origin/main' into next 2021-03-18 14:43:50 -07:00
Arnold Schwaighofer
340ccb2a5a Revert "arm64e: Workaround ptrauth-returns failure for swifttailcc"
This reverts commit 3c125a74f0.
2021-03-18 10:44:35 -07:00
Arnold Schwaighofer
cf55973973 Remove unused ResumeParentExecutor 2021-03-18 09:05:45 -07:00
Arnold Schwaighofer
249b27672a Remove unused error result storage from AsyncContext 2021-03-18 08:59:11 -07:00
swift_jenkins
4d0cb687f7 Merge remote-tracking branch 'origin/main' into next 2021-03-18 08:27:45 -07:00
Slava Pestov
c4c91e2393 Merge pull request #36482 from slavapestov/gencall-unused-var
IRGen: Remove unused variable
2021-03-18 10:20:34 -04:00
swift_jenkins
2ed5dcd3a9 Merge remote-tracking branch 'origin/main' into next 2021-03-18 04:38:36 -07:00
Slava Pestov
6d7714a57d IRGen: Remove unused variable 2021-03-18 00:10:56 -04:00
Arnold Schwaighofer
3bdd5cb99a IRGen: async error ABI
Throwing functions pass the error result in `swiftself` to the resume
partial function.
Therefore, `() async -> ()` to `() async throws -> ()` is not ABI compatible.

TODO: go through remaining failing IRGen async tests and replace the
illegal convert_functions.
2021-03-17 17:17:12 -07:00
swift_jenkins
1d89275fa1 Merge remote-tracking branch 'origin/main' into next 2021-03-17 10:21:31 -07:00
Arnold Schwaighofer
3c125a74f0 arm64e: Workaround ptrauth-returns failure for swifttailcc
The current code generation will emit an autibsp after adjusting the
stack pointe for the tail call. If callee and caller argument area does
not match this would fail.
2021-03-17 07:41:10 -07:00
swift_jenkins
e4761dd263 Merge remote-tracking branch 'origin/main' into next 2021-03-17 07:41:06 -07:00
Arnold Schwaighofer
f75fbb7594 IRGen: Async ABI passing parameter and results directly
The error is still passed in the async context. I will fix this in a
follow-up.
2021-03-17 07:41:01 -07:00
John McCall
6c879d6fd3 Change the async ABI to not pass the active task and executor.
Most of the async runtime functions have been changed to not
expect the task and executor to be passed in.  When knowing the
task and executor is necessary, there are runtime functions
available to recover them.

The biggest change I had to make to a runtime function signature
was to swift_task_switch, which has been altered to expect to be
passed the context and resumption function instead of requiring
the caller to park the task.  This has the pleasant consequence
of allowing the implementation to very quickly turn around when
it recognizes that the current executor is satisfactory.  It does
mean that on arm64e we have to sign the continuation function
pointer as an argument and then potentially resign it when
assigning into the task's resume slot.

rdar://70546948
2021-03-16 22:52:54 -04:00
swift_jenkins
2f9ee052a0 Merge remote-tracking branch 'origin/main' into next 2021-03-15 18:40:35 -07:00
Nate Chandler
ee63777332 [IRGen] Fix ABI for thick async functions.
Previously, thick async functions were represented sometimes as a pair
of (AsyncFunctionPointer, nullptr)--when the thick function was produced
via a thin_to_thick_function, e.g.--and sometimes as a pair of
(FunctionPointer, ThickContext)--when the thick function was produced by
a partial_apply--with the size stored in the slot of the ThickContext.

That optimized for the wrong case: partial applies of dynamic async
functions; in that case, there is no appropriate AsyncFunctionPointer to
form when lowering the partial_apply instruction.  The far more common
case is to know exactly which function is being partially applied.  In
that case, we can form the appropriate AsyncFunctionPointer.

Furthermore, the previous representation made calling a thick function
more complex: it was always necessary to check whether the context was
in fact null and then proceed along two different paths depending.

Here, that behavior is corrected by creating a thunk in a mandatory
IRGen SIL pass in the case that the function that is being partially
applied is dynamic.  That new thunk is then partially applied in place
of the original partial_apply of the dynamic function.
2021-03-15 13:37:40 -07:00
swift_jenkins
a6896e3b9d Merge remote-tracking branch 'origin/main' into next 2021-03-11 13:40:31 -08:00
Varun Gandhi
4be2f3a62d Merge pull request #36376 from varungandhi-apple/vg-coro-end-async
[IRGen] Use coro.end.async to return from an async function
2021-03-11 13:39:39 -08:00
Arnold Schwaighofer
8c5fc073fd [IRGen] Use coro.end.async to return from an async function
The `coro.end.async` intrinsic allow specifying a function that is to be
tail-called as the last thing before returning.

LLVM lowering will inline the `must-tail-call` function argument to
`coro.end.async`. This `must-tail-call` function can contain a
`musttail` call.

```
define @my_must_tail_call_func(void (*)(i64) %fnptr, i64 %args) {
  musttail call void %fnptr(i64 %args)
  ret void
}

define @async_func() {
  ...
  coro.end.async(..., @my_must_tail_call_func, %return_continuation, i64 %args)
  unreachable
}
```
2021-03-10 10:15:27 -08:00
swift_jenkins
76cbcfdf1f Merge remote-tracking branch 'origin/main' into next 2021-03-09 14:20:55 -08:00
Joe Groff
872afda50b Merge pull request #36298 from jckarter/created-task-closure-context-leak
SIL: Clean up ownership handling in `createAsyncTask` builtins.
2021-03-09 14:17:13 -08:00
Joe Groff
d9798c0868 Concurrency: Redo non-_f variants of swift_task_create to accept closures as is.
In their previous form, the non-`_f` variants of these entry points were unused, and IRGen
lowered the `createAsyncTask` builtins to use the `_f` variants with a large amount of caller-side
codegen to manually unpack closure values. Amid all this, it also failed to make anyone responsible
for releasing the closure context after the task completed, causing every task creation to leak.
Redo the `swift_task_create_*` entry points to accept the two words of an async closure value
directly, and unpack the closure to get its invocation entry point and initial context size
inside the runtime. (Also get rid of the non-future `swift_task_create` variant, since it's unused
and it's subtly different in a lot of hairy ways from the future forms. Better to add it later
when it's needed than to have a broken unexercised version now.)
2021-03-08 16:54:19 -08:00
Robert Widmann
7e8cf9b2d3 [next] Adapt To RISC-V V Builtin Types
https://reviews.llvm.org/D92715 Adds new builtins for use with RISC-V
intrinsics. Match clang here and define stubs for these types.
2021-03-03 17:16:39 -08:00
Arnold Schwaighofer
7104cb130c Merge pull request #36110 from aschwaighofer/irgen_adjust_to_async_suspend_context_index
Adjust to llvm change that requires suspend.async to specify the index of the async context
2021-03-03 08:25:53 -08:00
Konrad `ktoso` Malawski
6f4fca8721 Merge branch 'main' into wip-no-escape-group 2021-02-24 08:59:53 +09:00
Arnold Schwaighofer
cb3703c47d Adjust to llvm change that requires suspend.async to specify the index of the async context 2021-02-23 13:28:38 -08:00
John McCall
2012195cd5 Alter the runtime interface for awaiting futures and task groups.
First, just call an async -> T function instead of forcing the caller
to piece together which case we're in and perform its own copy.  This
ensures that the task is actually kept alive properly.

Second, now that we no longer implicitly depend on the waiting tasks
being run synchronously, go ahead and schedule them to run on the
global executor.

This solves some problems which were blocking the work on TLS-ifying
the task/executor state.
2021-02-21 23:48:13 -05:00
Konrad `ktoso` Malawski
a226259d84 [Concurrency] TaskGroup moves out of AsyncTask, non escaping body 2021-02-22 13:26:27 +09:00
Arnold Schwaighofer
4373bdd6d0 Conditionally start using llvm::CallingConv::SwiftTail for async functions
This is conditional on UseAsyncLowering and in the future should also be
conditional on `clangTargetInfo.isSwiftAsyncCCSupported()` once that
support is merged.

Update tests to work either with swiftcc or swifttailcc.
2021-02-18 09:25:15 -08:00
Nate Chandler
e60ccba7e8 [gardening] Call llvm_unreachable after exhaustive switches.
Failing to provokes warnings from MSVC.
2021-02-16 15:59:55 -08:00
nate-chandler
de63a23e77 Merge pull request #35603 from nate-chandler/concurrency/irgen/rdar71378532
[Async CC] Make error indirect.
2021-02-16 07:39:14 -08:00
Arnold Schwaighofer
59c5841bc2 Merge pull request #35946 from aschwaighofer/use_polymorphic_supend_async
[IRGen] Use the result polymorphic coro.suspend.async intrinsic
2021-02-15 08:14:25 -08:00
Slava Pestov
72e1f02ae2 IRGen: Fix async dispatch thunk emission with loadable return value
Fixes <rdar://problem/74246091>.
2021-02-12 14:06:07 -05:00
Arnold Schwaighofer
84eac93568 [IRGen] Use the result polymorphic coro.suspend.async intrinsic
This needs llvm-project PR 2481.
2021-02-12 10:17:11 -08:00
Nate Chandler
e2a8abc9e5 [Async CC] Make error indirect.
Previously, the error stored in the async context was of type SwiftError
*.  In order to enable the context to be callee released, make it
indirect and change its type to SwiftError **.

rdar://71378532
2021-02-11 11:34:47 -08:00
Arnold Schwaighofer
5a6de1ba77 IRGen: Use opaque storage types for non-fixed indirect result types
LLVM does type based analysis on sret storage types. This is a problem
with non-fixed types whose storage type does not contain the non-fixed
part.

rdar://73778591
2021-02-10 16:19:12 -08:00
swift-ci
89c8005a80 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-27 15:52:25 -08:00
Slava Pestov
c79de40225 IRGen: Emit async function pointers for resilient class and protocol dispatch thunks
This adds new kinds of link entities corresponding to the three
dispatch thunk link entity kinds:

- DispatchThunkAsyncFunctionPointer
- DispatchThunkInitializerAsyncFunctionPointer
- DispatchThunkAllocatorAsyncFunctionPointer
2021-01-27 15:21:22 -05:00
swift-ci
9d0d1fff60 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-26 06:12:31 -08:00
Arnold Schwaighofer
daa72d3cc5 Add llvm::Attribute::SwiftAsync to the context parameter
* Adds support for generating code that uses swiftasync parameter lowering.

* Currently only arm64's llvm lowering supports the swift_async_context_addr intrinsic.

* Add arm64e pointer signing of updated swift_async_context_addr.

This commit needs the PR llvm-project#2291.

* [runtime] unittests should use just-built compiler if the runtime did

This will start to matter with the introduction of usage of swiftasync parameters which only very recent compilers support.

rdar://71499498
2021-01-22 10:01:55 -08:00
swift-ci
d2bafec8a4 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-20 11:12:03 -08:00
Varun Gandhi
a6d0cca201 [IRGen] Add hack to handle _Atomic(_Bool) correctly. 2021-01-20 08:52:07 -08:00
Arnold Schwaighofer
25ff64686d Adjust to llvm's byVal parameter attributes needing the storage type
rdar://73172496
2021-01-14 15:33:42 -08:00
swift_jenkins
6fe8b0edbd Merge remote-tracking branch 'origin/main' into next 2020-12-22 18:03:22 -08:00
Arnold Schwaighofer
59b1deea06 Adjust to addition of llvm::Attribute::SwiftAsync
This the Swift change to go with the llvm PR
https://github.com/apple/llvm-project/pull/2274.
2020-12-21 13:22:22 -08:00