Commit Graph

33 Commits

Author SHA1 Message Date
Anthony Latsis
17fc00f8a7 [test] IRGen: Adjust FileCheck patterns for new nuw attribute in upstream LLVM
This attribute was introduced in
7eca38ce76d5d1915f4ab7e665964062c0b37697 (llvm-project).

Match it using a wildcard regex, since it is not relevant to these
tests.

This is intended to reduce future conflicts with rebranch.
2025-05-04 03:28:56 +01:00
Felipe de Azevedo Piovezan
2880517113 [DebugInfo] Don't emit debug info for async suspend/dispatch functions
Those functions are effectively outlined functions with an alwaysinline
attribute. By removing their debug info and relying on the inliner to propagate
the call site location to the inlined instructions, we restore the "original"
locations as if the function had never been outlined.

This is technically relying on an implementation detail of the inliner, but it
seems to be the simplest way of addressing this issue.
2024-08-14 09:25:44 -07:00
Yuta Saito
5f684ec75f [wasm][test] Add objc_codegen feature to exclude enable-objc-interop tests
Clang does not accept `-x objective-c` with WebAssembly target and it
crashes with "Objective-C support is unimplemented for object file
format" for now. `-enable-objc-interop` can work without the objc
runtime support (which is indicated by `objc_interop` feature), so this
adds a new `objc_codegen` feature to require Objective-C support only
at compile-time.
2023-10-11 00:51:17 +00:00
Erik Eckstein
b5de7e4e49 IRGen: fix -disable-llvm-optzns
If LLVM optimizations are to be disabled, we cannot just not run all LLVM passes, because there are some mandatory LLVM passes, like coro splitting.
Instead, just run the -O0 LLVM pipeline if -disable-llvm-optzns is used.

Fixes compiler crashes if -disable-llvm-optzns is used.

Note: if one wants to see the output of IRGen, -emit-irgen can be used.
2023-09-25 09:20:04 +02:00
Andrew Trick
da52e752c0 Update IRGen test for opaque pointers 2023-06-23 06:57:38 -07:00
Arnold Schwaighofer
c1a93e0bde Move tests over to use the %use_no_opaque_pointers option 2023-06-14 10:49:48 -07:00
swift_jenkins
8dd0293923 Merge remote-tracking branch 'origin/main' into next 2022-03-04 08:21:34 -08:00
Arnold Schwaighofer
189b0ac5e5 IRGen: Emit the proper linkageName debug info of the containing function for async suspend dispatch thunks
Improvement upon #41645 to emit the async suspend dispatch thunk's debug
info with the `linkageName` of the containing function of the async
await.

rdar://88579737
2022-03-03 15:16:41 -08:00
swift_jenkins
40930e6138 Merge remote-tracking branch 'origin/main' into next 2022-03-03 14:21:15 -08:00
Arnold Schwaighofer
6dcd90d112 IRGen: Use the current function name for the swift_suspend_dispatch thunk
This is an incremental improvement of the debug info at a suspend apply site.

Before this patch the debug info at the call site would use the
`__swift_suspend_dispatch` function name as the current function after
coro lowering has inlined the thunk.

The proper fix is to rewire the debug info such that the thunk name is
never mentioned rather the current function that suspend site sits in is
used.

Until I have figured out how to do that using the current function name
instead of `__swift_suspend_dispatch.5` for the thunk is an incremental
improvement in the debug information consumers can observe.

