Skip to content

Commit e853eb1

Browse files
committed
[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.
1 parent 3ba0a4d commit e853eb1

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,10 @@ static void reconstituteInverses(GenericSignature genericSig,
14721472
for (auto tp : typeParams) {
14731473
assert(tp);
14741474

1475+
// Any generic parameter requiring a class could not have an inverse.
1476+
if (genericSig->requiresClass(tp))
1477+
continue;
1478+
14751479
auto defaults = InverseRequirement::expandDefault(tp);
14761480
for (auto ip : defaults) {
14771481
auto *proto = ctx.getProtocol(getKnownProtocolKind(ip));

test/ModuleInterface/Inputs/NoncopyableGenerics_Misc.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ public typealias SomeAlias<G> = Hello<G>
6868
public typealias AliasWithInverse<G> = Hello<G> where G: ~Copyable, G: ~Escapable
6969

7070
public struct RudePointer<T: ~Copyable>: Copyable {}
71+
72+
public class C {}
73+
74+
public func noInversesSTART() {}
75+
public func checkAny<Result>(_ t: Result) where Result: Any {}
76+
public func usingClassConstraint<Result>(arg: Result) -> Result? where Result: C { return arg }
77+
public func checkAnyObject<Result>(_ t: Result) where Result: AnyObject {}
78+
public func noInversesEND() {}

test/ModuleInterface/noncopyable_generics.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ import NoncopyableGenerics_Misc
9696
// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
9797
// CHECK-MISC-NEXT: public struct RudePointer<T> : Swift.Copyable where T : ~Copyable {
9898

99+
// CHECK-MISC: noInversesSTART
100+
// CHECK-MISC-NOT: ~
101+
// CHECK-MISC: noInversesEND
102+
99103
///////////////////////////////////////////////////////////////////////
100104
// Synthesized conditional conformances are next
101105

0 commit comments

Comments
 (0)