Skip to content
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

[SR-13818] Concurrency: compiler crash #56215

Open
igor-makarov opened this issue Nov 3, 2020 · 4 comments
Open

[SR-13818] Concurrency: compiler crash #56215

igor-makarov opened this issue Nov 3, 2020 · 4 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@igor-makarov
Copy link

Previous ID SR-13818
Radar rdar://71247879
Original Reporter @igor-makarov
Type Bug
Environment

Latest `main` snapshot.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @DougGregor
Priority Medium

md5: 804fbff6a0fff303583f552386c04579

Issue Description:

Compile with `main` snapshot with flags `-Xfrontend -enable-experimental-concurrency`

import Foundation

@asyncHandler
func handle(task: () async throws -> String) {
    do {
        let x = try await task()
    } catch let e {
    }
}
@DougGregor
Copy link
Member

Oh, this is because we haven't implemented code generation for `@asyncHandler`

@igor-makarov
Copy link
Author

@DougGregor I'm gonna venture that there can't be a workaround, because that's what `@asyncHandler` was intended for, workarounds...

Let me know when this gets unblocked. The reason I'm writing this weird code is because I was trying to implement a RxSwift bridging layer to Swift-async.

@DougGregor
Copy link
Member

In general, code generation for concurrency isn't implemented yet. It's coming up in stages, but right now the GitHub main is mostly useful for type checking. You can dodge the `@asyncHandler` issue by making it a synchronous function that does `Task.runDetached`.

@igor-makarov
Copy link
Author

@DougGregor what do you think makes this crash?

extension Array {
    func mapAsync<T>(_ transform: (Element) async throws -> T) async rethrows -> [T] {
        try await Task.withGroup(resultType: (Int, T).self) { group in
            var results = [T?].init(repeating: nil, count: self.count)
            for i in self.indices {
                await group.add {
                    (i, try await transform(self[i]))
                }
            }
            while let (index, result) = await try group.next() {
                results[index] = result
            }
            return results.map { $0! }
        }
    }
}

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants