Skip to content

Commit 784a7c5

Browse files
authored
Merge pull request swiftlang#72408 from xymus/fix-deser-diags
Serialization: update for new diagnostics format
2 parents 56d207a + 59e0af7 commit 784a7c5

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,24 @@ void
213213
ModularizationError::diagnose(const ModuleFile *MF,
214214
DiagnosticBehavior limit) const {
215215
auto &ctx = MF->getContext();
216+
auto loc = getSourceLoc();
216217

217218
auto diagnoseError = [&](Kind errorKind) {
218219
switch (errorKind) {
219220
case Kind::DeclMoved:
220-
return ctx.Diags.diagnose(getSourceLoc(),
221+
return ctx.Diags.diagnose(loc,
221222
diag::modularization_issue_decl_moved,
222223
declIsType, name, expectedModule,
223224
foundModule);
224225
case Kind::DeclKindChanged:
225226
return
226-
ctx.Diags.diagnose(getSourceLoc(),
227+
ctx.Diags.diagnose(loc,
227228
diag::modularization_issue_decl_type_changed,
228229
declIsType, name, expectedModule,
229230
referenceModule->getName(), foundModule,
230231
foundModule != expectedModule);
231232
case Kind::DeclNotFound:
232-
return ctx.Diags.diagnose(getSourceLoc(),
233+
return ctx.Diags.diagnose(loc,
233234
diag::modularization_issue_decl_not_found,
234235
declIsType, name, expectedModule);
235236
}
@@ -245,7 +246,7 @@ ModularizationError::diagnose(const ModuleFile *MF,
245246
// expected module name and the decl name from the diagnostic.
246247

247248
// Show context with relevant file paths.
248-
ctx.Diags.diagnose(SourceLoc(),
249+
ctx.Diags.diagnose(loc,
249250
diag::modularization_issue_note_expected,
250251
declIsType, expectedModule,
251252
expectedModule->getModuleSourceFilename());
@@ -257,14 +258,14 @@ ModularizationError::diagnose(const ModuleFile *MF,
257258
auto CML = ctx.getClangModuleLoader();
258259
auto &CSM = CML->getClangASTContext().getSourceManager();
259260
StringRef filename = CSM.getFilename(expectedUnderlying->DefinitionLoc);
260-
ctx.Diags.diagnose(SourceLoc(),
261+
ctx.Diags.diagnose(loc,
261262
diag::modularization_issue_note_expected_underlying,
262263
expectedUnderlying->Name,
263264
filename);
264265
}
265266

266267
if (foundModule)
267-
ctx.Diags.diagnose(SourceLoc(),
268+
ctx.Diags.diagnose(loc,
268269
diag::modularization_issue_note_found,
269270
declIsType, foundModule,
270271
foundModule->getModuleSourceFilename());
@@ -277,7 +278,7 @@ ModularizationError::diagnose(const ModuleFile *MF,
277278
clientLangVersion = MF->getContext().LangOpts.EffectiveLanguageVersion;
278279
ModuleDecl *referenceModuleDecl = referenceModule->getAssociatedModule();
279280
if (clientLangVersion != moduleLangVersion) {
280-
ctx.Diags.diagnose(SourceLoc(),
281+
ctx.Diags.diagnose(loc,
281282
diag::modularization_issue_swift_version,
282283
referenceModuleDecl, moduleLangVersion,
283284
clientLangVersion);
@@ -292,7 +293,7 @@ ModularizationError::diagnose(const ModuleFile *MF,
292293
if (referenceModule->getResilienceStrategy() ==
293294
ResilienceStrategy::Resilient &&
294295
referenceModuleIsDistributed) {
295-
ctx.Diags.diagnose(SourceLoc(),
296+
ctx.Diags.diagnose(loc,
296297
diag::modularization_issue_stale_module,
297298
referenceModuleDecl,
298299
referenceModule->getModuleFilename());
@@ -302,7 +303,7 @@ ModularizationError::diagnose(const ModuleFile *MF,
302303
// it may be hidden by some clang defined passed via `-Xcc` affecting how
303304
// headers are seen.
304305
if (expectedUnderlying) {
305-
ctx.Diags.diagnose(SourceLoc(),
306+
ctx.Diags.diagnose(loc,
306307
diag::modularization_issue_audit_headers,
307308
expectedModule->isNonSwiftModule(), expectedModule);
308309
}
@@ -313,11 +314,11 @@ ModularizationError::diagnose(const ModuleFile *MF,
313314
// Local modules can reference both local modules and distributed modules.
314315
if (referenceModuleIsDistributed) {
315316
if (!expectedModule->isNonUserModule()) {
316-
ctx.Diags.diagnose(SourceLoc(),
317+
ctx.Diags.diagnose(loc,
317318
diag::modularization_issue_layering_expected_local,
318319
referenceModuleDecl, expectedModule);
319320
} else if (foundModule && !foundModule->isNonUserModule()) {
320-
ctx.Diags.diagnose(SourceLoc(),
321+
ctx.Diags.diagnose(loc,
321322
diag::modularization_issue_layering_found_local,
322323
referenceModuleDecl, foundModule);
323324
}
@@ -335,11 +336,13 @@ ModularizationError::diagnose(const ModuleFile *MF,
335336
expectedModuleName.starts_with(foundModuleName)) &&
336337
(expectedUnderlying ||
337338
expectedModule->findUnderlyingClangModule())) {
338-
ctx.Diags.diagnose(SourceLoc(),
339+
ctx.Diags.diagnose(loc,
339340
diag::modularization_issue_related_modules,
340341
declIsType, name);
341342
}
342343
}
344+
345+
ctx.Diags.flushConsumers();
343346
}
344347

345348
void TypeError::diagnose(const ModuleFile *MF) const {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,38 @@
1717
// 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'
1818

1919
/// Contextual notes about the modules involved.
20-
// CHECK-MOVED: <unknown>:0: note: the type was expected to be found in module 'A' at '
20+
// CHECK-MOVED: note: the type was expected to be found in module 'A' at '
2121
// CHECK-MOVED-SAME: A.swiftmodule'
22-
// CHECK-MOVED: <unknown>:0: note: or expected to be found in the underlying module 'A' defined at '
22+
// CHECK-MOVED: note: or expected to be found in the underlying module 'A' defined at '
2323
// CHECK-MOVED-SAME: module.modulemap'
24-
// CHECK-MOVED: <unknown>:0: note: the type was actually found in module 'A_related' at '
24+
// CHECK-MOVED: note: the type was actually found in module 'A_related' at '
2525
// CHECK-MOVED-SAME: A_related.swiftmodule'
2626

2727
/// More notes depending on the context
28-
// CHECK-MOVED: <unknown>:0: note: the module 'LibWithXRef' was built with a Swift language version set to 5
28+
// CHECK-MOVED: note: the module 'LibWithXRef' was built with a Swift language version set to 5
2929
// CHECK-MOVED-SAME: while the current invocation uses 4
3030

31-
// CHECK-MOVED: <unknown>:0: note: the module 'LibWithXRef' has enabled library-evolution; the following file may need to be deleted if the SDK was modified: '
31+
// CHECK-MOVED: note: the module 'LibWithXRef' has enabled library-evolution; the following file may need to be deleted if the SDK was modified: '
3232
// CHECK-MOVED-SAME: LibWithXRef.swiftmodule'
33-
// CHECK-MOVED: <unknown>:0: note: declarations in the underlying clang module 'A' may be hidden by clang preprocessor macros
34-
// CHECK-MOVED: <unknown>:0: note: the distributed module 'LibWithXRef' refers to the local module 'A'; this may be caused by header maps or search paths
35-
// CHECK-MOVED: <unknown>:0: note: the type 'MyType' moved between related modules; clang preprocessor macros may affect headers shared between these modules
33+
// CHECK-MOVED: note: declarations in the underlying clang module 'A' may be hidden by clang preprocessor macros
34+
// 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
3636
// CHECK-MOVED: note: could not deserialize type for 'foo()'
3737
// CHECK-MOVED: error: cannot find 'foo' in scope
3838

3939
/// Move A to the SDK, triggering a different note about layering.
4040
// RUN: mv %t/A.swiftmodule %t/sdk/A.swiftmodule
4141
// RUN: not %target-swift-frontend -c -O %t/Client.swift -I %t -I %t/sdk -Rmodule-recovery -sdk %t/sdk 2>&1 \
4242
// RUN: | %FileCheck --check-prefixes CHECK-LAYERING-FOUND %s
43-
// CHECK-LAYERING-FOUND: <unknown>:0: note: the reference may break layering; the candidate was found in the local module 'A_related' for a reference from the distributed module 'LibWithXRef'
43+
// CHECK-LAYERING-FOUND: note: the reference may break layering; the candidate was found in the local module 'A_related' for a reference from the distributed module 'LibWithXRef'
4444
// CHECK-LAYERING-FOUND: error: cannot find 'foo' in scope
4545

4646
/// Delete A, keep only the underlying clangmodule for notes about clang modules.
4747
// RUN: rm %t/sdk/A.swiftmodule
4848
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/A_related.swiftmodule -module-name A_related
4949
// RUN: not %target-swift-frontend -c -O %t/Client.swift -I %t -I %t/sdk -Rmodule-recovery -sdk %t/sdk 2>&1 \
5050
// RUN: | %FileCheck --check-prefixes CHECK-CLANG %s
51-
// CHECK-CLANG: <unknown>:0: note: declarations in the clang module 'A' may be hidden by clang preprocessor macros
51+
// CHECK-CLANG: note: declarations in the clang module 'A' may be hidden by clang preprocessor macros
5252
// CHECK-CLANG: error: cannot find 'foo' in scope
5353

5454

test/Serialization/modularization-error.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
// CHECK-WORKAROUND: LibWithXRef.swiftmodule:1:1: warning: reference to type 'MyType' broken by a context change; 'MyType' was expected to be in 'A', but now a candidate is found only in 'B'
2222
// CHECK-WORKAROUND-NEXT: A.MyType
2323
// CHECK-WORKAROUND-NEXT: ^
24-
// CHECK-WORKAROUND: <unknown>:0: note: the type was expected to be found in module 'A' at '
24+
// CHECK-WORKAROUND: note: the type was expected to be found in module 'A' at '
2525
// CHECK-WORKAROUND-SAME: A.swiftmodule'
26-
// CHECK-WORKAROUND: <unknown>:0: note: the type was actually found in module 'B' at '
26+
// CHECK-WORKAROUND: note: the type was actually found in module 'B' at '
2727
// CHECK-WORKAROUND-SAME: B.swiftmodule'
28-
// CHECK-WORKAROUND: <unknown>:0: note: attempting forced recovery enabled by -experimental-force-workaround-broken-modules
28+
// CHECK-WORKAROUND: note: attempting forced recovery enabled by -experimental-force-workaround-broken-modules
2929
// CHECK-WORKAROUND: func foo() -> some Proto
3030

3131
/// Change MyType into a function.

0 commit comments

Comments
 (0)