Skip to content

Commit 8d115b8

Browse files
committed
Revert "Allow inout arguments that differ in optionality than the expected parameter."
This partially reverts commit 8685ee0. The tests are still in place, but the code change is no longer necessary now that IUOs are removed from the type system. Fixes: rdar://problem/37013789
1 parent f088237 commit 8d115b8

File tree

5 files changed

+14
-82
lines changed

5 files changed

+14
-82
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,17 +1069,8 @@ class Verifier : public ASTWalker {
10691069
Type srcObj = checkLValue(E->getSubExpr()->getType(),
10701070
"result of InOutExpr");
10711071
auto DestTy = E->getType()->castTo<InOutType>()->getObjectType();
1072-
1073-
// HACK: Allow differences in optionality of the source and
1074-
// result types. When IUO is gone from the type system we'll no
1075-
// longer need this.
1076-
auto srcOptObjTy = srcObj->getAnyOptionalObjectType();
1077-
auto dstOptObjTy = DestTy->getAnyOptionalObjectType();
1078-
if (srcOptObjTy && dstOptObjTy) {
1079-
checkSameType(srcOptObjTy, dstOptObjTy, "object types for InOutExpr");
1080-
} else {
1081-
checkSameType(DestTy, srcObj, "object types for InOutExpr");
1082-
}
1072+
1073+
checkSameType(DestTy, srcObj, "object types for InOutExpr");
10831074
verifyCheckedBase(E);
10841075
}
10851076

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5544,38 +5544,6 @@ static unsigned computeCallLevel(ConstraintSystem &cs, ConcreteDeclRef callee,
55445544
return 0;
55455545
}
55465546

5547-
// HACK: Support calling functions with inouts of differing kinds of
5548-
// optionality so that we can warn about overloading by IUO vs. plain
5549-
// Optional and allow users to correct the issue by removing an
5550-
// overload and passing the differently-optional value to the
5551-
// remaining overload.
5552-
bool inOutOptionalityDifferenceHack(Expr *arg, Type paramType,
5553-
ConstraintSystem &cs) {
5554-
auto *inOutArgTy = cs.getType(arg)->getAs<InOutType>();
5555-
if (!inOutArgTy)
5556-
return false;
5557-
5558-
auto *inOutParamTy = paramType->getAs<InOutType>();
5559-
if (!inOutParamTy)
5560-
return false;
5561-
5562-
OptionalTypeKind argOTK;
5563-
OptionalTypeKind paramOTK;
5564-
auto argObjTy = inOutArgTy->getObjectType()->getAnyOptionalObjectType(argOTK);
5565-
auto paramObjTy =
5566-
inOutParamTy->getObjectType()->getAnyOptionalObjectType(paramOTK);
5567-
5568-
if (argOTK == paramOTK || argOTK == OTK_None || paramOTK == OTK_None)
5569-
return false;
5570-
5571-
if (!argObjTy->isEqual(paramObjTy))
5572-
return false;
5573-
5574-
// Hammer over the argument type with the expected parameter type.
5575-
cs.setType(arg, paramType);
5576-
return true;
5577-
}
5578-
55795547
Expr *ExprRewriter::coerceCallArguments(
55805548
Expr *arg, AnyFunctionType *funcType,
55815549
ApplyExpr *apply,
@@ -5806,16 +5774,11 @@ Expr *ExprRewriter::coerceCallArguments(
58065774
continue;
58075775
}
58085776

5809-
Expr *convertedArg;
5810-
if (inOutOptionalityDifferenceHack(arg, paramType, cs)) {
5811-
convertedArg = arg;
5812-
} else {
5813-
// Convert the argument.
5814-
convertedArg =
5815-
coerceToType(arg, paramType, getArgLocator(argIdx, paramIdx));
5816-
if (!convertedArg)
5817-
return nullptr;
5818-
}
5777+
// Convert the argument.
5778+
auto convertedArg = coerceToType(arg, paramType,
5779+
getArgLocator(argIdx, paramIdx));
5780+
if (!convertedArg)
5781+
return nullptr;
58195782

58205783
// Add the converted argument.
58215784
fromTupleExpr[argIdx] = convertedArg;

lib/Sema/CSRanking.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
8080
case SK_ValueToPointerConversion:
8181
log << "value-to-pointer conversion";
8282
break;
83-
case SK_InOutOptionalityConversion:
84-
log << "inout optionality conversion";
8583
}
8684
log << ")\n";
8785
}

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,32 +1863,16 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
18631863
locator.withPathElement(
18641864
ConstraintLocator::ArrayElementType));
18651865

1866-
case TypeKind::InOut: {
1866+
case TypeKind::InOut:
18671867
// If the RHS is an inout type, the LHS must be an @lvalue type.
18681868
if (kind == ConstraintKind::BindParam ||
18691869
kind >= ConstraintKind::OperatorArgumentConversion)
18701870
return getTypeMatchFailure(locator);
1871-
1872-
auto inoutObjTy1 = cast<InOutType>(desugar1)->getObjectType();
1873-
auto inoutObjTy2 = cast<InOutType>(desugar2)->getObjectType();
1874-
1875-
OptionalTypeKind OTK1;
1876-
OptionalTypeKind OTK2;
1877-
auto optionalObjTy1 = inoutObjTy1->getAnyOptionalObjectType(OTK1);
1878-
auto optionalObjTy2 = inoutObjTy2->getAnyOptionalObjectType(OTK2);
1879-
if (OTK1 != OTK2 && optionalObjTy1 && optionalObjTy2) {
1880-
increaseScore(ScoreKind::SK_InOutOptionalityConversion);
1881-
return matchTypes(inoutObjTy1,
1882-
inoutObjTy2,
1883-
ConstraintKind::ArgumentConversion, subflags,
1884-
locator.withPathElement(ConstraintLocator::ArrayElementType));
1885-
} else {
1886-
return matchTypes(inoutObjTy1,
1887-
inoutObjTy2,
1888-
ConstraintKind::Equal, subflags,
1889-
locator.withPathElement(ConstraintLocator::ArrayElementType));
1890-
}
1891-
}
1871+
1872+
return matchTypes(cast<InOutType>(desugar1)->getObjectType(),
1873+
cast<InOutType>(desugar2)->getObjectType(),
1874+
ConstraintKind::Equal, subflags,
1875+
locator.withPathElement(ConstraintLocator::ArrayElementType));
18921876

18931877
case TypeKind::UnboundGeneric:
18941878
llvm_unreachable("Unbound generic type should have been opened");

lib/Sema/ConstraintSystem.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,8 @@ enum ScoreKind {
462462
SK_KeyPathSubscript,
463463
/// A conversion from a string, array, or inout to a pointer.
464464
SK_ValueToPointerConversion,
465-
/// A conversion from 'inout Optional<T>' to 'inout
466-
/// ImplicitlyUnwrappedOptional<T>' or vice-versa.
467-
/// FIXME: This goes away when IUO-as-a-type goes away.
468-
SK_InOutOptionalityConversion,
469465

470-
SK_LastScoreKind = SK_InOutOptionalityConversion,
466+
SK_LastScoreKind = SK_ValueToPointerConversion,
471467
};
472468

473469
/// The number of score kinds.

0 commit comments

Comments
 (0)