Skip to content

Commit 6f43efe

Browse files
committed
[interop][SwiftToCxx] add a restriction for calling only supported type metadata accessor function for generic types
1 parent 9f26709 commit 6f43efe

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/PrintAsClang/ClangSyntaxPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ void ClangSyntaxPrinter::printValueWitnessTableAccessSequenceFromTypeMetadata(
191191
void ClangSyntaxPrinter::printCTypeMetadataTypeFunction(
192192
const NominalTypeDecl *typeDecl, StringRef typeMetadataFuncName,
193193
llvm::ArrayRef<GenericRequirement> genericRequirements) {
194+
// FIXME: Support generic requirements > 3.
195+
if (!genericRequirements.empty())
196+
os << "static_assert(" << genericRequirements.size()
197+
<< " <= " << NumDirectGenericTypeMetadataAccessFunctionArgs
198+
<< ", \"unsupported generic requirement list for metadata func\");\n";
194199
os << "// Type metadata accessor for " << typeDecl->getNameStr() << "\n";
195200
os << "SWIFT_EXTERN ";
196201
printSwiftImplQualifier();

test/Interop/SwiftToCxx/generics/generic-struct-in-cxx.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public func takeGenericPair<T, T1>(_ x: GenericPair<T, T1>) {
2929
// CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0> && swift::isUsableInGenericContext<T_0_1>
3030
// CHECK-NEXT: class _impl_GenericPair;
3131
// CHECK-EMPTY:
32+
// CHECK-NEXT: static_assert(2 <= 3, "unsupported generic requirement list for metadata func");
3233
// CHECK-NEXT: // Type metadata accessor for GenericPair
3334
// CHECK-NEXT: SWIFT_EXTERN swift::_impl::MetadataResponseTy $s8Generics11GenericPairVMa(swift::_impl::MetadataRequestTy, void * _Nonnull, void * _Nonnull) SWIFT_NOEXCEPT SWIFT_CALL;
3435

0 commit comments

Comments
 (0)