Skip to content

Commit 7c34c3b

Browse files
committed
AST: Drop useless AnyObject requirement in ArchetypeType::getExistentialType()
Fixes rdar://problem/101917443.
1 parent a0652cc commit 7c34c3b

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

lib/AST/Type.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3503,15 +3503,21 @@ Type ArchetypeType::getExistentialType() const {
35033503
// Otherwise, compute it from scratch.
35043504
SmallVector<Type, 4> constraintTypes;
35053505

3506+
bool hasExplicitAnyObject = requiresClass();
3507+
35063508
if (auto super = getSuperclass()) {
3509+
hasExplicitAnyObject = false;
35073510
constraintTypes.push_back(super);
35083511
}
35093512
for (auto proto : getConformsTo()) {
3513+
if (proto->requiresClass())
3514+
hasExplicitAnyObject = false;
35103515
constraintTypes.push_back(proto->getDeclaredInterfaceType());
35113516
}
3517+
35123518
auto &ctx = const_cast<ArchetypeType*>(this)->getASTContext();
35133519
auto constraint = ProtocolCompositionType::get(
3514-
ctx, constraintTypes, requiresClass());
3520+
ctx, constraintTypes, hasExplicitAnyObject);
35153521

35163522
// If the archetype is only constrained to a class type,
35173523
// return the class type directly.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@import Foundation;
2+
3+
@protocol P
4+
@end
5+
6+
@interface C: NSObject
7+
@end
8+
9+
@interface Base<T> : NSObject
10+
@end
11+
12+
@interface Derived: Base
13+
@end
14+
15+
@interface BaseWithProtocol<T: id<P>> : NSObject
16+
@end
17+
18+
@interface DerivedWithProtocol: BaseWithProtocol
19+
@end
20+
21+
@interface BaseWithClass<T: C *> : NSObject
22+
@end
23+
24+
@interface DerivedWithClass: BaseWithClass
25+
@end
26+
27+
@interface BaseWithBoth<T: C<P> *> : NSObject
28+
@end
29+
30+
@interface DerivedWithBoth: BaseWithBoth
31+
@end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s -import-objc-header %S/Inputs/objc_generics_upper_bound.h
2+
3+
// REQUIRES: objc_interop
4+
5+
func upperBound(derived: Derived) -> Base<AnyObject> {
6+
return derived
7+
}
8+
9+
func upperBound(derived: DerivedWithProtocol) -> BaseWithProtocol<any P> {
10+
return derived
11+
}
12+
13+
func upperBound(derived: DerivedWithClass) -> BaseWithClass<C> {
14+
return derived
15+
}
16+
17+
func upperBound(derived: DerivedWithBoth) -> BaseWithBoth<any C & P> {
18+
return derived
19+
}

test/IRGen/objc_extensions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ class SwiftSubGizmo : SwiftBaseGizmo {
206206
extension FungingArray {
207207
// CHECK-LABEL: define {{.*}} @"$sSo12FungingArrayC15objc_extensionsEyAByxGxcfC"
208208
// CHECK-SAME: (%objc_object* %0, %swift.type* swiftself %1)
209-
// CHECK: @__swift_instantiateConcreteTypeFromMangledName{{.*}}@"$sSo9NSFunging_XlMD"{{.*}}!dbg
209+
// CHECK: @__swift_instantiateConcreteTypeFromMangledName{{.*}}@"$sSo9NSFunging_pMD"{{.*}}!dbg
210210

211211
// CHECK-LABEL: define {{.*}} @"$sSo12FungingArrayC15objc_extensionsEyAByxGxcfc"
212212
// CHECK-SAME: (%objc_object* %0, %TSo12FungingArrayC* swiftself %1)
213213
// CHECK: [[ALLOCA:%[^, =]+]] = alloca %Any, align 8
214-
// CHECK: @__swift_instantiateConcreteTypeFromMangledName{{.*}}@"$sSo9NSFunging_XlMD"{{.*}}!dbg
214+
// CHECK: @__swift_instantiateConcreteTypeFromMangledName{{.*}}@"$sSo9NSFunging_pMD"{{.*}}!dbg
215215
// CHECK: {{%[^, =]+}} = getelementptr inbounds %Any, %Any* [[ALLOCA]], i32 0, i32 0
216216
// CHECK: [[ANYBUF:%[^, =]+]] = getelementptr inbounds %Any, %Any* [[ALLOCA]], i32 0, i32 0
217217
// CHECK: [[BUFPTR:%[^, =]+]] = {{.*}} [[ANYBUF]]
@@ -225,12 +225,12 @@ extension FungingArray {
225225

226226
// CHECK-LABEL: define {{.*}} @"$sSo12FungingArrayC15objc_extensionsE7pinningAByxGxm_tcfC"
227227
// CHECK-SAME: (%swift.type* %0, %swift.type* swiftself %1)
228-
// CHECK: @__swift_instantiateConcreteTypeFromMangledName{{.*}}@"$sSo9NSFunging_XlMD"{{.*}}!dbg
228+
// CHECK: @__swift_instantiateConcreteTypeFromMangledName{{.*}}@"$sSo9NSFunging_pMD"{{.*}}!dbg
229229

230230
// CHECK-LABEL: define {{.*}} @"$sSo12FungingArrayC15objc_extensionsE7pinningAByxGxm_tcfc"
231231
// CHECK-SAME: (%swift.type* %0, %TSo12FungingArrayC* swiftself %1)
232232
// CHECK: [[ALLOCA:%[^, =]+]] = alloca %Any, align 8
233-
// CHECK: @__swift_instantiateConcreteTypeFromMangledName{{.*}}@"$sSo9NSFunging_XlMD"{{.*}}!dbg
233+
// CHECK: @__swift_instantiateConcreteTypeFromMangledName{{.*}}@"$sSo9NSFunging_pMD"{{.*}}!dbg
234234
// CHECK: [[OBJC_CLASS:%[^, =]+]] = call %objc_class* @swift_getObjCClassFromMetadata(%swift.type* %0)
235235
// CHECK: [[OBJC_CLASS_OBJ:%[^, =]+]] = bitcast %objc_class* [[OBJC_CLASS]]
236236
// CHECK: {{%[^, =]+}} = getelementptr inbounds %Any, %Any* [[ALLOCA]], i32 0, i32 0

0 commit comments

Comments
 (0)