Skip to content

Back swift_task_enqueueGlobal with public Dispatch API #34997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 11, 2020

Conversation

rjmccall
Copy link
Contributor

@rjmccall rjmccall commented Dec 8, 2020

We expect to iterate on this quite a bit, both publicly and internally, but this is a fine starting-point.

I've renamed runAsync to runAsyncAndBlock to underline very clearly what it does and why it's not long for this world. I've also had to give it a radically different implementation in an effort to make it continue to work given an actor implementation that is no longer just running all work synchronously.

The major remaining bit of actor-scheduling work is to make swift_task_enqueue actually do something sensible based on the executor it's been given; currently it's expecting a flag that IRGen simply doesn't know to set. But we may want to express this as a more general actor-to-executor projection step.

@rjmccall
Copy link
Contributor Author

rjmccall commented Dec 8, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 8, 2020

Build failed
Swift Test Linux Platform
Git Sha - 2661455384886b96a061b9673e74afcc4f7e2792

@swift-ci
Copy link
Contributor

swift-ci commented Dec 8, 2020

Build failed
Swift Test OS X Platform
Git Sha - 2661455384886b96a061b9673e74afcc4f7e2792

@@ -308,6 +306,9 @@ extension Task {
// Create the asynchronous task future.
let (task, _) = Builtin.createAsyncTaskFuture(flags.bits, nil, operation)

// Enqueue the resulting job.
_enqueueJobGlobal(Builtin.convertTaskToJob(task))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to do this for _runChildTask as well.

CMakeLists.txt Outdated
@@ -941,7 +941,7 @@ if (LLVM_ENABLE_DOXYGEN)
message(STATUS "Doxygen: enabled")
endif()

if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT OR SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing you'll need to teach _Concurrency to link against the (C) lib dispatch on Linux and Windows.

@rjmccall rjmccall force-pushed the global-actor-dispatch branch 2 times, most recently from df7bd87 to 5b2db3d Compare December 9, 2020 04:20
@rjmccall
Copy link
Contributor Author

rjmccall commented Dec 9, 2020

@swift-ci Please test

@rjmccall rjmccall marked this pull request as ready for review December 9, 2020 04:47
@DougGregor
Copy link
Member

Windows failure:

/Fostdlib\public\Concurrency\CMakeFiles\swift_Concurrency-windows-x86_64.dir\Actor.cpp.obj /Fdstdlib\public\Concurrency\CMakeFiles\swift_Concurrency-windows-x86_64.dir\ /FS -c S:\jenkins\workspace\swift-PR-windows\swift\stdlib\public\Concurrency\Actor.cpp
S:\jenkins\workspace\swift-PR-windows\swift\stdlib\public\Concurrency\Actor.cpp(1419,43): error: use of undeclared identifier 'qos_class_t'
  auto queue = dispatch_get_global_queue((qos_class_t) priority,
                                          ^

@DougGregor
Copy link
Member

Okay, I think the Windows failure is because you need to use dispatch_qos_class_t instead of qos_class_t. qos_class_t seems like the Darwin one.

@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - 5b2db3dbb91166bab98cf09e2f6fec2101f0748a

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from 5b2db3d to 4d3d562 Compare December 9, 2020 06:42
@rjmccall
Copy link
Contributor Author

rjmccall commented Dec 9, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - 4d3d562947747da1f8417e8ad68e5e6e8dd36ac4

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from 4d3d562 to f79c87a Compare December 9, 2020 09:01
@rjmccall
Copy link
Contributor Author

rjmccall commented Dec 9, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - f79c87aaee1d61321d99b51b9971b593a798979f

@rjmccall
Copy link
Contributor Author

rjmccall commented Dec 9, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - f79c87aaee1d61321d99b51b9971b593a798979f

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from f79c87a to f96a6bf Compare December 9, 2020 18:57
@rjmccall
Copy link
Contributor Author

rjmccall commented Dec 9, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2020

Build failed
Swift Test OS X Platform
Git Sha - f96a6bf3233cfbd783efb1c60957b21e50532a0f

@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - f96a6bf3233cfbd783efb1c60957b21e50532a0f

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from f96a6bf to 3cbb4b8 Compare December 9, 2020 21:26
@rjmccall
Copy link
Contributor Author

rjmccall commented Dec 9, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - 3cbb4b8ad6ceba6a28d05640f89a597a071abbb7

@rjmccall
Copy link
Contributor Author

rjmccall commented Dec 9, 2020

@swift-ci Please test

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from 0070c27 to b14af23 Compare December 10, 2020 00:10
@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9f877852156f23b7d6591cc495a0cecd0d5d3cc4

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 9f877852156f23b7d6591cc495a0cecd0d5d3cc4

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from 9f87785 to be5a66d Compare December 10, 2020 07:39
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from be5a66d to 0d368ec Compare December 10, 2020 08:33
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@rjmccall
Copy link
Contributor Author

Okay, there's a remaining test failure on Windows, but a bunch of work is blocking on this, so I marked the test as unsupported and filed rdar://72171028 to fix it post-commit.

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 0d368ecfe565a53d74f14b1b0940b6a96bdbaab6

@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from 79f0ad3 to 2f7636a Compare December 10, 2020 19:28
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2f7636ad3a30089a0db6d3bd3f7d028c754ab967

@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from 2f7636a to c5fcaef Compare December 10, 2020 20:28
@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2f7636ad3a30089a0db6d3bd3f7d028c754ab967

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2f7636ad3a30089a0db6d3bd3f7d028c754ab967

@rjmccall
Copy link
Contributor Author

@swift-ci Please test Windows

@rjmccall rjmccall force-pushed the global-actor-dispatch branch from c5fcaef to f788445 Compare December 10, 2020 22:09
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

We expect to iterate on this quite a bit, both publicly
and internally, but this is a fine starting-point.

I've renamed runAsync to runAsyncAndBlock to underline
very clearly what it does and why it's not long for this
world.  I've also had to give it a radically different
implementation in an effort to make it continue to work
given an actor implementation that is no longer just
running all work synchronously.

The major remaining bit of actor-scheduling work is to
make swift_task_enqueue actually do something sensible
based on the executor it's been given; currently it's
expecting a flag that IRGen simply doesn't know to set.
It would be more abstractly correct if this got DI support so
that we destroy the member if the constructor terminates
abnormally, but we can get to that later.
Currently, the only thing in the system that donates a thread
to run it is swift_runAndBlockThread, but we'll probably need
others.  Nothing in the concurrency runtime should block via a
semaphore in this configuration.

As an outrageous hack, work around the layering problems with
using libdispatch from the concurrency library on non-Darwin
systems by making those systems use the cooperative global
executor.  This is only acceptable as a temporary solution
for landing this change and setting things onto the right
long-term design.
@rjmccall rjmccall force-pushed the global-actor-dispatch branch from f788445 to 7cc63f9 Compare December 11, 2020 00:19
@rjmccall
Copy link
Contributor Author

@swift-ci Please test

@rjmccall rjmccall merged commit cce0600 into swiftlang:main Dec 11, 2020
@rjmccall rjmccall deleted the global-actor-dispatch branch December 11, 2020 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants