Skip to content

Commit b32f4f4

Browse files
committed
[NamedLazyMemberLoading] Bail on cases that interact with protocol member mirroring.
1 parent 0e3bde6 commit b32f4f4

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3280,6 +3280,20 @@ ClangImporter::Implementation::loadNamedMembers(
32803280
auto *CD = D->getClangDecl();
32813281
assert(CD && "loadNamedMembers on a Decl without a clangDecl");
32823282

3283+
3284+
// FIXME: The legacy of mirroring protocol members rears its ugly head,
3285+
// and as a result we have to bail on any @interface or @category that
3286+
// has a declared protocol conformance.
3287+
if (auto *ID = dyn_cast<clang::ObjCInterfaceDecl>(CD)) {
3288+
if (ID->protocol_begin() != ID->protocol_end())
3289+
return None;
3290+
}
3291+
if (auto *CCD = dyn_cast<clang::ObjCCategoryDecl>(CD)) {
3292+
if (CCD->protocol_begin() != CCD->protocol_end())
3293+
return None;
3294+
}
3295+
3296+
32833297
// There are 3 cases:
32843298
//
32853299
// - The decl is from a bridging header, CMO is Some(nullptr)

test/NameBinding/Inputs/NamedLazyMembers/NamedLazyMembers.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,28 @@
5050

5151
@end
5252

53+
54+
@protocol MirroredBase
55+
+ (void)mirroredBaseClassMethod;
56+
- (void)mirroredBaseInstanceMethod;
57+
@end
58+
59+
@protocol MirroredDoer <MirroredBase>
60+
+ (void)mirroredDerivedClassMethod;
61+
- (void)mirroredDerivedInstanceMethod;
62+
@end
63+
64+
@interface MirroringDoer : NSObject<MirroredDoer>
65+
- (void)unobtrusivelyGoForWalk;
66+
- (void)unobtrusivelyTakeNap;
67+
- (void)unobtrusivelyEatMeal;
68+
- (void)unobtrusivelyTidyHome;
69+
- (void)unobtrusivelyCallFamily;
70+
- (void)unobtrusivelySingSong;
71+
- (void)unobtrusivelyReadBook;
72+
- (void)unobtrusivelyAttendLecture;
73+
- (void)unobtrusivelyWriteLetter;
74+
@end
75+
76+
@interface DerivedFromMirroringDoer : MirroringDoer
77+
@end

test/NameBinding/named_lazy_member_loading_objc_protocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// Check that named-lazy-member-loading reduces the number of Decls deserialized
99
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -disable-named-lazy-member-loading -stats-output-dir %t/stats-pre %s
1010
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -stats-output-dir %t/stats-post %s
11-
// RUN: %utils/process-stats-dir.py --evaluate-delta 'NumTotalClangImportedEntities < -10' %t/stats-pre %t/stats-post
11+
// RUN: %utils/process-stats-dir.py --evaluate-delta 'NumTotalClangImportedEntities < -9' %t/stats-pre %t/stats-post
1212

1313
import NamedLazyMembers
1414

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// REQUIRES: objc_interop
2+
// REQUIRES: OS=macosx
3+
// RUN: rm -rf %t && mkdir -p %t/stats-pre && mkdir -p %t/stats-post
4+
//
5+
// Prime module cache
6+
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -typecheck %s
7+
//
8+
// Check that named-lazy-member-loading reduces the number of Decls deserialized
9+
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -disable-named-lazy-member-loading -stats-output-dir %t/stats-pre %s
10+
// RUN: %target-swift-frontend -typecheck -I %S/Inputs/NamedLazyMembers -stats-output-dir %t/stats-post %s
11+
12+
import NamedLazyMembers
13+
14+
public func foo(d: MirroringDoer) {
15+
let _ = MirroringDoer.mirroredBaseClassMethod()
16+
let _ = MirroringDoer.mirroredDerivedClassMethod()
17+
let _ = d.mirroredBaseInstanceMethod()
18+
let _ = d.mirroredDerivedInstanceMethod()
19+
}
20+
21+
public func foo(d: DerivedFromMirroringDoer) {
22+
let _ = MirroringDoer.mirroredBaseClassMethod()
23+
let _ = MirroringDoer.mirroredDerivedClassMethod()
24+
let _ = d.mirroredBaseInstanceMethod()
25+
let _ = d.mirroredDerivedInstanceMethod()
26+
}

0 commit comments

Comments
 (0)