Commit Graph

464 Commits

Author SHA1 Message Date
John McCall
186c53000d Introduce basic support for custom executors.
- Introduce an UnownedSerialExecutor type into the concurrency library.
- Create a SerialExecutor protocol which allows an executor type to
  change how it executes jobs.
- Add an unownedExecutor requirement to the Actor protocol.
- Change the ABI for ExecutorRef so that it stores a SerialExecutor
  witness table pointer in the implementation field.  This effectively
  makes ExecutorRef an `unowned(unsafe) SerialExecutor`, except that
  default actors are represented without a witness table pointer (just
  a bit-pattern).
- Synthesize the unownedExecutor method for default actors (i.e. actors
  that don't provide an unownedExecutor property).
- Make synthesized unownedExecutor properties `final`, and give them
  a semantics attribute specifying that they're for default actors.
- Split `Builtin.buildSerialExecutorRef` into a few more precise
  builtins.  We're not using the main-actor one yet, though.

Pitch thread:
  https://forums.swift.org/t/support-custom-executors-in-swift-concurrency/44425
2021-04-30 03:11:56 -04:00
Doug Gregor
a2cdef73a6 [SE-0306] Enable actors by default.
With the acceptance of SE-0306, enable actors by default and add a
ChangeLog entry.

Tracked by rdar://77223763.
2021-04-27 12:25:41 -07:00
swift-ci
a11acd3140 Merge pull request #37023 from DougGregor/builtin-executor-feature 2021-04-22 19:24:28 -07:00
Doug Gregor
0d5ec20549 [Concurrency] Put Builtin.Executor type behind a feature flag.
Fixes rdar://77041644.
2021-04-22 16:25:11 -07:00
Doug Gregor
cdd6ad8bfd Introduce a feature for @_inheritActorContext
Add a feature for this new attribute, and make sure we use the feature
guard for functions that use it, e.g., the new `async`.

Finishes rdar://76927008.
2021-04-22 15:49:48 -07:00
John McCall
efeb818161 Clean up the TaskGroup ABI:
- stop storing the parent task in the TaskGroup at the .swift level
- make sure that swift_taskGroup_isCancelled is implied by the parent
  task being cancelled
- make the TaskGroup structs frozen
- make the withTaskGroup functions inlinable
- remove swift_taskGroup_create
- teach IRGen to allocate memory for the task group
- don't deallocate the task group in swift_taskGroup_destroy

To achieve the allocation change, introduce paired create/destroy builtins.

Furthermore, remove the _swiftRetain and _swiftRelease functions and
several calls to them.  Replace them with uses of the appropriate builtins.
I should probably change the builtins to return retained, since they're
working with a managed type, but I'll do that in a separate commit.
2021-04-09 03:06:31 -04:00
Doug Gregor
492bca113d [Module interface] Retain #if's with feature checks in inline bodies. 2021-03-30 17:56:42 -07:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
Doug Gregor
5f9b8982bd Add a feature and module interface printing support for Builtin.Job 2021-02-22 21:07:03 -08:00
Doug Gregor
e7d7585503 Add a feature for global actors & module interface support 2021-02-22 20:46:58 -08:00
Doug Gregor
f21c60928c Add feature for rethrows protocols and use it in module interface generation 2021-02-22 16:18:47 -08:00
Doug Gregor
e8375e13ee Define a feature for @concurrent functions. 2021-02-12 16:36:12 -08:00
Doug Gregor
aa139a101c [Module interface] Use features in module interface generation.
When generating a module interface, emit `#if` around any declarations
that are tied to specific, named language features. This allows module
interfaces to be processed by older Swift compilers that do not
support these newer features, such as async/await or actors.

The amount of effort required to correctly handle a new kind of
feature varies somewhat drastically based on the feature itself. The
"simple" case is where a particular declaration can only exist if a
feature is available. For example, and `async` declaration is fairly
easy to handle; a `@_marker` protocol's conformances are not.

Fixes rdar://73326633.
2021-02-08 16:01:39 -08:00
Doug Gregor
fd16deecba Introduce checking for language features via "#if $FeatureName"
Introduce some basic support for defining specific language features
that can be checked by name, e.g.,

    #if $AsyncAwait
    // use the feature
    #endif

For backward compatibility with older compilers, to actually prevent
the parser from parsing, one will have to do a Swift compiler version
check, even though the version number doesn't matter. For example:

    #if compiler(>=5.3) && $AsyncAwait
    // use the feature
    #endif
2021-02-05 15:22:02 -08:00