Skip to content

Commit 10d7479

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents d2aa3b8 + 443e091 commit 10d7479

File tree

6 files changed

+176
-11
lines changed

6 files changed

+176
-11
lines changed

lib/PrintAsObjC/DeclAndTypePrinter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,7 @@ class DeclAndTypePrinter::Implementation
13401340
return true;
13411341
}
13421342

1343+
public:
13431344
/// If \p nominal is bridged to an Objective-C class (via a conformance to
13441345
/// _ObjectiveCBridgeable), return that class.
13451346
///
@@ -1370,6 +1371,7 @@ class DeclAndTypePrinter::Implementation
13701371
return objcType->getClassOrBoundGenericClass();
13711372
}
13721373

1374+
private:
13731375
/// If the nominal type is bridged to Objective-C (via a conformance
13741376
/// to _ObjectiveCBridgeable), print the bridged type.
13751377
void printObjCBridgeableType(const NominalTypeDecl *swiftNominal,
@@ -2068,6 +2070,14 @@ bool DeclAndTypePrinter::isEmptyExtensionDecl(const ExtensionDecl *ED) {
20682070
return getImpl().isEmptyExtensionDecl(ED);
20692071
}
20702072

2073+
const TypeDecl *DeclAndTypePrinter::getObjCTypeDecl(const TypeDecl* TD) {
2074+
if (auto *nominal = dyn_cast<NominalTypeDecl>(TD))
2075+
if (auto *bridged = getImpl().getObjCBridgedClass(nominal))
2076+
return bridged;
2077+
2078+
return TD;
2079+
}
2080+
20712081
StringRef
20722082
DeclAndTypePrinter::maybeGetOSObjectBaseName(const clang::NamedDecl *decl) {
20732083
StringRef name = decl->getName();

lib/PrintAsObjC/DeclAndTypePrinter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class DeclAndTypePrinter {
7373
/// Is \p ED empty of members and protocol conformances to include?
7474
bool isEmptyExtensionDecl(const ExtensionDecl *ED);
7575

76+
/// Returns the type that will be printed by PrintAsObjC for a parameter or
77+
/// result type resolved to this declaration.
78+
///
79+
/// \warning This handles \c _ObjectiveCBridgeable types, but it doesn't
80+
/// currently know about other aspects of PrintAsObjC behavior, like known
81+
/// types.
82+
const TypeDecl *getObjCTypeDecl(const TypeDecl* TD);
83+
7684
/// Prints a category declaring the given members.
7785
///
7886
/// All members must have the same parent type. The list must not be empty.

lib/PrintAsObjC/ModuleContentsWriter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "swift/AST/ExistentialLayout.h"
1818
#include "swift/AST/Module.h"
19+
#include "swift/AST/PrettyStackTrace.h"
1920
#include "swift/AST/ProtocolConformance.h"
2021
#include "swift/AST/SwiftNameTranslation.h"
2122
#include "swift/AST/TypeDeclFinder.h"
@@ -236,6 +237,8 @@ class ModuleWriter {
236237
}
237238

238239
bool forwardDeclareMemberTypes(DeclRange members, const Decl *container) {
240+
PrettyStackTraceDecl
241+
entry("printing forward declarations needed by members of", container);
239242
switch (container->getKind()) {
240243
case DeclKind::Class:
241244
case DeclKind::Protocol:
@@ -248,6 +251,7 @@ class ModuleWriter {
248251
bool hadAnyDelayedMembers = false;
249252
SmallVector<ValueDecl *, 4> nestedTypes;
250253
for (auto member : members) {
254+
PrettyStackTraceDecl loopEntry("printing for member", member);
251255
auto VD = dyn_cast<ValueDecl>(member);
252256
if (!VD || !printer.shouldInclude(VD))
253257
continue;
@@ -270,9 +274,14 @@ class ModuleWriter {
270274
ReferencedTypeFinder::walk(VD->getInterfaceType(),
271275
[&](ReferencedTypeFinder &finder,
272276
const TypeDecl *TD) {
277+
PrettyStackTraceDecl
278+
entry("walking its interface type, currently at", TD);
273279
if (TD == container)
274280
return;
275281

282+
// Bridge, if necessary.
283+
TD = printer.getObjCTypeDecl(TD);
284+
276285
if (finder.needsDefinition() && isa<NominalTypeDecl>(TD)) {
277286
// We can delay individual members of classes; do so if necessary.
278287
if (isa<ClassDecl>(container)) {

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -946,17 +946,22 @@ class OverrideFilteringConsumer : public VisibleDeclConsumer {
946946
/*wouldConflictInSwift5*/nullptr,
947947
/*skipProtocolExtensionCheck*/true)) {
948948
FoundConflicting = true;
949-
// Prefer derived requirements over their witnesses.
950-
if (Reason ==
951-
DeclVisibilityKind::MemberOfProtocolDerivedByCurrentNominal ||
952-
VD->getFormalAccess() > OtherVD->getFormalAccess() ||
953-
//Prefer available one.
954-
(!AvailableAttr::isUnavailable(VD) &&
955-
AvailableAttr::isUnavailable(OtherVD))) {
956-
FilteredResults.remove(
957-
FoundDeclTy(OtherVD, DeclVisibilityKind::LocalVariable, {}));
958-
FilteredResults.insert(DeclAndReason);
959-
*I = VD;
949+
950+
if (!AvailableAttr::isUnavailable(VD)) {
951+
bool preferVD = (
952+
// Prefer derived requirements over their witnesses.
953+
Reason == DeclVisibilityKind::
954+
MemberOfProtocolDerivedByCurrentNominal ||
955+
// Prefer available one.
956+
AvailableAttr::isUnavailable(OtherVD) ||
957+
// Prefer more accessible one.
958+
VD->getFormalAccess() > OtherVD->getFormalAccess());
959+
if (preferVD) {
960+
FilteredResults.remove(
961+
FoundDeclTy(OtherVD, DeclVisibilityKind::LocalVariable, {}));
962+
FilteredResults.insert(DeclAndReason);
963+
*I = VD;
964+
}
960965
}
961966
}
962967
}

test/IDE/complete_rdar67155695.swift

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=PUBLIC | %FileCheck %s --check-prefix=PUBLIC
2+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=INTERNAL | %FileCheck %s --check-prefix=INTERNAL
3+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token=PRIVATE | %FileCheck %s --check-prefix=PRIVATE
4+
5+
public protocol PubP {}
6+
7+
public extension PubP {
8+
func availableP_availableC() {}
9+
10+
func availableP_unavailableC() {}
11+
12+
@available(*, unavailable)
13+
func unavailableP_availableC() {}
14+
15+
@available(*, unavailable)
16+
func unavailableP_unavailableC() {}
17+
}
18+
19+
struct TestForPubP: PubP {
20+
func availableP_availableC() {}
21+
22+
@available(*, unavailable)
23+
func availableP_unavailableC() {}
24+
25+
func unavailableP_availableC() {}
26+
27+
@available(*, unavailable)
28+
func unavailableP_unavailableC() {}
29+
}
30+
31+
func test(val: TestForPubP) {
32+
val.#^PUBLIC^#
33+
// PUBLIC: Begin completions, 4 items
34+
// PUBLIC-DAG: Keyword[self]/CurrNominal: self[#TestForPubP#];
35+
// PUBLIC-DAG: Decl[InstanceMethod]/CurrNominal: unavailableP_availableC()[#Void#];
36+
// PUBLIC-DAG: Decl[InstanceMethod]/Super: availableP_availableC()[#Void#];
37+
// PUBLIC-DAG: Decl[InstanceMethod]/Super: availableP_unavailableC()[#Void#];
38+
// PUBLIC: End completions
39+
}
40+
41+
protocol InternalP {}
42+
43+
extension InternalP {
44+
func availableP_availableC() {}
45+
46+
func availableP_unavailableC() {}
47+
48+
@available(*, unavailable)
49+
func unavailableP_availableC() {}
50+
51+
@available(*, unavailable)
52+
func unavailableP_unavailableC() {}
53+
}
54+
55+
struct TestForInternalP: InternalP {
56+
func availableP_availableC() {}
57+
58+
@available(*, unavailable)
59+
func availableP_unavailableC() {}
60+
61+
func unavailableP_availableC() {}
62+
63+
@available(*, unavailable)
64+
func unavailableP_unavailableC() {}
65+
}
66+
67+
func test(val: TestForInternalP) {
68+
val.#^INTERNAL^#
69+
// INTERNAL: Begin completions, 4 items
70+
// INTERNAL-DAG: Keyword[self]/CurrNominal: self[#TestForInternalP#];
71+
// INTERNAL-DAG: Decl[InstanceMethod]/CurrNominal: availableP_availableC()[#Void#];
72+
// INTERNAL-DAG: Decl[InstanceMethod]/CurrNominal: unavailableP_availableC()[#Void#];
73+
// INTERNAL-DAG: Decl[InstanceMethod]/Super: availableP_unavailableC()[#Void#];
74+
// INTERNAL: End completions
75+
}
76+
77+
private protocol PrivP {}
78+
79+
private extension PrivP {
80+
func availableP_availableC() {}
81+
82+
func availableP_unavailableC() {}
83+
84+
@available(*, unavailable)
85+
func unavailableP_availableC() {}
86+
87+
@available(*, unavailable)
88+
func unavailableP_unavailableC() {}
89+
}
90+
91+
struct TestForPrivP: PrivP {
92+
func availableP_availableC() {}
93+
94+
@available(*, unavailable)
95+
func availableP_unavailableC() {}
96+
97+
func unavailableP_availableC() {}
98+
99+
@available(*, unavailable)
100+
func unavailableP_unavailableC() {}
101+
}
102+
103+
func test(val: TestForPrivP) {
104+
val.#^PRIVATE^#
105+
// PRIVATE: Begin completions, 4 items
106+
// PRIVATE-DAG: Keyword[self]/CurrNominal: self[#TestForPrivP#];
107+
// PRIVATE-DAG: Decl[InstanceMethod]/CurrNominal: availableP_availableC()[#Void#];
108+
// PRIVATE-DAG: Decl[InstanceMethod]/CurrNominal: unavailableP_availableC()[#Void#];
109+
// PRIVATE-DAG: Decl[InstanceMethod]/Super: availableP_unavailableC()[#Void#];
110+
// PRIVATE-DAG: End completions
111+
}

test/PrintAsObjC/classes.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,26 @@ import SingleGenericClass
4949
// CHECK-NEXT: @end
5050
@objc class B1 : A1 {}
5151

52+
// Used in BridgedTypes test case
53+
struct Notification: _ObjectiveCBridgeable {
54+
func _bridgeToObjectiveC() -> NSNotification { fatalError() }
55+
static func _forceBridgeFromObjectiveC(
56+
_ source: NSNotification,
57+
result: inout Self?
58+
) { fatalError() }
59+
@discardableResult
60+
static func _conditionallyBridgeFromObjectiveC(
61+
_ source: NSNotification,
62+
result: inout Self?
63+
) -> Bool { fatalError() }
64+
@_effects(readonly)
65+
static func _unconditionallyBridgeFromObjectiveC(_ source: _ObjectiveCType?)
66+
-> Self { fatalError() }
67+
}
68+
5269
// CHECK-LABEL: @interface BridgedTypes
5370
// CHECK-NEXT: - (NSDictionary * _Nonnull)dictBridge:(NSDictionary * _Nonnull)x SWIFT_WARN_UNUSED_RESULT;
71+
// CHECK-NEXT: - (NSNotification * _Nonnull)noteBridge:(NSNotification * _Nonnull)x SWIFT_WARN_UNUSED_RESULT;
5472
// CHECK-NEXT: - (NSSet * _Nonnull)setBridge:(NSSet * _Nonnull)x SWIFT_WARN_UNUSED_RESULT;
5573
// CHECK-NEXT: init
5674
// CHECK-NEXT: @end
@@ -59,6 +77,10 @@ import SingleGenericClass
5977
return x
6078
}
6179

80+
@objc func noteBridge(_ x: Notification) -> Notification {
81+
return x
82+
}
83+
6284
@objc func setBridge(_ x: Set<NSObject>) -> Set<NSObject> {
6385
return x
6486
}

0 commit comments

Comments
 (0)