rdar://88579737
2022-03-03 08:29:01 -08:00
swift_jenkins
a8504ad70e Merge remote-tracking branch 'origin/main' into next 2022-02-25 20:40:23 -08:00
John McCall
aca744b211 Remove the Flags field from AsyncContext.
Generated code has never actually initialized this field, so we
might as well remove it.  Doing so mostly doesn't impact the ABI
since we don't store anything for arguments or results in the
context as part of the normal call sequence.  We do need to adjust
some of the hard-coded contexts, however, such as continuation
contexts and the statically-sized context for special runtime
async functions.
2022-02-25 16:57:49 -05:00
Arnold Schwaighofer
66ce0ee901 Fix tests 2021-11-29 14:01:21 -08:00
Doug Gregor
eeeea49764 Remove -enable-experimental-concurrency almost everywhere. 2021-07-26 21:24:43 -07:00
John McCall
3aa04db87b Track whether a task is actively running.
Tracking this as a single bit is actually largely uninteresting
to the runtime.  To handle priority escalation properly, we really
need to track this at a finer grain of detail: recording that the
task is running on a specific thread, enqueued on a specific actor,
or so on.  But starting by tracking a single bit is important for
two reasons:

- First, it's more realistic about the performance overheads of
  tasks: we're going to be doing this tracking eventually, and
  the cost of that tracking will be dominated by the atomic
  access, so doing that access now sets the baseline about right.

- Second, it ensures that we've actually got runtime involvement
  in all the right places to do this tracking.

A propos of the latter: there was no runtime involvement with
awaiting a continuation, which is a point at which the task
potentially transitions from running to suspended.  We must do
the tracking as part of this transition, rather than recognizing
in the run-loops that a task is still active and treating it as
having suspended, because the latter point potentially races with
the resumption of the task.  To do this, I've had to introduce
a runtime function, swift_continuation_await, to do this awaiting
rather than inlining the atomic operation on the continuation.

As part of doing this work, I've also fixed a bug where we failed
to load-acquire in swift_task_escalate before walking the task
status records to invoke escalation actions.

I've also fixed several places where the handling of task statuses
may have accidentally allowed the task to revert to uncancelled.
2021-07-14 20:24:01 -04:00
Arnold Schwaighofer
a26f10d4b5 Fix test case for windows 2021-06-01 17:34:21 -07:00
Arnold Schwaighofer
d06c9f3247 IRGen: Add the swiftasync attribute to the resume function call for await_async_continuation
Without this we are going to crash (timing dependent) in
withUnsafeContinuation and bridged async objective c calls.

rdar://78031499
2021-06-01 15:47:32 -07:00
Arnold Schwaighofer
97852791cc Fix test on arm64e 2021-04-02 15:03:26 -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
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
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
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
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
893d28c9b3 [IRGen] Signed parent async context. 2021-02-03 17:51:18 -08:00
Nate Chandler
5261c31ed0 [IRGen] Sign TaskResumeFunction. 2021-02-03 17:51:02 -08:00
Nate Chandler
c31cb54d35 [IRGen] Sign TaskResumeContext. 2021-02-03 17:50:50 -08:00
Slava Pestov
c133e13efd Merge pull request #34916 from slavapestov/with-unsafe-continuation
Concurrency: Implement withUnsafe[Throwing]Continuation
2020-12-03 11:18:49 -05:00
Erik Eckstein
752558ce18 IRGen: fix the LLVM struct definition of AsyncTask.
The object header was missing.
2020-12-03 11:56:44 +01:00
Slava Pestov
a2dbdecdab SIL: Refactor get_async_continuation[_addr] to return a RawUnsafeContinuation 2020-12-01 20:04:09 -05:00
Erik Eckstein
bf2be9eb5d [concurrency] IRGen: update task/executor/context on every suspend point
For this, store those 3 values on the stack at function entry and update them with the return values of coro_suspend_async intrinsic calls.

This fixes a correctness issue, because the executor may be different after a resume.
It also is more efficient, because this means that the 3 values don't have to preserved in the context over a suspension point.
2020-12-01 15:19:39 +01:00
Arnold Schwaighofer
505a6ee1d3 Also store the current executor in the async_continuation_context at the time of 2020-11-20 14:46:41 -08:00
Arnold Schwaighofer
cca2425ef0 Add expected output to test 2020-11-20 13:09:58 -08:00
Arnold Schwaighofer
d75e4c2bd2 IRGen: get/await_async_continuation support.
rdar://71124933
2020-11-19 08:43:26 -08:00