Skip to content

Commit

Permalink
Add a default-actor bit to actor class descriptors.
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmccall committed Apr 8, 2021
1 parent 2274f7e commit 95e90ea
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -4288,6 +4288,10 @@ class TargetClassDescriptor final
return FieldOffsetVectorOffset;
}

bool isDefaultActor() const {
return this->getTypeContextDescriptorFlags().class_isDefaultActor();
}

bool hasVTable() const {
return this->getTypeContextDescriptorFlags().class_hasVTable();
}
Expand Down
11 changes: 11 additions & 0 deletions include/swift/ABI/MetadataValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,14 @@ class TypeContextDescriptorFlags : public FlagSet<uint16_t> {

// Type-specific flags:

/// Set if the class is a default actor class. Note that this is
/// based on the best knowledge available to the class; actor
/// classes with resilient superclassess might be default actors
/// without knowing it.
///
/// Only meaningful for class descriptors.
Class_IsDefaultActor = 8,

/// The kind of reference that this class makes to its resilient superclass
/// descriptor. A TypeReferenceKind.
///
Expand Down Expand Up @@ -1464,6 +1472,9 @@ class TypeContextDescriptorFlags : public FlagSet<uint16_t> {
FLAGSET_DEFINE_FLAG_ACCESSORS(Class_AreImmediateMembersNegative,
class_areImmediateMembersNegative,
class_setAreImmediateMembersNegative)
FLAGSET_DEFINE_FLAG_ACCESSORS(Class_IsDefaultActor,
class_isDefaultActor,
class_setIsDefaultActor)

FLAGSET_DEFINE_FIELD_ACCESSORS(Class_ResilientSuperclassReferenceKind,
Class_ResilientSuperclassReferenceKind_width,
Expand Down
4 changes: 4 additions & 0 deletions lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,10 @@ namespace {

if (MetadataLayout->hasResilientSuperclass())
flags.class_setHasResilientSuperclass(true);

if (getType()->isDefaultActor(IGM.getSwiftModule(),
ResilienceExpansion::Maximal))
flags.class_setIsDefaultActor(true);
}

if (ResilientSuperClassRef) {
Expand Down
13 changes: 13 additions & 0 deletions test/IRGen/async/Inputs/resilient_actor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
open actor ResilientBaseActor {
public init() {}
}

@_fixed_layout
open actor FixedSubclassOfResilientBaseActor : ResilientBaseActor {
public override init() {}
}

@_fixed_layout
open actor FixedBaseActor {
public init() {}
}
46 changes: 46 additions & 0 deletions test/IRGen/async/default_actor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-experimental-concurrency -enable-library-evolution -emit-module-path=%t/resilient_actor.swiftmodule -module-name=resilient_actor %S/Inputs/resilient_actor.swift
// RUN: %target-swift-frontend -I %t -emit-ir -enable-experimental-concurrency -enable-library-evolution %s | %IRGenFileCheck %s
// REQUIRES: concurrency

// CHECK: @"$s13default_actor1ACMn" = hidden constant
// 0x81000050: 0x01000000 IsDefaultActor
// CHECK-SAME: i32 -2130706352,

// CHECK: @"$s13default_actor1BCMn" = hidden constant
// 0x62010050: 0x02000000 IndirectTypeDescriptor + 0x01000000 IsDefaultActor
// CHECK-SAME: i32 1644232784,

// CHECK: @"$s13default_actor1CCMn" = hidden constant
// 0x62010050: 0x02000000 IndirectTypeDescriptor + 0x01000000 IsDefaultActor
// CHECK-SAME: i32 1644232784,

// CHECK: @"$s13default_actor1DCMn" = hidden constant
// 0x63010050: 0x02000000 IndirectTypeDescriptor + 0x01000000 IsDefaultActor
// CHECK-SAME: i32 1661010000,

import resilient_actor

// CHECK-LABEL: define hidden swiftcc void @"$s13default_actor1ACfD"(%T13default_actor1AC* swiftself %0)
// CHECK-NOT: ret void
// CHECK: call swiftcc void @swift_deallocObject(
// CHECK: ret void
actor A {}

// CHECK-LABEL: define hidden swiftcc void @"$s13default_actor1BCfD"(%T13default_actor1BC* swiftself %0)
// CHECK-NOT: ret void
// CHECK: call swiftcc void @swift_deallocObject(
// CHECK: ret void
actor B : ResilientBaseActor {}

// CHECK-LABEL: define hidden swiftcc void @"$s13default_actor1CCfD"(%T13default_actor1CC* swiftself %0)
// CHECK-NOT: ret void
// CHECK: call swiftcc void @swift_deallocObject(
// CHECK: ret void
actor C : FixedSubclassOfResilientBaseActor {}

// CHECK-LABEL: define hidden swiftcc void @"$s13default_actor1DCfD"(%T13default_actor1DC* swiftself %0)
// CHECK-NOT: ret void
// CHECK: call swiftcc void @swift_deallocObject(
// CHECK: ret void
actor D : FixedBaseActor {}

0 comments on commit 95e90ea

Please sign in to comment.