Skip to content

[Constraint solver] Revert the "common type" optimization. #23077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,49 +131,25 @@ bool constraints::areConservativelyCompatibleArgumentLabels(
hasCurriedSelf = false;
} else if (baseType->is<AnyMetatypeType>() && decl->isInstanceMember()) {
hasCurriedSelf = false;
} else if (isa<EnumElementDecl>(decl)) {
hasCurriedSelf = false;
} else {
hasCurriedSelf = true;
}

return areConservativelyCompatibleArgumentLabels(
decl, hasCurriedSelf, labels, hasTrailingClosure);
}

Expr *constraints::getArgumentLabelTargetExpr(Expr *fn) {
// Dig out the function, looking through, parentheses, ?, and !.
do {
fn = fn->getSemanticsProvidingExpr();

if (auto force = dyn_cast<ForceValueExpr>(fn)) {
fn = force->getSubExpr();
continue;
}

if (auto bind = dyn_cast<BindOptionalExpr>(fn)) {
fn = bind->getSubExpr();
continue;
}

return fn;
} while (true);
}

bool constraints::
areConservativelyCompatibleArgumentLabels(ValueDecl *decl,
bool hasCurriedSelf,
ArrayRef<Identifier> labels,
bool hasTrailingClosure) {
const AnyFunctionType *fTy;

if (auto fn = dyn_cast<AbstractFunctionDecl>(decl)) {
fTy = fn->getInterfaceType()->castTo<AnyFunctionType>();
} else if (auto subscript = dyn_cast<SubscriptDecl>(decl)) {
assert(!hasCurriedSelf && "Subscripts never have curried 'self'");
fTy = subscript->getInterfaceType()->castTo<AnyFunctionType>();
} else if (auto enumElement = dyn_cast<EnumElementDecl>(decl)) {
fTy = enumElement->getInterfaceType()->castTo<AnyFunctionType>();
} else {
return true;
}

SmallVector<AnyFunctionType::Param, 8> argInfos;
for (auto argLabel : labels) {
argInfos.push_back(AnyFunctionType::Param(Type(), argLabel, {}));
Expand All @@ -184,7 +160,7 @@ areConservativelyCompatibleArgumentLabels(ValueDecl *decl,
levelTy = levelTy->getResult()->getAs<AnyFunctionType>();
assert(levelTy && "Parameter list curry level does not match type");
}

auto params = levelTy->getParams();
SmallBitVector defaultMap =
computeDefaultMap(params, decl, hasCurriedSelf);
Expand All @@ -198,6 +174,25 @@ areConservativelyCompatibleArgumentLabels(ValueDecl *decl,
listener, unusedParamBindings);
}

Expr *constraints::getArgumentLabelTargetExpr(Expr *fn) {
// Dig out the function, looking through, parentheses, ?, and !.
do {
fn = fn->getSemanticsProvidingExpr();

if (auto force = dyn_cast<ForceValueExpr>(fn)) {
fn = force->getSubExpr();
continue;
}

if (auto bind = dyn_cast<BindOptionalExpr>(fn)) {
fn = bind->getSubExpr();
continue;
}

return fn;
} while (true);
}

/// Determine the default type-matching options to use when decomposing a
/// constraint into smaller constraints.
static ConstraintSystem::TypeMatchOptions getDefaultDecompositionOptions(
Expand Down
Loading