Skip to content

Commit d30feef

Browse files
committed
Ensure that we serialize declarations in synthesized files
Without this, conformances synthesized by macros aren't visible across modules. Fixes rdar://109051626.
1 parent fc9d97f commit d30feef

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6230,7 +6230,12 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
62306230
Scratch.push_back(synthesizedFile);
62316231
files = llvm::makeArrayRef(Scratch);
62326232
} else {
6233-
files = M->getFiles();
6233+
for (auto file : M->getFiles()) {
6234+
Scratch.push_back(file);
6235+
if (auto *synthesizedFile = file->getSynthesizedFile())
6236+
Scratch.push_back(synthesizedFile);
6237+
}
6238+
files = llvm::makeArrayRef(Scratch);
62346239
}
62356240
for (auto nextFile : files) {
62366241
if (nextFile->hasEntryPoint())

test/Macros/macro_expand_conformances.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
// RUN: %empty-directory(%t)
44
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
5-
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) %s -disable-availability-checking -dump-macro-expansions > %t/expansions-dump.txt 2>&1
5+
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/ModuleWithEquatable.swiftmodule %s -DMODULE_EXPORTING_TYPE -module-name ModuleWithEquatable -load-plugin-library %t/%target-library-name(MacroDefinition)
6+
7+
// RUN: %target-swift-frontend -swift-version 5 -typecheck -load-plugin-library %t/%target-library-name(MacroDefinition) %s -I %t -disable-availability-checking -dump-macro-expansions > %t/expansions-dump.txt 2>&1
68
// RUN: %FileCheck -check-prefix=CHECK-DUMP %s < %t/expansions-dump.txt
7-
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -swift-version 5
8-
// RUN: %target-build-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) %s -o %t/main -module-name MacroUser -swift-version 5 -emit-tbd -emit-tbd-path %t/MacroUser.tbd
9+
// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS -swift-version 5 -I %t
10+
// RUN: %target-build-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) %s -o %t/main -module-name MacroUser -swift-version 5 -emit-tbd -emit-tbd-path %t/MacroUser.tbd -I %t
911
// RUN: %target-codesign %t/main
1012
// RUN: %target-run %t/main | %FileCheck %s
1113

@@ -15,10 +17,20 @@ macro Equatable() = #externalMacro(module: "MacroDefinition", type: "EquatableMa
1517
@attached(conformance)
1618
macro Hashable() = #externalMacro(module: "MacroDefinition", type: "HashableMacro")
1719

20+
#if MODULE_EXPORTING_TYPE
21+
@Equatable
22+
public struct PublicEquatable {
23+
public init() { }
24+
}
25+
26+
#else
27+
import ModuleWithEquatable
28+
1829
func requireEquatable(_ value: some Equatable) {
1930
print(value == value)
2031
}
2132

33+
// expected-note@+1{{where 'some Hashable' = 'PublicEquatable'}}
2234
func requireHashable(_ value: some Hashable) {
2335
print(value.hashValue)
2436
}
@@ -44,6 +56,13 @@ requireHashable(S2())
4456

4557
requireEquatable(E.Nested())
4658

59+
#if TEST_DIAGNOSTICS
60+
requireEquatable(PublicEquatable())
61+
62+
requireHashable(PublicEquatable())
63+
//expected-error@-1{{global function 'requireHashable' requires that 'PublicEquatable' conform to 'Hashable'}}
64+
#endif
65+
4766
@attached(conformance)
4867
@attached(member, names: named(requirement))
4968
macro DelegatedConformance() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceMacro")
@@ -70,3 +89,4 @@ func requiresP(_ value: (some P).Type) {
7089

7190
// CHECK: Wrapped.requirement
7291
requiresP(Generic<Wrapped>.self)
92+
#endif

0 commit comments

Comments
 (0)