Skip to content

Commit e7f493e

Browse files
committed
[cxx-interop] Use clang lookups for std::pair conformance
Instead of looking up the *imported* first_type and second_type Swift type aliases, this patch shifts the conformance to look up these typedefs from Clang, and *then* imports them to Swift types to satisfy the CxxPair conformance. Doing so removes the conformance's dependency on eagerly importing such typedefs.
1 parent 55bd1ce commit e7f493e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lib/ClangImporter/ClangDerivedConformances.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,18 +1125,26 @@ static void conformToCxxPair(ClangImporter::Implementation &impl,
11251125
const clang::CXXRecordDecl *clangDecl) {
11261126
PrettyStackTraceDecl trace("conforming to CxxPair", decl);
11271127
ASTContext &ctx = decl->getASTContext();
1128+
clang::Sema &clangSema = impl.getClangSema();
1129+
1130+
auto *first_type = lookupCxxTypeMember(clangSema, clangDecl, "first_type",
1131+
/*mustBeComplete=*/true);
1132+
auto *second_type = lookupCxxTypeMember(clangSema, clangDecl, "second_type",
1133+
/*mustBeComplete=*/true);
1134+
if (!first_type || !second_type)
1135+
return;
11281136

1129-
auto firstType = lookupDirectSingleWithoutExtensions<TypeAliasDecl>(
1130-
decl, ctx.getIdentifier("first_type"));
1131-
auto secondType = lookupDirectSingleWithoutExtensions<TypeAliasDecl>(
1132-
decl, ctx.getIdentifier("second_type"));
1133-
if (!firstType || !secondType)
1137+
auto *First = dyn_cast_or_null<TypeAliasDecl>(
1138+
impl.importDecl(first_type, impl.CurrentVersion));
1139+
auto *Second = dyn_cast_or_null<TypeAliasDecl>(
1140+
impl.importDecl(second_type, impl.CurrentVersion));
1141+
if (!First || !Second)
11341142
return;
11351143

11361144
impl.addSynthesizedTypealias(decl, ctx.getIdentifier("First"),
1137-
firstType->getUnderlyingType());
1145+
First->getUnderlyingType());
11381146
impl.addSynthesizedTypealias(decl, ctx.getIdentifier("Second"),
1139-
secondType->getUnderlyingType());
1147+
Second->getUnderlyingType());
11401148
impl.addSynthesizedProtocolAttrs(decl, {KnownProtocolKind::CxxPair});
11411149
}
11421150

0 commit comments

Comments
 (0)