Skip to content

Commit 49e0015

Browse files
committed
SIL: Emit symbols methods associated with methods from SILSymbolVisitor when visiting a FuncDecl.
Previously, dispatch thunks and method descriptors were only emitted when visiting the containing `ClassDecl`. IRGen for `#_hasSymbol` requires visiting the `FuncDecl` directly.
1 parent 6f78e21 commit 49e0015

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "swift/AST/ParameterList.h"
2525
#include "swift/AST/PropertyWrappers.h"
2626
#include "swift/AST/SynthesizedFileUnit.h"
27+
#include "swift/Basic/Defer.h"
2728
#include "swift/SIL/FormalLinkage.h"
2829
#include "swift/SIL/SILLinkage.h"
2930
#include "swift/SIL/SILModule.h"
@@ -63,6 +64,7 @@ static Optional<DynamicKind> getDynamicKind(ValueDecl *VD) {
6364
class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
6465
SILSymbolVisitor &Visitor;
6566
const SILSymbolVisitorContext &Ctx;
67+
llvm::SmallVector<Decl *, 4> DeclStack;
6668

6769
/// A set of original function and derivative configuration pairs for which
6870
/// derivative symbols have been emitted.
@@ -356,12 +358,33 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
356358
return true;
357359
}
358360

361+
void addMethodIfNecessary(FuncDecl *FD) {
362+
auto CD = dyn_cast<ClassDecl>(FD->getDeclContext());
363+
if (!CD)
364+
return;
365+
366+
// If we're already visiting the parent ClassDecl then this was handled by
367+
// its vtable visitor.
368+
if (llvm::find(DeclStack, CD) != DeclStack.end())
369+
return;
370+
371+
SILDeclRef method = SILDeclRef(FD);
372+
if (Ctx.getOpts().VirtualFunctionElimination ||
373+
CD->hasResilientMetadata()) {
374+
Visitor.addDispatchThunk(method);
375+
}
376+
Visitor.addMethodDescriptor(method);
377+
}
378+
359379
public:
360380
SILSymbolVisitorImpl(SILSymbolVisitor &Visitor,
361381
const SILSymbolVisitorContext &Ctx)
362382
: Visitor{Visitor}, Ctx{Ctx} {}
363383

364384
void visit(Decl *D) {
385+
DeclStack.push_back(D);
386+
SWIFT_DEFER { DeclStack.pop_back(); };
387+
365388
if (!Visitor.willVisitDecl(D))
366389
return;
367390
ASTVisitor::visit(D);
@@ -478,6 +501,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
478501
// If there's an opaque return type, its descriptor is exported.
479502
addOpaqueResultIfNecessary(FD);
480503
visitAbstractFunctionDecl(FD);
504+
addMethodIfNecessary(FD);
481505
}
482506

483507
void visitAccessorDecl(AccessorDecl *AD) {

0 commit comments

Comments
 (0)