Skip to content

[cxx-interop] Avoid a ClangImporter dependency on Sema #61847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/ClangImporter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ add_swift_host_library(swiftClangImporter STATIC
target_link_libraries(swiftClangImporter PRIVATE
swiftAST
swiftParse
swiftSema
clangTooling
LLVMBitstreamReader)

Expand Down
29 changes: 24 additions & 5 deletions lib/ClangImporter/ClangDerivedConformances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ lookupDirectWithoutExtensions(NominalTypeDecl *decl, Identifier id) {
return result;
}

/// Similar to ModuleDecl::conformsToProtocol, but doesn't introduce a
/// dependency on Sema.
static bool isConcreteAndValid(ProtocolConformanceRef conformanceRef,
ModuleDecl *module) {
if (conformanceRef.isInvalid())
return false;
if (!conformanceRef.isConcrete())
return false;
auto conformance = conformanceRef.getConcrete();
auto subMap = conformance->getSubstitutions(module);
return llvm::all_of(subMap.getConformances(),
[&](ProtocolConformanceRef each) -> bool {
return isConcreteAndValid(each, module);
});
}

static clang::TypeDecl *
getIteratorCategoryDecl(const clang::CXXRecordDecl *clangDecl) {
clang::IdentifierInfo *iteratorCategoryDeclName =
Expand Down Expand Up @@ -126,7 +142,9 @@ static ValueDecl *getMinusOperator(NominalTypeDecl *decl) {
if (lhsNominal != rhsNominal || lhsNominal != decl)
return false;
auto returnTy = minus->getResultInterfaceType();
if (!module->conformsToProtocol(returnTy, binaryIntegerProto))
auto conformanceRef =
module->lookupConformance(returnTy, binaryIntegerProto);
if (!isConcreteAndValid(conformanceRef, module))
return false;
return true;
};
Expand Down Expand Up @@ -331,9 +349,10 @@ void swift::conformToCxxSequenceIfNeeded(
return;

// Check if RawIterator conforms to UnsafeCxxInputIterator.
auto rawIteratorConformanceRef = decl->getModuleContext()->conformsToProtocol(
rawIteratorTy, cxxIteratorProto);
if (!rawIteratorConformanceRef || !rawIteratorConformanceRef.isConcrete())
ModuleDecl *module = decl->getModuleContext();
auto rawIteratorConformanceRef =
module->lookupConformance(rawIteratorTy, cxxIteratorProto);
if (!isConcreteAndValid(rawIteratorConformanceRef, module))
return;
auto rawIteratorConformance = rawIteratorConformanceRef.getConcrete();
auto pointeeDecl =
Expand All @@ -356,7 +375,7 @@ void swift::conformToCxxSequenceIfNeeded(
return declSelfTy;
return Type(dependentType);
},
LookUpConformanceInModule(decl->getModuleContext()));
LookUpConformanceInModule(module));

impl.addSynthesizedTypealias(decl, ctx.Id_Element, pointeeTy);
impl.addSynthesizedTypealias(decl, ctx.Id_Iterator, iteratorTy);
Expand Down
4 changes: 3 additions & 1 deletion lib/SIL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ target_link_libraries(swiftSIL PUBLIC
swiftDemangling)
target_link_libraries(swiftSIL PRIVATE
swiftAST
swiftClangImporter)
swiftClangImporter
swiftSema
swiftSerialization)

add_subdirectory(IR)
add_subdirectory(Utils)
Expand Down
1 change: 1 addition & 0 deletions lib/SILGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_swift_host_library(swiftSILGen STATIC
SILGenThunk.cpp
SILGenType.cpp)
target_link_libraries(swiftSILGen PRIVATE
swiftSerialization
swiftSIL)

set_swift_llvm_is_available(swiftSILGen)
1 change: 1 addition & 0 deletions tools/sil-passpipeline-dumper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_swift_host_tool(sil-passpipeline-dumper
target_link_libraries(sil-passpipeline-dumper PRIVATE
swiftFrontend
swiftIRGen
swiftSema
swiftSILGen
swiftSILOptimizer
# Clang libraries included to appease the linker on linux.
Expand Down