Skip to content

Commit c5dc68a

Browse files
committed
Emit diagnostics/remarks out of wrapped ModularizationError
The diagnostics/remarks out of the ModularizationError wrapped in a TypeError (eg. coming from resolveCrossReference) is otherwise just dropped but could help better understand C/C++ interop issues.
1 parent d0a3082 commit c5dc68a

File tree

7 files changed

+62
-4
lines changed

7 files changed

+62
-4
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7518,9 +7518,9 @@ ModuleFile::getClangType(ClangTypeID TID) {
75187518
return clangType;
75197519
}
75207520

7521-
Decl *handleErrorAndSupplyMissingClassMember(ASTContext &context,
7522-
llvm::Error &&error,
7523-
ClassDecl *containingClass) {
7521+
Decl *ModuleFile::handleErrorAndSupplyMissingClassMember(
7522+
ASTContext &context, llvm::Error &&error,
7523+
ClassDecl *containingClass) const {
75247524
Decl *suppliedMissingMember = nullptr;
75257525
auto handleMissingClassMember = [&](const DeclDeserializationError &error) {
75267526
if (error.isDesignatedInitializer())
@@ -7534,7 +7534,26 @@ Decl *handleErrorAndSupplyMissingClassMember(ASTContext &context,
75347534
error.getNumberOfVTableEntries(),
75357535
error.needsFieldOffsetVectorEntry());
75367536
};
7537-
llvm::handleAllErrors(std::move(error), handleMissingClassMember);
7537+
7538+
// Emit the diagnostics/remarks out of the ModularizationError
7539+
// wrapped in a TypeError (eg. coming from resolveCrossReference),
7540+
// which is otherwise just dropped but could help better understand
7541+
// C/C++ interop issues.
7542+
assert(context.LangOpts.EnableDeserializationRecovery);
7543+
auto handleModularizationError = [&](ModularizationError &error)
7544+
-> llvm::Error {
7545+
if (context.LangOpts.EnableModuleRecoveryRemarks)
7546+
error.diagnose(this, DiagnosticBehavior::Remark);
7547+
return llvm::Error::success();
7548+
};
7549+
auto handleTypeError = [&](TypeError &typeError) {
7550+
handleMissingClassMember(typeError);
7551+
typeError.diagnoseUnderlyingReason(handleModularizationError);
7552+
if (context.LangOpts.EnableModuleRecoveryRemarks)
7553+
typeError.diagnose(this);
7554+
};
7555+
llvm::handleAllErrors(std::move(error), handleTypeError,
7556+
handleMissingClassMember);
75387557
return suppliedMissingMember;
75397558
}
75407559

lib/Serialization/ModuleFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ class ModuleFile
349349
Decl *handleErrorAndSupplyMissingMember(ASTContext &context,
350350
Decl *container,
351351
llvm::Error &&error) const;
352+
Decl *handleErrorAndSupplyMissingClassMember(
353+
ASTContext &context, llvm::Error &&error,
354+
ClassDecl *containingClass) const;
352355

353356
public:
354357
/// Change the status of the current module.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import CxxLib
2+
3+
open class Window {
4+
open func queryInterface(_ iid: IID) -> Int32? {
5+
return nil
6+
}
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import A
2+
3+
public class CustomWindow: Window {
4+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef GUID_DEFINED
2+
#define GUID_DEFINED
3+
typedef struct _GUID {
4+
} GUID;
5+
#endif
6+
7+
#ifndef __IID_DEFINED__
8+
#define __IID_DEFINED__
9+
typedef GUID IID;
10+
#endif
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module CxxLib {
2+
header "CxxLib.h"
3+
4+
export *
5+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module %S/Inputs/wrapped-modularization-error-remarks/A/A.swift -cxx-interoperability-mode=default -Xcc -fmodule-map-file=%S/Inputs/wrapped-modularization-error-remarks/CxxLib/include/module.modulemap -Xcc -I -Xcc %S/Inputs/wrapped-modularization-error-remarks/CxxLib/include -module-name A -o %t/A.swiftmodule
3+
// RUN: not %target-swift-frontend -c -primary-file %S/Inputs/wrapped-modularization-error-remarks/B/B.swift -cxx-interoperability-mode=default -I %t -Xcc -fmodule-map-file=%S/Inputs/wrapped-modularization-error-remarks/CxxLib/include/module.modulemap -Xcc -I -Xcc %S/Inputs/wrapped-modularization-error-remarks/CxxLib/include -module-name B -o %t/B.swift.o -Rmodule-recovery 2>&1 | %FileCheck %s
4+
// REQUIRES: OS=windows-msvc
5+
6+
// Check that the diagnostics/remark from the wrapped ModularizationError is emitted.
7+
// CHECK: remark: reference to type '_GUID' broken by a context change; '_GUID' is not found, it was expected to be in 'CxxLib'
8+
// CHECK: note: could not deserialize type for 'queryInterface'
9+
// CHECK: error: cannot inherit from class 'Window' because it has overridable members that could not be loaded
10+
// CHECK: note: could not deserialize 'queryInterface'

0 commit comments

Comments
 (0)