-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Disambiguate template instantiations with parameter packs #77450
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
Conversation
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
void VisitPackTemplateArgument(const clang::TemplateArgument &arg, | ||
llvm::raw_svector_ostream &buffer) { | ||
VisitTemplateArgumentArray(arg.getPackAsArray(), buffer); | ||
} | ||
|
||
void VisitTemplateArgumentArray(ArrayRef<clang::TemplateArgument> args, | ||
llvm::raw_svector_ostream &buffer) { | ||
bool needsComma = false; | ||
for (auto &arg : args) { | ||
// Do not try to print empty packs. | ||
if (arg.getKind() == clang::TemplateArgument::ArgKind::Pack && | ||
arg.getPackAsArray().empty()) | ||
continue; | ||
|
||
if (needsComma) | ||
buffer << ", "; | ||
Visit(arg, buffer); | ||
needsComma = true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit is the new functionality, the rest is just refactoring.
// Unfortunately, clang::templateargumentvisitor::Base does not correctly | ||
// perform static dispatch for methods that aren't overloaded, so we have to | ||
// overload all of them here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to submit a patch to upstream Clang to fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Patch up: llvm/llvm-project#115336
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you're converting a Clang Type into something that looks like a string printout of a Swift Type. Don't you already have the Swift Type for the template argument somewhere so you can just print that out instead?
@slavapestov we don't always import the types of template arguments. They are only imported if used elsewhere in the header within fields, parameters, etc. The template parameter could also have a type that we don't import into Swift, or it can be a literal value or an expression that we wouldn't import into Swift. |
This makes sure that different template instantiations of `std::tuple` get distinct Swift type names. Similar to aa6804a. This also refactors `swift::importer::printClassTemplateSpecializationName` to follow a proper visitor pattern for the C++ template arguments. rdar://139435937
09c373f
to
d66c8ed
Compare
Please test with following PR: @swift-ci please smoke test |
Please test with following PR: @swift-ci please smoke test |
Please test with following PR: @swift-ci please clean smoke test |
Please test with following PR: @swift-ci please smoke test |
C++ class template instantiations previously did not get a valid generated Swift type name if they used variadic generics. See swiftlang/swift#77450. Since fully enabling the test requires the Swift PR to be merged, and the Swift PR relies on this test passing, this PR temporarily disables the failing asserts. rdar://139435937 rdar://106459037
Please test with following PR: @swift-ci please smoke test |
C++ class template instantiations previously did not get a valid generated Swift type name if they used variadic generics. See swiftlang/swift#77450. rdar://139435937 rdar://106459037
This makes sure that different template instantiations of
std::tuple
get distinct Swift type names.Similar to aa6804a.
This also refactors
swift::importer::printClassTemplateSpecializationName
to follow a proper visitor pattern for the C++ template arguments.rdar://139435937