Skip to content

Make sure we visit auxiliary declarations for all SIL symbol visitation #64134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions lib/SIL/IR/SILSymbolVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
addMainIfNecessary(file);

for (auto D : decls) {
D->visitAuxiliaryDecls([&](Decl *decl) {
if (Ctx.getOpts().LinkerDirectivesOnly && !requiresLinkerDirective(decl))
return;

visit(decl);
});

if (Ctx.getOpts().LinkerDirectivesOnly && !requiresLinkerDirective(D))
continue;

Expand Down Expand Up @@ -573,6 +580,20 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
visitAbstractStorageDecl(SD);
}

template<typename NominalOrExtension>
void visitMembers(NominalOrExtension *D) {
if (!Ctx.getOpts().VisitMembers)
return;

for (auto member : D->getMembers()) {
member->visitAuxiliaryDecls([&](Decl *decl) {
visit(decl);
});

visit(member);
}
}

void visitNominalTypeDecl(NominalTypeDecl *NTD) {
auto declaredType = NTD->getDeclaredType()->getCanonicalType();

Expand All @@ -591,9 +612,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {

addRuntimeDiscoverableAttrGenerators(NTD);

if (Ctx.getOpts().VisitMembers)
for (auto member : NTD->getMembers())
visit(member);
visitMembers(NTD);
}

void visitClassDecl(ClassDecl *CD) {
Expand Down Expand Up @@ -682,9 +701,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
addConformances(ED);
}

if (Ctx.getOpts().VisitMembers)
for (auto member : ED->getMembers())
visit(member);
visitMembers(ED);
}

#ifndef NDEBUG
Expand Down
3 changes: 3 additions & 0 deletions test/Macros/macro_expand_peers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
// RUN: %target-build-swift -swift-version 5 -Xfrontend -disable-availability-checking -load-plugin-library %t/%target-library-name(MacroDefinition) -parse-as-library -I %swift-host-lib-dir -L %swift-host-lib-dir %s -o %t/main -module-name MacroUser
// RUN: %target-run %t/main | %FileCheck %s -check-prefix=CHECK-EXEC

// Emit module while skipping function bodies
// RUN: %target-swift-frontend -swift-version 5 -emit-module -load-plugin-library %t/%target-library-name(MacroDefinition) -parse-as-library -I %swift-host-lib-dir %s -disable-availability-checking -o %t/macro_expand_peers.swiftmodule -experimental-skip-non-inlinable-function-bodies-without-types

// FIXME: Swift parser is not enabled on Linux CI yet.
// REQUIRES: OS=macosx

Expand Down