Skip to content

Commit 145bf5f

Browse files
authored
Merge pull request #61847 from apple/egorzhdan/cxx-dependency-on-sema
[cxx-interop] Avoid a ClangImporter dependency on Sema
2 parents f7909a8 + a7f00d6 commit 145bf5f

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

lib/ClangImporter/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ add_swift_host_library(swiftClangImporter STATIC
2828
target_link_libraries(swiftClangImporter PRIVATE
2929
swiftAST
3030
swiftParse
31-
swiftSema
3231
clangTooling
3332
LLVMBitstreamReader)
3433

lib/ClangImporter/ClangDerivedConformances.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ lookupDirectWithoutExtensions(NominalTypeDecl *decl, Identifier id) {
4141
return result;
4242
}
4343

44+
/// Similar to ModuleDecl::conformsToProtocol, but doesn't introduce a
45+
/// dependency on Sema.
46+
static bool isConcreteAndValid(ProtocolConformanceRef conformanceRef,
47+
ModuleDecl *module) {
48+
if (conformanceRef.isInvalid())
49+
return false;
50+
if (!conformanceRef.isConcrete())
51+
return false;
52+
auto conformance = conformanceRef.getConcrete();
53+
auto subMap = conformance->getSubstitutions(module);
54+
return llvm::all_of(subMap.getConformances(),
55+
[&](ProtocolConformanceRef each) -> bool {
56+
return isConcreteAndValid(each, module);
57+
});
58+
}
59+
4460
static clang::TypeDecl *
4561
getIteratorCategoryDecl(const clang::CXXRecordDecl *clangDecl) {
4662
clang::IdentifierInfo *iteratorCategoryDeclName =
@@ -126,7 +142,9 @@ static ValueDecl *getMinusOperator(NominalTypeDecl *decl) {
126142
if (lhsNominal != rhsNominal || lhsNominal != decl)
127143
return false;
128144
auto returnTy = minus->getResultInterfaceType();
129-
if (!module->conformsToProtocol(returnTy, binaryIntegerProto))
145+
auto conformanceRef =
146+
module->lookupConformance(returnTy, binaryIntegerProto);
147+
if (!isConcreteAndValid(conformanceRef, module))
130148
return false;
131149
return true;
132150
};
@@ -331,9 +349,10 @@ void swift::conformToCxxSequenceIfNeeded(
331349
return;
332350

333351
// Check if RawIterator conforms to UnsafeCxxInputIterator.
334-
auto rawIteratorConformanceRef = decl->getModuleContext()->conformsToProtocol(
335-
rawIteratorTy, cxxIteratorProto);
336-
if (!rawIteratorConformanceRef || !rawIteratorConformanceRef.isConcrete())
352+
ModuleDecl *module = decl->getModuleContext();
353+
auto rawIteratorConformanceRef =
354+
module->lookupConformance(rawIteratorTy, cxxIteratorProto);
355+
if (!isConcreteAndValid(rawIteratorConformanceRef, module))
337356
return;
338357
auto rawIteratorConformance = rawIteratorConformanceRef.getConcrete();
339358
auto pointeeDecl =
@@ -356,7 +375,7 @@ void swift::conformToCxxSequenceIfNeeded(
356375
return declSelfTy;
357376
return Type(dependentType);
358377
},
359-
LookUpConformanceInModule(decl->getModuleContext()));
378+
LookUpConformanceInModule(module));
360379

361380
impl.addSynthesizedTypealias(decl, ctx.Id_Element, pointeeTy);
362381
impl.addSynthesizedTypealias(decl, ctx.Id_Iterator, iteratorTy);

lib/SIL/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ target_link_libraries(swiftSIL PUBLIC
44
swiftDemangling)
55
target_link_libraries(swiftSIL PRIVATE
66
swiftAST
7-
swiftClangImporter)
7+
swiftClangImporter
8+
swiftSema
9+
swiftSerialization)
810

911
add_subdirectory(IR)
1012
add_subdirectory(Utils)

lib/SILGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ add_swift_host_library(swiftSILGen STATIC
3636
SILGenThunk.cpp
3737
SILGenType.cpp)
3838
target_link_libraries(swiftSILGen PRIVATE
39+
swiftSerialization
3940
swiftSIL)
4041

4142
set_swift_llvm_is_available(swiftSILGen)

tools/sil-passpipeline-dumper/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_swift_host_tool(sil-passpipeline-dumper
55
target_link_libraries(sil-passpipeline-dumper PRIVATE
66
swiftFrontend
77
swiftIRGen
8+
swiftSema
89
swiftSILGen
910
swiftSILOptimizer
1011
# Clang libraries included to appease the linker on linux.

0 commit comments

Comments
 (0)