Skip to content

Commit 231f4d5

Browse files
Merge pull request swiftlang#38918 from nate-chandler/rdar82045176
[TBD] Add initializers' AFPs.
2 parents 79b33ef + cde4534 commit 231f4d5

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

include/swift/IRGen/Linking.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,12 @@ class LinkEntity {
11961196
return entity;
11971197
}
11981198

1199-
static LinkEntity forAsyncFunctionPointer(AbstractFunctionDecl *decl) {
1199+
static LinkEntity forAsyncFunctionPointer(SILDeclRef declRef) {
12001200
LinkEntity entity;
1201-
entity.setForDecl(Kind::AsyncFunctionPointerAST, decl);
1201+
entity.setForDecl(Kind::AsyncFunctionPointerAST,
1202+
declRef.getAbstractFunctionDecl());
1203+
entity.SecondaryPointer =
1204+
reinterpret_cast<void *>(static_cast<uintptr_t>(declRef.kind));
12021205
return entity;
12031206
}
12041207

lib/IRGen/Linking.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,10 @@ std::string LinkEntity::mangleAsString() const {
468468

469469
case Kind::AsyncFunctionPointerAST: {
470470
std::string Result;
471-
Result = SILDeclRef(const_cast<ValueDecl *>(getDecl())).mangle();
471+
Result = SILDeclRef(const_cast<ValueDecl *>(getDecl()),
472+
static_cast<SILDeclRef::Kind>(
473+
reinterpret_cast<uintptr_t>(SecondaryPointer)))
474+
.mangle();
472475
Result.append("Tu");
473476
return Result;
474477
}

lib/TBDGen/TBDGen.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,14 @@ void TBDGenVisitor::addSymbol(SILDeclRef declRef) {
411411
addSymbol(declRef.mangle(), SymbolSource::forSILDeclRef(declRef));
412412
}
413413

414-
void TBDGenVisitor::addAsyncFunctionPointerSymbol(AbstractFunctionDecl *AFD) {
415-
auto declRef = SILDeclRef(AFD);
414+
void TBDGenVisitor::addAsyncFunctionPointerSymbol(SILDeclRef declRef) {
416415
auto silLinkage = effectiveLinkageForClassMember(
417416
declRef.getLinkage(ForDefinition),
418417
declRef.getSubclassScope());
419418
if (Opts.PublicSymbolsOnly && silLinkage != SILLinkage::Public)
420419
return;
421420

422-
auto entity = LinkEntity::forAsyncFunctionPointer(AFD);
421+
auto entity = LinkEntity::forAsyncFunctionPointer(declRef);
423422
auto linkage =
424423
LinkInfo::get(UniversalLinkInfo, SwiftModule, entity, ForDefinition);
425424
addSymbol(linkage.getName(), SymbolSource::forSILDeclRef(declRef));
@@ -742,7 +741,7 @@ void TBDGenVisitor::visitAbstractFunctionDecl(AbstractFunctionDecl *AFD) {
742741
visitDefaultArguments(AFD, AFD->getParameters());
743742

744743
if (AFD->hasAsync()) {
745-
addAsyncFunctionPointerSymbol(AFD);
744+
addAsyncFunctionPointerSymbol(SILDeclRef(AFD));
746745
}
747746
}
748747

@@ -989,6 +988,10 @@ void TBDGenVisitor::visitConstructorDecl(ConstructorDecl *CD) {
989988
// default ValueDecl handling gives the allocating one, so we have to
990989
// manually include the non-allocating one.
991990
addSymbol(SILDeclRef(CD, SILDeclRef::Kind::Initializer));
991+
if (CD->hasAsync()) {
992+
addAsyncFunctionPointerSymbol(
993+
SILDeclRef(CD, SILDeclRef::Kind::Initializer));
994+
}
992995
if (auto parentClass = CD->getParent()->getSelfClassDecl()) {
993996
if (parentClass->isObjC() || CD->isObjC())
994997
recorder.addObjCMethod(parentClass, SILDeclRef(CD));

lib/TBDGen/TBDGenVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
121121
SymbolKind kind = SymbolKind::GlobalSymbol);
122122

123123
void addSymbol(SILDeclRef declRef);
124-
void addAsyncFunctionPointerSymbol(AbstractFunctionDecl *AFD);
124+
void addAsyncFunctionPointerSymbol(SILDeclRef declRef);
125125

126126
void addSymbol(LinkEntity entity);
127127

test/TBD/rdar82045176.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift-dylib(%t/%target-library-name(first)) %s -emit-module -module-name thing -emit-tbd -enable-testing -Xfrontend -disable-availability-checking -Xfrontend -validate-tbd-against-ir=all
3+
4+
class Test {
5+
init() async { }
6+
}

0 commit comments

Comments
 (0)