Skip to content

Commit 0cd47b9

Browse files
committed
---
yaml --- r: 341975 b: refs/heads/rxwei-patch-1 c: f9e5de9 h: refs/heads/master i: 341973: ba13a42 341971: a3a51f8 341967: 39dc72e
1 parent 1a46403 commit 0cd47b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+138
-571
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: 934b60e299492389e11f11925cf86cb7b3a628ab
1018+
refs/heads/rxwei-patch-1: f9e5de9371b09eb66506c9c7ba42b862795a1b4b
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/docs/StandardLibraryProgrammersManual.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,6 @@ TODO: Should this subsume or link to [AccessControlInStdlib.rst](https://github.
5050

5151
Optionals can be unwrapped with `!`, which triggers a trap on nil. Alternatively, they can be `.unsafelyUnwrapped()`, which will check and trap in debug builds of user code. Internal to the standard library is `._unsafelyUnwrappedUnchecked()` which will only check and trap in debug builds of the standard library itself. These correspond directly with `_precondition`, `_debugPrecondition`, and `_sanityCheck`. See [that section](#precondition) for details.
5252

53-
#### UnsafeBitCast and Casting References
54-
55-
In general `unsafeBitCast` should be avoided because it's correctness relies on subtle assumptions that will never be enforced, and it indicates a bug in Swift's type system that should be fixed. It's less bad for non-pointer trivial types. Pointer casting should go through one of the memory binding API instead as a last resort.
56-
57-
Reference casting is more interesting. References casting can include converting to an Optional reference and converting from a class constrained existential.
58-
59-
The regular `as` operator should be able to convert between reference types with full dynamic checking.
60-
61-
`unsafeDownCast` is just as capable, but is only dynamically checked in debug mode or if the cast requires runtime support.
62-
63-
`_unsafeUncheckedDowncast` is the same but is only dynamically checked in the stdlib asserts build, or if the cast requires runtime support.
64-
65-
`_unsafeReferenceCast` is only dynamically checked if the cast requires runtime support. Additionally, it does not impose any static `AnyObject` constraint on the incoming reference. This is useful in a generic context where the object-ness can be determined dynamically, as done in some bridged containers.
6653

6754
### Builtins
6855

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,6 @@ BUILTIN_SIL_OPERATION(BeginUnpairedModifyAccess, "beginUnpairedModifyAccess",
314314
/// be a pointer to an UnsafeValueBuffer that records an in progress access.
315315
BUILTIN_SIL_OPERATION(EndUnpairedAccess, "endUnpairedAccess", Special)
316316

317-
/// condfail(Int1) -> ()
318-
/// Triggers a runtime failure if the condition is true.
319-
/// This builtin is deprecated. Use condfail_message instead.
320-
BUILTIN_SIL_OPERATION(LegacyCondFail, "condfail", Special)
321-
322317
/// fixLifetime(T) -> ()
323318
/// Fixes the lifetime of any heap references in a value.
324319
BUILTIN_SIL_OPERATION(FixLifetime, "fixLifetime", Special)
@@ -405,9 +400,9 @@ BUILTIN_RUNTIME_CALL(IsOptionalType, "isOptional", "")
405400
BUILTIN(Id, Name, Attrs)
406401
#endif
407402

408-
/// condfail_message(Int1, RawPointer) -> ()
403+
/// condfail(Int1, RawPointer) -> ()
409404
/// Triggers a runtime failure if the condition is true.
410-
BUILTIN_MISC_OPERATION(CondFailMessage, "condfail_message", "", Special)
405+
BUILTIN_MISC_OPERATION(CondFail, "condfail", "", Special)
411406

412407
/// Sizeof has type T.Type -> Int
413408
BUILTIN_MISC_OPERATION(Sizeof, "sizeof", "n", Special)

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4105,20 +4105,7 @@ class ProtocolDecl final : public NominalTypeDecl {
41054105
/// by this protocol.
41064106
const Requirement *RequirementSignature = nullptr;
41074107

4108-
/// Returns the cached result of \c requiresClass or \c None if it hasn't yet
4109-
/// been computed.
4110-
Optional<bool> getCachedRequiresClass() const {
4111-
if (Bits.ProtocolDecl.RequiresClassValid)
4112-
return Bits.ProtocolDecl.RequiresClass;
4113-
4114-
return None;
4115-
}
4116-
4117-
/// Caches the result of \c requiresClass
4118-
void setCachedRequiresClass(bool requiresClass) {
4119-
Bits.ProtocolDecl.RequiresClassValid = true;
4120-
Bits.ProtocolDecl.RequiresClass = requiresClass;
4121-
}
4108+
bool requiresClassSlow();
41224109

41234110
bool existentialConformsToSelfSlow();
41244111

@@ -4133,7 +4120,6 @@ class ProtocolDecl final : public NominalTypeDecl {
41334120
friend class SuperclassDeclRequest;
41344121
friend class SuperclassTypeRequest;
41354122
friend class RequirementSignatureRequest;
4136-
friend class ProtocolRequiresClassRequest;
41374123
friend class TypeChecker;
41384124

41394125
public:
@@ -4197,7 +4183,19 @@ class ProtocolDecl final : public NominalTypeDecl {
41974183
}
41984184

41994185
/// True if this protocol can only be conformed to by class types.
4200-
bool requiresClass() const;
4186+
bool requiresClass() const {
4187+
if (Bits.ProtocolDecl.RequiresClassValid)
4188+
return Bits.ProtocolDecl.RequiresClass;
4189+
4190+
return const_cast<ProtocolDecl *>(this)->requiresClassSlow();
4191+
}
4192+
4193+
/// Specify that this protocol is class-bounded, e.g., because it was
4194+
/// annotated with the 'class' keyword.
4195+
void setRequiresClass(bool requiresClass = true) {
4196+
Bits.ProtocolDecl.RequiresClassValid = true;
4197+
Bits.ProtocolDecl.RequiresClass = requiresClass;
4198+
}
42014199

42024200
/// Determine whether an existential conforming to this protocol can be
42034201
/// matched with a generic type parameter constrained to this protocol.

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ ERROR(circular_class_inheritance,none,
153153
ERROR(circular_enum_inheritance,none,
154154
"%0 has a raw type that depends on itself", (Identifier))
155155

156-
ERROR(circular_protocol_def,none,
157-
"protocol %0 refines itself", (Identifier))
158-
159-
NOTE(kind_declname_declared_here,none,
160-
"%0 %1 declared here", (DescriptiveDeclKind, DeclName))
161-
162156
#ifndef DIAG_NO_UNDEF
163157
# if defined(DIAG)
164158
# undef DIAG

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -762,13 +762,6 @@ ERROR(extra_rbracket,PointsToFirstBadToken,
762762
"unexpected ']' in type; did you mean to write an array type?", ())
763763
ERROR(extra_colon,PointsToFirstBadToken,
764764
"unexpected ':' in type; did you mean to write a dictionary type?", ())
765-
WARNING(subscript_array_element, none,
766-
"unexpected subscript in array literal; did you mean to write two "
767-
"separate elements instead?", ())
768-
NOTE(subscript_array_element_fix_it_add_comma, none, "add a separator between "
769-
"the elements", ())
770-
NOTE(subscript_array_element_fix_it_remove_space, none,
771-
"remove the space between the elements to silence this warning", ())
772765

773766
// Tuple Types
774767
ERROR(expected_rparen_tuple_type_list,none,
@@ -861,8 +854,6 @@ ERROR(expected_parameter_name,PointsToFirstBadToken,
861854
"expected parameter name followed by ':'", ())
862855
ERROR(expected_parameter_colon,PointsToFirstBadToken,
863856
"expected ':' following argument label and parameter name", ())
864-
ERROR(expected_assignment_instead_of_comparison_operator,none,
865-
"expected '=' instead of '==' to assign default value for parameter", ())
866857
ERROR(missing_parameter_type,PointsToFirstBadToken,
867858
"parameter requires an explicit type", ())
868859
ERROR(multiple_parameter_ellipsis,none,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
DIAG(NOTE,ID,Options,Text,Signature)
3838
#endif
3939

40+
NOTE(kind_declname_declared_here,none,
41+
"%0 %1 declared here", (DescriptiveDeclKind, DeclName))
4042
NOTE(decl_declared_here,none,
4143
"%0 declared here", (DeclName))
4244
NOTE(kind_declared_here,none,
@@ -2035,6 +2037,8 @@ ERROR(typealias_outside_of_protocol,none,
20352037
"type alias %0 can only be used with a concrete type or "
20362038
"generic parameter base", (Identifier))
20372039

2040+
ERROR(circular_protocol_def,none,
2041+
"protocol %0 refines itself", (Identifier))
20382042
ERROR(objc_protocol_inherits_non_objc_protocol,none,
20392043
"@objc protocol %0 cannot refine non-@objc protocol %1", (Type, Type))
20402044

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -176,31 +176,6 @@ class IsObjCRequest :
176176
void cacheResult(bool value) const;
177177
};
178178

179-
/// Determine whether the given protocol declaration is class-bounded.
180-
class ProtocolRequiresClassRequest:
181-
public SimpleRequest<ProtocolRequiresClassRequest,
182-
bool(ProtocolDecl *),
183-
CacheKind::SeparatelyCached> {
184-
public:
185-
using SimpleRequest::SimpleRequest;
186-
187-
private:
188-
friend SimpleRequest;
189-
190-
// Evaluation.
191-
llvm::Expected<bool> evaluate(Evaluator &evaluator, ProtocolDecl *decl) const;
192-
193-
public:
194-
// Cycle handling.
195-
void diagnoseCycle(DiagnosticEngine &diags) const;
196-
void noteCycleStep(DiagnosticEngine &diags) const;
197-
198-
// Separate caching.
199-
bool isCached() const { return true; }
200-
Optional<bool> getCachedResult() const;
201-
void cacheResult(bool value) const;
202-
};
203-
204179
/// Determine whether the given declaration is 'final'.
205180
class IsFinalRequest :
206181
public SimpleRequest<IsFinalRequest,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ SWIFT_TYPEID(SuperclassTypeRequest)
1919
SWIFT_TYPEID(EnumRawTypeRequest)
2020
SWIFT_TYPEID(OverriddenDeclsRequest)
2121
SWIFT_TYPEID(IsObjCRequest)
22-
SWIFT_TYPEID(ProtocolRequiresClassRequest)
2322
SWIFT_TYPEID(IsFinalRequest)
2423
SWIFT_TYPEID(IsDynamicRequest)
2524
SWIFT_TYPEID(RequirementRequest)

branches/rxwei-patch-1/include/swift/Parse/Parser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,6 @@ class Parser {
14351435

14361436
UnresolvedDeclRefExpr *parseExprOperator();
14371437

1438-
void validateCollectionElement(ParserResult<Expr> element);
1439-
14401438
//===--------------------------------------------------------------------===//
14411439
// Statement Parsing
14421440

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,13 +1035,6 @@ static ValueDecl *getCanBeObjCClassOperation(ASTContext &Context,
10351035
return builder.build(Id);
10361036
}
10371037

1038-
static ValueDecl *getLegacyCondFailOperation(ASTContext &C, Identifier Id) {
1039-
// Int1 -> ()
1040-
auto CondTy = BuiltinIntegerType::get(1, C);
1041-
auto VoidTy = TupleType::getEmpty(C);
1042-
return getBuiltinFunction(Id, {CondTy}, VoidTy);
1043-
}
1044-
10451038
static ValueDecl *getCondFailOperation(ASTContext &C, Identifier Id) {
10461039
// Int1 -> ()
10471040
auto CondTy = BuiltinIntegerType::get(1, C);
@@ -1897,14 +1890,11 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
18971890
if (!Types.empty()) return nullptr;
18981891
return getAddressOfOperation(Context, Id);
18991892

1900-
case BuiltinValueKind::LegacyCondFail:
1901-
return getLegacyCondFailOperation(Context, Id);
1902-
19031893
case BuiltinValueKind::AddressOfBorrow:
19041894
if (!Types.empty()) return nullptr;
19051895
return getAddressOfBorrowOperation(Context, Id);
19061896

1907-
case BuiltinValueKind::CondFailMessage:
1897+
case BuiltinValueKind::CondFail:
19081898
return getCondFailOperation(Context, Id);
19091899

19101900
case BuiltinValueKind::AssertConf:

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

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4320,9 +4320,41 @@ bool ProtocolDecl::inheritsFrom(const ProtocolDecl *super) const {
43204320
});
43214321
}
43224322

4323-
bool ProtocolDecl::requiresClass() const {
4324-
return evaluateOrDefault(getASTContext().evaluator,
4325-
ProtocolRequiresClassRequest{const_cast<ProtocolDecl *>(this)}, false);
4323+
bool ProtocolDecl::requiresClassSlow() {
4324+
// Set this first to catch (invalid) circular inheritance.
4325+
Bits.ProtocolDecl.RequiresClassValid = true;
4326+
Bits.ProtocolDecl.RequiresClass = false;
4327+
4328+
// Quick check: @objc protocols require a class.
4329+
if (isObjC())
4330+
return Bits.ProtocolDecl.RequiresClass = true;
4331+
4332+
// Determine the set of nominal types that this protocol inherits.
4333+
bool anyObject = false;
4334+
auto allInheritedNominals =
4335+
getDirectlyInheritedNominalTypeDecls(this, anyObject);
4336+
4337+
// Quick check: do we inherit AnyObject?
4338+
if (anyObject) {
4339+
Bits.ProtocolDecl.RequiresClass = true;
4340+
return true;
4341+
}
4342+
4343+
// Look through all of the inherited nominals for a superclass or a
4344+
// class-bound protocol.
4345+
for (const auto found : allInheritedNominals) {
4346+
// Superclass bound.
4347+
if (isa<ClassDecl>(found.second))
4348+
return Bits.ProtocolDecl.RequiresClass = true;
4349+
4350+
// A protocol that might be class-constrained;
4351+
if (auto proto = dyn_cast<ProtocolDecl>(found.second)) {
4352+
if (proto->requiresClass())
4353+
return Bits.ProtocolDecl.RequiresClass = true;
4354+
}
4355+
}
4356+
4357+
return Bits.ProtocolDecl.RequiresClass;
43264358
}
43274359

43284360
bool ProtocolDecl::requiresSelfConformanceWitnessTable() const {

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -185,32 +185,6 @@ void IsObjCRequest::cacheResult(bool value) const {
185185
decl->setIsObjC(value);
186186
}
187187

188-
//----------------------------------------------------------------------------//
189-
// requiresClass computation.
190-
//----------------------------------------------------------------------------//
191-
192-
void ProtocolRequiresClassRequest::diagnoseCycle(DiagnosticEngine &diags) const {
193-
auto decl = std::get<0>(getStorage());
194-
diags.diagnose(decl, diag::circular_protocol_def, decl->getName());
195-
}
196-
197-
void ProtocolRequiresClassRequest::noteCycleStep(DiagnosticEngine &diags) const {
198-
auto requirement = std::get<0>(getStorage());
199-
diags.diagnose(requirement, diag::kind_declname_declared_here,
200-
DescriptiveDeclKind::Protocol,
201-
requirement->getName());
202-
}
203-
204-
Optional<bool> ProtocolRequiresClassRequest::getCachedResult() const {
205-
auto decl = std::get<0>(getStorage());
206-
return decl->getCachedRequiresClass();
207-
}
208-
209-
void ProtocolRequiresClassRequest::cacheResult(bool value) const {
210-
auto decl = std::get<0>(getStorage());
211-
decl->setCachedRequiresClass(value);
212-
}
213-
214188
//----------------------------------------------------------------------------//
215189
// isFinal computation.
216190
//----------------------------------------------------------------------------//

branches/rxwei-patch-1/lib/IRGen/MetadataRequest.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,6 @@ static MetadataResponse emitNominalMetadataRef(IRGenFunction &IGF,
642642
bool irgen::isTypeMetadataAccessTrivial(IRGenModule &IGM, CanType type) {
643643
assert(!type->hasArchetype());
644644

645-
// Support dynamically replacing opaque result types. Don't cache the
646-
// accessor result.
647-
if (!IGM.getOptions().shouldOptimize() && type->hasOpaqueArchetype())
648-
return true;
649-
650645
// Value type metadata only requires dynamic initialization on first
651646
// access if it contains a resilient type.
652647
if (isa<StructType>(type) || isa<EnumType>(type)) {
@@ -1489,6 +1484,7 @@ void irgen::emitCacheAccessFunction(IRGenModule &IGM,
14891484

14901485
// If the load yielded null, emit the type metadata.
14911486
IGF.Builder.emitBlock(isNullBB);
1487+
14921488
MetadataResponse response = getValue(IGF, parameters);
14931489

14941490
// Ensure that we have a dynamically-correct state value.

branches/rxwei-patch-1/lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3447,10 +3447,8 @@ Parser::parseExprCollectionElement(Optional<bool> &isDictionary) {
34473447
if (!isDictionary.hasValue())
34483448
isDictionary = Tok.is(tok::colon);
34493449

3450-
if (!*isDictionary) {
3451-
validateCollectionElement(Element);
3450+
if (!*isDictionary)
34523451
return Element;
3453-
}
34543452

34553453
if (Element.isNull())
34563454
return Element;
@@ -3473,43 +3471,6 @@ Parser::parseExprCollectionElement(Optional<bool> &isDictionary) {
34733471
TupleExpr::createImplicit(Context, {Element.get(), Value.get()}, {}));
34743472
}
34753473

3476-
/// validateCollectionElement - Check if a given collection element is valid.
3477-
///
3478-
/// At the moment, this checks whether a given collection element is a subscript
3479-
/// expression and whether we're subscripting into an array. If we are, then it
3480-
/// we emit a diagnostic in case it was not something that the user was
3481-
/// expecting.
3482-
///
3483-
/// For example: `let array [ [0, 1] [42] ]`
3484-
void Parser::validateCollectionElement(ParserResult<Expr> element) {
3485-
if (element.isNull())
3486-
return;
3487-
3488-
auto elementExpr = element.get();
3489-
if (!isa<SubscriptExpr>(elementExpr))
3490-
return;
3491-
3492-
auto subscriptExpr = cast<SubscriptExpr>(elementExpr);
3493-
if (!isa<ArrayExpr>(subscriptExpr->getBase()))
3494-
return;
3495-
3496-
auto arrayExpr = cast<ArrayExpr>(subscriptExpr->getBase());
3497-
3498-
auto startLocOfSubscript = subscriptExpr->getIndex()->getStartLoc();
3499-
auto endLocOfArray = arrayExpr->getEndLoc();
3500-
auto locForEndOfTokenArray = L->getLocForEndOfToken(SourceMgr, endLocOfArray);
3501-
3502-
if (locForEndOfTokenArray != startLocOfSubscript) {
3503-
auto subscriptLoc = subscriptExpr->getLoc();
3504-
diagnose(subscriptLoc, diag::subscript_array_element)
3505-
.highlight(subscriptExpr->getSourceRange());
3506-
diagnose(subscriptLoc, diag::subscript_array_element_fix_it_add_comma)
3507-
.fixItInsertAfter(endLocOfArray, ",");
3508-
diagnose(subscriptLoc, diag::subscript_array_element_fix_it_remove_space)
3509-
.fixItRemoveChars(locForEndOfTokenArray, startLocOfSubscript);
3510-
}
3511-
}
3512-
35133474
void Parser::addPatternVariablesToScope(ArrayRef<Pattern *> Patterns) {
35143475
for (Pattern *Pat : Patterns) {
35153476
Pat->forEachVariable([&](VarDecl *VD) {

0 commit comments

Comments
 (0)