|
24 | 24 | #include "swift/AST/ParameterList.h"
|
25 | 25 | #include "swift/AST/PropertyWrappers.h"
|
26 | 26 | #include "swift/AST/SynthesizedFileUnit.h"
|
| 27 | +#include "swift/Basic/Defer.h" |
27 | 28 | #include "swift/SIL/FormalLinkage.h"
|
28 | 29 | #include "swift/SIL/SILLinkage.h"
|
29 | 30 | #include "swift/SIL/SILModule.h"
|
@@ -63,6 +64,7 @@ static Optional<DynamicKind> getDynamicKind(ValueDecl *VD) {
|
63 | 64 | class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
|
64 | 65 | SILSymbolVisitor &Visitor;
|
65 | 66 | const SILSymbolVisitorContext &Ctx;
|
| 67 | + llvm::SmallVector<Decl *, 4> DeclStack; |
66 | 68 |
|
67 | 69 | /// A set of original function and derivative configuration pairs for which
|
68 | 70 | /// derivative symbols have been emitted.
|
@@ -356,12 +358,33 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
|
356 | 358 | return true;
|
357 | 359 | }
|
358 | 360 |
|
| 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 | + |
359 | 379 | public:
|
360 | 380 | SILSymbolVisitorImpl(SILSymbolVisitor &Visitor,
|
361 | 381 | const SILSymbolVisitorContext &Ctx)
|
362 | 382 | : Visitor{Visitor}, Ctx{Ctx} {}
|
363 | 383 |
|
364 | 384 | void visit(Decl *D) {
|
| 385 | + DeclStack.push_back(D); |
| 386 | + SWIFT_DEFER { DeclStack.pop_back(); }; |
| 387 | + |
365 | 388 | if (!Visitor.willVisitDecl(D))
|
366 | 389 | return;
|
367 | 390 | ASTVisitor::visit(D);
|
@@ -478,6 +501,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
|
478 | 501 | // If there's an opaque return type, its descriptor is exported.
|
479 | 502 | addOpaqueResultIfNecessary(FD);
|
480 | 503 | visitAbstractFunctionDecl(FD);
|
| 504 | + addMethodIfNecessary(FD); |
481 | 505 | }
|
482 | 506 |
|
483 | 507 | void visitAccessorDecl(AccessorDecl *AD) {
|
|
0 commit comments