Skip to content

Commit f39a0a8

Browse files
committed
RequirementMachine: Use the correct predicate to determine if a class uses Objective-C reference counting
Also, introduce the layout requirement implied by a superclass requirement when lowering requirements, instead of when building the property map. Right now this is functionally equivalent, but if we ever start to test properties by checking for joinability of T with T.[p] instead of looking at the property map entry of T, this new formulation is the right one.
1 parent 990d93f commit f39a0a8

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

lib/AST/RequirementMachine/PropertyMap.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -493,17 +493,6 @@ void PropertyBag::addProperty(
493493
return;
494494

495495
case Symbol::Kind::Superclass: {
496-
auto superclass = property.getSuperclass();
497-
498-
// A superclass requirement implies a layout requirement.
499-
auto layout =
500-
LayoutConstraint::getLayoutConstraint(
501-
superclass->getClassOrBoundGenericClass()->isObjC()
502-
? LayoutConstraintKind::Class
503-
: LayoutConstraintKind::NativeClass,
504-
ctx.getASTContext());
505-
addProperty(Symbol::forLayout(layout, ctx), ctx, inducedRules, debug);
506-
507496
// FIXME: This needs to find the most derived subclass and also call
508497
// unifyConcreteTypes()
509498
Superclass = property;

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ void RewriteSystemBuilder::addRequirement(const Requirement &req,
171171
// A superclass requirement T : C<X, Y> becomes a rewrite rule
172172
//
173173
// T.[superclass: C<X, Y>] => T
174+
//
175+
// Together with a rewrite rule
176+
//
177+
// T.[layout: L] => T
178+
//
179+
// Where 'L' is either AnyObject or _NativeObject, depending on the
180+
// ancestry of C.
174181
auto otherType = CanType(req.getSecondType());
175182

176183
SmallVector<Term, 1> substitutions;
@@ -180,6 +187,16 @@ void RewriteSystemBuilder::addRequirement(const Requirement &req,
180187
constraintTerm = subjectTerm;
181188
constraintTerm.add(Symbol::forSuperclass(otherType, substitutions,
182189
Context));
190+
Rules.emplace_back(subjectTerm, constraintTerm);
191+
192+
constraintTerm = subjectTerm;
193+
auto layout =
194+
LayoutConstraint::getLayoutConstraint(
195+
otherType->getClassOrBoundGenericClass()->usesObjCObjectModel()
196+
? LayoutConstraintKind::Class
197+
: LayoutConstraintKind::NativeClass,
198+
Context.getASTContext());
199+
constraintTerm.add(Symbol::forLayout(layout, Context));
183200
break;
184201
}
185202

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-typecheck-verify-swift %clang-importer-sdk -requirement-machine=verify -debug-requirement-machine 2>&1 | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
import Foundation
6+
7+
class Generic<T> : NSObject {}
8+
9+
func foo<T : Generic<U>, U>(_: T, _: U) {
10+
_ = T.self
11+
_ = U.self
12+
}
13+
14+
// CHECK-LABEL: Requirement machine for <τ_0_0, τ_0_1 where τ_0_0 : Generic<τ_0_1>>
15+
// CHECK-NEXT: Rewrite system: {
16+
// CHECK-NEXT: - τ_0_0.[superclass: Generic<τ_0_0> with <τ_0_1>] => τ_0_0
17+
// CHECK-NEXT: - τ_0_0.[layout: AnyObject] => τ_0_0
18+
// CHECK-NEXT: }
19+
// CHECK-NEXT: Property map: {
20+
// CHECK-NEXT: τ_0_0 => { layout: AnyObject superclass: [superclass: Generic<τ_0_0> with <τ_0_1>] }
21+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)