{"id":31914,"date":"2021-03-18T20:09:23","date_gmt":"2021-03-19T00:09:23","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=31914"},"modified":"2022-05-05T13:48:04","modified_gmt":"2022-05-05T17:48:04","slug":"swift-proposal-actors","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2021\/03\/18\/swift-proposal-actors\/","title":{"rendered":"Swift Proposal: Actors"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0306-actors.md\">SE-0306<\/a> (<a href=\"https:\/\/forums.swift.org\/t\/se-0306-actors\/45734\">forum<\/a>, <a href=\"https:\/\/news.ycombinator.com\/item?id=26480922\">Hacker News<\/a>):<\/p>\n<blockquote cite=\"https:\/\/github.com\/apple\/swift-evolution\/blob\/main\/proposals\/0306-actors.md\"><p>Actors allow you as a programmer to declare that a bag of state is held within a concurrency domain and then define multiple operations that act upon it. Each actor protects its own data through <em>data isolation<\/em>, ensuring that only a single thread will access that data at a given time, even when many clients are concurrently making requests of the actor. As part of the Swift Concurrency Model, actors provide the same race and memory safety properties as structured concurrency, but provide the familiar abstraction and reuse features that other explicitly declared types in Swift enjoy.<\/p><p>[&#8230;]<\/p><p>As a special exception to the rule that an actor can only inherit from another actor, an actor can inherit from <code>NSObject<\/code>. This allows actors to themselves be declared <code>@objc<\/code>, and implicitly provides conformance to <code>NSObjectProtocol<\/code>[&#8230;]<\/p><p>[&#8230;]<\/p><p>Like classes, actors as proposed allow inheritance. However, actors and classes cannot be co-mingled in an inheritance hierarchy, so there are essentially two different kinds of type hierarchies. It has been <a href=\"https:\/\/docs.google.com\/document\/d\/14e3p6yBt1kPrakLcEHV4C9mqNBkNibXIZsozdZ6E71c\/edit#\">proposed<\/a> that actors should not permit inheritance at all, because doing so would simplify actors: features such as method overriding, initializer inheritance, required and convenience initializers, and inheritance of protocol conformances would not need to be specified, and users would not need to consider them. The <a href=\"https:\/\/forums.swift.org\/t\/actors-are-reference-types-but-why-classes\/42281\">discussion thread<\/a> on the proposal to eliminate inheritance provides several reasons to keep actor inheritance[&#8230;]<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/02\/22\/swift-proposal-concurrentvalue-and-concurrent-closures\/\">Swift Proposal: ConcurrentValue and @concurrent Closures<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/01\/20\/swift-asyncsequence\/\">Swift AsyncSequence<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/12\/11\/swift-concurrency-interoperability-with-objective-c\/\">Swift Concurrency Interoperability With Objective-C<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/12\/07\/swift-proposal-for-async-await\/\">Swift Proposal for async\/await<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2020\/11\/03\/swift-concurrency-roadmap\/\">Swift Concurrency Roadmap<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>SE-0306 (forum, Hacker News): Actors allow you as a programmer to declare that a bag of state is held within a concurrency domain and then define multiple operations that act upon it. Each actor protects its own data through data isolation, ensuring that only a single thread will access that data at a given time, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2021-03-19T00:09:26Z","apple_news_api_id":"253f3d47-22d4-4284-9bf1-a0964259fd89","apple_news_api_modified_at":"2022-05-05T17:48:08Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAA==","apple_news_api_share_url":"https:\/\/apple.news\/AJT89RyLUQoSb8aCWQln9iQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[800,46,71,2200,901],"class_list":["post-31914","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-concurrency","tag-languagedesign","tag-programming","tag-swift-concurrency","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/31914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=31914"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/31914\/revisions"}],"predecessor-version":[{"id":31915,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/31914\/revisions\/31915"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=31914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=31914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=31914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}