Skip to content

Commit 9d0423a

Browse files
authored
---
yaml --- r: 277439 b: refs/heads/tensorflow-merge c: b9b7f00 h: refs/heads/master i: 277437: bb9f5c0 277435: 080c4f2 277431: ed9605f 277423: 4a3dcd9 277407: 01fd2ec 277375: f02aaf9
1 parent 0233973 commit 9d0423a

File tree

3 files changed

+45
-54
lines changed

3 files changed

+45
-54
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-10-29-a: 1b087071edaea398480fb778e
11241124
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-10-30-a: 8bc9e108e1480d9217299984e428c601c7aaac75
11251125
refs/tags/swift-4.2.1-RELEASE: 02a6ca969ea1387475b6caeb69c31186df7d30b6
11261126
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-11-01-a: 3b0299288f8287094b9ef587f46df54f42a347af
1127-
refs/heads/tensorflow-merge: c9683d5d231b0b9102803f6155218dfd33b0726e
1127+
refs/heads/tensorflow-merge: b9b7f003efcd1f9697495f401ce14a0188bc57f1
11281128
refs/heads/TensorFlowLite: b91446471276e37bbfe64767c875f3c7f7102954
11291129
refs/heads/ad-side-effects: 19e0c0de1f59b0929c381925df2e8c72cdf4a728
11301130
refs/heads/add-test-for-asan-compiler-crash: 3cdeecffb47bf28707b299fa2b5bdf0769a4a826

branches/tensorflow-merge/lib/Sema/CSApply.cpp

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,16 @@ diagnoseInvalidDynamicConstructorReferences(ConstraintSystem &cs,
395395
}
396396

