Skip to content

Commit ae5c8e3

Browse files
committed
---
yaml --- r: 349604 b: refs/heads/master-next c: 83bf812 h: refs/heads/master
1 parent 1b296b2 commit ae5c8e3

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 6ce93ce73af9c0dfd965071a7396b4ac890c03fd
3+
refs/heads/master-next: 83bf812d9190f82f073c36d6a8c441df9e9d78ac
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/lib/SILOptimizer/Mandatory/SemanticARCOpts.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ struct SemanticARCOptVisitor
191191
bool visitBeginBorrowInst(BeginBorrowInst *bbi);
192192
bool visitLoadInst(LoadInst *li);
193193

194-
/// Return true if all of load insts destroy_value users are within the
195-
/// guaranteed lifetime of the storage that is being loaded from.
196-
bool isLoadGuaranteedByStorage(LoadInst *li);
194+
bool isWrittenTo(LoadInst *li);
197195

198196
bool processWorklist();
199197

@@ -716,7 +714,7 @@ class StorageGuaranteesLoadVisitor
716714
};
717715
} // namespace
718716

719-
bool SemanticARCOptVisitor::isLoadGuaranteedByStorage(LoadInst *load) {
717+
bool SemanticARCOptVisitor::isWrittenTo(LoadInst *load) {
720718
StorageGuaranteesLoadVisitor visitor(*this, load);
721719
return visitor.doIt();
722720
}
@@ -738,10 +736,9 @@ bool SemanticARCOptVisitor::visitLoadInst(LoadInst *li) {
738736
if (!isDeadLiveRange(li, destroyValues))
739737
return false;
740738

741-
// Then check if our address is guaranteed to never be written to within the
742-
// lifetime of our loaded value. If so, we can convert the loaded value to be
743-
// at +0 instead of +1.
744-
if (isLoadGuaranteedByStorage(li))
739+
// Then check if our address is ever written to. If it is, then we
740+
// can not use the load_borrow.
741+
if (isWrittenTo(li))
745742
return false;
746743

747744
// Ok, we can perform our optimization. Convert the load [copy] into a

branches/master-next/lib/Sema/CSSimplify.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3836,8 +3836,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
38363836
ConstraintKind kind,
38373837
ConstraintLocatorBuilder locator,
38383838
TypeMatchOptions flags) {
3839+
auto *typeVar = type->getAs<TypeVariableType>();
38393840
if (shouldAttemptFixes()) {
3840-
auto *typeVar = type->getAs<TypeVariableType>();
38413841
// If type variable, associated with this conformance check,
38423842
// has been determined to be a "hole" in constraint system,
38433843
// let's consider this check a success without recording
@@ -3987,6 +3987,23 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
39873987
return SolutionKind::Error;
39883988

39893989
if (path.back().is<LocatorPathElt::AnyRequirement>()) {
3990+
// If this is a requirement associated with `Self` which is bound
3991+
// to `Any`, let's consider this "too incorrect" to continue.
3992+
//
3993+
// This helps us to filter out cases like operator overloads where
3994+
// `Self` type comes from e.g. default for collection element -
3995+
// `[1, "hello"].map { $0 + 1 }`. Main problem here is that
3996+
// collection type couldn't be determined without unification to
3997+
// `Any` and `+` failing for all numeric overloads is just a consequence.
3998+
if (typeVar && type->isAny()) {
3999+
auto *GP = typeVar->getImpl().getGenericParameter();
4000+
if (auto *GPD = GP->getDecl()) {
4001+
auto *DC = GPD->getDeclContext();
4002+
if (DC->isTypeContext() && DC->getSelfInterfaceType()->isEqual(GP))
4003+
return SolutionKind::Error;
4004+
}
4005+
}
4006+
39904007
if (auto *fix =
39914008
fixRequirementFailure(*this, type, protocolTy, anchor, path)) {
39924009
if (!recordFix(fix)) {

branches/master-next/test/Constraints/closures.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ func r22162441(_ lines: [String]) {
182182

183183
func testMap() {
184184
let a = 42
185-
[1,a].map { $0 + 1.0 } // expected-error {{binary operator '+' cannot be applied to operands of type 'Any' and 'Double'}}
186-
// expected-note @-1 {{expected an argument list of type '(Double, Double)'}}
185+
[1,a].map { $0 + 1.0 } // expected-error {{cannot convert value of type 'Int' to expected element type 'Double'}}
187186
}
188187

189188
// <rdar://problem/22414757> "UnresolvedDot" "in wrong phase" assertion from verifier

0 commit comments

Comments
 (0)