Commit Graph

542 Commits

Author SHA1 Message Date
swift_jenkins
50c215ca92 Merge remote-tracking branch 'origin/main' into next 2021-04-23 13:28:08 -07:00
Arnold Schwaighofer
1f890dc6a2 IRGen: Fix async dynamic replacements
We need to emit a full async suspend sequence when calling the
replacement.

rdar://77072724
2021-04-23 09:03:51 -07:00
swift_jenkins
2c2f2ae3db Merge remote-tracking branch 'origin/main' into next 2021-04-23 01:41:35 -07:00
Yuta Saito
619226b480 Fix calling convention mismatch on Builtin.getCurrentAsyncTask (#37008)
* Add explicit calling convention on builtin GetCurrentTask

This builtin function emits a call of swift_task_getCurrent, and user
code can declare the same name function with slightly different
signature at LLVM level (data size should be same) using @_silgen_name.
In that case, IRGen insert cast inst to cast the function to the
expected signature. But this cast inst drops calling convention info, so
call inst was emitted without swiftcc.

This patch changed to emit a call of swift_task_getCurrent with the
explicit calling convention.

* Add test case to ensure builtin function cc when conflict
2021-04-23 09:35:37 +01:00
swift_jenkins
8a495314e8 Merge remote-tracking branch 'origin/main' into next 2021-04-20 00:21:01 -07:00
Konrad `ktoso` Malawski
d3c5ebc9b7 [AsyncLet] reimplemented with new ABI and builtins 2021-04-19 10:06:23 +09:00
Konrad `ktoso` Malawski
ba615029c7 [Concurrency] Store child record when async let child task spawned 2021-04-19 10:06:23 +09:00
swift_jenkins
11c3675001 Merge remote-tracking branch 'origin/main' into next 2021-04-08 14:01:51 -07:00
John McCall
156264f8e8 Make ExecutorRef two words. 2021-04-08 12:57:12 -04:00
swift_jenkins
d90eb93471 Merge remote-tracking branch 'origin/main' into next 2021-04-07 23:21:42 -07:00
Nate Chandler
6bbc96b8c8 [IRGen] Added fn ptr to async FunctionPointer.
The address of the function to be called when generating code to invoke
the function associated with FunctionPointer which is produced via
direct reference is by definition statically known; it is neither necessary
nor desireable to load this address out of the AsyncFunctionPointer
corresponding to the function.

Here, that spurious additional work is skipped.  The approach is to add
a second value to the FunctionPointer struct.  For FunctionPointers
whose kind is AsyncFunctionPointer, this value is either null or else
the address of the corresponding function.

rdar://71376092
2021-04-07 16:11:09 -07:00
swift_jenkins
54cd4d21cb Merge remote-tracking branch 'origin/main' into next 2021-04-06 13:41:18 -07:00
Nate Chandler
d3e0e7af07 [ptrauth] Signed AsyncFunctionPointers as data.
Previously, AsyncFunctionPointer constants were signed as code.  That
was incorrect considering that these constants are in fact data.  Here,
that is fixed.

rdar://76118522
2021-04-05 18:24:41 -07:00
swift_jenkins
96a053afeb Merge remote-tracking branch 'origin/main' into next 2021-04-01 19:02:19 -07:00
Arnold Schwaighofer
8e1d25b9f9 IRGen: Fix async throw emission for indirect direct values
rdar://76009728
2021-04-01 07:22:13 -07:00
Arnold Schwaighofer
027119fecb Merge remote-tracking branch 'upstream/main' into next 2021-03-29 12:33:25 -07:00
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