Skip to content

[embedded] Initial Swift Concurrency for embedded Swift #68928

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 8 commits into from
Oct 8, 2023

Conversation

kubamracek
Copy link
Contributor

PR starts building a (simplified, cut-down) embedded version of the Swift Concurrency runtime library, implements a modified contract between the compiler and swift_task_create() that doesn't rely on metadata, and adds an executable test that exercises a simple task creation showing the setup working (!).

Note that there is definitely a lot of Swift Concurrency functionality still missing, this doesn't achieve full Swift Concurrency parity.

Major parts involved:

  • SILOptimizer rewrites CreateAsyncTask builtin to use a thin metatype instead of thick
  • IRGen of CreateAsyncTask builtin synthesizes a set of witnesses for the result type and passes that to the runtime as a new TaskOptionRecord.
  • swift_task_create() parses the new TaskOptionRecord, forms a ResultTypeInfo (data structure in the runtime can hold either a Metadata*, or the separate witnesses pass down by the compiler)
  • FutureFragment, PollResult, TaskGroup stop using Metadata* in favor of ResultTypeInfo
  • CMake for Concurrency starts building a subset of the Concurrency runtime, for macOS only for now.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@@ -141,6 +141,19 @@ class AsyncLetWithBufferTaskOptionRecord : public TaskOptionRecord {
}
};

class ResultTypeInfoTaskOptionRecord : public TaskOptionRecord {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be #if to only be for embedded, or is it useful outside of that context? Also, should this store a ResultTypeInfo rather than repeating its fields.

Copy link
Member

Choose a reason for hiding this comment

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

I was fretting about this in the definition of ResultTypeInfo. Should we have ResultTypeInfo always have the five fields, so we have consistent layout between "embedded" and non-embedded? That makes our development easier, and maybe possibly allows some level of interoperability between embedded-ish and non-embedded code, but it wastes a couple of pointers worth of storage per task.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure there's any prospect of such interoperability. In any case, the embedded side doesn't have to be ABI stable so we could fix this up later if need be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the class ifdef'd to embedded only, for now, and I'll explore the idea of using ResultTypeInfo in desktop Swift separately.

@kubamracek kubamracek force-pushed the embedded-concurrency branch from 1a0ff97 to b7415fb Compare October 3, 2023 22:06
@kubamracek
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

Overall looks good but incredibly unfortunate to have yet another #if in concurrency library... it's already messy with all the various #ifs there...

Will the embedded configuration be tested in normal smoke tests, so we don't have to hunt for fixing it afterwards?

@kubamracek
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@kubamracek
Copy link
Contributor Author

@swift-ci please test

Comment on lines +1015 to +1016
// Explicitly allowed in embedded Swift because we generate value witnesses
// (but not witness tables) for Swift Concurrency usage.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we guard this on Swift concurrency being enabled? Maybe I'm being overly paranoid, but I could see some unrelated thing asking for value witness tables, and clients that don't enable concurrency shouldn't have to pay for anything (even vwt).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the right tradeoff is to catch emitting witness tables (for which the assert is still active, a few lines below), but allow individual value witness methods (this code). Even if we somehow had a bug where unexpected value witness methods are emitted, they will be dead-stripped if there isn't a table holding them. WDYT?

Copy link
Contributor

@zoecarver zoecarver left a comment

Choose a reason for hiding this comment

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

This is so awesome!

@kubamracek
Copy link
Contributor Author

@swift-ci please test Windows platform

@kubamracek kubamracek force-pushed the embedded-concurrency branch from b111c2e to df58797 Compare October 7, 2023 03:32
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

Will the embedded configuration be tested in normal smoke tests, so we don't have to hunt for fixing it afterwards?

Yes. It will build as part of regular builds, tests will run as part of regular PR testing too.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test Windows platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
embedded Embedded Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants