Skip to content

Commit caf4a22

Browse files
authored
---
yaml --- r: 326655 b: refs/heads/tensorflow c: 1f023c6 h: refs/heads/master i: 326653: d5e0b17 326651: d0b6b38 326647: 503d825 326639: edf8aef 326623: 2d0b34a 326591: 14b4b3d 326527: e67cc5e 326399: 7607adc 326143: a994ee4 325631: 757ef7a
1 parent bd8e7a6 commit caf4a22

File tree

16 files changed

+214
-89
lines changed

16 files changed

+214
-89
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: 1d9f1ec3f8cb537bcec974b9474edac7ccbd7b11
819+
refs/heads/tensorflow: 1f023c6b8847d939c9858e58bd236065849c2b49
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/SILOptimizer/UtilityPasses/LoopRegionPrinter.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,66 @@
2020
#include "swift/SILOptimizer/Analysis/LoopRegionAnalysis.h"
2121
#include "swift/SILOptimizer/PassManager/Passes.h"
2222
#include "swift/SILOptimizer/PassManager/Transforms.h"
23+
#include "llvm/Support/CommandLine.h"
2324

2425
using namespace swift;
2526

27+
static llvm::cl::opt<std::string>
28+
SILViewCFGOnlyFun("sil-loop-region-view-cfg-only-function",
29+
llvm::cl::init(""),
30+
llvm::cl::desc("Only produce a graphviz file for the "
31+
"loop region info of this function"));
32+
33+
static llvm::cl::opt<std::string>
34+
SILViewCFGOnlyFuns("sil-loop-region-view-cfg-only-functions",
35+
llvm::cl::init(""),
36+
llvm::cl::desc("Only produce a graphviz file for the "
37+
"loop region info for the functions "
38+
"whose name contains this substring"));
39+
2640
namespace {
2741

2842
class LoopRegionViewText : public SILModuleTransform {
2943
void run() override {
3044
invalidateAll();
31-
LoopRegionAnalysis *LRA = PM->getAnalysis<LoopRegionAnalysis>();
32-
for (auto &Fn : *getModule()) {
33-
if (Fn.isExternalDeclaration()) continue;
45+
auto *lra = PM->getAnalysis<LoopRegionAnalysis>();
46+
47+
for (auto &fn : *getModule()) {
48+
if (fn.isExternalDeclaration())
49+
continue;
50+
if (!SILViewCFGOnlyFun.empty() && fn.getName() != SILViewCFGOnlyFun)
51+
continue;
52+
if (!SILViewCFGOnlyFuns.empty() &&
53+
fn.getName().find(SILViewCFGOnlyFuns, 0) == StringRef::npos)
54+
continue;
3455

35-
llvm::outs() << "@" << Fn.getName() << "@\n";
36-
LRA->get(&Fn)->dump();
37-
llvm::outs() << "\n";
56+
// Ok, we are going to analyze this function. Invalidate all state
57+
// associated with it so we recompute the loop regions.
58+
llvm::outs() << "Start @" << fn.getName() << "@\n";
59+
lra->get(&fn)->dump();
60+
llvm::outs() << "End @" << fn.getName() << "@\n";
3861
llvm::outs().flush();
3962
}
4063
}
41-
4264
};
4365

4466
class LoopRegionViewCFG : public SILModuleTransform {
4567
void run() override {
68+
invalidateAll();
69+
auto *lra = PM->getAnalysis<LoopRegionAnalysis>();
4670

47-
LoopRegionAnalysis *LRA = PM->getAnalysis<LoopRegionAnalysis>();
48-
49-
auto *M = getModule();
50-
for (auto &Fn : M->getFunctions()) {
51-
if (Fn.isExternalDeclaration())
71+
for (auto &fn : *getModule()) {
72+
if (fn.isExternalDeclaration())
5273
continue;
53-
LRA->get(&Fn)->viewLoopRegions();
74+
if (!SILViewCFGOnlyFun.empty() && fn.getName() != SILViewCFGOnlyFun)
75+
continue;
76+
if (!SILViewCFGOnlyFuns.empty() &&
77+
fn.getName().find(SILViewCFGOnlyFuns, 0) == StringRef::npos)
78+
continue;
79+
80+
// Ok, we are going to analyze this function. Invalidate all state
81+
// associated with it so we recompute the loop regions.
82+
lra->get(&fn)->viewLoopRegions();
5483
}
5584
}
5685
};

branches/tensorflow/lib/Sema/CSDiagnostics.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,36 @@ ValueDecl *RequirementFailure::getDeclRef() const {
373373
if (isFromContextualType())
374374
return getAffectedDeclFromType(cs.getContextualType());
375375

376-
if (auto overload = getChoiceFor(getRawAnchor()))
377-
return overload->choice.getDecl();
376+
if (auto overload = getChoiceFor(getRawAnchor())) {
377+
// If there is a declaration associated with this
378+
// failure e.g. an overload choice of the call
379+
// expression, let's see whether failure is
380+
// associated with it directly or rather with
381+
// one of its parents.
382+
if (auto *decl = overload->choice.getDeclOrNull()) {
383+
auto *DC = decl->getDeclContext();
384+
385+
do {
386+
if (auto *parent = DC->getAsDecl()) {
387+
if (auto *GC = parent->getAsGenericContext()) {
388+
if (GC->getGenericSignature() != Signature)
389+
continue;
390+
391+
// If this is a signature if an extension
392+
// then it means that code has referenced
393+
// something incorrectly and diagnostic
394+
// should point to the referenced declaration.
395+
if (isa<ExtensionDecl>(parent))
396+
break;
397+
398+
return cast<ValueDecl>(parent);
399+
}
400+
}
401+
} while ((DC = DC->getParent()));
402+
403+
return decl;
404+
}
405+
}
378406

379407
return getAffectedDeclFromType(getOwnerType());
380408
}

branches/tensorflow/lib/Sema/CSDiagnostics.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,31 +304,12 @@ class RequirementFailure : public FailureDiagnostic {
304304
if (isConditional())
305305
return true;
306306

307-
auto *anchor = getAnchor();
308-
// In the situations like this:
309-
//
310-
// ```swift
311-
// enum E<T: P> { case foo(T) }
312-
// let _: E = .foo(...)
313-
// ```
314-
//
315-
// `E` is going to be opened twice. First, when
316-
// it's used as a contextual type, and when `E.foo`
317-
// is found and its function type is opened.
318-
// We still want to record both fixes but should
319-
// avoid diagnosing the same problem multiple times.
320-
if (isa<UnresolvedMemberExpr>(anchor)) {
321-
auto path = getLocator()->getPath();
322-
if (path.front().getKind() != ConstraintLocator::UnresolvedMember)
323-
return false;
324-
}
325-
326307
// For static/initializer calls there is going to be
327308
// a separate fix, attached to the argument, which is
328309
// much easier to diagnose.
329310
// For operator calls we can't currently produce a good
330311
// diagnostic, so instead let's refer to expression diagnostics.
331-
return !(Apply && (isOperator(Apply) || isa<TypeExpr>(anchor)));
312+
return !(Apply && isOperator(Apply));
332313
}
333314

334315
static bool isOperator(const ApplyExpr *apply) {

branches/tensorflow/lib/Sema/CSSimplify.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,8 +2502,14 @@ bool ConstraintSystem::repairFailures(
25022502
if (lhs->hasDependentMember() || rhs->hasDependentMember())
25032503
break;
25042504

2505-
if (auto *fix = fixRequirementFailure(*this, lhs, rhs, anchor, path))
2505+
auto reqKind = static_cast<RequirementKind>(elt.getValue2());
2506+
if (hasFixedRequirement(lhs, reqKind, rhs))
2507+
return true;
2508+
2509+
if (auto *fix = fixRequirementFailure(*this, lhs, rhs, anchor, path)) {
2510+
recordFixedRequirement(lhs, reqKind, rhs);
25062511
conversionsOrFixes.push_back(fix);
2512+
}
25072513
break;
25082514
}
25092515

@@ -3775,6 +3781,11 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
37753781
if (type->isVoid() || type->isUninhabited())
37763782
return SolutionKind::Error;
37773783

3784+
auto protocolTy = protocol->getDeclaredType();
3785+
// If this conformance has been fixed already, let's just consider this done.
3786+
if (hasFixedRequirement(type, RequirementKind::Conformance, protocolTy))
3787+
return SolutionKind::Solved;
3788+
37783789
// If this is a generic requirement let's try to record that
37793790
// conformance is missing and consider this a success, which
37803791
// makes it much easier to diagnose problems like that.
@@ -3787,10 +3798,14 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
37873798

37883799
if (path.back().isTypeParameterRequirement() ||
37893800
path.back().isConditionalRequirement()) {
3790-
if (auto *fix = fixRequirementFailure(
3791-
*this, type, protocol->getDeclaredType(), anchor, path)) {
3792-
if (!recordFix(fix))
3801+
if (auto *fix =
3802+
fixRequirementFailure(*this, type, protocolTy, anchor, path)) {
3803+
if (!recordFix(fix)) {
3804+
// Record this conformance requirement as "fixed".
3805+
recordFixedRequirement(type, RequirementKind::Conformance,
3806+
protocolTy);
37933807
return SolutionKind::Solved;
3808+
}
37943809
}
37953810
}
37963811

branches/tensorflow/lib/Sema/CSSolver.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ ConstraintSystem::SolverScope::SolverScope(ConstraintSystem &cs)
452452
numSavedBindings = cs.solverState->savedBindings.size();
453453
numConstraintRestrictions = cs.ConstraintRestrictions.size();
454454
numFixes = cs.Fixes.size();
455+
numFixedRequirements = cs.FixedRequirements.size();
455456
numDisjunctionChoices = cs.DisjunctionChoices.size();
456457
numOpenedTypes = cs.OpenedTypes.size();
457458
numOpenedExistentialTypes = cs.OpenedExistentialTypes.size();
@@ -505,6 +506,10 @@ ConstraintSystem::SolverScope::~SolverScope() {
505506
// Remove any opened types.
506507
truncate(cs.OpenedTypes, numOpenedTypes);
507508

509+
// Remove any conformances solver had to fix along
510+
// the current path.
511+
truncate(cs.FixedRequirements, numFixedRequirements);
512+
508513
// Remove any opened existential types.
509514
truncate(cs.OpenedExistentialTypes, numOpenedExistentialTypes);
510515

branches/tensorflow/lib/Sema/ConstraintSystem.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,23 @@ class ConstraintSystem {
11191119
SmallVector<std::pair<ConstraintLocator *, ArrayRef<OpenedType>>, 4>
11201120
OpenedTypes;
11211121

1122+
/// The list of all generic requirements fixed along the current
1123+
/// solver path.
1124+
using FixedRequirement = std::tuple<TypeBase *, RequirementKind, TypeBase *>;
1125+
SmallVector<FixedRequirement, 4> FixedRequirements;
1126+
1127+
bool hasFixedRequirement(Type lhs, RequirementKind kind, Type rhs) {
1128+
auto reqInfo = std::make_tuple(lhs.getPointer(), kind, rhs.getPointer());
1129+
return llvm::any_of(
1130+
FixedRequirements,
1131+
[&reqInfo](const FixedRequirement &entry) { return entry == reqInfo; });
1132+
}
1133+
1134+
void recordFixedRequirement(Type lhs, RequirementKind kind, Type rhs) {
1135+
FixedRequirements.push_back(
1136+
std::make_tuple(lhs.getPointer(), kind, rhs.getPointer()));
1137+
}
1138+
11221139
/// A mapping from constraint locators to the opened existential archetype
11231140
/// used for the 'self' of an existential type.
11241141
SmallVector<std::pair<ConstraintLocator *, OpenedArchetypeType *>, 4>
@@ -1614,6 +1631,9 @@ class ConstraintSystem {
16141631
/// The length of \c Fixes.
16151632
unsigned numFixes;
16161633

1634+
/// The length of \c FixedRequirements.
1635+
unsigned numFixedRequirements;
1636+
16171637
/// The length of \c DisjunctionChoices.
16181638
unsigned numDisjunctionChoices;
16191639

branches/tensorflow/stdlib/public/core/DictionaryBridging.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
313313
let bridgedKeys = bridgeKeys()
314314
let bridgedValues = bridgeValues()
315315
var i = 0 // Current position in the output buffers
316-
let bucketCount = native._storage._bucketCount
317316

318317
defer { _fixLifetime(self) }
319318

branches/tensorflow/stdlib/public/core/KeyPath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public class ReferenceWritableKeyPath<
357357
internal final func _projectMutableAddress(from origBase: Root)
358358
-> (pointer: UnsafeMutablePointer<Value>, owner: AnyObject?) {
359359
var keepAlive: AnyObject?
360-
var address: UnsafeMutablePointer<Value> = withBuffer {
360+
let address: UnsafeMutablePointer<Value> = withBuffer {
361361
var buffer = $0
362362
// Project out the reference prefix.
363363
var base: Any = origBase

branches/tensorflow/stdlib/public/core/Sort.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ extension MutableCollection where Self: RandomAccessCollection {
246246
public mutating func sort(
247247
by areInIncreasingOrder: (Element, Element) throws -> Bool
248248
) rethrows {
249-
let didSortUnsafeBuffer = try _withUnsafeMutableBufferPointerIfSupported {
250-
buffer -> Void? in
249+
let didSortUnsafeBuffer: Void? = try _withUnsafeMutableBufferPointerIfSupported {
250+
buffer -> Void in
251251
try buffer._stableSortImpl(by: areInIncreasingOrder)
252252
}
253253
if didSortUnsafeBuffer == nil {

branches/tensorflow/test/Constraints/generics.swift

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ func testFixIts() {
335335
_ = AnyClassAndProtoBound() // expected-error {{generic parameter 'Foo' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{28-28=<<#Foo: SubProto & AnyObject#>>}}
336336
_ = AnyClassAndProtoBound2() // expected-error {{generic parameter 'Foo' could not be inferred}} expected-note {{explicitly specify the generic arguments to fix this issue}} {{29-29=<<#Foo: SubProto & AnyObject#>>}}
337337

338-
_ = ClassAndProtoBound() // expected-error {{referencing initializer 'init()' on 'ClassAndProtoBound' requires that 'X' conform to 'SubProto'}}
338+
_ = ClassAndProtoBound() // expected-error {{generic struct 'ClassAndProtoBound' requires that 'X' conform to 'SubProto'}}
339339

340-
_ = ClassAndProtosBound()
341-
// expected-error@-1 {{referencing initializer 'init()' on 'ClassAndProtosBound' requires that 'X' conform to 'NSCopyish'}}
342-
// expected-error@-2 {{referencing initializer 'init()' on 'ClassAndProtosBound' requires that 'X' conform to 'SubProto'}}
340+
_ = ClassAndProtosBound()
341+
// expected-error@-1 {{generic struct 'ClassAndProtosBound' requires that 'X' conform to 'SubProto'}}
342+
// expected-error@-2 {{generic struct 'ClassAndProtosBound' requires that 'X' conform to 'NSCopyish'}}
343343
_ = ClassAndProtosBound2()
344-
// expected-error@-1 {{referencing initializer 'init()' on 'ClassAndProtosBound2' requires that 'X' conform to 'NSCopyish'}}
345-
// expected-error@-2 {{referencing initializer 'init()' on 'ClassAndProtosBound2' requires that 'X' conform to 'SubProto'}}
344+
// expected-error@-1 {{generic struct 'ClassAndProtosBound2' requires that 'X' conform to 'SubProto'}}
345+
// expected-error@-2 {{generic struct 'ClassAndProtosBound2' requires that 'X' conform to 'NSCopyish'}}
346346

347347
_ = Pair()
348348
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
@@ -631,16 +631,16 @@ func rdar40537858() {
631631
}
632632

633633
var arr: [S] = []
634-
_ = List(arr, id: \.id) // expected-error {{referencing initializer 'init(_:id:)' on 'List' requires that 'S.Id' conform to 'Hashable'}}
634+
_ = List(arr, id: \.id) // expected-error {{generic struct 'List' requires that 'S.Id' conform to 'Hashable'}}
635635

636636
enum E<T: P> { // expected-note 2 {{where 'T' = 'S'}}
637637
case foo(T)
638638
case bar([T])
639639
}
640640

641641
var s = S(id: S.Id())
642-
let _: E = .foo(s) // expected-error {{enum case 'foo' requires that 'S' conform to 'P'}}
643-
let _: E = .bar([s]) // expected-error {{enum case 'bar' requires that 'S' conform to 'P'}}
642+
let _: E = .foo(s) // expected-error {{generic enum 'E' requires that 'S' conform to 'P'}}
643+
let _: E = .bar([s]) // expected-error {{generic enum 'E' requires that 'S' conform to 'P'}}
644644
}
645645

646646
// https://bugs.swift.org/browse/SR-8934
@@ -798,3 +798,20 @@ struct R_51413254 {
798798
self.str = try anyDict ==> Key("a") // Ok
799799
}
800800
}
801+
802+
func test_correct_identification_of_requirement_source() {
803+
struct X<T: P> { // expected-note {{where 'T' = 'Int'}}
804+
init<U: P>(_: T, _: U) {} // expected-note {{where 'U' = 'Int'}}
805+
}
806+
807+
struct A : P {
808+
static func foo(_ arg: A) -> A {
809+
return A()
810+
}
811+
}
812+
813+
_ = X(17, A())
814+
// expected-error@-1 {{generic struct 'X' requires that 'Int' conform to 'P'}}
815+
_ = X(A(), 17)
816+
// expected-error@-1 {{initializer 'init(_:_:)' requires that 'Int' conform to 'P'}}
817+
}

branches/tensorflow/test/Constraints/rdar44569159.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ struct S<V> where V: P { // expected-note {{where 'V' = 'Double'}}
66
}
77

88
struct A {
9-
subscript<T>(_ v: S<T>) -> A { // expected-note {{where 'T' = 'Double'}}
9+
subscript<T>(_ v: S<T>) -> A {
1010
fatalError()
1111
}
1212
}
1313

1414
func foo(_ v: Double) {
1515
_ = A()[S(value: v)]
16-
// expected-error@-1 {{subscript 'subscript(_:)' requires that 'Double' conform to 'P'}}
17-
// expected-error@-2 {{referencing initializer 'init(value:)' on 'S' requires that 'Double' conform to 'P'}}
16+
// expected-error@-1 {{generic struct 'S' requires that 'Double' conform to 'P'}}
1817
}

0 commit comments

Comments
 (0)