[Compile Time Constant Extraction] Ensure macro-expanded declarations are visited in WMO

Resolves rdar://130036855
This commit is contained in:
Artem Chikin
2024-06-25 14:22:38 -07:00
parent fbe7d89311
commit 1be5dbba38
2 changed files with 11 additions and 0 deletions

View File

@@ -572,6 +572,13 @@ gatherConstValuesForModule(const std::unordered_set<std::string> &Protocols,
NominalTypeConformanceCollector ConformanceCollector(Protocols,
ConformanceDecls);
Module->walk(ConformanceCollector);
// Visit macro expanded extensions
for (auto *FU : Module->getFiles())
if (auto *synthesizedSF = FU->getSynthesizedFile())
for (auto D : synthesizedSF->getTopLevelDecls())
if (isa<ExtensionDecl>(D))
D->walk(ConformanceCollector);
for (auto *CD : ConformanceDecls)
Result.emplace_back(evaluateOrDefault(CD->getASTContext().evaluator,
ConstantValueInfoRequest{CD, Module},

View File

@@ -7,6 +7,10 @@
// RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/ExtractFromMacroExpansion.swiftconstvalues -const-gather-protocols-file %t/protocols.json -primary-file %s -load-plugin-library %t/%target-library-name(MacroDefinition)
// RUN: cat %t/ExtractFromMacroExpansion.swiftconstvalues 2>&1 | %FileCheck %s
// Do the same, but ensure the WMO compilation flow produces the same result
// RUN: %target-swift-frontend -typecheck -emit-const-values-path %t/ExtractFromMacroExpansionWMO.swiftconstvalues -const-gather-protocols-file %t/protocols.json -O %s -load-plugin-library %t/%target-library-name(MacroDefinition)
// RUN: cat %t/ExtractFromMacroExpansionWMO.swiftconstvalues 2>&1 | %FileCheck %s
protocol MyProto { }
@freestanding(declaration, names: named(MacroAddedStruct))