[ConstraintSystem] NFC: Remove workarounds related to (now deprecated) CSDiag

This commit is contained in:
Pavel Yaskevich
2020-02-18 10:13:09 -08:00
parent b905113f5c
commit 2dccdbfabf
5 changed files with 28 additions and 67 deletions

View File

@@ -2285,16 +2285,8 @@ namespace {
auto locator = cs.getConstraintLocator(expr); auto locator = cs.getConstraintLocator(expr);
// Find the overload choice used for this declaration reference. // Find the overload choice used for this declaration reference.
auto selected = solution.getOverloadChoiceIfAvailable(locator); auto selected = solution.getOverloadChoice(locator);
if (!selected.hasValue()) { return buildDeclRef(selected, expr->getNameLoc(), locator,
auto *varDecl = cast<VarDecl>(expr->getDecl());
assert(varDecl->getType()->is<UnresolvedType>() &&
"should only happen for closure arguments in CSDiags");
cs.setType(expr, varDecl->getType());
return expr;
}
return buildDeclRef(*selected, expr->getNameLoc(), locator,
expr->isImplicit(), expr->getAccessSemantics()); expr->isImplicit(), expr->getAccessSemantics());
} }
@@ -3868,19 +3860,7 @@ namespace {
Expr *visitEditorPlaceholderExpr(EditorPlaceholderExpr *E) { Expr *visitEditorPlaceholderExpr(EditorPlaceholderExpr *E) {
simplifyExprType(E); simplifyExprType(E);
auto valueType = cs.getType(E); auto valueType = cs.getType(E);
assert(!valueType->hasUnresolvedType());
// TODO(diagnostics): Once all of the diagnostics are moved to
// new diagnostics framework this check could be eliminated.
//
// Only way for this to happen is CSDiag try to re-typecheck
// sub-expression which contains this placeholder with
// `AllowUnresolvedTypeVariables` flag set.
//
// A better solution could be to replace placeholders with this
// implicit call early on and type-check that call together with
// the rest of the constraint system.
if (valueType->hasUnresolvedType())
return nullptr;
auto &ctx = cs.getASTContext(); auto &ctx = cs.getASTContext();
// Synthesize a call to _undefined() of appropriate type. // Synthesize a call to _undefined() of appropriate type.

View File

@@ -575,8 +575,6 @@ Optional<Diag<Type, Type>> GenericArgumentsMismatchFailure::getDiagnosticFor(
return diag::cannot_convert_closure_result; return diag::cannot_convert_closure_result;
case CTP_ArrayElement: case CTP_ArrayElement:
return diag::cannot_convert_array_element; return diag::cannot_convert_array_element;
// TODO(diagnostics): Make dictionary related diagnostics take prescedence
// over CSDiag. Currently these won't ever be produced.
case CTP_DictionaryKey: case CTP_DictionaryKey:
return diag::cannot_convert_dict_key; return diag::cannot_convert_dict_key;
case CTP_DictionaryValue: case CTP_DictionaryValue:
@@ -5051,9 +5049,7 @@ void MissingGenericArgumentsFailure::emitGenericSignatureNote(
continue; continue;
auto type = resolveType(typeVar); auto type = resolveType(typeVar);
// This could happen if the diagnostic is used by CSDiag. assert(!type->is<TypeVariableType>());
if (type->is<TypeVariableType>())
continue;
// If this is one of the defaulted parameter types, attempt // If this is one of the defaulted parameter types, attempt
// to emit placeholder for it instead of `Any`. // to emit placeholder for it instead of `Any`.

View File

@@ -1689,17 +1689,13 @@ public:
/// func bar(_ v: Int) { foo(v) } // `Int` is not convertible to `String` /// func bar(_ v: Int) { foo(v) } // `Int` is not convertible to `String`
/// ``` /// ```
class ArgumentMismatchFailure : public ContextualFailure { class ArgumentMismatchFailure : public ContextualFailure {
// FIXME: Currently ArgumentMismatchFailure can be used from CSDiag, in which FunctionArgApplyInfo Info;
// case it's possible we're not able to resolve the arg apply info. Once
// the CSDiag logic has been removed, we should be able to store Info
// unwrapped.
Optional<FunctionArgApplyInfo> Info;
public: public:
ArgumentMismatchFailure(ConstraintSystem &cs, Type argType, ArgumentMismatchFailure(ConstraintSystem &cs, Type argType, Type paramType,
Type paramType, ConstraintLocator *locator) ConstraintLocator *locator)
: ContextualFailure(cs, argType, paramType, locator), : ContextualFailure(cs, argType, paramType, locator),
Info(cs.getFunctionArgApplyInfo(getLocator())) {} Info(*cs.getFunctionArgApplyInfo(getLocator())) {}
bool diagnoseAsError() override; bool diagnoseAsError() override;
bool diagnoseAsNote() override; bool diagnoseAsNote() override;
@@ -1722,10 +1718,10 @@ public:
protected: protected:
/// \returns The position of the argument being diagnosed, starting at 1. /// \returns The position of the argument being diagnosed, starting at 1.
unsigned getArgPosition() const { return Info->getArgPosition(); } unsigned getArgPosition() const { return Info.getArgPosition(); }
/// \returns The position of the parameter being diagnosed, starting at 1. /// \returns The position of the parameter being diagnosed, starting at 1.
unsigned getParamPosition() const { return Info->getParamPosition(); } unsigned getParamPosition() const { return Info.getParamPosition(); }
/// Returns the argument expression being diagnosed. /// Returns the argument expression being diagnosed.
/// ///
@@ -1735,7 +1731,7 @@ protected:
/// the conversion from T to U may fail. In this case, \c getArgExpr() will /// the conversion from T to U may fail. In this case, \c getArgExpr() will
/// return the (T, U) expression, whereas \c getAnchor() will return the T /// return the (T, U) expression, whereas \c getAnchor() will return the T
/// expression. /// expression.
Expr *getArgExpr() const { return Info->getArgExpr(); } Expr *getArgExpr() const { return Info.getArgExpr(); }
/// Returns the argument type for the conversion being diagnosed. /// Returns the argument type for the conversion being diagnosed.
/// ///
@@ -1748,27 +1744,25 @@ protected:
/// In this case, \c getArgType() will return T?, whereas \c getFromType() /// In this case, \c getArgType() will return T?, whereas \c getFromType()
/// will return T. /// will return T.
Type getArgType(bool withSpecifier = false) const { Type getArgType(bool withSpecifier = false) const {
return Info->getArgType(withSpecifier); return Info.getArgType(withSpecifier);
} }
/// \returns A textual description of the argument suitable for diagnostics. /// \returns A textual description of the argument suitable for diagnostics.
/// For an argument with an unambiguous label, this will the label. Otherwise /// For an argument with an unambiguous label, this will the label. Otherwise
/// it will be its position in the argument list. /// it will be its position in the argument list.
StringRef getArgDescription(SmallVectorImpl<char> &scratch) const { StringRef getArgDescription(SmallVectorImpl<char> &scratch) const {
return Info->getArgDescription(scratch); return Info.getArgDescription(scratch);
} }
/// \returns The interface type for the function being applied. /// \returns The interface type for the function being applied.
Type getFnInterfaceType() const { return Info->getFnInterfaceType(); } Type getFnInterfaceType() const { return Info.getFnInterfaceType(); }
/// \returns The function type being applied, including any generic /// \returns The function type being applied, including any generic
/// substitutions. /// substitutions.
FunctionType *getFnType() const { return Info->getFnType(); } FunctionType *getFnType() const { return Info.getFnType(); }
/// \returns The callee for the argument conversion, if any. /// \returns The callee for the argument conversion, if any.
const ValueDecl *getCallee() const { const ValueDecl *getCallee() const { return Info.getCallee(); }
return Info ? Info->getCallee() : nullptr;
}
/// \returns The full name of the callee, or a null decl name if there is no /// \returns The full name of the callee, or a null decl name if there is no
/// callee. /// callee.
@@ -1784,7 +1778,7 @@ protected:
/// ///
/// Note this may differ from \c getToType(), see the note on \c getArgType(). /// Note this may differ from \c getToType(), see the note on \c getArgType().
Type getParamType(bool lookThroughAutoclosure = true) const { Type getParamType(bool lookThroughAutoclosure = true) const {
return Info->getParamType(lookThroughAutoclosure); return Info.getParamType(lookThroughAutoclosure);
} }
/// Returns the type of the parameter involved in the mismatch. /// Returns the type of the parameter involved in the mismatch.
@@ -1794,17 +1788,17 @@ protected:
/// ///
/// Note this may differ from \c getToType(), see the note on \c getArgType(). /// Note this may differ from \c getToType(), see the note on \c getArgType().
Type getParamInterfaceType(bool lookThroughAutoclosure = true) const { Type getParamInterfaceType(bool lookThroughAutoclosure = true) const {
return Info->getParamInterfaceType(lookThroughAutoclosure); return Info.getParamInterfaceType(lookThroughAutoclosure);
} }
/// \returns The flags of the parameter involved in the mismatch. /// \returns The flags of the parameter involved in the mismatch.
ParameterTypeFlags getParameterFlags() const { ParameterTypeFlags getParameterFlags() const {
return Info->getParameterFlags(); return Info.getParameterFlags();
} }
/// \returns The flags of a parameter at a given index. /// \returns The flags of a parameter at a given index.
ParameterTypeFlags getParameterFlagsAtIndex(unsigned idx) const { ParameterTypeFlags getParameterFlagsAtIndex(unsigned idx) const {
return Info->getParameterFlagsAtIndex(idx); return Info.getParameterFlagsAtIndex(idx);
} }
/// Situations like this: /// Situations like this:

View File

@@ -1351,17 +1351,7 @@ namespace {
knownType = VD->getInterfaceType(); knownType = VD->getInterfaceType();
if (knownType) { if (knownType) {
// If this is a ParamDecl for a closure argument that is a hole, assert(!knownType->isHole());
// then this is a situation where CSDiags is trying to perform
// error recovery within a ClosureExpr. Just create a new type
// variable for the decl that isn't bound to anything.
// This will ensure that it is considered ambiguous.
if (knownType && knownType->isHole()) {
return CS.createTypeVariable(locator,
TVO_CanBindToLValue |
TVO_CanBindToNoEscape);
}
// If the known type has an error, bail out. // If the known type has an error, bail out.
if (knownType->hasError()) { if (knownType->hasError()) {
if (!CS.hasType(E)) if (!CS.hasType(E))

View File

@@ -453,6 +453,10 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
} }
} }
if (locator->findLast<LocatorPathElt::DynamicCallable>()) {
return getConstraintLocator(anchor, LocatorPathElt::ApplyFunction());
}
// If we have a locator that starts with a key path component element, we // If we have a locator that starts with a key path component element, we
// may have a callee given by a property or subscript component. // may have a callee given by a property or subscript component.
if (auto componentElt = if (auto componentElt =
@@ -491,13 +495,10 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
return getConstraintLocator(anchor, ConstraintLocator::SubscriptMember); return getConstraintLocator(anchor, ConstraintLocator::SubscriptMember);
auto getSpecialFnCalleeLoc = [&](Type fnTy) -> ConstraintLocator * { auto getSpecialFnCalleeLoc = [&](Type fnTy) -> ConstraintLocator * {
// FIXME: We should probably assert that we don't get a type variable
// here to make sure we only retrieve callee locators for resolved calls,
// ensuring that callee locators don't change after binding a type.
// Unfortunately CSDiag currently calls into getCalleeLocator, so all bets
// are off. Once we remove that legacy diagnostic logic, we should be able
// to assert here.
fnTy = simplifyType(fnTy); fnTy = simplifyType(fnTy);
// It's okay for function type to contain type variable(s) e.g.
// opened generic function types, but not to be one.
assert(!fnTy->is<TypeVariableType>());
// For an apply of a metatype, we have a short-form constructor. Unlike // For an apply of a metatype, we have a short-form constructor. Unlike
// other locators to callees, these are anchored on the apply expression // other locators to callees, these are anchored on the apply expression