[NCGenerics] printing class-constrained generics

In cases where the generic parameter is class-constrained,
`GenericSignature::requiresProtocol` will not contain `Copyable` or
`Escapable` because GenericSignature minimization will recognize that
the class already requires them.

Thus, because classes always require those protocols, we can
simply ask if the generic parameter is required to be a class to
determine if it had any inverses.
This commit is contained in:
Kavon Farvardin
2024-01-04 17:35:31 -08:00
parent a9b2725520
commit af7ff43d0d
3 changed files with 16 additions and 0 deletions

View File

@@ -1470,6 +1470,10 @@ static void reconstituteInverses(GenericSignature genericSig,
for (auto tp : typeParams) {
assert(tp);
// Any generic parameter requiring a class could not have an inverse.
if (genericSig->requiresClass(tp))
continue;
auto defaults = InverseRequirement::expandDefault(tp);
for (auto ip : defaults) {
auto *proto = ctx.getProtocol(getKnownProtocolKind(ip));

View File

@@ -68,3 +68,11 @@ public typealias SomeAlias<G> = Hello<G>
public typealias AliasWithInverse<G> = Hello<G> where G: ~Copyable, G: ~Escapable
public struct RudePointer<T: ~Copyable>: Copyable {}
public class C {}
public func noInversesSTART() {}
public func checkAny<Result>(_ t: Result) where Result: Any {}
public func usingClassConstraint<Result>(arg: Result) -> Result? where Result: C { return arg }
public func checkAnyObject<Result>(_ t: Result) where Result: AnyObject {}
public func noInversesEND() {}

View File

@@ -96,6 +96,10 @@ import NoncopyableGenerics_Misc
// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public struct RudePointer<T> : Swift.Copyable where T : ~Copyable {
// CHECK-MISC: noInversesSTART
// CHECK-MISC-NOT: ~
// CHECK-MISC: noInversesEND
///////////////////////////////////////////////////////////////////////
// Synthesized conditional conformances are next