Skip to content

Commit defcd37

Browse files
authored
Merge pull request swiftlang#74708 from artemcm/ConstExtractWMOMacroExpansionExtraction
[Compile Time Constant Extraction] Ensure macro-expanded declarations are visited in WMO
2 parents 86ff1f9 + 1be5dbb commit defcd37

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
@@ -572,6 +572,13 @@ gatherConstValuesForModule(const std::unordered_set<std::string> &Protocols,
572572
NominalTypeConformanceCollector ConformanceCollector(Protocols,
573573
ConformanceDecls);
574574
Module->walk(ConformanceCollector);
575+
// Visit macro expanded extensions
576+
for (auto *FU : Module->getFiles())
577+
if (auto *synthesizedSF = FU->getSynthesizedFile())
578+
for (auto D : synthesizedSF->getTopLevelDecls())
579+
if (isa<ExtensionDecl>(D))
580+
D->walk(ConformanceCollector);
581+
575582
for (auto *CD : ConformanceDecls)
576583
Result.emplace_back(evaluateOrDefault(CD->getASTContext().evaluator,
577584
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)