Skip to content

Commit 4b9369e

Browse files
committed
---
yaml --- r: 343927 b: refs/heads/master-rebranch c: 7c4c2fb h: refs/heads/master i: 343925: ce4e8fa 343923: 937e917 343919: 7966c5c
1 parent e8f01fe commit 4b9369e

File tree

2 files changed

+1
-200
lines changed

2 files changed

+1
-200
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 015129cb36ece9b8830f5760d2d557415ea6b86e
1458+
refs/heads/master-rebranch: 7c4c2fb56d35f320868881e3bea886fa30939142
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/lib/Sema/CSDiag.cpp

Lines changed: 0 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,6 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
468468
CalleeCandidateInfo &calleeInfo,
469469
SourceLoc applyLoc);
470470

471-
/// Produce diagnostic for failures related to unfulfilled requirements
472-
/// of the generic parameters used as arguments.
473-
bool diagnoseArgumentGenericRequirements(TypeChecker &TC, Expr *callExpr,
474-
Expr *fnExpr, Expr *argExpr,
475-
CalleeCandidateInfo &candidates,
476-
ArrayRef<Identifier> argLabels);
477-
478471
bool diagnoseMemberFailures(
479472
Expr *E, Expr *baseEpxr, ConstraintKind lookupKind, DeclName memberName,
480473
FunctionRefKind funcRefKind, ConstraintLocator *locator,
@@ -3065,185 +3058,6 @@ bool FailureDiagnosis::diagnoseNilLiteralComparison(
30653058
return true;
30663059
}
30673060

3068-
bool FailureDiagnosis::diagnoseArgumentGenericRequirements(
3069-
TypeChecker &TC, Expr *callExpr, Expr *fnExpr, Expr *argExpr,
3070-
CalleeCandidateInfo &candidates, ArrayRef<Identifier> argLabels) {
3071-
if (candidates.closeness != CC_ExactMatch || candidates.size() != 1)
3072-
return false;
3073-
3074-
AbstractFunctionDecl *AFD = nullptr;
3075-
if (auto *DRE = dyn_cast<DeclRefExpr>(fnExpr)) {
3076-
AFD = dyn_cast<AbstractFunctionDecl>(DRE->getDecl());
3077-
} else if (auto *candidate = candidates[0].getDecl()) {
3078-
AFD = dyn_cast<AbstractFunctionDecl>(candidate);
3079-
}
3080-
3081-
if (!AFD || !AFD->getGenericSignature() || !AFD->hasInterfaceType())
3082-
return false;
3083-
3084-
auto env = AFD->getGenericEnvironment();
3085-
if (!env)
3086-
return false;
3087-
3088-
auto const &candidate = candidates.candidates[0];
3089-
3090-
if (!candidate.hasParameters())
3091-
return false;
3092-
3093-
auto params = candidate.getParameters();
3094-
auto paramInfo = candidate.getParameterListInfo(params);
3095-
auto args = decomposeArgType(CS.getType(argExpr), argLabels);
3096-
3097-
SmallVector<ParamBinding, 4> bindings;
3098-
MatchCallArgumentListener listener;
3099-
if (matchCallArguments(args, params, paramInfo,
3100-
candidates.hasTrailingClosure,
3101-
/*allowFixes=*/false, listener, bindings))
3102-
return false;
3103-
3104-
TypeSubstitutionMap substitutions;
3105-
// First, let's collect all of the archetypes and their substitutions,
3106-
// that's going to help later on if there are cross-archetype
3107-
// requirements e.g. <A, B where A.Element == B.Element>.
3108-
for (unsigned i = 0, e = bindings.size(); i != e; ++i) {
3109-
auto param = params[i];
3110-
auto paramType = param.getPlainType();
3111-
3112-
auto archetype = paramType->getAs<ArchetypeType>();
3113-
if (!archetype)
3114-
continue;
3115-
3116-
// Bindings specify the arguments that source the parameter. The only case
3117-
// this returns a non-singular value is when there are varargs in play.
3118-
for (auto argNo : bindings[i]) {
3119-
auto argType = args[argNo]
3120-
.getOldType()
3121-
->getWithoutSpecifierType();
3122-
3123-
if (auto *archetype = argType->getAs<ArchetypeType>()) {
3124-
auto interfaceTy = archetype->getInterfaceType();
3125-
if (auto *paramTy = interfaceTy->getAs<GenericTypeParamType>()) {
3126-
diagnoseAmbiguousGenericParameter(paramTy, fnExpr);
3127-
return true;
3128-
}
3129-
}
3130-
3131-
if (isUnresolvedOrTypeVarType(argType) || argType->hasError())
3132-
return false;
3133-
3134-
// Record substitution from generic parameter to the argument type.
3135-
substitutions[archetype->getInterfaceType()->getCanonicalType()
3136-
->castTo<SubstitutableType>()] = argType;
3137-
}
3138-
}
3139-
3140-
if (substitutions.empty())
3141-
return false;
3142-
3143-
class RequirementsListener : public GenericRequirementsCheckListener {
3144-
ConstraintSystem &CS;
3145-
AbstractFunctionDecl *Candidate;
3146-
TypeSubstitutionFn Substitutions;
3147-
3148-
Expr *CallExpr;
3149-
Expr *FnExpr;
3150-
Expr *ArgExpr;
3151-
3152-
public:
3153-
RequirementsListener(ConstraintSystem &cs, AbstractFunctionDecl *AFD,
3154-
TypeSubstitutionFn subs,
3155-
Expr *callExpr, Expr *fnExpr, Expr *argExpr)
3156-
: CS(cs), Candidate(AFD), Substitutions(subs), CallExpr(callExpr),
3157-
FnExpr(fnExpr), ArgExpr(argExpr) {}
3158-
3159-
bool shouldCheck(RequirementKind kind, Type first, Type second) override {
3160-
// This means that we have encountered requirement which references
3161-
// generic parameter not used in the arguments, we can't diagnose it here.
3162-
return !(first->hasTypeParameter() || first->isTypeVariableOrMember());
3163-
}
3164-
3165-
bool diagnoseUnsatisfiedRequirement(
3166-
const Requirement &req, Type first, Type second,
3167-
ArrayRef<ParentConditionalConformance> parents) override {
3168-
Diag<Type, Type, Type, Type, StringRef> note;
3169-
switch (req.getKind()) {
3170-
case RequirementKind::Conformance:
3171-
case RequirementKind::Layout:
3172-
return false;
3173-
3174-
case RequirementKind::Superclass:
3175-
note = diag::candidate_types_inheritance_requirement;
3176-
break;
3177-
3178-
case RequirementKind::SameType:
3179-
note = diag::candidate_types_equal_requirement;
3180-
break;
3181-
}
3182-
3183-
TypeChecker &TC = CS.TC;
3184-
SmallVector<char, 8> scratch;
3185-
auto overloadName = Candidate->getFullName().getString(scratch);
3186-
3187-
if (isa<BinaryExpr>(CallExpr) && isa<TupleExpr>(ArgExpr)) {
3188-
auto argTuple = cast<TupleExpr>(ArgExpr);
3189-
auto lhsExpr = argTuple->getElement(0),
3190-
rhsExpr = argTuple->getElement(1);
3191-
auto lhsType = CS.getType(lhsExpr)->getRValueType();
3192-
auto rhsType = CS.getType(rhsExpr)->getRValueType();
3193-
3194-
TC.diagnose(FnExpr->getLoc(), diag::cannot_apply_binop_to_args,
3195-
overloadName, lhsType, rhsType)
3196-
.highlight(lhsExpr->getSourceRange())
3197-
.highlight(rhsExpr->getSourceRange());
3198-
} else if (isa<PrefixUnaryExpr>(CallExpr) ||
3199-
isa<PostfixUnaryExpr>(CallExpr)) {
3200-
TC.diagnose(ArgExpr->getLoc(), diag::cannot_apply_unop_to_arg,
3201-
overloadName, CS.getType(ArgExpr));
3202-
} else {
3203-
bool isInitializer = isa<ConstructorDecl>(Candidate);
3204-
3205-
SmallVector<AnyFunctionType::Param, 8> Params;
3206-
AnyFunctionType::decomposeInput(CS.getType(ArgExpr), Params);
3207-
TC.diagnose(ArgExpr->getLoc(), diag::cannot_call_with_params,
3208-
overloadName, AnyFunctionType::getParamListAsString(Params),
3209-
isInitializer);
3210-
}
3211-
3212-
auto rawFirstType = req.getFirstType();
3213-
auto rawSecondType = req.getSecondType();
3214-
auto *genericSig = Candidate->getGenericSignature();
3215-
3216-
TC.diagnose(Candidate, note, first, second,
3217-
rawFirstType, rawSecondType,
3218-
TypeChecker::gatherGenericParamBindingsText(
3219-
{rawFirstType, rawSecondType},
3220-
genericSig->getGenericParams(),
3221-
Substitutions));
3222-
3223-
ParentConditionalConformance::diagnoseConformanceStack(
3224-
TC.Diags, Candidate->getLoc(), parents);
3225-
3226-
return true;
3227-
}
3228-
};
3229-
3230-
auto substitutionFn = QueryTypeSubstitutionMap{substitutions};
3231-
RequirementsListener genericReqListener(CS, AFD, substitutionFn,
3232-
callExpr, fnExpr, argExpr);
3233-
3234-
auto result = TC.checkGenericArguments(
3235-
AFD, callExpr->getLoc(), fnExpr->getLoc(), AFD->getInterfaceType(),
3236-
env->getGenericSignature()->getGenericParams(),
3237-
env->getGenericSignature()->getRequirements(),
3238-
substitutionFn,
3239-
LookUpConformanceInModule{AFD->getParentModule()},
3240-
ConformanceCheckFlags::SuppressDependencyTracking, &genericReqListener);
3241-
3242-
// Note: If result is RequirementCheckResult::SubstitutionFailure, we did
3243-
// not emit a diagnostic, so we must return false in that case.
3244-
return result == RequirementCheckResult::Failure;
3245-
}
3246-
32473061
static bool diagnoseClosureExplicitParameterMismatch(
32483062
ConstraintSystem &CS, SourceLoc loc,
32493063
ArrayRef<AnyFunctionType::Param> params,
@@ -3980,10 +3794,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
39803794
}
39813795
}
39823796

3983-
if (diagnoseArgumentGenericRequirements(CS.TC, callExpr, fnExpr, argExpr,
3984-
calleeInfo, argLabels))
3985-
return true;
3986-
39873797
if (isContextualConversionFailure(argTuple))
39883798
return false;
39893799

@@ -4053,15 +3863,6 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
40533863
return true;
40543864
}
40553865

4056-
// If all of the arguments are a perfect match, let's check if there
4057-
// are problems with requirements placed on generic parameters, because
4058-
// CalleeCandidateInfo validates only conformance of the parameters
4059-
// to their protocol types (if any) but it doesn't check additional
4060-
// requirements placed on e.g. nested types or between parameters.
4061-
if (diagnoseArgumentGenericRequirements(CS.TC, callExpr, fnExpr, argExpr,
4062-
calleeInfo, argLabels))
4063-
return true;
4064-
40653866
// If we have a failure where closeness is an exact match, but there is
40663867
// still a failed argument, it is because one (or more) of the arguments
40673868
// types are unresolved.

0 commit comments

Comments
 (0)