Skip to content

Commit 5a3e0b3

Browse files
authored
Merge pull request #40750 from ktoso/pick-55-tbd-fix
🍒 [5.5] Add Initializers' AFPs
2 parents c1776ee + f506e54 commit 5a3e0b3

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
@@ -462,7 +462,10 @@ std::string LinkEntity::mangleAsString() const {
462462

463463
case Kind::AsyncFunctionPointerAST: {
464464
std::string Result;
465-
Result = SILDeclRef(const_cast<ValueDecl *>(getDecl())).mangle();
465+
Result = SILDeclRef(const_cast<ValueDecl *>(getDecl()),
466+
static_cast<SILDeclRef::Kind>(
467+
reinterpret_cast<uintptr_t>(SecondaryPointer)))
468+
.mangle();
466469
Result.append("Tu");
467470
return Result;
468471
}

lib/TBDGen/TBDGen.cpp

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

429-
void TBDGenVisitor::addAsyncFunctionPointerSymbol(AbstractFunctionDecl *AFD) {
430-
auto declRef = SILDeclRef(AFD);
429+
void TBDGenVisitor::addAsyncFunctionPointerSymbol(SILDeclRef declRef) {
431430
auto silLinkage = effectiveLinkageForClassMember(
432431
declRef.getLinkage(ForDefinition),
433432
declRef.getSubclassScope());
434433
if (Opts.PublicSymbolsOnly && silLinkage != SILLinkage::Public)
435434
return;
436435

437-
auto entity = LinkEntity::forAsyncFunctionPointer(AFD);
436+
auto entity = LinkEntity::forAsyncFunctionPointer(declRef);
438437
auto linkage =
439438
LinkInfo::get(UniversalLinkInfo, SwiftModule, entity, ForDefinition);
440439
addSymbol(linkage.getName(), SymbolSource::forSILDeclRef(declRef));
@@ -753,7 +752,7 @@ void TBDGenVisitor::visitAbstractFunctionDecl(AbstractFunctionDecl *AFD) {
753752
visitDefaultArguments(AFD, AFD->getParameters());
754753

755754
if (AFD->hasAsync()) {
756-
addAsyncFunctionPointerSymbol(AFD);
755+
addAsyncFunctionPointerSymbol(SILDeclRef(AFD));
757756
}
758757
}
759758

@@ -1000,6 +999,10 @@ void TBDGenVisitor::visitConstructorDecl(ConstructorDecl *CD) {
1000999
// default ValueDecl handling gives the allocating one, so we have to
10011000
// manually include the non-allocating one.
10021001
addSymbol(SILDeclRef(CD, SILDeclRef::Kind::Initializer));
1002+
if (CD->hasAsync()) {
1003+
addAsyncFunctionPointerSymbol(
1004+
SILDeclRef(CD, SILDeclRef::Kind::Initializer));
1005+
}
10031006
if (auto parentClass = CD->getParent()->getSelfClassDecl()) {
10041007
if (parentClass->isObjC() || CD->isObjC())
10051008
recorder.addObjCMethod(parentClass, SILDeclRef(CD));

lib/TBDGen/TBDGenVisitor.h

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

124124
void addSymbol(SILDeclRef declRef);
125-
void addAsyncFunctionPointerSymbol(AbstractFunctionDecl *AFD);
125+
void addAsyncFunctionPointerSymbol(SILDeclRef declRef);
126126

127127
void addSymbol(LinkEntity entity);
128128

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)