Skip to content

Commit b2ad562

Browse files
committed
Eliminated conversion from uninhabited.
1 parent ca6cf0c commit b2ad562

File tree

13 files changed

+3
-98
lines changed

13 files changed

+3
-98
lines changed

include/swift/AST/Expr.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4677,16 +4677,6 @@ class LazyInitializerExpr : public Expr {
46774677
}
46784678
};
46794679

4680-
class UninhabitedUpcastExpr : public ImplicitConversionExpr {
4681-
public:
4682-
UninhabitedUpcastExpr(Expr *subExpr, Type ty)
4683-
: ImplicitConversionExpr(ExprKind::UninhabitedUpcast, subExpr, ty) {}
4684-
4685-
static bool classof(const Expr *E) {
4686-
return E->getKind() == ExprKind::UninhabitedUpcast;
4687-
}
4688-
};
4689-
46904680
/// Produces the Objective-C selector of the referenced method.
46914681
///
46924682
/// \code

include/swift/AST/ExprNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ ABSTRACT_EXPR(ImplicitConversion, Expr)
169169
EXPR(StringToPointer, ImplicitConversionExpr)
170170
EXPR(PointerToPointer, ImplicitConversionExpr)
171171
EXPR(ForeignObjectConversion, ImplicitConversionExpr)
172-
EXPR(UninhabitedUpcast, ImplicitConversionExpr)
173172
EXPR(UnevaluatedInstance, ImplicitConversionExpr)
174173
EXPR(UnderlyingToOpaque, ImplicitConversionExpr)
175174
EXPR_RANGE(ImplicitConversion, Load, UnderlyingToOpaque)

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,11 +2293,6 @@ class PrintExpr : public ExprVisitor<PrintExpr> {
22932293
printRec(E->getSubExpr());
22942294
PrintWithColorRAII(OS, ParenthesisColor) << ')';
22952295
}
2296-
void visitUninhabitedUpcastExpr(UninhabitedUpcastExpr *E) {
2297-
printCommon(E, "uninhabited_upcast_expr") << '\n';
2298-
printRec(E->getSubExpr());
2299-
PrintWithColorRAII(OS, ParenthesisColor) << ')';
2300-
}
23012296
void visitInjectIntoOptionalExpr(InjectIntoOptionalExpr *E) {
23022297
printCommon(E, "inject_into_optional") << '\n';
23032298
printRec(E->getSubExpr());

lib/AST/Expr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ ConcreteDeclRef Expr::getReferencedDecl() const {
351351
PASS_THROUGH_REFERENCE(BridgeFromObjC, getSubExpr);
352352
PASS_THROUGH_REFERENCE(ConditionalBridgeFromObjC, getSubExpr);
353353
PASS_THROUGH_REFERENCE(UnderlyingToOpaque, getSubExpr);
354-
PASS_THROUGH_REFERENCE(UninhabitedUpcast, getSubExpr);
355354
NO_REFERENCE(Coerce);
356355
NO_REFERENCE(ForcedCheckedCast);
357356
NO_REFERENCE(ConditionalCheckedCast);
@@ -670,7 +669,6 @@ bool Expr::canAppendPostfixExpression(bool appendingPostfixOperator) const {
670669
case ExprKind::BridgeFromObjC:
671670
case ExprKind::BridgeToObjC:
672671
case ExprKind::UnderlyingToOpaque:
673-
case ExprKind::UninhabitedUpcast:
674672
// Implicit conversion nodes have no syntax of their own; defer to the
675673
// subexpression.
676674
return cast<ImplicitConversionExpr>(this)->getSubExpr()

lib/SILGen/SILGenExpr.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ 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);
420419
RValue visitConditionalBridgeFromObjCExpr(ConditionalBridgeFromObjCExpr *E,
421420
SGFContext C);
422421
RValue visitArchetypeToSuperExpr(ArchetypeToSuperExpr *E, SGFContext C);
@@ -1406,15 +1405,6 @@ RValueEmitter::visitBridgeFromObjCExpr(BridgeFromObjCExpr *E, SGFContext C) {
14061405
return RValue(SGF, E, result);
14071406
}
14081407

1409-
RValue
1410-
RValueEmitter::visitUninhabitedUpcastExpr(UninhabitedUpcastExpr *E,
1411-
SGFContext C) {
1412-
// Emit code which force casts the expr of uninhabited type to the right type.
1413-
// TODO: Emit something more appropriate.
1414-
return emitUnconditionalCheckedCast(SGF, E, E->getSubExpr(), E->getType(),
1415-
CheckedCastKind::ValueCast, C);
1416-
}
1417-
14181408
RValue
14191409
RValueEmitter::visitBridgeToObjCExpr(BridgeToObjCExpr *E, SGFContext C) {
14201410
if (tryPeepholeBridgingConversion(SGF, Conversion::BridgeToObjC, E, C))

lib/Sema/CSApply.cpp

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

393-
Expr *coerceUninhabited(Expr *expr, Type toType,
394-
ConstraintLocatorBuilder locator);
395-
396393
/// Coerce the given value to existential type.
397394
///
398395
/// The following conversions are supported:
@@ -5257,13 +5254,6 @@ Expr *ExprRewriter::coerceSuperclass(Expr *expr, Type toType,
52575254
new (tc.Context) DerivedToBaseExpr(expr, toType));
52585255
}
52595256

5260-
Expr *ExprRewriter::coerceUninhabited(Expr *expr, Type toType,
5261-
ConstraintLocatorBuilder locator) {
5262-
auto &tc = cs.getTypeChecker();
5263-
return cs.cacheType(
5264-
new (tc.Context) UninhabitedUpcastExpr(expr, toType));
5265-
}
5266-
52675257
/// Collect the conformances for all the protocols of an existential type.
52685258
/// If the source type is also existential, we don't want to check conformance
52695259
/// because most protocols do not conform to themselves -- however we still
@@ -6325,8 +6315,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
63256315
case ConversionRestrictionKind::Superclass:
63266316
case ConversionRestrictionKind::ExistentialMetatypeToMetatype:
63276317
return coerceSuperclass(expr, toType, locator);
6328-
case ConversionRestrictionKind::UninhabitedUpcast:
6329-
return coerceUninhabited(expr, toType, locator);
63306318

63316319
case ConversionRestrictionKind::Existential:
63326320
case ConversionRestrictionKind::MetatypeToExistentialMetatype:

lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
407407
case ConstraintKind::Conversion:
408408
case ConstraintKind::ArgumentConversion:
409409
case ConstraintKind::OperatorArgumentConversion:
410-
case ConstraintKind::OptionalObject:
411-
case ConstraintKind::SingleExpressionFunctionReturnConversion: {
410+
case ConstraintKind::OptionalObject: {
412411
// If there is a `bind param` constraint associated with
413412
// current type variable, result should be aware of that
414413
// fact. Binding set might be incomplete until

lib/Sema/CSRanking.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ 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;
8380
case SK_ValueToPointerConversion:
8481
log << "value-to-pointer conversion";
8582
break;

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,6 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
10791079
case ConstraintKind::OperatorArgumentConversion:
10801080
case ConstraintKind::ArgumentConversion:
10811081
case ConstraintKind::Conversion:
1082-
case ConstraintKind::SingleExpressionFunctionReturnConversion:
10831082
subKind = ConstraintKind::Conversion;
10841083
break;
10851084

@@ -1171,7 +1170,6 @@ static bool matchFunctionRepresentations(FunctionTypeRepresentation rep1,
11711170
case ConstraintKind::ValueMember:
11721171
case ConstraintKind::FunctionInput:
11731172
case ConstraintKind::FunctionResult:
1174-
case ConstraintKind::SingleExpressionFunctionReturnConversion:
11751173
return false;
11761174
}
11771175

@@ -1318,7 +1316,6 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
13181316
case ConstraintKind::ArgumentConversion:
13191317
case ConstraintKind::OperatorArgumentConversion:
13201318
case ConstraintKind::OpaqueUnderlyingType:
1321-
case ConstraintKind::SingleExpressionFunctionReturnConversion:
13221319
subKind = ConstraintKind::Subtype;
13231320
break;
13241321

@@ -1593,18 +1590,6 @@ matchDeepTypeArguments(ConstraintSystem &cs,
15931590
return cs.getTypeMatchSuccess();
15941591
}
15951592

1596-
ConstraintSystem::TypeMatchResult
1597-
ConstraintSystem::matchUninhabitedUpcastTypes(Type type1, Type type2,
1598-
TypeMatchOptions flags,
1599-
ConstraintLocatorBuilder locator) {
1600-
if (type1->isUninhabited()) {
1601-
increaseScore(SK_UninhabitedUpcast);
1602-
return getTypeMatchSuccess();
1603-
}
1604-
1605-
return getTypeMatchFailure(locator);
1606-
}
1607-
16081593
ConstraintSystem::TypeMatchResult
16091594
ConstraintSystem::matchDeepEqualityTypes(Type type1, Type type2,
16101595
ConstraintLocatorBuilder locator) {
@@ -2241,7 +2226,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
22412226
case ConstraintKind::Conversion:
22422227
case ConstraintKind::ArgumentConversion:
22432228
case ConstraintKind::OperatorArgumentConversion:
2244-
case ConstraintKind::SingleExpressionFunctionReturnConversion:
22452229
return formUnsolvedResult();
22462230

22472231
case ConstraintKind::OpaqueUnderlyingType:
@@ -2498,12 +2482,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
24982482
}
24992483
}
25002484

2501-
if (kind == ConstraintKind::SingleExpressionFunctionReturnConversion) {
2502-
if (type1->isUninhabited()) {
2503-
conversionsOrFixes.push_back(ConversionRestrictionKind::UninhabitedUpcast);
2504-
}
2505-
}
2506-
25072485
if (kind >= ConstraintKind::Subtype) {
25082486
// Subclass-to-superclass conversion.
25092487
if (type1->mayHaveSuperclass() &&
@@ -6008,10 +5986,6 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
60085986
addContextualScore();
60095987
return matchSuperclassTypes(type1, type2, subflags, locator);
60105988

6011-
case ConversionRestrictionKind::UninhabitedUpcast:
6012-
addContextualScore();
6013-
return matchUninhabitedUpcastTypes(type1, type2, subflags, locator);
6014-
60155989
// for $< in { <, <c, <oc }:
60165990
// T $< U, U : P_i ===> T $< protocol<P_i...>
60175991
case ConversionRestrictionKind::Existential:
@@ -6513,7 +6487,6 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
65136487
case ConstraintKind::Conversion:
65146488
case ConstraintKind::ArgumentConversion:
65156489
case ConstraintKind::OperatorArgumentConversion:
6516-
case ConstraintKind::SingleExpressionFunctionReturnConversion:
65176490
return matchTypes(first, second, kind, subflags, locator);
65186491

65196492
case ConstraintKind::OpaqueUnderlyingType:
@@ -6773,8 +6746,7 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
67736746
case ConstraintKind::Conversion:
67746747
case ConstraintKind::ArgumentConversion:
67756748
case ConstraintKind::OperatorArgumentConversion:
6776-
case ConstraintKind::OpaqueUnderlyingType:
6777-
case ConstraintKind::SingleExpressionFunctionReturnConversion: {
6749+
case ConstraintKind::OpaqueUnderlyingType: {
67786750
// Relational constraints.
67796751
auto matchKind = constraint.getKind();
67806752

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,8 +1558,7 @@ void ConstraintSystem::ArgumentInfoCollector::walk(Type argType) {
15581558
case ConstraintKind::Conversion:
15591559
case ConstraintKind::BridgingConversion:
15601560
case ConstraintKind::BindParam:
1561-
case ConstraintKind::OpaqueUnderlyingType:
1562-
case ConstraintKind::SingleExpressionFunctionReturnConversion: {
1561+
case ConstraintKind::OpaqueUnderlyingType: {
15631562
auto secondTy = constraint->getSecondType();
15641563
if (secondTy->is<TypeVariableType>()) {
15651564
auto otherRep =

0 commit comments

Comments
 (0)