Skip to content

Commit 558ed7b

Browse files
authored
Merge pull request #71887 from slavapestov/cxx-assert
C++Interop: Relax some noncopyable generics assertions
2 parents 40cbdd3 + 6cc4738 commit 558ed7b

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

lib/AST/SwiftNameTranslation.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,19 @@ swift::cxx_translation::getDeclRepresentation(const ValueDecl *VD) {
283283
// Generic requirements are not yet supported in C++.
284284
if (genericSignature) {
285285

286-
// FIXME: We're using getRequirementsWithInverses() here as a shortcut for
287-
// checking for "no requirements except the implied Copyable ones".
286+
// FIXME: This should use getRequirements() and actually
287+
// support arbitrary requirements. We don't really want
288+
// to use getRequirementsWithInverses() here.
288289
//
289-
// Eventually you don't want to call getRequirementsWithInverses() at all;
290-
// instead, the code here should walk the desugared requirements of the
291-
// signature directly and handle everything.
290+
// For now, we use the inverse transform as a quick way to
291+
// check for the "default" generic signature where each
292+
// generic parameter is Copyable and Escapable, but not
293+
// subject to any other requirements; that's exactly the
294+
// generic signature that C++ interop supports today.
292295
SmallVector<Requirement, 2> reqs;
293296
SmallVector<InverseRequirement, 2> inverseReqs;
294297
genericSignature->getRequirementsWithInverses(reqs, inverseReqs);
295-
assert(inverseReqs.empty() && "Non-copyable generics not supported here!");
296-
if (!reqs.empty())
298+
if (!reqs.empty() || !inverseReqs.empty())
297299
return {Unsupported, UnrepresentableGenericRequirements};
298300
}
299301

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,17 @@ class DeclAndTypePrinter::Implementation
386386
SmallVector<Requirement, 2> reqs;
387387
SmallVector<InverseRequirement, 2> inverseReqs;
388388
if (auto sig = ed->getGenericSignature()) {
389+
// FIXME: This should use getRequirements() and actually
390+
// support arbitrary requirements. We don't really want
391+
// to use getRequirementsWithInverses() here.
392+
//
393+
// For now, we use the inverse transform as a quick way to
394+
// check for the "default" generic signature where each
395+
// generic parameter is Copyable and Escapable, but not
396+
// subject to any other requirements; that's exactly the
397+
// generic signature that C++ interop supports today.
389398
sig->getRequirementsWithInverses(reqs, inverseReqs);
390-
assert(inverseReqs.empty() &&
391-
"Non-copyable generics not supported here!");
392-
// FIXME: support requirements.
393-
if (!reqs.empty())
399+
if (!reqs.empty() || !inverseReqs.empty())
394400
continue;
395401
}
396402
printMembers(ed->getMembers());

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,19 @@ ClangRepresentation DeclAndTypeClangFunctionPrinter::printFunctionSignature(
701701
if (FD->isGeneric()) {
702702
auto Signature = FD->getGenericSignature().getCanonicalSignature();
703703

704-
// FIXME: Support generic requirements.
704+
// FIXME: This should use getRequirements() and actually
705+
// support arbitrary requirements. We don't really want
706+
// to use getRequirementsWithInverses() here.
707+
//
708+
// For now, we use the inverse transform as a quick way to
709+
// check for the "default" generic signature where each
710+
// generic parameter is Copyable and Escapable, but not
711+
// subject to any other requirements; that's exactly the
712+
// generic signature that C++ interop supports today.
705713
SmallVector<Requirement, 2> reqs;
706714
SmallVector<InverseRequirement, 2> inverseReqs;
707715
Signature->getRequirementsWithInverses(reqs, inverseReqs);
708-
assert(inverseReqs.empty() && "Non-copyable generics not supported here!");
709-
710-
if (!reqs.empty())
716+
if (!reqs.empty() || !inverseReqs.empty())
711717
return ClangRepresentation::unsupported;
712718
// Print the template and requires clauses for this function.
713719
if (kind == FunctionSignatureKind::CxxInlineThunk)

lib/PrintAsClang/PrintClangValueType.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,15 @@ void ClangValueTypePrinter::printValueTypeDecl(
194194
if (typeDecl->isGeneric()) {
195195
genericSignature = typeDecl->getGenericSignature();
196196

197-
// FIXME: Support generic requirements.
197+
// FIXME: This should use getRequirements() and actually
198+
// support arbitrary requirements. We don't really want
199+
// to use getRequirementsWithInverses() here.
200+
//
201+
// For now, we use the inverse transform as a quick way to
202+
// check for the "default" generic signature where each
203+
// generic parameter is Copyable and Escapable, but not
204+
// subject to any other requirements; that's exactly the
205+
// generic signature that C++ interop supports today.
198206
SmallVector<Requirement, 2> reqs;
199207
SmallVector<InverseRequirement, 2> inverseReqs;
200208
genericSignature->getRequirementsWithInverses(reqs, inverseReqs);

0 commit comments

Comments
 (0)