Skip to content

[Mangling] Mangle presence of @execution(caller) in a function type #79504

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
Feb 20, 2025
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
3 changes: 3 additions & 0 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,9 @@ Types
function-isolation ::= type 'YA' // @isolated(any) on function type
sending-result ::= 'YT' // -> sending T
#endif
#if SWIFT_RUNTIME_VERSION >= 6.2
function-isolation :== 'YC' // @execution(caller) on function type
#endif
differentiable ::= 'Yjf' // @differentiable(_forward) on function type
differentiable ::= 'Yjr' // @differentiable(reverse) on function type
differentiable ::= 'Yjd' // @differentiable on function type
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 @@ -1222,6 +1222,7 @@ class TargetExtendedFunctionTypeFlags {

// Values for the enumerated isolation kinds
IsolatedAny = 0x00000002U,
NonIsolatedCaller = 0x00000004U,

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

const TargetExtendedFunctionTypeFlags<int_type>
withNonIsolatedCaller() const {
return TargetExtendedFunctionTypeFlags<int_type>((Data & ~IsolationMask) |
NonIsolatedCaller);
}

const TargetExtendedFunctionTypeFlags<int_type>
withSendingResult(bool newValue = true) const {
return TargetExtendedFunctionTypeFlags<int_type>(
Expand All @@ -1273,6 +1280,10 @@ class TargetExtendedFunctionTypeFlags {
return (Data & IsolationMask) == IsolatedAny;
}

bool isNonIsolatedCaller() const {
return (Data & IsolationMask) == NonIsolatedCaller;
}

bool hasSendingResult() const {
return bool(Data & HasSendingResult);
}
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/ExtInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class FunctionTypeIsolation {
bool isErased() const {
return getKind() == Kind::Erased;
}
bool isNonIsolatedCaller() const {
return getKind() == Kind::NonIsolatedCaller;
}

// The opaque accessors below are just for the benefit of ExtInfoBuilder,
// which finds it convenient to break down the type separately. Normal
Expand Down
1 change: 1 addition & 0 deletions include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ NODE(Isolated)
CONTEXT_NODE(IsolatedDeallocator)
NODE(Sending)
NODE(IsolatedAnyFunctionType)
NODE(NonIsolatedCallerFunctionType)
NODE(SendingResultFunctionType)
NODE(KeyPathGetterThunkHelper)
NODE(KeyPathSetterThunkHelper)
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Demangling/TypeDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ class TypeDecoder {
NodeKind::IsolatedAnyFunctionType) {
extFlags = extFlags.withIsolatedAny();
++firstChildIdx;
} else if (Node->getChild(firstChildIdx)->getKind() ==
NodeKind::NonIsolatedCallerFunctionType) {
extFlags = extFlags.withNonIsolatedCaller();
++firstChildIdx;
}

FunctionMetadataDifferentiabilityKind diffKind;
Expand Down
2 changes: 2 additions & 0 deletions lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ Type ASTBuilder::createFunctionType(
isolation = FunctionTypeIsolation::forGlobalActor(globalActor);
} else if (extFlags.isIsolatedAny()) {
isolation = FunctionTypeIsolation::forErased();
} else if (extFlags.isNonIsolatedCaller()) {
isolation = FunctionTypeIsolation::forNonIsolatedCaller();
}

auto noescape =
Expand Down
3 changes: 1 addition & 2 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3287,8 +3287,7 @@ void ASTMangler::appendFunctionSignature(AnyFunctionType *fn,
break;

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

Expand Down
8 changes: 7 additions & 1 deletion lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ NodePointer Demangler::demangleTypeAnnotation() {
case 'c':
return createWithChild(
Node::Kind::GlobalActorFunctionType, popTypeAndGetChild());
case 'C':
return createNode(Node::Kind::NonIsolatedCallerFunctionType);
case 'i':
return createType(
createWithChild(Node::Kind::Isolated, popTypeAndGetChild()));
Expand Down Expand Up @@ -1654,7 +1656,8 @@ NodePointer Demangler::popFunctionType(Node::Kind kind, bool hasClangType) {
// function-isolation?
auto isFunctionIsolation = [](Node::Kind kind) {
return kind == Node::Kind::GlobalActorFunctionType ||
kind == Node::Kind::IsolatedAnyFunctionType;
kind == Node::Kind::IsolatedAnyFunctionType ||
kind == Node::Kind::NonIsolatedCallerFunctionType;
};
addChild(FuncType, popNode(isFunctionIsolation));

Expand Down Expand Up @@ -1717,6 +1720,9 @@ NodePointer Demangler::popFunctionParamLabels(NodePointer Type) {
if (FuncType->getChild(FirstChildIdx)->getKind()
== Node::Kind::IsolatedAnyFunctionType)
++FirstChildIdx;
if (FuncType->getChild(FirstChildIdx)->getKind()
== Node::Kind::NonIsolatedCallerFunctionType)
++FirstChildIdx;
if (FuncType->getChild(FirstChildIdx)->getKind()
== Node::Kind::DifferentiableFunctionType)
++FirstChildIdx;
Expand Down
15 changes: 15 additions & 0 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ class NodePrinter {
case Node::Kind::DifferentiableFunctionType:
case Node::Kind::GlobalActorFunctionType:
case Node::Kind::IsolatedAnyFunctionType:
case Node::Kind::NonIsolatedCallerFunctionType:
case Node::Kind::SendingResultFunctionType:
case Node::Kind::AsyncAnnotation:
case Node::Kind::ThrowsAnnotation:
Expand Down Expand Up @@ -915,6 +916,14 @@ class NodePrinter {
print(node->getChild(startIndex), depth + 1);
++startIndex;
}

Node *nonIsolatedCallerNode = nullptr;
if (node->getChild(startIndex)->getKind() ==
Node::Kind::NonIsolatedCallerFunctionType) {
nonIsolatedCallerNode = node->getChild(startIndex);
++startIndex;
}

if (node->getChild(startIndex)->getKind() ==
Node::Kind::GlobalActorFunctionType) {
print(node->getChild(startIndex), depth + 1);
Expand Down Expand Up @@ -963,6 +972,9 @@ class NodePrinter {
break;
}

if (nonIsolatedCallerNode)
print(nonIsolatedCallerNode, depth + 1);

if (isSendable)
Printer << "@Sendable ";

Expand Down Expand Up @@ -3108,6 +3120,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
case Node::Kind::IsolatedAnyFunctionType:
Printer << "@isolated(any) ";
return nullptr;
case Node::Kind::NonIsolatedCallerFunctionType:
Printer << "@execution(caller) ";
return nullptr;
case Node::Kind::SendingResultFunctionType:
Printer << "sending ";
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,12 @@ ManglingError Remangler::mangleIsolatedAnyFunctionType(Node *node,
return ManglingError::Success;
}

ManglingError Remangler::mangleNonIsolatedCallerFunctionType(Node *node,
unsigned depth) {
Buffer << "YC";
return ManglingError::Success;
}

ManglingError Remangler::mangleSendingResultFunctionType(Node *node,
unsigned depth) {
Buffer << "YT";
Expand Down
6 changes: 6 additions & 0 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,12 @@ ManglingError Remangler::mangleIsolatedAnyFunctionType(Node *node,
return ManglingError::Success;
}

ManglingError Remangler::mangleNonIsolatedCallerFunctionType(Node *node,
unsigned depth) {
Buffer << "YC";
return ManglingError::Success;
}

ManglingError Remangler::mangleSendingResultFunctionType(Node *node,
unsigned depth) {
Buffer << "YT";
Expand Down
3 changes: 3 additions & 0 deletions lib/IRGen/MetadataRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,9 @@ getFunctionTypeFlags(CanFunctionType type) {
if (isolation.isErased())
extFlags = extFlags.withIsolatedAny();

if (isolation.isNonIsolatedCaller())
extFlags = extFlags.withNonIsolatedCaller();

auto flags = FunctionTypeFlags()
.withConvention(metadataConvention)
.withAsync(type->isAsync())
Expand Down
6 changes: 6 additions & 0 deletions stdlib/public/RemoteInspection/TypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class PrintTypeRef : public TypeRefVisitor<PrintTypeRef, void> {
if (F->getExtFlags().hasSendingResult()) {
printField("", "sending-result");
}
if (F->getExtFlags().isNonIsolatedCaller()) {
printField("execution", "caller");
}

stream << "\n";
Indent += 2;
Expand Down Expand Up @@ -804,6 +807,9 @@ class DemanglingForTypeRef
} else if (F->getExtFlags().isIsolatedAny()) {
auto node = Dem.createNode(Node::Kind::IsolatedAnyFunctionType);
funcNode->addChild(node, Dem);
} else if (F->getExtFlags().isNonIsolatedCaller()) {
auto node = Dem.createNode(Node::Kind::NonIsolatedCallerFunctionType);
funcNode->addChild(node, Dem);
}

if (F->getFlags().isDifferentiable()) {
Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/runtime/Demangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,9 @@ swift::_swift_buildDemanglingForMetadata(const Metadata *type,
} else if (func->getExtendedFlags().isIsolatedAny()) {
funcNode->addChild(Dem.createNode(
Node::Kind::IsolatedAnyFunctionType), Dem);
} else if (func->getExtendedFlags().isNonIsolatedCaller()) {
funcNode->addChild(Dem.createNode(
Node::Kind::NonIsolatedCallerFunctionType), Dem);
}
switch (func->getDifferentiabilityKind().Value) {
case FunctionMetadataDifferentiabilityKind::NonDifferentiable:
Expand Down
1 change: 1 addition & 0 deletions test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -487,3 +487,4 @@ $s3red7MyActorC3runyxxyYaKACYcYTXEYaKlFZ ---> static red.MyActor.run<A>(@red.MyA
$s3red7MyActorC3runyxxyYaKYAYTXEYaKlFZ ---> static red.MyActor.run<A>(@isolated(any) () async throws -> sending A) async throws -> A
$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)
$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)
$s3red7MyActorC3runyxxyYaKYCXEYaKlFZ ---> static red.MyActor.run<A>(@execution(caller) () async throws -> A) async throws -> A