Commit Graph

1608 Commits

Author SHA1 Message Date
swift-ci
2a0c8a186a Merge pull request #40157 from DougGregor/unchecked-sendable-stdlib 2021-11-12 09:54:47 -08:00
Doug Gregor
353daabf8d Replace UnsafeSendable with @unchecked Sendable in the standard library. 2021-11-12 07:56:10 -08:00
Guillaume Lessard
8cc076000a Merge pull request #40116 from glessard/concurrency-assertions
[stdlib] replace uses of assert in the Concurrency module
2021-11-11 09:50:20 -07:00
Philippe Hausler
71cc7666f9 Correct lifetime based cancellation of AsyncStream and AsyncThrowingStream (#40087) 2021-11-11 08:30:28 -08:00
Guillaume Lessard
eb6348447b [stdlib] replace uses of assert in the Concurrency module
- we define a local equialent to `_internalInvariant` that will compile to nothing in release builds
- `assert` was still detectable in release builds, presumably costing execution time
2021-11-09 19:02:30 -07:00
Alex Martini
dee26fbc99 Restore stray whitespace. 2021-11-09 17:23:38 -08:00
Alex Martini
28f15008ee Cherry pick Swift 5.5 doc changes in TaskSleep.swift 2021-11-09 17:23:38 -08:00
Alex Martini
3977d8ede8 Cherry pick Swift 5.5 doc changes in TaskGroup.swift 2021-11-09 17:23:38 -08:00
Alex Martini
0f75fc7f51 Cherry pick Swift 5.5 doc changes in Task.swift 2021-11-09 17:23:38 -08:00
Alex Martini
699421c79b Cherry pick Swift 5.5 doc changes in PartialAsyncTask.swift 2021-11-09 17:23:38 -08:00
Alex Martini
e7d229af7f Cherry pick Swift 5.5 doc changes in GlobalActor.swift 2021-11-09 17:23:38 -08:00
Alex Martini
7913b82839 Cherry pick Swift 5.5 doc changes in Executor.swift 2021-11-09 17:23:38 -08:00
Alex Martini
c7aec3d6b7 Cherry pick Swift 5.5 doc changes in CheckedContinuation.swift 2021-11-09 17:23:38 -08:00
Alex Martini
4aa1485c49 Cherry pick Swift 5.5 doc changes in AsyncThrowingStream.swift 2021-11-09 17:23:38 -08:00
Alex Martini
8162400215 Cherry pick Swift 5.5 doc changes in AsyncThrowingPrefixWhileSequence.swift 2021-11-09 17:18:24 -08:00
Alex Martini
cd97ed714a Cherry pick Swift 5.5 doc changes in AsyncStream.swift 2021-11-09 17:18:24 -08:00
Alex Martini
64ab9dda79 Cherry pick Swift 5.5 doc changes in AsyncSequence.swift 2021-11-09 15:34:12 -08:00
Alex Martini
75dd98de42 Cherry pick Swift 5.5 doc changes in AsyncIteratorProtocol.swift 2021-11-09 15:31:29 -08:00
swift-ci
95129274bb Merge pull request #39817 from AtariDreams/unsafesendable 2021-11-05 17:44:37 -07:00
Karoy Lorentey
2732765096 [CMake] Introduce availability macros for all known stdlib releases
Introduce "SwiftStdlib x.y"-style availability macros for all known releases of the stdlib, adding them to the swift flags of all Swift libraries and tests.
2021-10-28 18:31:54 -07:00
Karoy Lorentey
47956908b7 [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (usages)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust macro usages accordingly.
2021-10-28 14:36:36 -07:00
Karoy Lorentey
fb090fde5e [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (definitions)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust the definition of the SwiftStdlib availability macro accordingly.
2021-10-28 14:36:21 -07:00
Doug Gregor
9e41e37e76 Merge pull request #39935 from DougGregor/watchos-noasyncframepointer-backdeploy
Disable the definition and use of swift_async_extendedFramePointerFlags on watchOS
2021-10-27 16:26:13 -07:00
Doug Gregor
26b7cbc4ae Define swift_async_extendedFramePointerFlags for the watchOS simulator 2021-10-27 12:04:20 -07:00
Doug Gregor
4aca32c0a4 Disable the definition and use of swift_async_extendedFramePointerFlags on watchOS
The asm definition of `swift_async_extendedFramePointerFlags` prevents
the use of bitcode with the back-deployment libraries, so remove the
definition and use of this symbol from watchOS binaries entirely.
Instead, always force the async frame bit to be set. This trades off
backtraces on older OS's for debuggability of newer ones. If it causes
problems, it can be disabled via the option
`-swift-async-frame-pointer=never`.

Fixes rdar://84687579.
2021-10-26 22:26:37 -07:00
Mike Ash
c60b68608c [Concurrency] Re-fix ABI regression in task groups due to Sendable requirements.
There was an attempted fix in bed3c4b313 but it had extra underscores at the start of the @_silgen_name identifiers.

rdar://83617067
2021-10-26 11:40:52 -04:00
Doug Gregor
48eab6d732 Merge pull request #39872 from DougGregor/mainactor-run-hop-back 2021-10-22 17:21:04 -07:00
Doug Gregor
420e21a287 Fix the other implementation, too. 2021-10-22 08:39:22 -07:00
Doug Gregor
2850b65bd9 Simplify implementation and fix a test 2021-10-22 08:30:50 -07:00
Doug Gregor
5f9721c7fb Ensure that we hop off the main actor after MainActor.run.
Asynchronous functions isolated to global actors hop to the global at
the beginning of the function but do not hop back on return. For
`MainActor.run`, this means that we would not "hop back" off the main
actor after executing the closure, which lead to too much code running
on the main thread. Dropping the "async" ensures that we hop back.
While we my also want the general "hop back" semantics for
asynchronous actor-isolated functions, for now this addresses the
problem with `MainActor.run`.

Fixes rdar://82138050.
2021-10-21 23:26:02 -07:00
Kavon Farvardin
006e2b446b Replace destoryDistributedActor builtin with destroyDefaultActor
Currently, they both end up doing the exact same thing, so there's
no need for both.
2021-10-21 19:41:31 -07:00
Arnold Schwaighofer
68b9ccc4ad Make sure that the future fragment's storage pointer is properly aligned 2021-10-20 00:52:07 -04:00
Rose
1415739caa Remove unused variable 2021-10-19 17:17:20 -04:00
Doug Gregor
307380ef9d Use the proper install name for back-deployed concurrency on macCatalyst.
Fixes rdar://84393581.
2021-10-18 16:46:33 -07:00
Saleem Abdulrasool
701130a5ee Update GlobalExecutor.cpp (#39798)
Correct the conditional include for non-Apple targets.  This would previously always resolve to false.
2021-10-18 10:21:48 +09:00
Konrad `ktoso` Malawski
52bde17e3b [Concurrency] set queue width on all non-apple platforms, not just linux (#39764) 2021-10-16 15:33:07 +09:00
Doug Gregor
6d2414ca4e Merge pull request #39732 from ktoso/wip-limit-width-linux
[Concurrency] Limit queue width with set_width SPI call on linux
2021-10-14 09:46:51 -07:00
Konrad `ktoso` Malawski
8578d225f7 [Concurrency] Limit cooperative queue width with set_width on linux 2021-10-14 21:05:30 +09:00
Doug Gregor
19e3f640f7 Drop unintended @_transparent. 2021-10-13 11:44:20 -07:00
Doug Gregor
c8315682db Make sure that Task.isCancelled fix works on older OSs.
Part of rdar://84146091 & SR-15309.
2021-10-13 10:25:04 -07:00
Konrad `ktoso` Malawski
737962e844 [Concurrency] SR-15309: Fix instance task.isCancelled impl to use _task (#39710) 2021-10-13 16:16:58 +09:00
Doug Gregor
5b2f36aa89 Merge pull request #39707 from DougGregor/concurrency-abi-sendable-fix 2021-10-12 21:14:01 -07:00
Doug Gregor
bed3c4b313 Fix ABI regression in task groups due to Sendable requirements.
Top-level functions still encode inferred requirements in the mangled name.
In this case, `Sendable` has no ABI impact beyond the effect on the mangled
name, so fix the mangled names to maintain ABI.

Fixes rdar://83617067.
2021-10-12 15:26:19 -07:00
Doug Gregor
ed06fdebd0 Revert "Allow AsyncSequence operators to be inlined in their construction (#38310)"
This reverts commit 6a80196da3.
2021-10-12 11:31:49 -07:00
Doug Gregor
5868ae9160 Stop re-exporting SwiftNativeNSObject in libswift_Concurrency.
We can't start doing this now.
2021-10-05 12:57:09 -07:00
Evan Wilde
d376ee9989 Run first thunk of Async main synchronously
This patch updates the asynchronous main function to run the first thunk
of the function synchronously through a call to `swift_job_run`.

The runloop is killed by exiting or aborting the task that it is running
on. As such, we need to ensure that the task contains an async function
that either calls exit explicitly or aborts. The AsyncEntryPoint, that
contains this code, was added in the previous patch. This patch adds the
pieces for the actual implementation of this behaviour as well as adding
the necessary code to start the runloop.

There are now four layers of main functions before hitting the "real"
code.

@main: This is the actual main entrypoint of the program. This
constructs the task containing @async_main, grabs the main executor,
runs swift_job_run to run the first part synchronously, and finally
kicks off the runloop with a call to _asyncMainDrainQueue. This is
generated in the call to `emitAsyncMainThreadStart`.

@async_main: This thunk exists to ensure that the main function calls
`exit` at some point so that the runloop stops. It also handles emitting
an error if the user-written main function throws.

e.g:

```
func async_main() async -> () {
  do {
    try await Main.$main()
    exit(0)
  } catch {
    _errorInMain(error)
  }
}
```

Main.$main(): This still has the same behaviour as with the
synchronous case. It just calls `try await Main.main()` and exists to
simplify typechecking.

Main.main(): This is the actual user-specified main. It serves the same
purpose as in the synchronous, allowing the programmer to write code,
but it's async!

The control flow in `emitFunctionDefinition` is a little confusing (to
me anyway), so here it is spelled out:

If the main function is synchronous, the `constant.kind` will be a
`SILDeclRef::Kind::EntryPoint`, but the `decl` won't be async, so it
drops down to `emitArtificalTopLevel` anyway.

If the main function is async and we're generating `@main`, the
`constant.kind` will be `SILDeclRef::Kind::AsyncEntryPoint`, so we also
call `emitArtificalTopLevel`. `emitArtificalTopLevel` is responsible for
detecting whether the decl is async and deciding whether to emit code to
extract the argc/argv variables that get passed into the actual main
entrypoint to the program. If we're generating the `@async_main` body,
the kind will be `SILDeclRef::Kind::EntryPoint` and the `decl` will be
async, so we grab the mainEntryPoint decl and call
`emitAsyncMainThreadStart` to generate the wrapping code.

Note; there is a curious change in `SILLocation::getSourceLoc()`
where instead of simply checking `isFilenameAndLocation()`, I change it
to `getStorageKind() == FilenameAndLocationKind`. This is because the
SILLocation returned is to a FilenameAndLocationKind, but the actual
storage returns true for the call to `isNull()` inside of the
`isFilenameAndLocation()` call. This results in us incorrectly falling
through to the `getASTNode()` call below that, which asserts when asked
to get the AST node of a location.

I also did a little bit of refactoring in the SILGenModule for grabbing
intrinsics. Previously, there was only a `getConcurrencyIntrinsic`
function, which would only load FuncDecls out of the concurrency
module. The `exit` function is in the concurrency shims module, so I
refactored the load code to take a ModuleDecl to search from.

The emitBuiltinCreateAsyncTask function symbol is exposed from
SILGenBuiltin so that it is available from SILGenFunction. There is a
fair bit of work involved going from what is available at the SGF to
what is needed for actually calling the CreateAsyncTask builtin, so in
order to avoid additional maintenance, it's good to re-use that.
2021-10-02 16:53:06 -07:00
John McCall
a76b304f00 Allow building a concurrent libSwiftConcurrency without libdispatch
The goal here is not to eventually implement a concurrent thread
pool ourselves.  We're just making it easier for integrators who
have their own pool and don't want to use Dispatch to build the
Swift concurrency runtime.  Just hook the right functions and
you should be fine.

The necessary functions to hook are:
- swift_task_enqueueGlobal
- swift_task_enqueueGlobalAfterDelay

The following functions *would* be necessary to hook:
- swift_task_enqueueMainExecutor
- swift_task_asyncMainDrainQueue (only if you have an async main?)
However, this configuration does not currently properly support
the main executor, and so `@MainActor` should be avoided for now.

rdar://83513751
2021-10-01 02:15:03 -04:00
swift-ci
3222322112 Merge pull request #39508 from DougGregor/sendable-unsafe-continuation 2021-09-29 12:29:37 -07:00
Doug Gregor
60763a07e2 CheckedContinuation, UnsafeContinuation, and UnownedJob are Sendable
Fixes rdar://82909334.
2021-09-29 09:51:44 -07:00
Doug Gregor
b2a902796c Force the mangled name of MainActor.run to not include the Sendable constraint.
This API already shipped without the Sendable constraint, and adding the
constraint (while it's fine with the compiler) changed the mangled name of
this API. Use `@_silgen_name` to restore the old existing mangled name so
we don't break the ABI.

Fixes rdar://83644760.
2021-09-29 09:25:22 -07:00