mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[ConstraintSystem] NFC: Remove workarounds related to (now deprecated) CSDiag
This commit is contained in:
@@ -2285,16 +2285,8 @@ namespace {
|
||||
auto locator = cs.getConstraintLocator(expr);
|
||||
|
||||
// Find the overload choice used for this declaration reference.
|
||||
auto selected = solution.getOverloadChoiceIfAvailable(locator);
|
||||
if (!selected.hasValue()) {
|
||||
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,
|
||||
auto selected = solution.getOverloadChoice(locator);
|
||||
return buildDeclRef(selected, expr->getNameLoc(), locator,
|
||||
expr->isImplicit(), expr->getAccessSemantics());
|
||||
}
|
||||
|
||||
@@ -3868,19 +3860,7 @@ namespace {
|
||||
Expr *visitEditorPlaceholderExpr(EditorPlaceholderExpr *E) {
|
||||
simplifyExprType(E);
|
||||
auto valueType = cs.getType(E);
|
||||
|
||||
// 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;
|
||||
assert(!valueType->hasUnresolvedType());
|
||||
|
||||
auto &ctx = cs.getASTContext();
|
||||
// Synthesize a call to _undefined() of appropriate type.
|
||||
|
||||
@@ -575,8 +575,6 @@ Optional<Diag<Type, Type>> GenericArgumentsMismatchFailure::getDiagnosticFor(
|
||||
return diag::cannot_convert_closure_result;
|
||||
case CTP_ArrayElement:
|
||||
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:
|
||||
return diag::cannot_convert_dict_key;
|
||||
case CTP_DictionaryValue:
|
||||
@@ -5051,9 +5049,7 @@ void MissingGenericArgumentsFailure::emitGenericSignatureNote(
|
||||
continue;
|
||||
|
||||
auto type = resolveType(typeVar);
|
||||
// This could happen if the diagnostic is used by CSDiag.
|
||||
if (type->is<TypeVariableType>())
|
||||
continue;
|
||||
assert(!type->is<TypeVariableType>());
|
||||
|
||||
// If this is one of the defaulted parameter types, attempt
|
||||
// to emit placeholder for it instead of `Any`.
|
||||
|
||||
@@ -1689,17 +1689,13 @@ public:
|
||||
/// func bar(_ v: Int) { foo(v) } // `Int` is not convertible to `String`
|
||||
/// ```
|
||||
class ArgumentMismatchFailure : public ContextualFailure {
|
||||
// FIXME: Currently ArgumentMismatchFailure can be used from CSDiag, in which
|
||||
// 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;
|
||||
FunctionArgApplyInfo Info;
|
||||
|
||||
public:
|
||||
ArgumentMismatchFailure(ConstraintSystem &cs, Type argType,
|
||||
Type paramType, ConstraintLocator *locator)
|
||||
ArgumentMismatchFailure(ConstraintSystem &cs, Type argType, Type paramType,
|
||||
ConstraintLocator *locator)
|
||||
: ContextualFailure(cs, argType, paramType, locator),
|
||||
Info(cs.getFunctionArgApplyInfo(getLocator())) {}
|
||||
Info(*cs.getFunctionArgApplyInfo(getLocator())) {}
|
||||
|
||||
bool diagnoseAsError() override;
|
||||
bool diagnoseAsNote() override;
|
||||
@@ -1722,10 +1718,10 @@ public:
|
||||
|
||||
protected:
|
||||
/// \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.
|
||||
unsigned getParamPosition() const { return Info->getParamPosition(); }
|
||||
unsigned getParamPosition() const { return Info.getParamPosition(); }
|
||||
|
||||
/// 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
|
||||
/// return the (T, U) expression, whereas \c getAnchor() will return the T
|
||||
/// expression.
|
||||
Expr *getArgExpr() const { return Info->getArgExpr(); }
|
||||
Expr *getArgExpr() const { return Info.getArgExpr(); }
|
||||
|
||||
/// 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()
|
||||
/// will return T.
|
||||
Type getArgType(bool withSpecifier = false) const {
|
||||
return Info->getArgType(withSpecifier);
|
||||
return Info.getArgType(withSpecifier);
|
||||
}
|
||||
|
||||
/// \returns A textual description of the argument suitable for diagnostics.
|
||||
/// For an argument with an unambiguous label, this will the label. Otherwise
|
||||
/// it will be its position in the argument list.
|
||||
StringRef getArgDescription(SmallVectorImpl<char> &scratch) const {
|
||||
return Info->getArgDescription(scratch);
|
||||
return Info.getArgDescription(scratch);
|
||||
}
|
||||
|
||||
/// \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
|
||||
/// substitutions.
|
||||
FunctionType *getFnType() const { return Info->getFnType(); }
|
||||
FunctionType *getFnType() const { return Info.getFnType(); }
|
||||
|
||||
/// \returns The callee for the argument conversion, if any.
|
||||
const ValueDecl *getCallee() const {
|
||||
return Info ? Info->getCallee() : nullptr;
|
||||
}
|
||||
const ValueDecl *getCallee() const { return Info.getCallee(); }
|
||||
|
||||
/// \returns The full name of the callee, or a null decl name if there is no
|
||||
/// callee.
|
||||
@@ -1784,7 +1778,7 @@ protected:
|
||||
///
|
||||
/// Note this may differ from \c getToType(), see the note on \c getArgType().
|
||||
Type getParamType(bool lookThroughAutoclosure = true) const {
|
||||
return Info->getParamType(lookThroughAutoclosure);
|
||||
return Info.getParamType(lookThroughAutoclosure);
|
||||
}
|
||||
|
||||
/// 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().
|
||||
Type getParamInterfaceType(bool lookThroughAutoclosure = true) const {
|
||||
return Info->getParamInterfaceType(lookThroughAutoclosure);
|
||||
return Info.getParamInterfaceType(lookThroughAutoclosure);
|
||||
}
|
||||
|
||||
/// \returns The flags of the parameter involved in the mismatch.
|
||||
ParameterTypeFlags getParameterFlags() const {
|
||||
return Info->getParameterFlags();
|
||||
return Info.getParameterFlags();
|
||||
}
|
||||
|
||||
/// \returns The flags of a parameter at a given index.
|
||||
ParameterTypeFlags getParameterFlagsAtIndex(unsigned idx) const {
|
||||
return Info->getParameterFlagsAtIndex(idx);
|
||||
return Info.getParameterFlagsAtIndex(idx);
|
||||
}
|
||||
|
||||
/// Situations like this:
|
||||
|
||||
@@ -1351,17 +1351,7 @@ namespace {
|
||||
knownType = VD->getInterfaceType();
|
||||
|
||||
if (knownType) {
|
||||
// If this is a ParamDecl for a closure argument that is a hole,
|
||||
// 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);
|
||||
}
|
||||
|
||||
assert(!knownType->isHole());
|
||||
// If the known type has an error, bail out.
|
||||
if (knownType->hasError()) {
|
||||
if (!CS.hasType(E))
|
||||
|
||||
@@ -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
|
||||
// may have a callee given by a property or subscript component.
|
||||
if (auto componentElt =
|
||||
@@ -491,13 +495,10 @@ ConstraintLocator *ConstraintSystem::getCalleeLocator(
|
||||
return getConstraintLocator(anchor, ConstraintLocator::SubscriptMember);
|
||||
|
||||
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);
|
||||
// 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
|
||||
// other locators to callees, these are anchored on the apply expression
|
||||
|
||||
Reference in New Issue
Block a user