mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ASTGen] Transform @_inheritActorContext into a custom attribute with an optional modifier
This commit is contained in:
@@ -1254,6 +1254,18 @@ BridgedNonisolatedAttr_createParsed(BridgedASTContext cContext,
|
||||
BridgedSourceRange cRange,
|
||||
BridgedNonIsolatedModifier modifier);
|
||||
|
||||
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedInheritActorContextModifier {
|
||||
BridgedInheritActorContextModifierNone,
|
||||
BridgedInheritActorContextModifierAlways,
|
||||
};
|
||||
|
||||
SWIFT_NAME("BridgedInheritActorContextAttr.createParsed(_:atLoc:range:modifier:)")
|
||||
BridgedInheritActorContextAttr
|
||||
BridgedInheritActorContextAttr_createParsed(BridgedASTContext cContext,
|
||||
BridgedSourceLoc cAtLoc,
|
||||
BridgedSourceRange cRange,
|
||||
BridgedInheritActorContextModifier modifier);
|
||||
|
||||
SWIFT_NAME("BridgedObjCAttr.createParsedUnnamed(_:atLoc:attrNameLoc:)")
|
||||
BridgedObjCAttr
|
||||
BridgedObjCAttr_createParsedUnnamed(BridgedASTContext cContext,
|
||||
|
||||
@@ -649,6 +649,25 @@ BridgedNonisolatedAttr_createParsed(BridgedASTContext cContext,
|
||||
/*implicit=*/false);
|
||||
}
|
||||
|
||||
static InheritActorContextModifier
|
||||
unbridged(BridgedInheritActorContextModifier modifier) {
|
||||
switch (modifier) {
|
||||
case BridgedInheritActorContextModifierNone:
|
||||
return InheritActorContextModifier::None;
|
||||
case BridgedInheritActorContextModifierAlways:
|
||||
return InheritActorContextModifier::Always;
|
||||
}
|
||||
llvm_unreachable("unhandled enum value");
|
||||
}
|
||||
|
||||
BridgedInheritActorContextAttr BridgedInheritActorContextAttr_createParsed(
|
||||
BridgedASTContext cContext, BridgedSourceLoc cAtLoc,
|
||||
BridgedSourceRange cRange, BridgedInheritActorContextModifier modifier) {
|
||||
return new (cContext.unbridged()) InheritActorContextAttr(
|
||||
cAtLoc.unbridged(), cRange.unbridged(), unbridged(modifier),
|
||||
/*implicit=*/false);
|
||||
}
|
||||
|
||||
BridgedObjCAttr
|
||||
BridgedObjCAttr_createParsedUnnamed(BridgedASTContext cContext,
|
||||
BridgedSourceLoc cAtLoc,
|
||||
|
||||
@@ -249,7 +249,6 @@ extension ASTGenVisitor {
|
||||
.ibSegueAction,
|
||||
.implementationOnly,
|
||||
.implicitSelfCapture,
|
||||
.inheritActorContext,
|
||||
.inheritsConvenienceInitializers,
|
||||
.inlinable,
|
||||
.isolated,
|
||||
@@ -312,6 +311,9 @@ extension ASTGenVisitor {
|
||||
case .referenceOwnership:
|
||||
// TODO: Diagnose.
|
||||
return handle(self.generateReferenceOwnershipAttr(attribute: node, attrName: attrName)?.asDeclAttribute)
|
||||
case .inheritActorContext:
|
||||
return handle(self.generateInheritActorContextAttr(attribute: node)?.asDeclAttribute)
|
||||
|
||||
case .async,
|
||||
.consuming,
|
||||
.borrowing,
|
||||
@@ -1411,6 +1413,28 @@ extension ASTGenVisitor {
|
||||
)
|
||||
}
|
||||
|
||||
func generateInheritActorContextAttr(attribute node: AttributeSyntax) -> BridgedInheritActorContextAttr? {
|
||||
let modifier: BridgedInheritActorContextModifier? = self.generateSingleAttrOption(
|
||||
attribute: node,
|
||||
{
|
||||
switch $0.rawText {
|
||||
case "always": return .always
|
||||
default: return nil
|
||||
}
|
||||
},
|
||||
valueIfOmitted: BridgedInheritActorContextModifier.none
|
||||
)
|
||||
guard let modifier else {
|
||||
return nil
|
||||
}
|
||||
return .createParsed(
|
||||
self.ctx,
|
||||
atLoc: self.generateSourceLoc(node.atSign),
|
||||
range: self.generateAttrSourceRange(node),
|
||||
modifier: modifier
|
||||
)
|
||||
}
|
||||
|
||||
/// E.g.:
|
||||
/// ```
|
||||
/// @objc
|
||||
|
||||
@@ -256,3 +256,6 @@ struct LayoutOuter {
|
||||
struct AnyEraser: EraserProto {
|
||||
init<T: EraserProto>(erasing: T) {}
|
||||
}
|
||||
|
||||
func takeNone(@_inheritActorContext param: () async -> ()) { }
|
||||
func takeAlways(@_inheritActorContext(always) param: () async -> ()) { }
|
||||
|
||||
Reference in New Issue
Block a user