Skip to content

Commit 7484f01

Browse files
authored
Merge pull request swiftlang#79504 from xedin/execution-caller-mangling
[Mangling] Mangle presence of `@execution(caller)` in a function type
2 parents 18a9987 + 1067ead commit 7484f01

File tree

15 files changed

+72
-3
lines changed

15 files changed

+72
-3
lines changed

docs/ABI/Mangling.rst

+3
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,9 @@ Types
756756
function-isolation ::= type 'YA' // @isolated(any) on function type
757757
sending-result ::= 'YT' // -> sending T
758758
#endif
759+
#if SWIFT_RUNTIME_VERSION >= 6.2
760+
function-isolation :== 'YC' // @execution(caller) on function type
761+
#endif
759762
differentiable ::= 'Yjf' // @differentiable(_forward) on function type
760763
differentiable ::= 'Yjr' // @differentiable(reverse) on function type
761764
differentiable ::= 'Yjd' // @differentiable on function type

include/swift/ABI/MetadataValues.h

+11
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ class TargetExtendedFunctionTypeFlags {
12221222

12231223
// Values for the enumerated isolation kinds
12241224
IsolatedAny = 0x00000002U,
1225+
NonIsolatedCaller = 0x00000004U,
12251226

12261227
// Values if we have a sending result.
12271228
HasSendingResult = 0x00000010U,
@@ -1253,6 +1254,12 @@ class TargetExtendedFunctionTypeFlags {
12531254
(Data & ~IsolationMask) | IsolatedAny);
12541255
}
12551256

