Skip to content

[interop][SwiftToCxx] do not support generics with requirements for now #60832

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 1 commit into from
Aug 30, 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
44 changes: 26 additions & 18 deletions lib/PrintAsClang/PrintClangFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,24 +318,32 @@ ClangRepresentation DeclAndTypeClangFunctionPrinter::printFunctionSignature(
const AbstractFunctionDecl *FD, StringRef name, Type resultTy,
FunctionSignatureKind kind, ArrayRef<AdditionalParam> additionalParams,
FunctionSignatureModifiers modifiers) {
if (kind == FunctionSignatureKind::CxxInlineThunk && FD->isGeneric()) {
os << "template<";
llvm::interleaveComma(FD->getGenericParams()->getParams(), os,
[&](const GenericTypeParamDecl *genericParam) {
os << "class ";
ClangSyntaxPrinter(os).printBaseName(genericParam);
});
os << ">\n";
os << "requires ";
llvm::interleave(
FD->getGenericParams()->getParams(), os,
[&](const GenericTypeParamDecl *genericParam) {
os << "swift::isUsableInGenericContext<";
ClangSyntaxPrinter(os).printBaseName(genericParam);
os << ">";
},
" && ");
os << "\n";
if (FD->isGeneric()) {
auto Signature = FD->getGenericSignature();
auto Requirements = Signature.getRequirements();
// FIXME: Support generic requirements.
if (!Requirements.empty())
return ClangRepresentation::unsupported;
if (kind == FunctionSignatureKind::CxxInlineThunk) {
os << "template<";
llvm::interleaveComma(FD->getGenericParams()->getParams(), os,
[&](const GenericTypeParamDecl *genericParam) {
os << "class ";
ClangSyntaxPrinter(os).printBaseName(
genericParam);
});
os << ">\n";
os << "requires ";
llvm::interleave(
FD->getGenericParams()->getParams(), os,
[&](const GenericTypeParamDecl *genericParam) {
os << "swift::isUsableInGenericContext<";
ClangSyntaxPrinter(os).printBaseName(genericParam);
os << ">";
},
" && ");
os << "\n";
}
}
auto emittedModule = FD->getModuleContext();
OutputLanguageMode outputLang = kind == FunctionSignatureKind::CFunctionProto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public func genericRet<T>(_ x: T) -> T {
return x
}

public func genericRequirementProtocol<T: Hashable>(_ x: T) {
}

public func genericRequirementClass<T>(_ x: T) where T: TestClass {
}

public class TestClass {
let field: Int

Expand Down Expand Up @@ -84,6 +90,8 @@ public func createTestSmallStruct(_ x: UInt32) -> TestSmallStruct {
// CHECK-NEXT: SWIFT_EXTERN void $s9Functions10genericRetyxxlF(SWIFT_INDIRECT_RESULT void * _Nonnull, const void * _Nonnull x, void * _Nonnull ) SWIFT_NOEXCEPT SWIFT_CALL; // genericRet(_:)
// CHECK-NEXT: SWIFT_EXTERN void $s9Functions11genericSwapyyxz_xztlF(void * _Nonnull x, void * _Nonnull y, void * _Nonnull ) SWIFT_NOEXCEPT SWIFT_CALL; // genericSwap(_:_:)

// CHECK-NOT: genericRequirement

// Skip templates in impl classes.
// CHECK: _impl_TestSmallStruct
// CHECK: template<class T>
Expand Down