Skip to content

Experimental async/await support #112

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 23 commits into from
Jan 13, 2021
Merged

Experimental async/await support #112

merged 23 commits into from
Jan 13, 2021

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Jan 2, 2021

import JavaScriptEventLoop
import JavaScriptKit

JavaScriptEventLoop.install()
let fetch = JSObject.global.fetch.function!.async

func printZen() async {
  let result = await try! fetch("https://api.github.com/zen").object!
  let text = await try! result.asyncing.text!()
  print(text)
}

JavaScriptEventLoop.runAsync {
  await printZen()
}

Current Issues

  • Many C++ headers are copied from LLVM and Swift repository even though the runtime uses only a few interfaces.
  • No tests
  • Use of unsafe flag -enable-experimental-concurrency. If we remove it from Package.swift, users have to pass it from command line.

@github-actions
Copy link

github-actions bot commented Jan 11, 2021

Time Change: -843ms (9%) ✅

Total Time: 9,170.5ms

Test name Duration Change
Serialization/Swift Int to JavaScript 2,759.75ms -455.25ms (16%) 👏
Serialization/Swift String to JavaScript 2,966ms -284.75ms (9%)
ℹ️ View Unchanged
Test name Duration Change
Serialization/Write JavaScript number directly 190.75ms +1.25ms (0%)
Serialization/Write JavaScript string directly 198.5ms +4.25ms (2%)
Object heap/Increment and decrement RC 3,055.5ms -108.5ms (3%)

performance-action

@kateinoigakukun kateinoigakukun changed the base branch from main to next January 11, 2021 05:44
@kateinoigakukun kateinoigakukun changed the title [Do not merge] Experimental async/await support Experimental async/await support Jan 11, 2021
@kateinoigakukun kateinoigakukun marked this pull request as ready for review January 11, 2021 05:44
@MaxDesiatov
Copy link
Contributor

Do I understand correctly that after this is merged we'll require our users to use dev toolchains and to compile with experimental concurrency enabled?

@MaxDesiatov
Copy link
Contributor

Also, could we link with Swift runtime parts that are already included in the toolchain/SDK? Is a copy of it and LLVM stuff in our codebase required for this to work?

@kateinoigakukun
Copy link
Member Author

kateinoigakukun commented Jan 13, 2021

Do I understand correctly that after this is merged we'll require our users to use dev toolchains and to compile with experimental concurrency enabled?

Yes, so I'm planning to merge this to next branch which will be used to use non-stable language features.

Also, could we link with Swift runtime parts that are already included in the toolchain/SDK? Is a copy of it and LLVM stuff in our codebase required for this to work?

JavaScriptEventLoop should be linked with libswiftCore.a and libswift_Concurrency.a to work. And LLVM headers are required for including swift/ABI/Task.h.

@MaxDesiatov
Copy link
Contributor

Fair enough. I'm only worried that contents of these headers can change in a breaking way, especially given that concurrency stuff isn't ABI-stable yet, and maybe there's a better way to track them. A submodule is probably not practical due to the size of repositories that have these headers, so I don't have a better alternative to propose... Maybe some kind of scripts that pull latest versions of these headers automatically? 🤔

@kateinoigakukun
Copy link
Member Author

kateinoigakukun commented Jan 13, 2021

Yes, so I wrote a shell script to fetch headers from swiftwasm/swift repository based on .swift-version snapshot.

https://github.com/swiftwasm/JavaScriptKit/blob/366d74e82e3aa40d604ac843743bb59b9412243b/Sources/_CJavaScriptEventLoop/README
https://github.com/swiftwasm/JavaScriptKit/blob/366d74e82e/Sources/_CJavaScriptEventLoop/scripts/copy-headers

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Seems legit then 👍

@kateinoigakukun kateinoigakukun merged commit d164af8 into next Jan 13, 2021
@kateinoigakukun kateinoigakukun deleted the katei/async-promise branch January 13, 2021 14:07
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.

3 participants