Skip to content

Commit 8afcfd1

Browse files
authored
Merge pull request #74712 from artemcm/60ConstExtractWMOMacroExpansionExtraction
[6.0 🍒][Compile Time Constant Extraction] Ensure macro-expanded declarations are visited in WMO
2 parents f5de520 + 2912260 commit 8afcfd1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/ConstExtract/ConstExtract.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,13 @@ gatherConstValuesForModule(const std::unordered_set<std::string> &Protocols,
549549
NominalTypeConformanceCollector ConformanceCollector(Protocols,
550550
ConformanceDecls);
551551
Module->walk(ConformanceCollector);
552+
// Visit macro expanded extensions
553+
for (auto *FU : Module->getFiles())
554+
if (auto *synthesizedSF = FU->getSynthesizedFile())
555+
for (auto D : synthesizedSF->getTopLevelDecls())
556+
if (isa<ExtensionDecl>(D))
557+
D->walk(ConformanceCollector);
558+
552559
for (auto *CD : ConformanceDecls)
553560
Result.emplace_back(evaluateOrDefault(CD->getASTContext().evaluator,
554561
ConstantValueInfoRequest{CD, Module},

test/ConstExtraction/ExtractFromMacroExpansion.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
// 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)
88
// RUN: cat %t/ExtractFromMacroExpansion.swiftconstvalues 2>&1 | %FileCheck %s
99

10+
// Do the same, but ensure the WMO compilation flow produces the same result
11+
// 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)
12+
// RUN: cat %t/ExtractFromMacroExpansionWMO.swiftconstvalues 2>&1 | %FileCheck %s
13+
1014
protocol MyProto { }
1115

1216
@freestanding(declaration, names: named(MacroAddedStruct))

0 commit comments

Comments
 (0)