[cxx-interop][serialization] resolve x-refs to instantiated/synthesized C++ iterator conformance operators

These x-refs might not be resolvable using regular lookup from the 'std' module as they could be instantiated/synthesized
by the clang importer. Augment the lookup logic in that case to try clang importer lookup logic that is used during
the conformance to the C++ iterator protocol.
This commit is contained in:
Alex Lorenz
2024-06-18 12:52:05 -07:00
parent d92f181ace
commit 983fb8025a
5 changed files with 95 additions and 0 deletions

View File

@@ -2039,6 +2039,26 @@ ModuleFile::resolveCrossReference(ModuleID MID, uint32_t pathLen) {
}
filterValues(filterTy, nullptr, nullptr, isType, inProtocolExt,
importedFromClang, isStatic, std::nullopt, values);
if (values.empty() && importedFromClang && name.isOperator() && filterTy) {
// This could be a Clang-importer instantiated/synthesized conformance
// operator, like '==', '-' or '+=', that are required for conformances to
// one of the Cxx iterator protocols. Attempt to resolve it using clang importer
// lookup logic for the given type instead of looking for it in the module.
if (auto *fty = dyn_cast<AnyFunctionType>(filterTy.getPointer())) {
if (fty->getNumParams()) {
assert(fty->getNumParams() <= 2);
auto p = fty->getParams()[0].getParameterType();
if (auto sty = dyn_cast<NominalType>(p.getPointer())) {
if (auto *op = importer::getImportedMemberOperator(
name, sty->getDecl(),
fty->getNumParams() > 1
? fty->getParams()[1].getParameterType()
: std::optional<Type>{}))
values.push_back(op);
}
}
}
}
break;
}