mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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));
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user