Skip to content

Commit 109d6c5

Browse files
authored
Merge pull request #37584 from jckarter/actor-to-async-closure-conversion
Allow conversions from actor-bound sync function type to unbound async function type.
2 parents e18f586 + 92f56e7 commit 109d6c5

File tree

19 files changed

+225
-17
lines changed

19 files changed

+225
-17
lines changed

docs/ABI/Mangling.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ types where the metadata itself has unknown layout.)
251251
REABSTRACT-THUNK-TYPE ::= 'R' // reabstraction thunk
252252
REABSTRACT-THUNK-TYPE ::= 'r' // reabstraction thunk (obsolete)
253253

254+
global ::= reabstraction-thunk type 'TU' // reabstraction thunk with global actor constraint
255+
254256
The `from-type` and `to-type` in a reabstraction thunk helper function
255257
are always non-polymorphic ``<impl-function-type>`` types.
256258

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ class ASTMangler : public Mangler {
163163
std::string mangleReabstractionThunkHelper(CanSILFunctionType ThunkType,
164164
Type FromType, Type ToType,
165165
Type SelfType,
166+
Type GlobalActorBound,
166167
ModuleDecl *Module);
167168

168169
/// Mangle a completion handler block implementation function, used for importing ObjC

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ NODE(ProtocolWitnessTablePattern)
194194
NODE(ReabstractionThunk)
195195
NODE(ReabstractionThunkHelper)
196196
NODE(ReabstractionThunkHelperWithSelf)
197+
NODE(ReabstractionThunkHelperWithGlobalActor)
197198
CONTEXT_NODE(ReadAccessor)
198199
NODE(RelatedEntityDeclName)
199200
NODE(RetroactiveConformance)

include/swift/SIL/FormalLinkage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum class FormalLinkage {
4343
};
4444

4545
FormalLinkage getDeclLinkage(const ValueDecl *decl);
46+
FormalLinkage getTypeLinkage(CanType formalType);
4647
SILLinkage getSILLinkage(FormalLinkage linkage,
4748
ForDefinition_t forDefinition);
4849
SILLinkage

lib/AST/ASTMangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ std::string ASTMangler::mangleReabstractionThunkHelper(
379379
Type FromType,
380380
Type ToType,
381381
Type SelfType,
382+
Type GlobalActorBound,
382383
ModuleDecl *Module) {
383384
Mod = Module;
384385
assert(ThunkType->getPatternSubstitutions().empty() && "not implemented");
@@ -399,6 +400,11 @@ std::string ASTMangler::mangleReabstractionThunkHelper(
399400
appendOperator("Ty");
400401
else
401402
appendOperator("TR");
403+
404+
if (GlobalActorBound) {
405+
appendType(GlobalActorBound);
406+
appendOperator("TU");
407+
}
402408

403409
return finalize();
404410
}

lib/Demangling/Demangler.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,20 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
25372537
return createNode(Node::Kind::OutlinedBridgedMethod, Params);
25382538
}
25392539
case 'u': return createNode(Node::Kind::AsyncFunctionPointer);
2540+
case 'U': {
2541+
auto globalActor = popNode(Node::Kind::Type);
2542+
if (!globalActor)
2543+
return nullptr;
2544+
2545+
auto reabstraction = popNode();
2546+
if (!reabstraction)
2547+
return nullptr;
2548+
2549+
auto node = createNode(Node::Kind::ReabstractionThunkHelperWithGlobalActor);
2550+
node->addChild(reabstraction, *this);
2551+
node->addChild(globalActor, *this);
2552+
return node;
2553+
}
25402554
case 'J':
25412555
switch (peekChar()) {
25422556
case 'S':

lib/Demangling/NodePrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ class NodePrinter {
471471
case Node::Kind::ReabstractionThunk:
472472
case Node::Kind::ReabstractionThunkHelper:
473473
case Node::Kind::ReabstractionThunkHelperWithSelf:
474+
case Node::Kind::ReabstractionThunkHelperWithGlobalActor:
474475
case Node::Kind::ReadAccessor:
475476
case Node::Kind::RelatedEntityDeclName:
476477
case Node::Kind::RetroactiveConformance:
@@ -1745,6 +1746,12 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
17451746
print(Node->getChild(idx));
17461747
return nullptr;
17471748
}
1749+
case Node::Kind::ReabstractionThunkHelperWithGlobalActor: {
1750+
print(Node->getChild(0));
1751+
Printer << " with global actor constraint ";
1752+
print(Node->getChild(1));
1753+
return nullptr;
1754+
}
17481755
case Node::Kind::ReabstractionThunkHelperWithSelf: {
17491756
Printer << "reabstraction thunk ";
17501757
unsigned idx = 0;

lib/Demangling/OldRemangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,10 @@ void Remangler::mangleReabstractionThunk(Node *node) {
755755
Buffer << "<reabstraction-thunk>";
756756
}
757757

758+
void Remangler::mangleReabstractionThunkHelperWithGlobalActor(Node *node) {
759+
Buffer << "<reabstraction-thunk-helper-with-global-actor>";
760+
}
761+
758762
void Remangler::mangleAutoDiffFunction(Node *node, EntityContext &ctx) {
759763
Buffer << "<autodiff-function>";
760764
}

lib/Demangling/Remangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,11 @@ void Remangler::mangleReabstractionThunkHelperWithSelf(Node *node) {
21252125
Buffer << "Ty";
21262126
}
21272127

2128+
void Remangler::mangleReabstractionThunkHelperWithGlobalActor(Node *node) {
2129+
mangleChildNodes(node);
2130+
Buffer << "TU";
2131+
}
2132+
21282133
void Remangler::mangleAutoDiffFunctionOrSimpleThunk(Node *node, StringRef op) {
21292134
auto childIt = node->begin();
21302135
while (childIt != node->end() &&

lib/SIL/IR/SIL.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,31 @@ bool SILModule::isTypeMetadataAccessible(CanType type) {
141141
});
142142
}
143143

144+
/// Return the minimum linkage structurally required to reference the given formal type.
145+
FormalLinkage swift::getTypeLinkage(CanType t) {
146+
assert(t->isLegalFormalType());
147+
148+
class Walker : public TypeWalker {
149+
public:
150+
FormalLinkage Linkage;
151+
Walker() : Linkage(FormalLinkage::PublicUnique) {}
152+
153+
Action walkToTypePre(Type ty) override {
154+
// Non-nominal types are always available.
155+
auto decl = ty->getNominalOrBoundGenericNominal();
156+
if (!decl)
157+
return Action::Continue;
158+
159+
Linkage = std::min(Linkage, getDeclLinkage(decl));
160+
return Action::Continue;
161+
}
162+
};
163+
164+
Walker w;
165+
t.walk(w);
166+
return w.Linkage;
167+
}
168+
144169
/// Answer whether IRGen's emitTypeMetadataForLayout can fetch metadata for
145170
/// a type, which is the necessary condition for being able to do value
146171
/// operations on the type using dynamic metadata.

0 commit comments

Comments
 (0)