Skip to content

Commit e83284e

Browse files
authored
---
yaml --- r: 342011 b: refs/heads/rxwei-patch-1 c: 54d00ab h: refs/heads/master i: 342009: 3084b28 342007: aa7306d
1 parent 72dd69e commit e83284e

File tree

16 files changed

+247
-67
lines changed

16 files changed

+247
-67
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 2cf9f09e2c4033414e14e53a67777bd5e0092691
1018+
refs/heads/rxwei-patch-1: 54d00abf47ca89650ccdd49d56a344711816bc8b
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/AST/Decl.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4120,7 +4120,20 @@ class ProtocolDecl final : public NominalTypeDecl {
41204120
Bits.ProtocolDecl.RequiresClass = requiresClass;
41214121
}
41224122

4123-
bool existentialConformsToSelfSlow();
4123+
/// Returns the cached result of \c existentialConformsToSelf or \c None if it
4124+
/// hasn't yet been computed.
4125+
Optional<bool> getCachedExistentialConformsToSelf() const {
4126+
if (Bits.ProtocolDecl.ExistentialConformsToSelfValid)
4127+
return Bits.ProtocolDecl.ExistentialConformsToSelf;
4128+
4129+
return None;
4130+
}
4131+
4132+
/// Caches the result of \c existentialConformsToSelf
4133+
void setCachedExistentialConformsToSelf(bool result) {
4134+
Bits.ProtocolDecl.ExistentialConformsToSelfValid = true;
4135+
Bits.ProtocolDecl.ExistentialConformsToSelf = result;
4136+
}
41244137

41254138
bool existentialTypeSupportedSlow();
41264139

