Skip to content

Commit b4eabd9

Browse files
committed
---
yaml --- r: 294897 b: refs/heads/swift-5.1-branch c: cf62e6b h: refs/heads/master i: 294895: b766fda
1 parent 705211c commit b4eabd9

File tree

18 files changed

+116
-89
lines changed

18 files changed

+116
-89
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ refs/heads/marcrasi-astverifier-disable: 3fac766a23a77ebd0640296bfd7fc116ea60a4e
12421242
refs/heads/revert-22227-a-tall-white-fountain-played: adfce60b2eaa54903ea189bed8a783bca609fa53
12431243
refs/heads/revert-22300-revert-22227-a-tall-white-fountain-played: 5f92040224df7dd4e618fdfb367349df64d8acad
12441244
refs/heads/swift-5.1-old-llvm-branch: 9cef8175146f25b72806154b8a0f4a3f52e3e400
1245-
refs/heads/swift-5.1-branch: c992e0abbb983363f30d41f4d876d46a04916b1e
1245+
refs/heads/swift-5.1-branch: cf62e6b05d24cffee80a47fe518630f40650cad9
12461246
refs/tags/swift-4.2.2-RELEASE: e429d1f1aaf59e69d38207a96e56265c7f6fccec
12471247
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-02-a: 3e5a03d32ff3b1e9af90d6c1198c14f938379a6e
12481248
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-03-a: 4591c933063ddcb0d6cd6d0cdd01086b2f9b244d

branches/swift-5.1-branch/include/swift/AST/Expr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4851,6 +4851,16 @@ class LazyInitializerExpr : public Expr {
48514851
}
48524852
};
48534853

4854+
class UninhabitedUpcastExpr : public ImplicitConversionExpr {
4855+
public:
4856+
UninhabitedUpcastExpr(Expr *subExpr, Type ty)
4857+
: ImplicitConversionExpr(ExprKind::UninhabitedUpcast, subExpr, ty) {}
4858+
4859+
static bool classof(const Expr *E) {
4860+
return E->getKind() == ExprKind::UninhabitedUpcast;
4861+
}
4862+
};
4863+
48544864
/// Produces the Objective-C selector of the referenced method.
48554865
///
48564866
/// \code

branches/swift-5.1-branch/include/swift/AST/ExprNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ ABSTRACT_EXPR(ImplicitConversion, Expr)
168168
EXPR(StringToPointer, ImplicitConversionExpr)
169169
EXPR(PointerToPointer, ImplicitConversionExpr)
170170
EXPR(ForeignObjectConversion, ImplicitConversionExpr)
171+
EXPR(UninhabitedUpcast, ImplicitConversionExpr)
171172
EXPR(UnevaluatedInstance, ImplicitConversionExpr)
172173
EXPR(UnderlyingToOpaque, ImplicitConversionExpr)
173174
EXPR_RANGE(ImplicitConversion, Load, UnderlyingToOpaque)

