Skip to content

Commit 35bc45d

Browse files
authored
---
yaml --- r: 327658 b: refs/heads/tensorflow c: bd3b827 h: refs/heads/master
1 parent 8eb0e07 commit 35bc45d

File tree

5 files changed

+78
-11
lines changed

5 files changed

+78
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-04-25-a: 22f738a831d43aff2b9c9773bcb65
816816
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-05-08-a: 7d98cc16689baba5c8a3b90a9329bdcc1a12b4e9
817817
refs/heads/cherr42: a566ad54b073c2c56ac0a705d0a5bed9743135a5
818818
"refs/heads/codable_test_comment_fix": fc8f6824f7f347e1e8db55bff62db385c5728b5a
819-
refs/heads/tensorflow: 56abf9e0f9265fabb135b94555d11dd658992aa0
819+
refs/heads/tensorflow: bd3b827fd613fc4d59509d5231366c269e2152fe
820820
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-11-a: 8126fd7a652e2f70ad6d76505239e34fb2ef3e1a
821821
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-12-a: b3fd3dd84df6717f2e2e9df58c6d7e99fed57086
822822
refs/tags/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-05-13-a: 71135119579039dc321c5f65d870050fe36efda2

branches/tensorflow/lib/Sema/CSRanking.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -822,17 +822,27 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
822822
continue;
823823
}
824824

