Skip to content

Commit

Permalink
Merge pull request swiftlang#11760 from CodaFi/inout-knockout
Browse files Browse the repository at this point in the history
[NFC] Scale back more uses of InOutType
  • Loading branch information
CodaFi authored Sep 7, 2017
2 parents df29438 + abce63a commit 87c5f19
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
31 changes: 16 additions & 15 deletions lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,9 +1433,10 @@ CalleeCandidateInfo::evaluateCloseness(UncurriedCandidate candidate,

// Check to see if the first argument expects an inout argument, but is not
// an lvalue.
Type firstArg = actualArgs[0].getType();
if (candArgs[0].getType()->is<InOutType>() && !(firstArg->hasLValueType() || firstArg->is<InOutType>()))
if (candArgs[0].isInOut() &&
!(actualArgs[0].getType()->hasLValueType() || actualArgs[0].isInOut())) {
return { CC_NonLValueInOut, {}};
}

// If we have exactly one argument mismatching, classify it specially, so that
// close matches are prioritized against obviously wrong ones.
Expand Down Expand Up @@ -4620,11 +4621,11 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
const auto &param = params[paramIdx];

// Determine the parameter type.
auto currentParamType = param.getType();
if (currentParamType->is<InOutType>())
if (param.isInOut())
options |= TCC_AllowLValue;

// Look at each of the arguments assigned to this parameter.
auto currentParamType = param.getType();
for (auto inArgNo : paramBindings[paramIdx]) {
// Determine the argument type.
auto currentArgType = TE->getElement(inArgNo);
Expand All @@ -4641,7 +4642,7 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,
// something of inout type, diagnose it.
if (auto IOE =
dyn_cast<InOutExpr>(exprResult->getSemanticsProvidingExpr())) {
if (!currentParamType->is<InOutType>()) {
if (!param.isInOut()) {
diagnose(exprResult->getLoc(), diag::extra_address_of,
CS.getType(exprResult)->getInOutObjectType())
.highlight(exprResult->getSourceRange())
Expand Down Expand Up @@ -4676,7 +4677,7 @@ typeCheckArgumentChildIndependently(Expr *argExpr, Type argType,

for (unsigned i = 0, e = TE->getNumElements(); i != e; i++) {
if (exampleInputTuple && i < exampleInputTuple->getNumElements() &&
exampleInputTuple->getElementType(i)->is<InOutType>())
exampleInputTuple->getElement(i).isInOut())
options |= TCC_AllowLValue;

auto elExpr = typeCheckChildIndependently(TE->getElement(i), options);
Expand Down Expand Up @@ -5218,9 +5219,9 @@ class ArgumentMatcher : public MatchCallArgumentListener {
insertText << name.str() << ": ";
Type Ty = param.getType();
// Explode inout type.
if (auto IOT = param.getType()->getAs<InOutType>()) {
if (param.isInOut()) {
insertText << "&";
Ty = IOT->getObjectType();
Ty = param.getType()->getInOutObjectType();
}
// @autoclosure; the type should be the result type.
if (auto FT = param.getType()->getAs<AnyFunctionType>())
Expand Down Expand Up @@ -7537,10 +7538,10 @@ bool FailureDiagnosis::diagnoseClosureExpr(
// If this is unresolved 'inout' parameter, it's better to drop
// 'inout' from type because that might help to diagnose actual problem
// e.g. type inference doesn't give us much information anyway.
if (paramType->is<InOutType>() && paramType->hasUnresolvedType()) {
if (param->isInOut() && paramType->hasUnresolvedType()) {
assert(!param->isLet() || !paramType->is<InOutType>());
param->setType(CS.getASTContext().TheUnresolvedType);
param->setInterfaceType(param->getType()->getInOutObjectType());
param->setInterfaceType(paramType->getInOutObjectType());
param->setSpecifier(swift::VarDecl::Specifier::Owned);
}
}
Expand All @@ -7556,7 +7557,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
for (auto VD : *CE->getParameters()) {
if (VD->getType()->hasTypeVariable() || VD->getType()->hasError()) {
VD->setType(CS.getASTContext().TheUnresolvedType);
VD->setInterfaceType(VD->getType());
VD->setInterfaceType(VD->getType()->getInOutObjectType());
}
}
}
Expand Down Expand Up @@ -8796,12 +8797,12 @@ bool FailureDiagnosis::visitTupleExpr(TupleExpr *TE) {

// Otherwise, it must match the corresponding expected argument type.
unsigned inArgNo = sources[i];
auto actualType = contextualTT->getElementType(i);


TCCOptions options;
if (actualType->is<InOutType>())
if (contextualTT->getElement(i).isInOut())
options |= TCC_AllowLValue;

auto actualType = contextualTT->getElementType(i);
auto exprResult =
typeCheckChildIndependently(TE->getElement(inArgNo), actualType,
CS.getContextualTypePurpose(), options);
Expand All @@ -8812,7 +8813,7 @@ bool FailureDiagnosis::visitTupleExpr(TupleExpr *TE) {
// something of inout type, diagnose it.
if (auto IOE =
dyn_cast<InOutExpr>(exprResult->getSemanticsProvidingExpr())) {
if (!actualType->is<InOutType>()) {
if (!contextualTT->getElement(i).isInOut()) {
diagnose(exprResult->getLoc(), diag::extra_address_of,
CS.getType(exprResult)->getInOutObjectType())
.highlight(exprResult->getSourceRange())
Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/CSSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,8 @@ enumerateDirectSupertypes(TypeChecker &tc, Type type) {
result.push_back(superclass);
}

if (auto lvalue = type->getAs<LValueType>())
result.push_back(lvalue->getObjectType());
if (auto iot = type->getAs<InOutType>())
result.push_back(iot->getObjectType());
if (!type->isMaterializable())
result.push_back(type->getWithoutSpecifierType());

// FIXME: lots of other cases to consider!
return result;
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,7 @@ void VarDeclUsageChecker::
markBaseOfAbstractStorageDeclStore(Expr *base, ConcreteDeclRef decl) {
// If the base is a class or an rvalue, then this store just loads the base.
if (base->getType()->isAnyClassReferenceType() ||
!(base->getType()->hasLValueType() || base->getType()->is<InOutType>())) {
!(base->getType()->hasLValueType() || base->isSemanticallyInOutExpr())) {
base->walk(*this);
return;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/Sema/TypeCheckCaptures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ class FindCapturedVars : public ASTWalker {
if (!validateForwardCapture(DRE->getDecl()))
return { false, DRE };

bool isInOut = (isa<ParamDecl>(D) &&
cast<ParamDecl>(D)->hasType() &&
cast<ParamDecl>(D)->getType()->is<InOutType>());
bool isInOut = (isa<ParamDecl>(D) && cast<ParamDecl>(D)->isInOut());
bool isNested = false;
if (auto f = AFR.getAbstractFunctionDecl())
isNested = f->getDeclContext()->isLocalContext();
Expand Down

0 comments on commit 87c5f19

Please sign in to comment.