Skip to content

[Concurrency] Fix crash when actor is dynamically subclassed. #67681

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 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion stdlib/public/BackDeployConcurrency/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,8 +1712,10 @@ static bool isDefaultActorClass(const ClassMetadata *metadata) {
assert(metadata->isTypeMetadata());
while (true) {
// Trust the class descriptor if it says it's a default actor.
if (metadata->getDescription()->isDefaultActor())
if (!metadata->isArtificialSubclass() &&
metadata->getDescription()->isDefaultActor()) {
return true;
}

// Go to the superclass.
metadata = metadata->Superclass;
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/Concurrency/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,8 @@ static bool isDefaultActorClass(const ClassMetadata *metadata) {
assert(metadata->isTypeMetadata());
while (true) {
// Trust the class descriptor if it says it's a default actor.
if (metadata->getDescription()->isDefaultActor()) {
if (!metadata->isArtificialSubclass() &&
metadata->getDescription()->isDefaultActor()) {
return true;
}

Expand Down
33 changes: 33 additions & 0 deletions test/Concurrency/Runtime/actor_dynamic_subclass.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -parse-as-library)

// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: objc_interop

// UNSUPPORTED: back_deployment_runtime
// UNSUPPORTED: use_os_stdlib

// Make sure the concurrency runtime tolerates dynamically-subclassed actors.

import ObjectiveC

actor Foo: NSObject {
var x = 0

func doit() async {
x += 1
try! await Task.sleep(nanoseconds: 1000)
x += 1
}
}

@main
enum Main {
static func main() async {
let FooSub = objc_allocateClassPair(Foo.self, "FooSub", 0) as! Foo.Type
objc_registerClassPair(FooSub)
let foosub = FooSub.init()
await foosub.doit()
}
}