branches/swift-5.1-branch/lib/AST/ASTDumper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,11 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
23212321
printRec(E->getSubExpr());
23222322
PrintWithColorRAII(OS, ParenthesisColor) << ')';
23232323
}
2324+
void visitUninhabitedUpcastExpr(UninhabitedUpcastExpr *E) {
2325+
printCommon(E, "uninhabited_upcast_expr") << '\n';
2326+
printRec(E->getSubExpr());
2327+
PrintWithColorRAII(OS, ParenthesisColor) << ')';
2328+
}
23242329
void visitInjectIntoOptionalExpr(InjectIntoOptionalExpr *E) {
23252330
printCommon(E, "inject_into_optional") << '\n';
23262331
printRec(E->getSubExpr());

branches/swift-5.1-branch/lib/AST/Expr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ ConcreteDeclRef Expr::getReferencedDecl() const {
349349
PASS_THROUGH_REFERENCE(BridgeFromObjC, getSubExpr);
350350
PASS_THROUGH_REFERENCE(ConditionalBridgeFromObjC, getSubExpr);
351351
PASS_THROUGH_REFERENCE(UnderlyingToOpaque, getSubExpr);
352+
PASS_THROUGH_REFERENCE(UninhabitedUpcast, getSubExpr);
352353
NO_REFERENCE(Coerce);
353354
NO_REFERENCE(ForcedCheckedCast);
354355
NO_REFERENCE(ConditionalCheckedCast);
@@ -666,6 +667,7 @@ bool Expr::canAppendPostfixExpression(bool appendingPostfixOperator) const {
666667
case ExprKind::BridgeFromObjC:
667668
case ExprKind::BridgeToObjC:
668669
case ExprKind::UnderlyingToOpaque:
670+
case ExprKind::UninhabitedUpcast:
669671
// Implicit conversion nodes have no syntax of their own; defer to the
670672
// subexpression.
671673
return cast<ImplicitConversionExpr>(this)->getSubExpr()

branches/swift-5.1-branch/lib/SILGen/SILGenExpr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ namespace {
416416
SGFContext C);
417417
RValue visitBridgeToObjCExpr(BridgeToObjCExpr *E, SGFContext C);
418418
RValue visitBridgeFromObjCExpr(BridgeFromObjCExpr *E, SGFContext C);
419+
RValue visitUninhabitedUpcastExpr(UninhabitedUpcastExpr *E, SGFContext C);
419420
RValue visitConditionalBridgeFromObjCExpr(ConditionalBridgeFromObjCExpr *E,
420421
SGFContext C);
421422
RValue visitArchetypeToSuperExpr(ArchetypeToSuperExpr *E, SGFContext C);
@@ -1416,6 +1417,15 @@ RValueEmitter::visitBridgeFromObjCExpr(BridgeFromObjCExpr *E, SGFContext C) {
14161417
return RValue(SGF, E, result);
14171418
}
14181419

1420+
RValue
1421+
RValueEmitter::visitUninhabitedUpcastExpr(UninhabitedUpcastExpr *E,
1422+
SGFContext C) {
1423+
// Emit code which force casts the expr of uninhabited type to the right type.
1424+
// TODO: Emit something more appropriate.
1425+
return emitUnconditionalCheckedCast(SGF, E, E->getSubExpr(), E->getType(),
1426+
CheckedCastKind::ValueCast, C);
1427+
}
1428+
14191429
RValue
14201430
RValueEmitter::visitBridgeToObjCExpr(BridgeToObjCExpr *E, SGFContext C) {
14211431
if (tryPeepholeBridgingConversion(SGF, Conversion::BridgeToObjC, E, C))

branches/swift-5.1-branch/lib/Sema/CSApply.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ namespace {
390390
Expr *coerceSuperclass(Expr *expr, Type toType,
391391
ConstraintLocatorBuilder locator);
392392

393+
Expr *coerceUninhabited(Expr *expr, Type toType,
394+
ConstraintLocatorBuilder locator);
395+
393396
/// Coerce the given value to existential type.
394397
///
395398
/// The following conversions are supported:
@@ -5268,6 +5271,13 @@ Expr *ExprRewriter::coerceSuperclass(Expr *expr, Type toType,
52685271
new (tc.Context) DerivedToBaseExpr(expr, toType));
52695272
}
52705273

5274+
Expr *ExprRewriter::coerceUninhabited(Expr *expr, Type toType,
5275+
ConstraintLocatorBuilder locator) {
5276+
auto &tc = cs.getTypeChecker();
5277+
return cs.cacheType(
5278+
new (tc.Context) UninhabitedUpcastExpr(expr, toType));
5279+
}
5280+
52715281
/// Collect the conformances for all the protocols of an existential type.
52725282
/// If the source type is also existential, we don't want to check conformance
52735283
/// because most protocols do not conform to themselves -- however we still
@@ -6348,6 +6358,8 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
63486358
case ConversionRestrictionKind::Superclass:
63496359
case ConversionRestrictionKind::ExistentialMetatypeToMetatype:
63506360
return coerceSuperclass(expr, toType, locator);
6361+
case ConversionRestrictionKind::UninhabitedUpcast:
6362+
return coerceUninhabited(expr, toType, locator);
63516363

63526364
case ConversionRestrictionKind::Existential:
63536365
case ConversionRestrictionKind::MetatypeToExistentialMetatype:

branches/swift-5.1-branch/lib/Sema/CSBindings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
416416
case ConstraintKind::Conversion:
417417
case ConstraintKind::ArgumentConversion:
418418
case ConstraintKind::OperatorArgumentConversion:
419-
case ConstraintKind::OptionalObject: {
419+
case ConstraintKind::OptionalObject:
420+
case ConstraintKind::SingleExpressionFunctionReturnConversion: {
420421
// If there is a `bind param` constraint associated with
421422
// current type variable, result should be aware of that
422423
// fact. Binding set might be incomplete until

branches/swift-5.1-branch/lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,7 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
21572157
}
21582158
};
21592159
break;
2160+
case CTP_ReturnSingleExpr:
21602161
case CTP_ReturnStmt:
21612162
// Special case the "conversion to void" case.
21622163
if (contextualType->isVoid()) {

branches/swift-5.1-branch/lib/Sema/CSRanking.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
7777
case SK_KeyPathSubscript:
7878
log << "key path subscript";
7979
break;
80+
case SK_UninhabitedUpcast:
81+
log << "uninhabited upcast conversion";
82+
break;
8083
case SK_ValueToPointerConversion:
8184
log << "value-to-pointer conversion";
8285
break;

branches/swift-5.1-branch/lib/Sema/CSSimplify.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
10731073
case ConstraintKind::OperatorArgumentConversion:
10741074
case ConstraintKind::ArgumentConversion:
10751075
case ConstraintKind::Conversion:
1076+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
10761077
subKind = ConstraintKind::Conversion;
10771078
break;
10781079

@@ -1164,6 +1165,7 @@ static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
11641165
case ConstraintKind::ValueMember:
11651166
case ConstraintKind::FunctionInput:
11661167
case ConstraintKind::FunctionResult:
1168+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
11671169
return false;
11681170
}
11691171

@@ -1309,6 +1311,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
13091311
case ConstraintKind::ArgumentConversion:
13101312
case ConstraintKind::OperatorArgumentConversion:
13111313
case ConstraintKind::OpaqueUnderlyingType:
1314+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
13121315
subKind = ConstraintKind::Subtype;
13131316
break;
13141317

@@ -1582,6 +1585,18 @@ matchDeepTypeArguments(ConstraintSystem &cs,
15821585
return cs.getTypeMatchSuccess();
15831586
}
15841587

1588+
ConstraintSystem::TypeMatchResult
1589+
ConstraintSystem::matchUninhabitedUpcastTypes(Type type1, Type type2,
1590+
TypeMatchOptions flags,
1591+
ConstraintLocatorBuilder locator) {
1592+
if (type1->isUninhabited()) {
1593+
increaseScore(SK_UninhabitedUpcast);
1594+
return getTypeMatchSuccess();
1595+
}
1596+
1597+
return getTypeMatchFailure(locator);
1598+
}
1599+
15851600
ConstraintSystem::TypeMatchResult
15861601
ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
15871602
ConstraintLocatorBuilder locator) {
@@ -2220,6 +2235,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
22202235
case ConstraintKind::Conversion:
22212236
case ConstraintKind::ArgumentConversion:
22222237
case ConstraintKind::OperatorArgumentConversion:
2238+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
22232239
return formUnsolvedResult();
22242240

22252241
case ConstraintKind::OpaqueUnderlyingType:
@@ -2476,6 +2492,12 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
24762492
}
24772493
}
24782494

2495+
if (kind == ConstraintKind::SingleExpressionFunctionReturnConversion) {
2496+
if (type1->isUninhabited()) {
2497+
conversionsOrFixes.push_back(ConversionRestrictionKind::UninhabitedUpcast);
2498+
}
2499+
}
2500+
24792501
if (kind >= ConstraintKind::Subtype) {
24802502
// Subclass-to-superclass conversion.
24812503
if (type1->mayHaveSuperclass() &&
@@ -5992,6 +6014,10 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
59926014
addContextualScore();
59936015
return matchSuperclassTypes(type1, type2, subflags, locator);
59946016

6017+
case ConversionRestrictionKind::UninhabitedUpcast:
6018+
addContextualScore();
6019+
return matchUninhabitedUpcastTypes(type1, type2, subflags, locator);
6020+
59956021
// for $< in { <, <c, <oc }:
59966022
// T $< U, U : P_i ===> T $< protocol<P_i...>
59976023
case ConversionRestrictionKind::Existential:
@@ -6491,6 +6517,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
64916517
case ConstraintKind::Conversion:
64926518
case ConstraintKind::ArgumentConversion:
64936519
case ConstraintKind::OperatorArgumentConversion:
6520+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
64946521
return matchTypes(first, second, kind, subflags, locator);
64956522

64966523
case ConstraintKind::OpaqueUnderlyingType:
@@ -6750,7 +6777,8 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
67506777
case ConstraintKind::Conversion:
67516778
case ConstraintKind::ArgumentConversion:
67526779
case ConstraintKind::OperatorArgumentConversion:
6753-
case ConstraintKind::OpaqueUnderlyingType: {
6780+
case ConstraintKind::OpaqueUnderlyingType:
6781+
case ConstraintKind::SingleExpressionFunctionReturnConversion: {
67546782
// Relational constraints.
67556783
auto matchKind = constraint.getKind();
67566784

branches/swift-5.1-branch/lib/Sema/CSSolver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,8 @@ ConstraintSystem::solveImpl(Expr *&expr,
11251125

11261126
if (getContextualTypePurpose() == CTP_CallArgument)
11271127
constraintKind = ConstraintKind::ArgumentConversion;
1128+
else if (getContextualTypePurpose() == CTP_ReturnSingleExpr)
1129+
constraintKind = ConstraintKind::SingleExpressionFunctionReturnConversion;
11281130

11291131
// In a by-reference yield, we expect the contextual type to be an
11301132
// l-value type, so the result must be bound to that.
@@ -1531,7 +1533,8 @@ void ConstraintSystem::ArgumentInfoCollector::walk(Type argType) {
15311533
case ConstraintKind::Conversion:
15321534
case ConstraintKind::BridgingConversion:
15331535
case ConstraintKind::BindParam:
1534-
case ConstraintKind::OpaqueUnderlyingType: {
1536+
case ConstraintKind::OpaqueUnderlyingType:
1537+
case ConstraintKind::SingleExpressionFunctionReturnConversion: {
15351538
auto secondTy = constraint->getSecondType();
15361539
if (secondTy->is<TypeVariableType>()) {
15371540
auto otherRep =

branches/swift-5.1-branch/lib/Sema/Constraint.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
6666
case ConstraintKind::FunctionInput:
6767
case ConstraintKind::FunctionResult:
6868
case ConstraintKind::OpaqueUnderlyingType:
69+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
6970
assert(!First.isNull());
7071
assert(!Second.isNull());
7172
break;
@@ -134,6 +135,7 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second, Type Third,
134135
case ConstraintKind::FunctionInput:
135136
case ConstraintKind::FunctionResult:
136137
case ConstraintKind::OpaqueUnderlyingType:
138+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
137139
llvm_unreachable("Wrong constructor");
138140

139141
case ConstraintKind::KeyPath:
@@ -237,6 +239,7 @@ Constraint *Constraint::clone(ConstraintSystem &cs) const {
237239
case ConstraintKind::FunctionInput:
238240
case ConstraintKind::FunctionResult:
239241
case ConstraintKind::OpaqueUnderlyingType:
242+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
240243
return create(cs, getKind(), getFirstType(), getSecondType(), getLocator());
241244

242245
case ConstraintKind::BindOverload:
@@ -330,6 +333,8 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
330333
Out << " bind function input of "; break;
331334
case ConstraintKind::FunctionResult:
332335
Out << " bind function result of "; break;
336+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
337+
Out << " single expression function return of "; break;
333338
case ConstraintKind::BindOverload: {
334339
Out << " bound to ";
335340
auto overload = getOverloadChoice();
@@ -437,6 +442,8 @@ StringRef swift::constraints::getName(ConversionRestrictionKind kind) {
437442
return "[deep equality]";
438443
case ConversionRestrictionKind::Superclass:
439444
return "[superclass]";
445+
case ConversionRestrictionKind::UninhabitedUpcast:
446+
return "[uninhabited-upcast]";
440447
case ConversionRestrictionKind::Existential:
441448
return "[existential]";
442449
case ConversionRestrictionKind::MetatypeToExistentialMetatype:
@@ -517,6 +524,7 @@ gatherReferencedTypeVars(Constraint *constraint,
517524
case ConstraintKind::FunctionInput:
518525
case ConstraintKind::FunctionResult:
519526
case ConstraintKind::OpaqueUnderlyingType:
527+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
520528
constraint->getFirstType()->getTypeVariables(typeVars);
521529
constraint->getSecondType()->getTypeVariables(typeVars);
522530
break;

branches/swift-5.1-branch/lib/Sema/Constraint.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ enum class ConstraintKind : char {
150150
/// The first type is a type that's a candidate to be the underlying type of
151151
/// the second opaque archetype.
152152
OpaqueUnderlyingType,
153+
/// The first type is being implicitly returned from a function, the second is
154+
/// the function's result type.
155+
SingleExpressionFunctionReturnConversion,
153156
};
154157

155158
/// Classification of the different kinds of constraints.
@@ -181,6 +184,8 @@ enum class ConversionRestrictionKind {
181184
DeepEquality,
182185
/// Subclass-to-superclass conversion.
183186
Superclass,
187+
/// Uninhabited-to-any conversion.
188+
UninhabitedUpcast,
184189
/// Class metatype to AnyObject conversion.
185190
ClassMetatypeToAnyObject,
186191
/// Existential metatype to AnyObject conversion.
@@ -489,6 +494,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
489494
case ConstraintKind::BindOverload:
490495
case ConstraintKind::OptionalObject:
491496
case ConstraintKind::OpaqueUnderlyingType:
497+
case ConstraintKind::SingleExpressionFunctionReturnConversion:
492498
return ConstraintClassification::Relational;
493499

494500
case ConstraintKind::ValueMember:

branches/swift-5.1-branch/lib/Sema/ConstraintSystem.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ enum ScoreKind {
444444
SK_Fix,
445445
/// A reference to an @unavailable declaration.
446446
SK_Unavailable,
447+
/// An implicit upcast from uninhabited to some type.
448+
SK_UninhabitedUpcast,
447449
/// An implicit force of an implicitly unwrapped optional value.
448450
SK_ForceUnchecked,
449451
/// A user-defined conversion.
@@ -2583,6 +2585,12 @@ class ConstraintSystem {
25832585
TypeMatchResult matchSuperclassTypes(Type type1, Type type2,
25842586
TypeMatchOptions flags,
25852587
ConstraintLocatorBuilder locator);
2588+
2589+
/// Subroutine of \c matchTypes(), which matches up an uninhabited
2590+
/// value to anything.
2591+
TypeMatchResult matchUninhabitedUpcastTypes(Type type1, Type type2,
2592+
TypeMatchOptions flags,
2593+
ConstraintLocatorBuilder locator);
25862594

25872595
/// Subroutine of \c matchTypes(), which matches up two types that
25882596
/// refer to the same declaration via their generic arguments.

0 commit comments

Comments
 (0)