397397
/// Form a type checked expression for the index of a @dynamicMemberLookup
398-
/// subscript index parameter.
398+
/// subscript index parameter, using the specified name, type, and source loc.
399399
/// The index expression will have a tuple type of `(dynamicMember: T)`.
400+
///
401+
/// Note: propagating source location is necessary to prevent diagnostics with
402+
/// unknown location.
400403
static Expr *buildDynamicMemberLookupIndexExpr(StringRef name, Type ty,
401404
SourceLoc loc, DeclContext *dc,
402405
ConstraintSystem &cs) {
403406
auto &ctx = cs.TC.Context;
404-
407+
405408
// Build and type check the string literal index value to the specific
406409
// string type expected by the subscript.
407410
Expr *nameExpr = new (ctx) StringLiteralExpr(name, loc, /*implicit*/true);
@@ -7317,101 +7320,82 @@ static Expr *finishApplyDynamicCallable(ExprRewriter &rewriter,
73177320
Expr *memberExpr = rewriter.buildMemberRef(
73187321
member->getBase(), selected.openedFullType, member->getDotLoc(),
73197322
selected.choice, member->getNameLoc(), selected.openedType,
7320-
cs.getConstraintLocator(member), loc, true,
7323+
cs.getConstraintLocator(member), loc, /*Implicit*/ true,
73217324
selected.choice.getFunctionRefKind(), member->getAccessSemantics(),
73227325
isDynamic);
73237326

73247327
// Construct argument to the method (either an array or dictionary
73257328
// expression).
73267329
Expr *argument = nullptr;
7330+
auto expectedParamType = methodType->getParams().front().getParameterType();
73277331
if (!useKwargsMethod) {
7328-
auto paramArrayType = methodType->getParams()[0].getParameterType();
73297332
auto arrayLitProto = cs.TC.getProtocol(
73307333
fn->getLoc(), KnownProtocolKind::ExpressibleByArrayLiteral);
73317334
auto conformance =
7332-
cs.TC.conformsToProtocol(paramArrayType, arrayLitProto, cs.DC,
7335+
cs.TC.conformsToProtocol(expectedParamType, arrayLitProto, cs.DC,
73337336
ConformanceCheckFlags::InExpression);
73347337
auto paramType = ProtocolConformanceRef::getTypeWitnessByName(
7335-
paramArrayType, *conformance,
7338+
expectedParamType, *conformance,
73367339
cs.getASTContext().Id_ArrayLiteralElement, &cs.TC)
73377340
->getDesugaredType();
73387341

7339-
std::vector<Expr *> convertedElements;
7340-
for (Expr *dynamicArg : arg->getElements()) {
7341-
convertedElements.push_back(rewriter.coerceToType(
7342-
dynamicArg, paramType,
7343-
loc.withPathElement(LocatorPathElt::getApplyArgToParam(0, 0))));
7344-
}
7345-
auto *argumentTmp =
7346-
ArrayExpr::create(ctx, SourceLoc(), convertedElements, {}, SourceLoc());
7347-
argument = argumentTmp;
7348-
7349-
cs.setType(argument, paramArrayType);
7350-
rewriter.finishArrayExpr(argumentTmp);
7342+
auto arrayElements =
7343+
map<std::vector<Expr *>>(arg->getElements(), [&](Expr *origArgElt) {
7344+
return rewriter.coerceToType(origArgElt, paramType, loc);
7345+
});
7346+
auto *arrayExpr = ArrayExpr::create(
7347+
ctx, arg->getStartLoc(), arrayElements, {}, arg->getEndLoc());
7348+
cs.setType(arrayExpr, expectedParamType);
7349+
rewriter.finishArrayExpr(arrayExpr);
7350+
argument = arrayExpr;
73517351
} else {
7352-
// Get Key and Value associated types.
7353-
auto paramDictType = methodType->getParams()[0].getParameterType();
73547352
auto dictLitProto = cs.TC.getProtocol(
73557353
fn->getLoc(), KnownProtocolKind::ExpressibleByDictionaryLiteral);
73567354
auto conformance =
7357-
cs.TC.conformsToProtocol(paramDictType, dictLitProto, cs.DC,
7355+
cs.TC.conformsToProtocol(expectedParamType, dictLitProto, cs.DC,
73587356
ConformanceCheckFlags::InExpression);
73597357
auto keyAssocType =
73607358
ProtocolConformanceRef::getTypeWitnessByName(
7361-
paramDictType, *conformance, cs.getASTContext().Id_Key, &cs.TC)
7359+
expectedParamType, *conformance, ctx.Id_Key, &cs.TC)
73627360
->getDesugaredType();
73637361
auto valueAssocType =
73647362
ProtocolConformanceRef::getTypeWitnessByName(
7365-
paramDictType, *conformance, cs.getASTContext().Id_Value, &cs.TC)
7363+
expectedParamType, *conformance, ctx.Id_Value, &cs.TC)
73667364
->getDesugaredType();
73677365

7368-
SmallVector<Identifier, 4> names;
73697366
SmallVector<Expr *, 4> dictElements;
73707367
for (unsigned i = 0, n = arg->getNumElements(); i < n; i++) {
73717368
auto *labelExpr = new (ctx) StringLiteralExpr(
73727369
arg->getElementName(i).get(), arg->getElementNameLoc(i),
73737370
/*Implicit*/ true);
73747371
cs.setType(labelExpr, keyAssocType);
73757372

7376-
Expr *pair = TupleExpr::createImplicit(
7373+
Expr *dictElt = TupleExpr::createImplicit(
73777374
ctx,
73787375
{rewriter.visitStringLiteralExpr(labelExpr),
7379-
rewriter.coerceToType(
7380-
arg->getElement(i), valueAssocType,
7381-
loc.withPathElement(LocatorPathElt::getApplyArgToParam(0, 0)))},
7376+
rewriter.coerceToType(arg->getElement(i), valueAssocType, loc)},
73827377
{});
7383-
7384-
cs.setType(pair, TupleType::get({TupleTypeElt{keyAssocType},
7385-
TupleTypeElt{valueAssocType}},
7386-
ctx));
7387-
dictElements.push_back(pair);
7388-
}
7389-
auto *argumentTmp =
7390-
DictionaryExpr::create(ctx, SourceLoc(), dictElements, {}, SourceLoc());
7391-
7392-
cs.setType(argumentTmp, paramDictType);
7393-
rewriter.finishDictionaryExpr(argumentTmp);
7394-
argument = argumentTmp;
7378+
cs.setType(dictElt, TupleType::get({TupleTypeElt{keyAssocType},
7379+
TupleTypeElt{valueAssocType}},
7380+
ctx));
7381+
dictElements.push_back(dictElt);
7382+
}
7383+
auto *dictExpr = DictionaryExpr::create(
7384+
ctx, arg->getStartLoc(), dictElements, {}, arg->getEndLoc());
7385+
cs.setType(dictExpr, expectedParamType);
7386+
rewriter.finishDictionaryExpr(dictExpr);
7387+
argument = dictExpr;
73957388
}
73967389
argument->setImplicit();
73977390

7398-
auto getType = [&](const Expr *E) -> Type { return cs.getType(E); };
7399-
74007391
// Construct call to the `dynamicallyCall` method.
7392+
auto getType = [&](const Expr *E) -> Type { return cs.getType(E); };
74017393
CallExpr *result = CallExpr::createImplicit(ctx, memberExpr, argument,
74027394
{argumentLabel}, getType);
7403-
74047395
cs.setType(result, methodType->getResult());
7405-
7406-
{
7407-
// The implicitly constructed tuple_expr may have a type, but this type
7408-
// is not known in the constraint system.
7409-
Expr *arg = result->getArg();
7410-
if (arg->getType()) {
7411-
cs.setType(arg, arg->getType());
7412-
}
7413-
}
7414-
7396+
// Set the type of the newly constructed argument in the constraint system.
7397+
if (result->getArg()->getType())
7398+
cs.setType(result->getArg(), result->getArg()->getType());
74157399
return result;
74167400
}
74177401

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// https://bugs.swift.org/browse/TF-198: `@dynamicCallable` REPL completer crash.
2+
// RUN: %target-swift-ide-test -repl-code-completion -source-filename=%s
3+
4+
// TODO(TF-214): Require `python` lit feature, after it is created.
5+
6+
import Python
7+
Python.str("name").strip(

0 commit comments

Comments
 (0)