Skip to content

Commit 6852e0b

Browse files
authored
Merge pull request #79092 from xymus/more-serial-remarks
Serialization: Report deserialization remarks from lookup services
2 parents 310a75b + 66402f1 commit 6852e0b

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

lib/Serialization/ModuleFile.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ ModuleFile::loadNamedMembers(const IterableDeclContext *IDC, DeclBaseName N,
830830
} else {
831831
if (!getContext().LangOpts.EnableDeserializationRecovery)
832832
fatal(mem.takeError());
833-
consumeError(mem.takeError());
833+
diagnoseAndConsumeError(mem.takeError());
834834
}
835835
}
836836
}
@@ -860,7 +860,7 @@ void ModuleFile::lookupClassMember(ImportPath::Access accessPath,
860860
if (!declOrError) {
861861
if (!getContext().LangOpts.EnableDeserializationRecovery)
862862
fatal(declOrError.takeError());
863-
consumeError(declOrError.takeError());
863+
diagnoseAndConsumeError(declOrError.takeError());
864864
continue;
865865
}
866866

@@ -878,7 +878,7 @@ void ModuleFile::lookupClassMember(ImportPath::Access accessPath,
878878
if (!declOrError) {
879879
if (!getContext().LangOpts.EnableDeserializationRecovery)
880880
fatal(declOrError.takeError());
881-
consumeError(declOrError.takeError());
881+
diagnoseAndConsumeError(declOrError.takeError());
882882
continue;
883883
}
884884

@@ -902,7 +902,7 @@ void ModuleFile::lookupClassMember(ImportPath::Access accessPath,
902902
if (!declOrError) {
903903
if (!getContext().LangOpts.EnableDeserializationRecovery)
904904
fatal(declOrError.takeError());
905-
consumeError(declOrError.takeError());
905+
diagnoseAndConsumeError(declOrError.takeError());
906906
continue;
907907
}
908908

@@ -975,7 +975,7 @@ void ModuleFile::lookupObjCMethods(
975975
// Deserialize the method and add it to the list.
976976
auto declOrError = getDeclChecked(std::get<2>(result));
977977
if (!declOrError) {
978-
consumeError(declOrError.takeError());
978+
diagnoseAndConsumeError(declOrError.takeError());
979979
continue;
980980
}
981981

@@ -1002,13 +1002,16 @@ void ModuleFile::getTopLevelDecls(
10021002
if (declOrError.errorIsA<DeclAttributesDidNotMatch>()) {
10031003
// Decl rejected by matchAttributes, ignore it.
10041004
assert(matchAttributes);
1005-
consumeError(declOrError.takeError());
1005+
1006+
// We don't diagnose DeclAttributesDidNotMatch at the moment but
1007+
// let's use the diagnose consume variant for consistency.
1008+
diagnoseAndConsumeError(declOrError.takeError());
10061009
continue;
10071010
}
10081011

10091012
if (!getContext().LangOpts.EnableDeserializationRecovery)
10101013
fatal(declOrError.takeError());
1011-
consumeError(declOrError.takeError());
1014+
diagnoseAndConsumeError(declOrError.takeError());
10121015
continue;
10131016
}
10141017
if (!ABIRoleInfo(declOrError.get()).providesAPI()) // FIXME: flags
@@ -1024,7 +1027,7 @@ void ModuleFile::getExportedPrespecializations(
10241027
if (!declOrError) {
10251028
if (!getContext().LangOpts.EnableDeserializationRecovery)
10261029
fatal(declOrError.takeError());
1027-
consumeError(declOrError.takeError());
1030+
diagnoseAndConsumeError(declOrError.takeError());
10281031
continue;
10291032
}
10301033
results.push_back(declOrError.get());

test/Serialization/Recovery/module-recovery-remarks.swift

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %empty-directory(%t/sdk)
3-
// RUN: split-file %s %t
3+
// RUN: split-file %s %t --leading-lines
44

55
/// Compile two library modules A and A_related, and a middle library LibWithXRef with a reference to a type in A.
66
// RUN: %target-swift-frontend %t/LibOriginal.swift -emit-module-path %t/A.swiftmodule -module-name A -I %t
77
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/A_related.swiftmodule -module-name A_related
88
// RUN: %target-swift-frontend %t/LibWithXRef.swift -emit-module-path %t/sdk/LibWithXRef.swiftmodule -module-name LibWithXRef -I %t -swift-version 5 -enable-library-evolution
99

10-
/// Move MyType from A to A_related, triggering most notes.
10+
/// Move BrokenType from A to A_related, triggering most notes.
1111
// RUN: %target-swift-frontend %t/EmptyOverlay.swift -emit-module-path %t/A.swiftmodule -module-name A -I %t
1212
// RUN: %target-swift-frontend %t/LibOriginal.swift -emit-module-path %t/A_related.swiftmodule -module-name A_related -I %t
1313
// RUN: not %target-swift-frontend -c -O %t/Client.swift -I %t -I %t/sdk -Rmodule-recovery -sdk %t/sdk -swift-version 4 2>&1 \
1414
// RUN: | %FileCheck --check-prefixes CHECK-MOVED %s
1515

1616
/// Main error downgraded to a remark.
17-
// CHECK-MOVED: LibWithXRef.swiftmodule:1:1: remark: reference to type 'MyType' broken by a context change; 'MyType' was expected to be in 'A', but now a candidate is found only in 'A_related'
17+
// CHECK-MOVED: LibWithXRef.swiftmodule:1:1: remark: reference to type 'BrokenType' broken by a context change; 'BrokenType' was expected to be in 'A', but now a candidate is found only in 'A_related'
1818

1919
/// Contextual notes about the modules involved.
2020
// CHECK-MOVED: note: the type was expected to be found in module 'A' at '
@@ -32,10 +32,16 @@
3232
// CHECK-MOVED-SAME: LibWithXRef.swiftmodule'
3333
// CHECK-MOVED: note: declarations in the underlying clang module 'A' may be hidden by clang preprocessor macros
3434
// CHECK-MOVED: note: the distributed module 'LibWithXRef' refers to the local module 'A'; this may be caused by header maps or search paths
35-
// CHECK-MOVED: note: the type 'MyType' moved between related modules; clang preprocessor macros may affect headers shared between these modules
35+
// CHECK-MOVED: note: the type 'BrokenType' moved between related modules; clang preprocessor macros may affect headers shared between these modules
3636
// CHECK-MOVED: note: could not deserialize type for 'foo()'
3737
// CHECK-MOVED: error: cannot find 'foo' in scope
3838

39+
// CHECK-MOVED: remark: reference to type 'BrokenType' broken by a context change; 'BrokenType' was expected to be in 'A'
40+
// CHECK-MOVED: note: could not deserialize type for 'init(t:)'
41+
42+
// CHECK-MOVED: remark: reference to type 'BrokenType' broken by a context change; 'BrokenType' was expected to be in 'A'
43+
// CHECK-MOVED: note: could not deserialize type for 'member()'
44+
3945
/// Move A to the SDK, triggering a different note about layering.
4046
// RUN: mv %t/A.swiftmodule %t/sdk/A.swiftmodule
4147
// RUN: not %target-swift-frontend -c -O %t/Client.swift -I %t -I %t/sdk -Rmodule-recovery -sdk %t/sdk 2>&1 \
@@ -68,19 +74,30 @@ void foo() {}
6874
//--- LibOriginal.swift
6975
@_exported import A
7076

71-
public struct MyType {
77+
public struct BrokenType {
7278
public init() {}
7379
}
7480

7581
//--- LibWithXRef.swift
7682
import A
7783
import A_related
7884

79-
public func foo() -> MyType {
85+
public func foo() -> BrokenType {
8086
fatalError()
8187
}
8288

89+
public class StableType {
90+
public init() {}
91+
public convenience init(t: BrokenType) { self.init() }
92+
public func member() -> BrokenType { fatalError() }
93+
}
94+
8395
//--- Client.swift
8496
import LibWithXRef
8597

8698
foo()
99+
100+
let s = StableType()
101+
s.member()
102+
103+
let s2 = StableType(42)

0 commit comments

Comments
 (0)