Skip to content

Commit d03f910

Browse files
authored
Merge pull request #65790 from DougGregor/serialize-synthesized-files-5.9
Ensure that we serialize declarations in synthesized files
2 parents 75e4f98 + 938e8d6 commit d03f910

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-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: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
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) -emit-module-interface-path %t/ModuleWithEquatable.swiftinterface
6+
7+
// Check the generated .swiftinterface
8+
// RUN: %FileCheck -check-prefix INTERFACE %s < %t/ModuleWithEquatable.swiftinterface
9+
10+
// 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
611
// 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
12+
// 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
13+
// 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
914
// RUN: %target-codesign %t/main
1015
// RUN: %target-run %t/main | %FileCheck %s
1116

@@ -15,10 +20,23 @@ macro Equatable() = #externalMacro(module: "MacroDefinition", type: "EquatableMa
1520
@attached(conformance)
1621
macro Hashable() = #externalMacro(module: "MacroDefinition", type: "HashableMacro")
1722

23+
#if MODULE_EXPORTING_TYPE
24+
@Equatable
25+
public struct PublicEquatable {
26+
public init() { }
27+
}
28+
29+
// INTERFACE: public struct PublicEquatable
30+
// INTERFACE: extension ModuleWithEquatable.PublicEquatable : Swift.Equatable
31+
32+
#else
33+
import ModuleWithEquatable
34+
1835
func requireEquatable(_ value: some Equatable) {
1936
print(value == value)
2037
}
2138

39+
// expected-note@+1{{where 'some Hashable' = 'PublicEquatable'}}
2240
func requireHashable(_ value: some Hashable) {
2341
print(value.hashValue)
2442
}
@@ -44,6 +62,13 @@ requireHashable(S2())
4462

4563
requireEquatable(E.Nested())
4664

65+
#if TEST_DIAGNOSTICS
66+
requireEquatable(PublicEquatable())
67+
68+
requireHashable(PublicEquatable())
69+
//expected-error@-1{{global function 'requireHashable' requires that 'PublicEquatable' conform to 'Hashable'}}
70+
#endif
71+
4772
@attached(conformance)
4873
@attached(member, names: named(requirement))
4974
macro DelegatedConformance() = #externalMacro(module: "MacroDefinition", type: "DelegatedConformanceMacro")
@@ -70,3 +95,4 @@ func requiresP(_ value: (some P).Type) {
7095

7196
// CHECK: Wrapped.requirement
7297
requiresP(Generic<Wrapped>.self)
98+
#endif

0 commit comments

Comments
 (0)