@@ -4134,6 +4147,7 @@ class ProtocolDecl final : public NominalTypeDecl {
41344147
friend class SuperclassTypeRequest;
41354148
friend class RequirementSignatureRequest;
41364149
friend class ProtocolRequiresClassRequest;
4150+
friend class ExistentialConformsToSelfRequest;
41374151
friend class TypeChecker;
41384152

41394153
public:
@@ -4204,13 +4218,7 @@ class ProtocolDecl final : public NominalTypeDecl {
42044218
/// This is only permitted if there is nothing "non-trivial" that we
42054219
/// can do with the metatype, which means the protocol must not have
42064220
/// any static methods and must be declared @objc.
4207-
bool existentialConformsToSelf() const {
4208-
if (Bits.ProtocolDecl.ExistentialConformsToSelfValid)
4209-
return Bits.ProtocolDecl.ExistentialConformsToSelf;
4210-
4211-
return const_cast<ProtocolDecl *>(this)
4212-
->existentialConformsToSelfSlow();
4213-
}
4221+
bool existentialConformsToSelf() const;
42144222

42154223
/// Does this protocol require a self-conformance witness table?
42164224
bool requiresSelfConformanceWitnessTable() const;

branches/rxwei-patch-1/include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4523,6 +4523,9 @@ WARNING(property_wrapper_init_initialValue,none,
45234523
())
45244524
ERROR(property_wrapper_projection_value_missing,none,
45254525
"could not find projection value property %0", (Identifier))
4526+
ERROR(property_wrapper_missing_arg_init, none, "missing argument for parameter "
4527+
"%0 in property wrapper initializer; add 'wrappedValue' and %0 "
4528+
"arguments in '@%1(...)'", (Identifier, StringRef))
45264529

45274530
//------------------------------------------------------------------------------
45284531
// MARK: function builder diagnostics

branches/rxwei-patch-1/include/swift/AST/TypeCheckRequests.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,32 @@ class ProtocolRequiresClassRequest:
201201
void cacheResult(bool value) const;
202202
};
203203

204+
/// Determine whether an existential conforming to a protocol can be matched
205+
/// with a generic type parameter constrained to that protocol.
206+
class ExistentialConformsToSelfRequest:
207+
public SimpleRequest<ExistentialConformsToSelfRequest,
208+
bool(ProtocolDecl *),
209+
CacheKind::SeparatelyCached> {
210+
public:
211+
using SimpleRequest::SimpleRequest;
212+
213+
private:
214+
friend SimpleRequest;
215+
216+
// Evaluation.
217+
llvm::Expected<bool> evaluate(Evaluator &evaluator, ProtocolDecl *decl) const;
218+
219+
public:
220+
// Cycle handling.
221+
void diagnoseCycle(DiagnosticEngine &diags) const;
222+
void noteCycleStep(DiagnosticEngine &diags) const;
223+
224+
// Separate caching.
225+
bool isCached() const { return true; }
226+
Optional<bool> getCachedResult() const;
227+
void cacheResult(bool value) const;
228+
};
229+
204230
/// Determine whether the given declaration is 'final'.
205231
class IsFinalRequest :
206232
public SimpleRequest<IsFinalRequest,

branches/rxwei-patch-1/include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ SWIFT_TYPEID(EnumRawTypeRequest)
2020
SWIFT_TYPEID(OverriddenDeclsRequest)
2121
SWIFT_TYPEID(IsObjCRequest)
2222
SWIFT_TYPEID(ProtocolRequiresClassRequest)
23+
SWIFT_TYPEID(ExistentialConformsToSelfRequest)
2324
SWIFT_TYPEID(IsFinalRequest)
2425
SWIFT_TYPEID(IsDynamicRequest)
2526
SWIFT_TYPEID(RequirementRequest)

branches/rxwei-patch-1/lib/AST/Decl.cpp

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4329,43 +4329,9 @@ bool ProtocolDecl::requiresSelfConformanceWitnessTable() const {
43294329
return isSpecificProtocol(KnownProtocolKind::Error);
43304330
}
43314331

4332-
bool ProtocolDecl::existentialConformsToSelfSlow() {
4333-
// Assume for now that the existential conforms to itself; this
4334-
// prevents circularity issues.
4335-
Bits.ProtocolDecl.ExistentialConformsToSelfValid = true;
4336-
Bits.ProtocolDecl.ExistentialConformsToSelf = true;
4337-
4338-
// If it's not @objc, it conforms to itself only if it has a
4339-
// self-conformance witness table.
4340-
if (!isObjC()) {
4341-
bool hasSelfConformance = requiresSelfConformanceWitnessTable();
4342-
Bits.ProtocolDecl.ExistentialConformsToSelf = hasSelfConformance;
4343-
return hasSelfConformance;
4344-
}
4345-
4346-
// Check whether this protocol conforms to itself.
4347-
for (auto member : getMembers()) {
4348-
if (member->isInvalid())
4349-
continue;
4350-
4351-
if (auto vd = dyn_cast<ValueDecl>(member)) {
4352-
if (!vd->isInstanceMember()) {
4353-
// A protocol cannot conform to itself if it has static members.
4354-
Bits.ProtocolDecl.ExistentialConformsToSelf = false;
4355-
return false;
4356-
}
4357-
}
4358-
}
4359-
4360-
// Check whether any of the inherited protocols fail to conform to
4361-
// themselves.
4362-
for (auto proto : getInheritedProtocols()) {
4363-
if (!proto->existentialConformsToSelf()) {
4364-
Bits.ProtocolDecl.ExistentialConformsToSelf = false;
4365-
return false;
4366-
}
4367-
}
4368-
return true;
4332+
bool ProtocolDecl::existentialConformsToSelf() const {
4333+
return evaluateOrDefault(getASTContext().evaluator,
4334+
ExistentialConformsToSelfRequest{const_cast<ProtocolDecl *>(this)}, true);
43694335
}
43704336

43714337
/// Classify usages of Self in the given type.

branches/rxwei-patch-1/lib/AST/TypeCheckRequests.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,31 @@ void ProtocolRequiresClassRequest::cacheResult(bool value) const {
211211
decl->setCachedRequiresClass(value);
212212
}
213213

214+
//----------------------------------------------------------------------------//
215+
// existentialConformsToSelf computation.
216+
//----------------------------------------------------------------------------//
217+
218+
void ExistentialConformsToSelfRequest::diagnoseCycle(DiagnosticEngine &diags) const {
219+
auto decl = std::get<0>(getStorage());
220+
diags.diagnose(decl, diag::circular_protocol_def, decl->getName());
221+
}
222+
223+
void ExistentialConformsToSelfRequest::noteCycleStep(DiagnosticEngine &diags) const {
224+
auto requirement = std::get<0>(getStorage());
225+
diags.diagnose(requirement, diag::kind_declname_declared_here,
226+
DescriptiveDeclKind::Protocol, requirement->getName());
227+
}
228+
229+
Optional<bool> ExistentialConformsToSelfRequest::getCachedResult() const {
230+
auto decl = std::get<0>(getStorage());
231+
return decl->getCachedExistentialConformsToSelf();
232+
}
233+
234+
void ExistentialConformsToSelfRequest::cacheResult(bool value) const {
235+
auto decl = std::get<0>(getStorage());
236+
decl->setCachedExistentialConformsToSelf(value);
237+
}
238+
214239
//----------------------------------------------------------------------------//
215240
// isFinal computation.
216241
//----------------------------------------------------------------------------//

branches/rxwei-patch-1/lib/IDE/ExprContextAnalysis.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,15 @@ class ExprContextAnalyzer {
583583
case ExprKind::Array: {
584584
if (auto type = ParsedExpr->getType()) {
585585
recordPossibleType(type);
586+
break;
587+
}
588+
589+
// Check context types of the array literal expression.
590+
ExprContextInfo arrayCtxtInfo(DC, Parent);
591+
for (auto arrayT : arrayCtxtInfo.getPossibleTypes()) {
592+
if (auto boundGenericT = arrayT->getAs<BoundGenericType>())
593+
if (boundGenericT->getDecl() == Context.getArrayDecl())
594+
recordPossibleType(boundGenericT->getGenericArgs()[0]);
586595
}
587596
break;
588597
}

branches/rxwei-patch-1/lib/Sema/CSDiag.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,13 +3219,20 @@ class ArgumentMatcher : public MatchCallArgumentListener {
32193219

32203220
assert(insertLoc.isValid() && "missing argument after trailing closure?");
32213221

3222-
if (name.empty())
3222+
if (name.empty()) {
32233223
TC.diagnose(insertLoc, diag::missing_argument_positional,
32243224
missingParamIdx + 1)
32253225
.fixItInsert(insertLoc, insertText.str());
3226-
else
3227-
TC.diagnose(insertLoc, diag::missing_argument_named, name)
3228-
.fixItInsert(insertLoc, insertText.str());
3226+
} else {
3227+
if (isPropertyWrapperImplicitInit()) {
3228+
auto TE = cast<TypeExpr>(FnExpr);
3229+
TC.diagnose(TE->getLoc(), diag::property_wrapper_missing_arg_init, name,
3230+
TE->getInstanceType()->getString());
3231+
} else {
3232+
TC.diagnose(insertLoc, diag::missing_argument_named, name)
3233+
.fixItInsert(insertLoc, insertText.str());
3234+
}
3235+
}
32293236

32303237
auto candidate = CandidateInfo[0];
32313238
if (candidate.getDecl())
@@ -3235,6 +3242,27 @@ class ArgumentMatcher : public MatchCallArgumentListener {
32353242
Diagnosed = true;
32363243
}
32373244

3245+
bool isPropertyWrapperImplicitInit() {
3246+
auto TE = dyn_cast<TypeExpr>(FnExpr);
3247+
if (!TE)
3248+
return false;
3249+
3250+
auto instanceTy = TE->getInstanceType();
3251+
if (!instanceTy)
3252+
return false;
3253+
3254+
auto nominalDecl = instanceTy->getAnyNominal();
3255+
if (!(nominalDecl &&
3256+
nominalDecl->getAttrs().hasAttribute<PropertyWrapperAttr>()))
3257+
return false;
3258+
3259+
if (auto *parentExpr = CandidateInfo.CS.getParentExpr(FnExpr)) {
3260+
return parentExpr->isImplicit() && isa<CallExpr>(parentExpr);
3261+
}
3262+
3263+
return false;
3264+
}
3265+
32383266
bool missingLabel(unsigned paramIdx) override {
32393267
return false;
32403268
}

branches/rxwei-patch-1/lib/Sema/TypeCheckDecl.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,34 @@ ProtocolRequiresClassRequest::evaluate(Evaluator &evaluator,
12691269
return false;
12701270
}
12711271

1272+
llvm::Expected<bool>
1273+
ExistentialConformsToSelfRequest::evaluate(Evaluator &evaluator,
1274+
ProtocolDecl *decl) const {
1275+
// If it's not @objc, it conforms to itself only if it has a self-conformance
1276+
// witness table.
1277+
if (!decl->isObjC())
1278+
return decl->requiresSelfConformanceWitnessTable();
1279+
1280+
// Check whether this protocol conforms to itself.
1281+
for (auto member : decl->getMembers()) {
1282+
if (member->isInvalid()) continue;
1283+
1284+
if (auto vd = dyn_cast<ValueDecl>(member)) {
1285+
// A protocol cannot conform to itself if it has static members.
1286+
if (!vd->isInstanceMember())
1287+
return false;
1288+
}
1289+
}
1290+
1291+
// Check whether any of the inherited protocols fail to conform to themselves.
1292+
for (auto proto : decl->getInheritedProtocols()) {
1293+
if (!proto->existentialConformsToSelf())
1294+
return false;
1295+
}
1296+
1297+
return true;
1298+
}
1299+
12721300
llvm::Expected<bool>
12731301
IsFinalRequest::evaluate(Evaluator &evaluator, ValueDecl *decl) const {
12741302
if (isa<ClassDecl>(decl))
@@ -2413,6 +2441,9 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
24132441
(void) VD->isGetterMutating();
24142442
(void) VD->isSetterMutating();
24152443

2444+
// Retrieve the backing property of a wrapped property.
2445+
(void) VD->getPropertyWrapperBackingProperty();
2446+
24162447
// Set up accessors, also lowering lazy and @NSManaged properties.
24172448
maybeAddAccessorsToStorage(VD);
24182449

@@ -5313,7 +5344,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
53135344
}
53145345

53155346
} else {
5316-
SmallPtrSet<VarDecl *, 4> backingStorageVars;
53175347
for (auto member : decl->getMembers()) {
53185348
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
53195349
// Initializers that were synthesized to fulfill derived conformances
@@ -5336,17 +5366,9 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
53365366
}
53375367

53385368
if (auto var = dyn_cast<VarDecl>(member)) {
5339-
// If this variable has a property wrapper, go validate it to ensure
5340-
// that we create the backing storage property.
5341-
if (auto backingVar = var->getPropertyWrapperBackingProperty()) {
5342-
validateDecl(var);
5343-
maybeAddAccessorsToStorage(var);
5344-
5345-
backingStorageVars.insert(backingVar);
5346-
}
5347-
5348-
// Ignore the backing storage for properties with attached wrappers.
5349-
if (backingStorageVars.count(var) > 0)
5369+
// If this is a backing storage property for a property wrapper,
5370+
// skip it.
5371+
if (var->getOriginalWrappedProperty())
53505372
continue;
53515373

53525374
if (var->isMemberwiseInitialized(/*preferDeclaredProperties=*/true)) {

branches/rxwei-patch-1/test/IDE/complete_call_arg.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@
8282
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_AFTERPAREN_2 | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_AFTERPAREN_2
8383
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_SECOND | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_SECOND
8484
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_SKIPPED | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_SKIPPED
85+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_ARRAY_1_AFTERPAREN_1 | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_AFTERPAREN_1
86+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_ARRAY_1_AFTERPAREN_2 | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_AFTERPAREN_2
87+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_ARRAY_1_SECOND | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_SECOND
88+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_ARRAY_1_SKIPPED | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_SKIPPED
89+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_ARRAY_2_AFTERPAREN_1 | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_AFTERPAREN_1
90+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_ARRAY_2_AFTERPAREN_2 | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_AFTERPAREN_2
91+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_ARRAY_2_SECOND | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_SECOND
92+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=IMPLICIT_MEMBER_ARRAY_2_SKIPPED | %FileCheck %s -check-prefix=IMPLICIT_MEMBER_SKIPPED
8593

8694
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ARCHETYPE_GENERIC_1 | %FileCheck %s -check-prefix=ARCHETYPE_GENERIC_1
8795

@@ -688,6 +696,39 @@ func testImplicitMember() {
688696
// IMPLICIT_MEMBER_SKIPPED: Keyword/ExprSpecific: arg4: [#Argument name#];
689697
// IMPLICIT_MEMBER_SKIPPED: End completions
690698
}
699+
func testImplicitMemberInArrayLiteral() {
700+
struct Receiver {
701+
init(_: [TestStaticMemberCall]) {}
702+
init(arg1: Int, arg2: [TestStaticMemberCall]) {}
703+
}
704+
705+
Receiver([
706+
.create1(x: 1),
707+
.create1(#^IMPLICIT_MEMBER_ARRAY_1_AFTERPAREN_1^#),
708+
// Same as IMPLICIT_MEMBER_AFTERPAREN_1.
709+
])
710+
Receiver([
711+
.create2(#^IMPLICIT_MEMBER_ARRAY_1_AFTERPAREN_2^#),
712+
// Same as IMPLICIT_MEMBER_AFTERPAREN_2.
713+
.create2(1, #^IMPLICIT_MEMBER_ARRAY_1_SECOND^#
714+
// Same as IMPLICIT_MEMBER_SECOND.
715+
])
716+
Receiver(arg1: 12, arg2: [
717+
.create2(1, arg3: 2, #^IMPLICIT_MEMBER_ARRAY_1_SKIPPED^#
718+
// Same as IMPLICIT_MEMBER_SKIPPED.
719+
.create1(x: 12)
720+
])
721+
let _: [TestStaticMemberCall] = [
722+
.create1(#^IMPLICIT_MEMBER_ARRAY_2_AFTERPAREN_1^#),
723+
// Same as STATIC_METHOD_AFTERPAREN_1.
724+
.create2(#^IMPLICIT_MEMBER_ARRAY_2_AFTERPAREN_2^#),
725+
// Same as STATIC_METHOD_AFTERPAREN_2.
726+
.create2(1, #^IMPLICIT_MEMBER_ARRAY_2_SECOND^#),
727+
// Same as STATIC_METHOD_SECOND.
728+
.create2(1, arg3: 2, #^IMPLICIT_MEMBER_ARRAY_2_SKIPPED^#),
729+
// Same as STATIC_METHOD_SKIPPED.
730+
]
731+
}
691732

692733
struct Wrap<T> {
693734
func method<U>(_ fn: (T) -> U) -> Wrap<U> {}

0 commit comments

Comments
 (0)