1257+
const TargetExtendedFunctionTypeFlags<int_type>
1258+
withNonIsolatedCaller() const {
1259+
return TargetExtendedFunctionTypeFlags<int_type>((Data & ~IsolationMask) |
1260+
NonIsolatedCaller);
1261+
}
1262+
12561263
const TargetExtendedFunctionTypeFlags<int_type>
12571264
withSendingResult(bool newValue = true) const {
12581265
return TargetExtendedFunctionTypeFlags<int_type>(
@@ -1273,6 +1280,10 @@ class TargetExtendedFunctionTypeFlags {
12731280
return (Data & IsolationMask) == IsolatedAny;
12741281
}
12751282

1283+
bool isNonIsolatedCaller() const {
1284+
return (Data & IsolationMask) == NonIsolatedCaller;
1285+
}
1286+
12761287
bool hasSendingResult() const {
12771288
return bool(Data & HasSendingResult);
12781289
}

include/swift/AST/ExtInfo.h

+3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class FunctionTypeIsolation {
123123
bool isErased() const {
124124
return getKind() == Kind::Erased;
125125
}
126+
bool isNonIsolatedCaller() const {
127+
return getKind() == Kind::NonIsolatedCaller;
128+
}
126129

127130
// The opaque accessors below are just for the benefit of ExtInfoBuilder,
128131
// which finds it convenient to break down the type separately. Normal

include/swift/Demangling/DemangleNodes.def

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ NODE(Isolated)
157157
CONTEXT_NODE(IsolatedDeallocator)
158158
NODE(Sending)
159159
NODE(IsolatedAnyFunctionType)
160+
NODE(NonIsolatedCallerFunctionType)
160161
NODE(SendingResultFunctionType)
161162
NODE(KeyPathGetterThunkHelper)
162163
NODE(KeyPathSetterThunkHelper)

include/swift/Demangling/TypeDecoder.h

+4
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,10 @@ class TypeDecoder {
941941
NodeKind::IsolatedAnyFunctionType) {
942942
extFlags = extFlags.withIsolatedAny();
943943
++firstChildIdx;
944+
} else if (Node->getChild(firstChildIdx)->getKind() ==
945+
NodeKind::NonIsolatedCallerFunctionType) {
946+
extFlags = extFlags.withNonIsolatedCaller();
947+
++firstChildIdx;
944948
}
945949

946950
FunctionMetadataDifferentiabilityKind diffKind;

lib/AST/ASTDemangler.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ Type ASTBuilder::createFunctionType(
460460
isolation = FunctionTypeIsolation::forGlobalActor(globalActor);
461461
} else if (extFlags.isIsolatedAny()) {
462462
isolation = FunctionTypeIsolation::forErased();
463+
} else if (extFlags.isNonIsolatedCaller()) {
464+
isolation = FunctionTypeIsolation::forNonIsolatedCaller();
463465
}
464466

465467
auto noescape =

lib/AST/ASTMangler.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -3287,8 +3287,7 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
32873287
break;
32883288

32893289
case FunctionTypeIsolation::Kind::NonIsolatedCaller:
3290-
// TODO: We need a special mangling for this to
3291-
// make it distinct from the `@execution(concurrent)`.
3290+
appendOperator("YC");
32923291
break;
32933292
}
32943293

lib/Demangling/Demangler.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ NodePointer Demangler::demangleTypeAnnotation() {
988988
case 'c':
989989
return createWithChild(
990990
Node::Kind::GlobalActorFunctionType, popTypeAndGetChild());
991+
case 'C':
992+
return createNode(Node::Kind::NonIsolatedCallerFunctionType);
991993
case 'i':
992994
return createType(
993995
createWithChild(Node::Kind::Isolated, popTypeAndGetChild()));
@@ -1654,7 +1656,8 @@ NodePointer Demangler::popFunctionType(Node::Kind kind, bool hasClangType) {
16541656
// function-isolation?
16551657
auto isFunctionIsolation = [](Node::Kind kind) {
16561658
return kind == Node::Kind::GlobalActorFunctionType ||
1657-
kind == Node::Kind::IsolatedAnyFunctionType;
1659+
kind == Node::Kind::IsolatedAnyFunctionType ||
1660+
kind == Node::Kind::NonIsolatedCallerFunctionType;
16581661
};
16591662
addChild(FuncType, popNode(isFunctionIsolation));
16601663

@@ -1717,6 +1720,9 @@ NodePointer Demangler::popFunctionParamLabels(NodePointer Type) {
17171720
if (FuncType->getChild(FirstChildIdx)->getKind()
17181721
== Node::Kind::IsolatedAnyFunctionType)
17191722
++FirstChildIdx;
1723+
if (FuncType->getChild(FirstChildIdx)->getKind()
1724+
== Node::Kind::NonIsolatedCallerFunctionType)
1725+
++FirstChildIdx;
17201726
if (FuncType->getChild(FirstChildIdx)->getKind()
17211727
== Node::Kind::DifferentiableFunctionType)
17221728
++FirstChildIdx;

lib/Demangling/NodePrinter.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ class NodePrinter {
572572
case Node::Kind::DifferentiableFunctionType:
573573
case Node::Kind::GlobalActorFunctionType:
574574
case Node::Kind::IsolatedAnyFunctionType:
575+
case Node::Kind::NonIsolatedCallerFunctionType:
575576
case Node::Kind::SendingResultFunctionType:
576577
case Node::Kind::AsyncAnnotation:
577578
case Node::Kind::ThrowsAnnotation:
@@ -915,6 +916,14 @@ class NodePrinter {
915916
print(node->getChild(startIndex), depth + 1);
916917
++startIndex;
917918
}
919+
920+
Node *nonIsolatedCallerNode = nullptr;
921+
if (node->getChild(startIndex)->getKind() ==
922+
Node::Kind::NonIsolatedCallerFunctionType) {
923+
nonIsolatedCallerNode = node->getChild(startIndex);
924+
++startIndex;
925+
}
926+
918927
if (node->getChild(startIndex)->getKind() ==
919928
Node::Kind::GlobalActorFunctionType) {
920929
print(node->getChild(startIndex), depth + 1);
@@ -963,6 +972,9 @@ class NodePrinter {
963972
break;
964973
}
965974

975+
if (nonIsolatedCallerNode)
976+
print(nonIsolatedCallerNode, depth + 1);
977+
966978
if (isSendable)
967979
Printer << "@Sendable ";
968980

@@ -3108,6 +3120,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
31083120
case Node::Kind::IsolatedAnyFunctionType:
31093121
Printer << "@isolated(any) ";
31103122
return nullptr;
3123+
case Node::Kind::NonIsolatedCallerFunctionType:
3124+
Printer << "@execution(caller) ";
3125+
return nullptr;
31113126
case Node::Kind::SendingResultFunctionType:
31123127
Printer << "sending ";
31133128
return nullptr;

lib/Demangling/OldRemangler.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,12 @@ ManglingError Remangler::mangleIsolatedAnyFunctionType(Node *node,
858858
return ManglingError::Success;
859859
}
860860

861+
ManglingError Remangler::mangleNonIsolatedCallerFunctionType(Node *node,
862+
unsigned depth) {
863+
Buffer << "YC";
864+
return ManglingError::Success;
865+
}
866+
861867
ManglingError Remangler::mangleSendingResultFunctionType(Node *node,
862868
unsigned depth) {
863869
Buffer << "YT";

lib/Demangling/Remangler.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -3475,6 +3475,12 @@ ManglingError Remangler::mangleIsolatedAnyFunctionType(Node *node,
34753475
return ManglingError::Success;
34763476
}
34773477

3478+
ManglingError Remangler::mangleNonIsolatedCallerFunctionType(Node *node,
3479+
unsigned depth) {
3480+
Buffer << "YC";
3481+
return ManglingError::Success;
3482+
}
3483+
34783484
ManglingError Remangler::mangleSendingResultFunctionType(Node *node,
34793485
unsigned depth) {
34803486
Buffer << "YT";

lib/IRGen/MetadataRequest.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,9 @@ getFunctionTypeFlags(CanFunctionType type) {
14631463
if (isolation.isErased())
14641464
extFlags = extFlags.withIsolatedAny();
14651465

1466+
if (isolation.isNonIsolatedCaller())
1467+
extFlags = extFlags.withNonIsolatedCaller();
1468+
14661469
auto flags = FunctionTypeFlags()
14671470
.withConvention(metadataConvention)
14681471
.withAsync(type->isAsync())

stdlib/public/RemoteInspection/TypeRef.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ class PrintTypeRef : public TypeRefVisitor<PrintTypeRef, void> {
178178
if (F->getExtFlags().hasSendingResult()) {
179179
printField("", "sending-result");
180180
}
181+
if (F->getExtFlags().isNonIsolatedCaller()) {
182+
printField("execution", "caller");
183+
}
181184

182185
stream << "\n";
183186
Indent += 2;
@@ -804,6 +807,9 @@ class DemanglingForTypeRef
804807
} else if (F->getExtFlags().isIsolatedAny()) {
805808
auto node = Dem.createNode(Node::Kind::IsolatedAnyFunctionType);
806809
funcNode->addChild(node, Dem);
810+
} else if (F->getExtFlags().isNonIsolatedCaller()) {
811+
auto node = Dem.createNode(Node::Kind::NonIsolatedCallerFunctionType);
812+
funcNode->addChild(node, Dem);
807813
}
808814

809815
if (F->getFlags().isDifferentiable()) {

stdlib/public/runtime/Demangle.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,9 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
761761
} else if (func->getExtendedFlags().isIsolatedAny()) {
762762
funcNode->addChild(Dem.createNode(
763763
Node::Kind::IsolatedAnyFunctionType), Dem);
764+
} else if (func->getExtendedFlags().isNonIsolatedCaller()) {
765+
funcNode->addChild(Dem.createNode(
766+
Node::Kind::NonIsolatedCallerFunctionType), Dem);
764767
}
765768
switch (func->getDifferentiabilityKind().Value) {
766769
case FunctionMetadataDifferentiabilityKind::NonDifferentiable:

test/Demangle/Inputs/manglings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -487,3 +487,4 @@ $s3red7MyActorC3runyxxyYaKACYcYTXEYaKlFZ ---> static red.MyActor.run<A>(@red.MyA
487487
$s3red7MyActorC3runyxxyYaKYAYTXEYaKlFZ ---> static red.MyActor.run<A>(@isolated(any) () async throws -> sending A) async throws -> A
488488
$s7ToolKit10TypedValueOACs5Error_pIgHTnTrzo_A2CsAD_pIegHiTrzr_TR ---> {T:} reabstraction thunk helper from @callee_guaranteed @async (@in_guaranteed sending ToolKit.TypedValue) -> sending (@out ToolKit.TypedValue, @error @owned Swift.Error) to @escaping @callee_guaranteed @async (@in sending ToolKit.TypedValue) -> (@out ToolKit.TypedValue, @error @out Swift.Error)
489489
$s16sending_mangling16NonSendableKlassCACIegTiTr_A2CIegTxTo_TR ---> {T:} reabstraction thunk helper from @escaping @callee_guaranteed (@in sending sending_mangling.NonSendableKlass) -> sending (@out sending_mangling.NonSendableKlass) to @escaping @callee_guaranteed (@owned sending sending_mangling.NonSendableKlass) -> sending (@owned sending_mangling.NonSendableKlass)
490+
$s3red7MyActorC3runyxxyYaKYCXEYaKlFZ ---> static red.MyActor.run<A>(@execution(caller) () async throws -> A) async throws -> A

0 commit comments

Comments
 (0)