825-
// Dynamic member lookup through a keypath is better than one using string
826-
// because it carries more type information.
827-
if (choice1.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup &&
828-
choice2.getKind() == OverloadChoiceKind::DynamicMemberLookup) {
829-
score1 += weight;
825+
if (choice1.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup) {
826+
if (choice2.getKind() == OverloadChoiceKind::DynamicMemberLookup)
827+
// Dynamic member lookup through a keypath is better than one using
828+
// string because it carries more type information.
829+
score1 += weight;
830+
else
831+
// Otherwise let's prefer non-dynamic declaration.
832+
score2 += weight;
833+
830834
continue;
831835
}
832836

833-
if (choice1.getKind() == OverloadChoiceKind::DynamicMemberLookup &&
834-
choice2.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup) {
835-
score2 += weight;
837+
if (choice2.getKind() == OverloadChoiceKind::KeyPathDynamicMemberLookup) {
838+
if (choice1.getKind() == OverloadChoiceKind::DynamicMemberLookup)
839+
// Dynamic member lookup through a keypath is better than one using
840+
// string because it carries more type information.
841+
score2 += weight;
842+
else
843+
// Otherwise let's prefer non-dynamic declaration.
844+
score1 += weight;
845+
836846
continue;
837847
}
838848

branches/tensorflow/lib/Sema/MiscDiagnostics.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
#include "swift/AST/Pattern.h"
2323
#include "swift/Basic/Defer.h"
2424
#include "swift/Basic/SourceManager.h"
25+
#include "swift/Basic/Statistic.h"
2526
#include "swift/Basic/StringExtras.h"
2627
#include "swift/Parse/Lexer.h"
2728
#include "swift/Parse/Parser.h"
2829
#include "swift/Sema/IDETypeChecking.h"
2930
#include "llvm/ADT/MapVector.h"
3031
#include "llvm/ADT/StringSwitch.h"
3132
#include "llvm/Support/SaveAndRestore.h"
33+
34+
#define DEBUG_TYPE "Sema"
3235
using namespace swift;
3336

3437
/// Return true if this expression is an implicit promotion from T to T?.
@@ -1992,6 +1995,10 @@ class VarDeclUsageChecker : public ASTWalker {
19921995
/// This is a mapping from VarDecls to the if/while/guard statement that they
19931996
/// occur in, when they are in a pattern in a StmtCondition.
19941997
llvm::SmallDenseMap<VarDecl*, LabeledConditionalStmt*> StmtConditionForVD;
1998+
1999+
#ifndef NDEBUG
2000+
llvm::SmallPtrSet<Expr*, 32> AllExprsSeen;
2001+
#endif
19952002

19962003
bool sawError = false;
19972004

@@ -2732,13 +2739,19 @@ void VarDeclUsageChecker::markStoredOrInOutExpr(Expr *E, unsigned Flags) {
27322739

27332740
/// The heavy lifting happens when visiting expressions.
27342741
std::pair<bool, Expr *> VarDeclUsageChecker::walkToExprPre(Expr *E) {
2742+
STATISTIC(VarDeclUsageCheckerExprVisits,
2743+
"# of times VarDeclUsageChecker::walkToExprPre is called");
2744+
++VarDeclUsageCheckerExprVisits;
2745+
27352746
// Sema leaves some subexpressions null, which seems really unfortunate. It
27362747
// should replace them with ErrorExpr.
27372748
if (E == nullptr || !E->getType() || E->getType()->hasError()) {
27382749
sawError = true;
27392750
return { false, E };
27402751
}
27412752

2753+
assert(AllExprsSeen.insert(E).second && "duplicate traversal");
2754+
27422755
// If this is a DeclRefExpr found in a random place, it is a load of the
27432756
// vardecl.
27442757
if (auto *DRE = dyn_cast<DeclRefExpr>(E)) {
@@ -2783,9 +2796,13 @@ std::pair<bool, Expr *> VarDeclUsageChecker::walkToExprPre(Expr *E) {
27832796
return { false, E };
27842797
}
27852798

2786-
// If we see an OpenExistentialExpr, remember the mapping for its OpaqueValue.
2787-
if (auto *oee = dyn_cast<OpenExistentialExpr>(E))
2799+
// If we see an OpenExistentialExpr, remember the mapping for its OpaqueValue
2800+
// and only walk the subexpr.
2801+
if (auto *oee = dyn_cast<OpenExistentialExpr>(E)) {
27882802
OpaqueValueMap[oee->getOpaqueValue()] = oee->getExistentialValue();
2803+
oee->getSubExpr()->walk(*this);
2804+
return { false, E };
2805+
}
27892806

27902807
// Visit bindings.
27912808
if (auto ove = dyn_cast<OpaqueValueExpr>(E)) {

branches/tensorflow/test/Constraints/keypath_dynamic_member_lookup.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,26 @@ func make_sure_delayed_keypath_dynamic_member_works() {
367367
}
368368
}
369369
}
370+
371+
372+
// SR-11465 - Ambiguity in expression which matches both dynamic member lookup and declaration from constrained extension
373+
374+
@dynamicMemberLookup
375+
struct SR_11465<RawValue> {
376+
var rawValue: RawValue
377+
378+
subscript<Subject>(dynamicMember keyPath: KeyPath<RawValue, Subject>) -> Subject {
379+
rawValue[keyPath: keyPath]
380+
}
381+
}
382+
383+
extension SR_11465: Hashable, Equatable where RawValue: Hashable {
384+
func hash(into hasher: inout Hasher) {
385+
hasher.combine(self.rawValue)
386+
}
387+
}
388+
389+
func test_constrained_ext_vs_dynamic_member() {
390+
// CHECK: function_ref @$s29keypath_dynamic_member_lookup8SR_11465VAASHRzlE9hashValueSivg
391+
_ = SR_11465<Int>(rawValue: 1).hashValue // Ok, keep choice from constrained extension
392+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %scale-test --begin 1 --end 5 --step 1 --select VarDeclUsageCheckerExprVisits %s
2+
// REQUIRES: OS=macosx
3+
// REQUIRES: asserts
4+
5+
protocol Proto {}
6+
extension Proto {
7+
var selfish: Proto { return self }
8+
}
9+
10+
struct X: Proto {}
11+
12+
func test(_ x: X) -> Proto {
13+
return x
14+
%for i in range(0, N*5):
15+
.selfish
16+
%end
17+
}

0 commit comments

Comments
 (0)