Skip to content

Commit d0b6b38

Browse files
authored
---
yaml --- r: 326651 b: refs/heads/tensorflow c: 586327a h: refs/heads/master i: 326649: 4418c3d 326647: 503d825
1 parent b5c03e8 commit d0b6b38

35 files changed

+394
-265
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: 5d5bb8cb403a1b3b3f70c8707407734b917549eb
819+
refs/heads/tensorflow: 586327ac33cdc250ad222dca00cff8207f019fbe
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/include/swift/AST/Expr.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3843,11 +3843,12 @@ class DynamicTypeExpr : public Expr {
38433843
/// node (say, an \c OpenExistentialExpr) and can only be used within the
38443844
/// subexpressions of that AST node.
38453845
class OpaqueValueExpr : public Expr {
3846-
SourceLoc Loc;
3846+
SourceRange Range;
38473847

38483848
public:
3849-
explicit OpaqueValueExpr(SourceLoc Loc, Type Ty, bool isPlaceholder = false)
3850-
: Expr(ExprKind::OpaqueValue, /*Implicit=*/true, Ty), Loc(Loc) {
3849+
explicit OpaqueValueExpr(SourceRange Range, Type Ty,
3850+
bool isPlaceholder = false)
3851+
: Expr(ExprKind::OpaqueValue, /*Implicit=*/true, Ty), Range(Range) {
38513852
Bits.OpaqueValueExpr.IsPlaceholder = isPlaceholder;
38523853
}
38533854

@@ -3856,8 +3857,8 @@ class OpaqueValueExpr : public Expr {
38563857
/// value to be specified later.
38573858
bool isPlaceholder() const { return Bits.OpaqueValueExpr.IsPlaceholder; }
38583859

3859-
SourceRange getSourceRange() const { return Loc; }
3860-
3860+
SourceRange getSourceRange() const { return Range; }
3861+
38613862
static bool classof(const Expr *E) {
38623863
return E->getKind() == ExprKind::OpaqueValue;
38633864
}

branches/tensorflow/lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,14 +1878,38 @@ static bool onlyForwardsNone(SILBasicBlock *noneBB, SILBasicBlock *someBB,
18781878
/// \ ... (more bbs?)
18791879
/// \ /
18801880
/// ulimateBB
1881-
static bool hasSameUlitmateSuccessor(SILBasicBlock *noneBB, SILBasicBlock *someBB) {
1881+
static bool hasSameUltimateSuccessor(SILBasicBlock *noneBB, SILBasicBlock *someBB) {
1882+
// Make sure that both our some, none blocks both have single successors that
1883+
// are not themselves (which can happen due to single block loops).
18821884
auto *someSuccessorBB = someBB->getSingleSuccessorBlock();
1883-
if (!someSuccessorBB)
1885+
if (!someSuccessorBB || someSuccessorBB == someBB)
18841886
return false;
18851887
auto *noneSuccessorBB = noneBB->getSingleSuccessorBlock();
1886-
while (noneSuccessorBB != nullptr && noneSuccessorBB != someSuccessorBB)
1887-
noneSuccessorBB = noneSuccessorBB->getSingleSuccessorBlock();
1888-
return noneSuccessorBB == someSuccessorBB;
1888+
if (!noneSuccessorBB || noneSuccessorBB == noneBB)
1889+
return false;
1890+
1891+
// If we immediately find a diamond, return true. We are done.
1892+
if (noneSuccessorBB == someSuccessorBB)
1893+
return true;
1894+
1895+
// Otherwise, lets keep looking down the none case.
1896+
auto *next = noneSuccessorBB;
1897+
while (next != someSuccessorBB) {
1898+
noneSuccessorBB = next;
1899+
next = noneSuccessorBB->getSingleSuccessorBlock();
1900+
1901+
// If we find another single successor and it is not our own block (due to a
1902+
// self-loop), continue.
1903+
if (next && next != noneSuccessorBB)
1904+
continue;
1905+
1906+
// Otherwise, we either have multiple successors or a self-loop. We do not
1907+
// support this, return false.
1908+
return false;
1909+
}
1910+
1911+
// At this point, we know that next must be someSuccessorBB.
1912+
return true;
18891913
}
18901914

18911915
/// Simplify switch_enums on class enums that branch to objc_method calls on
@@ -1920,7 +1944,7 @@ bool SimplifyCFG::simplifySwitchEnumOnObjcClassOptional(SwitchEnumInst *SEI) {
19201944
if (SEI->getCaseDestination(someDecl) != someBB)
19211945
std::swap(someBB, noneBB);
19221946

1923-
if (!hasSameUlitmateSuccessor(noneBB, someBB))
1947+
if (!hasSameUltimateSuccessor(noneBB, someBB))
19241948
return false;
19251949

19261950
if (!onlyForwardsNone(noneBB, someBB, SEI))

branches/tensorflow/lib/Sema/CSApply.cpp

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,8 @@ namespace {
668668
opaqueType = LValueType::get(opaqueType);
669669

670670
ASTContext &ctx = tc.Context;
671-
auto archetypeVal = new (ctx) OpaqueValueExpr(base->getLoc(), opaqueType);
671+
auto archetypeVal =
672+
new (ctx) OpaqueValueExpr(base->getSourceRange(), opaqueType);
672673
cs.cacheType(archetypeVal);
673674

674675
// Record the opened existential.
@@ -2169,8 +2170,8 @@ namespace {
21692170

21702171
// This OpaqueValueExpr represents the result of builderInit above in
21712172
// silgen.
2172-
OpaqueValueExpr *interpolationExpr =
2173-
new (tc.Context) OpaqueValueExpr(expr->getLoc(), interpolationType);
2173+
OpaqueValueExpr *interpolationExpr = new (tc.Context)
2174+
OpaqueValueExpr(expr->getSourceRange(), interpolationType);
21742175
cs.setType(interpolationExpr, interpolationType);
21752176
expr->setInterpolationExpr(interpolationExpr);
21762177

@@ -4634,7 +4635,8 @@ namespace {
46344635
}
46354636

46364637
Expr *visitOneWayExpr(OneWayExpr *E) {
4637-
return E->getSubExpr();
4638+
auto type = simplifyType(cs.getType(E));
4639+
return coerceToType(E->getSubExpr(), type, cs.getConstraintLocator(E));
46384640
}
46394641

46404642
Expr *visitTapExpr(TapExpr *E) {
@@ -5046,8 +5048,8 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr,
50465048
SmallVector<OpaqueValueExpr *, 4> destructured;
50475049
for (unsigned i = 0, e = sources.size(); i != e; ++i) {
50485050
auto fromEltType = fromTuple->getElementType(i);
5049-
auto *opaqueElt = new (tc.Context) OpaqueValueExpr(expr->getLoc(),
5050-
fromEltType);
5051+
auto *opaqueElt =
5052+
new (tc.Context) OpaqueValueExpr(expr->getSourceRange(), fromEltType);
50515053
cs.cacheType(opaqueElt);
50525054
destructured.push_back(opaqueElt);
50535055
}
@@ -5141,10 +5143,8 @@ Expr *ExprRewriter::coerceSuperclass(Expr *expr, Type toType,
51415143
// concrete superclass.
51425144
auto fromArchetype = OpenedArchetypeType::getAny(fromType);
51435145

5144-
auto *archetypeVal =
5145-
cs.cacheType(
5146-
new (tc.Context) OpaqueValueExpr(expr->getLoc(),
5147-
fromArchetype));
5146+
auto *archetypeVal = cs.cacheType(new (tc.Context) OpaqueValueExpr(
5147+
expr->getSourceRange(), fromArchetype));
51485148

51495149
auto *result = coerceSuperclass(archetypeVal, toType, locator);
51505150

@@ -5207,12 +5207,10 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
52075207
// For existential-to-existential coercions, open the source existential.
52085208
if (fromType->isAnyExistentialType()) {
52095209
fromType = OpenedArchetypeType::getAny(fromType);
5210-
5211-
auto *archetypeVal =
5212-
cs.cacheType(
5213-
new (ctx) OpaqueValueExpr(expr->getLoc(),
5214-
fromType));
5215-
5210+
5211+
auto *archetypeVal = cs.cacheType(
5212+
new (ctx) OpaqueValueExpr(expr->getSourceRange(), fromType));
5213+
52165214
auto *result = cs.cacheType(ErasureExpr::create(ctx, archetypeVal, toType,
52175215
conformances));
52185216
return cs.cacheType(
@@ -5897,10 +5895,8 @@ maybeDiagnoseUnsupportedFunctionConversion(ConstraintSystem &cs, Expr *expr,
58975895

58985896
/// Build the conversion of an element in a collection upcast.
58995897
static Expr *buildElementConversion(ExprRewriter &rewriter,
5900-
SourceLoc srcLoc,
5901-
Type srcType,
5902-
Type destType,
5903-
bool bridged,
5898+
SourceRange srcRange, Type srcType,
5899+
Type destType, bool bridged,
59045900
ConstraintLocatorBuilder locator,
59055901
Expr *element) {
59065902
auto &cs = rewriter.getConstraintSystem();
@@ -5920,12 +5916,9 @@ static Expr *buildElementConversion(ExprRewriter &rewriter,
59205916
}
59215917

59225918
static CollectionUpcastConversionExpr::ConversionPair
5923-
buildOpaqueElementConversion(ExprRewriter &rewriter,
5924-
SourceLoc srcLoc,
5925-
Type srcCollectionType,
5926-
Type destCollectionType,
5927-
bool bridged,
5928-
ConstraintLocatorBuilder locator,
5919+
buildOpaqueElementConversion(ExprRewriter &rewriter, SourceRange srcRange,
5920+
Type srcCollectionType, Type destCollectionType,
5921+
bool bridged, ConstraintLocatorBuilder locator,
59295922
unsigned typeArgIndex) {
59305923
// We don't need this stuff unless we've got generalized casts.
59315924
Type srcType = srcCollectionType->castTo<BoundGenericType>()
@@ -5937,14 +5930,13 @@ buildOpaqueElementConversion(ExprRewriter &rewriter,
59375930
auto &cs = rewriter.getConstraintSystem();
59385931
ASTContext &ctx = cs.getASTContext();
59395932
auto opaque =
5940-
rewriter.cs.cacheType(new (ctx) OpaqueValueExpr(srcLoc, srcType));
5933+
rewriter.cs.cacheType(new (ctx) OpaqueValueExpr(srcRange, srcType));
59415934

5942-
Expr *conversion =
5943-
buildElementConversion(rewriter, srcLoc, srcType, destType, bridged,
5944-
locator.withPathElement(
5945-
ConstraintLocator::PathElement::getGenericArgument(
5946-
typeArgIndex)),
5947-
opaque);
5935+
Expr *conversion = buildElementConversion(
5936+
rewriter, srcRange, srcType, destType, bridged,
5937+
locator.withPathElement(
5938+
ConstraintLocator::PathElement::getGenericArgument(typeArgIndex)),
5939+
opaque);
59485940

59495941
return { opaque, conversion };
59505942
}
@@ -6999,9 +6991,9 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
69996991
bodyFnTy->withExtInfo(bodyFnTy->getExtInfo().withNoEscape()));
70006992
body = coerceToType(body, bodyFnTy, locator);
70016993
assert(body && "can't make nonescaping?!");
7002-
6994+
70036995
auto escapable = new (tc.Context)
7004-
OpaqueValueExpr(apply->getFn()->getLoc(), Type());
6996+
OpaqueValueExpr(apply->getFn()->getSourceRange(), Type());
70056997
cs.setType(escapable, escapableParams[0].getOldType());
70066998

70076999
auto getType = [&](const Expr *E) -> Type {
@@ -7058,8 +7050,8 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
70587050
->getOpenedExistentialType()
70597051
->isEqual(existentialInstanceTy));
70607052

7061-
auto opaqueValue = new (tc.Context)
7062-
OpaqueValueExpr(apply->getLoc(), openedTy);
7053+
auto opaqueValue =
7054+
new (tc.Context) OpaqueValueExpr(apply->getSourceRange(), openedTy);
70637055
cs.setType(opaqueValue, openedTy);
70647056

70657057
auto getType = [&](const Expr *E) -> Type {

branches/tensorflow/lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
633633
}
634634
break;
635635

636-
case ConstraintKind::OneWayBind: {
636+
case ConstraintKind::OneWayEqual: {
637637
// Don't produce any bindings if this type variable is on the left-hand
638638
// side of a one-way binding.
639639
auto firstType = constraint->getFirstType();

branches/tensorflow/lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,19 +2199,6 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
21992199
if (!exprResult)
22002200
return nullptr;
22012201

2202-
// If the caller expected something inout, but we didn't have
2203-
// something of inout type, diagnose it.
2204-
if (auto IOE =
2205-
dyn_cast<InOutExpr>(exprResult->getSemanticsProvidingExpr())) {
2206-
if (!param.isInOut()) {
2207-
diagnose(exprResult->getLoc(), diag::extra_address_of,
2208-
CS.getType(exprResult)->getInOutObjectType())
2209-
.highlight(exprResult->getSourceRange())
2210-
.fixItRemove(IOE->getStartLoc());
2211-
return nullptr;
2212-
}
2213-
}
2214-
22152202
auto resultTy = CS.getType(exprResult);
22162203
resultElts[inArgNo] = exprResult;
22172204
resultEltTys[inArgNo] = {resultTy->getInOutObjectType(),
@@ -4592,13 +4579,6 @@ bool FailureDiagnosis::visitInOutExpr(InOutExpr *IOE) {
45924579
}
45934580
} else if (contextualType->is<InOutType>()) {
45944581
contextualType = contextualType->getInOutObjectType();
4595-
} else {
4596-
// If the caller expected something inout, but we didn't have
4597-
// something of inout type, diagnose it.
4598-
diagnose(IOE->getLoc(), diag::extra_address_of, contextualType)
4599-
.highlight(IOE->getSourceRange())
4600-
.fixItRemove(IOE->getStartLoc());
4601-
return true;
46024582
}
46034583
}
46044584

@@ -6015,19 +5995,6 @@ bool FailureDiagnosis::visitTupleExpr(TupleExpr *TE) {
60155995
CS.getContextualTypePurpose(), options);
60165996
// If there was an error type checking this argument, then we're done.
60175997
if (!exprResult) return true;
6018-
6019-
// If the caller expected something inout, but we didn't have
6020-
// something of inout type, diagnose it.
6021-
if (auto IOE =
6022-
dyn_cast<InOutExpr>(exprResult->getSemanticsProvidingExpr())) {
6023-
if (!contextualTT->getElement(i).isInOut()) {
6024-
diagnose(exprResult->getLoc(), diag::extra_address_of,
6025-
CS.getType(exprResult)->getInOutObjectType())
6026-
.highlight(exprResult->getSourceRange())
6027-
.fixItRemove(IOE->getStartLoc());
6028-
return true;
6029-
}
6030-
}
60315998
}
60325999

60336000
return false;

branches/tensorflow/lib/Sema/CSDiagnostics.cpp

Lines changed: 40 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
}
@@ -3606,6 +3634,16 @@ SourceLoc InvalidUseOfAddressOf::getLoc() const {
36063634
}
36073635

36083636
bool InvalidUseOfAddressOf::diagnoseAsError() {
3637+
if (auto argApplyInfo = getFunctionArgApplyInfo(getLocator())) {
3638+
if (!argApplyInfo->getParameterFlags().isInOut()) {
3639+
auto anchor = getAnchor();
3640+
emitDiagnostic(anchor->getLoc(), diag::extra_address_of, getToType())
3641+
.highlight(anchor->getSourceRange())
3642+
.fixItRemove(anchor->getStartLoc());
3643+
return true;
3644+
}
3645+
}
3646+
36093647
emitDiagnostic(getLoc(), diag::extraneous_address_of);
36103648
return true;
36113649
}

0 commit comments

Comments
 (0)