Skip to content

Commit 65119c8

Browse files
authored
Merge pull request #16575 from apple/revert-16556-rdar-40002266
2 parents f9f2fc3 + 8e0bba1 commit 65119c8

File tree

4 files changed

+18
-41
lines changed

4 files changed

+18
-41
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,7 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
893893
/// Attempt to produce a diagnostic for a mismatch between an expression's
894894
/// type and its assumed contextual type.
895895
bool diagnoseContextualConversionError(Expr *expr, Type contextualType,
896-
ContextualTypePurpose CTP,
897-
Type suggestedType = Type());
896+
ContextualTypePurpose CTP);
898897

899898
/// For an expression being type checked with a CTP_CalleeResult contextual
900899
/// type, try to diagnose a problem.
@@ -2789,8 +2788,7 @@ static bool tryDiagnoseNonEscapingParameterToEscaping(
27892788
}
27902789

27912790
bool FailureDiagnosis::diagnoseContextualConversionError(
2792-
Expr *expr, Type contextualType, ContextualTypePurpose CTP,
2793-
Type suggestedType) {
2791+
Expr *expr, Type contextualType, ContextualTypePurpose CTP) {
27942792
// If the constraint system has a contextual type, then we can test to see if
27952793
// this is the problem that prevents us from solving the system.
27962794
if (!contextualType) {
@@ -2809,16 +2807,11 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
28092807
if (contextualType->is<InOutType>())
28102808
options |= TCC_AllowLValue;
28112809

2812-
auto *recheckedExpr = typeCheckChildIndependently(expr, options);
2810+
auto recheckedExpr = typeCheckChildIndependently(expr, options);
28132811
auto exprType = recheckedExpr ? CS.getType(recheckedExpr) : Type();
28142812

2815-
// If there is a suggested type and re-typecheck failed, let's use it.
2816-
if (!exprType)
2817-
exprType = suggestedType;
2818-
28192813
// If it failed and diagnosed something, then we're done.
2820-
if (!exprType)
2821-
return CS.TC.Diags.hadAnyError();
2814+
if (!exprType) return true;
28222815

28232816
// If we contextually had an inout type, and got a non-lvalue result, then
28242817
// we fail with a mutability error.
@@ -5281,7 +5274,7 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
52815274
}
52825275
};
52835276

5284-
SmallPtrSet<TypeBase *, 4> possibleTypes;
5277+
SmallVector<Type, 4> possibleTypes;
52855278
auto currentType = CS.getType(fnExpr);
52865279

52875280
// If current type has type variables or unresolved types
@@ -5301,10 +5294,10 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
53015294
return diagnoseContextualConversionError(callExpr, contextualType,
53025295
CS.getContextualTypePurpose());
53035296
} else {
5304-
possibleTypes.insert(currentType.getPointer());
5297+
possibleTypes.push_back(currentType);
53055298
}
53065299

5307-
for (Type type : possibleTypes) {
5300+
for (auto type : possibleTypes) {
53085301
auto *fnType = type->getAs<AnyFunctionType>();
53095302
if (!fnType)
53105303
continue;
@@ -5395,7 +5388,7 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
53955388
auto *DC = CS.DC;
53965389

53975390
auto typeCheckExpr = [](TypeChecker &TC, Expr *expr, DeclContext *DC,
5398-
SmallPtrSetImpl<TypeBase *> &types,
5391+
SmallVectorImpl<Type> &types,
53995392
Type contextualType = Type()) {
54005393
CalleeListener listener(contextualType);
54015394
TC.getPossibleTypesOfExpressionWithoutApplying(
@@ -5405,7 +5398,7 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
54055398
// First let's type-check expression without contextual type, and
54065399
// see if that's going to produce a type, if so, let's type-check
54075400
// again, this time using given contextual type.
5408-
SmallPtrSet<TypeBase *, 4> withoutContextual;
5401+
SmallVector<Type, 4> withoutContextual;
54095402
typeCheckExpr(TC, callExpr, DC, withoutContextual);
54105403

54115404
// If there are no types returned, it means that problem was
@@ -5414,17 +5407,12 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
54145407
if (withoutContextual.empty())
54155408
return false;
54165409

5417-
SmallPtrSet<TypeBase *, 4> withContextual;
5410+
SmallVector<Type, 4> withContextual;
54185411
typeCheckExpr(TC, callExpr, DC, withContextual, contextualType);
54195412
// If type-checking with contextual type didn't produce any results
54205413
// it means that we have a contextual mismatch.
5421-
if (withContextual.empty()) {
5422-
// If there is just a single choice, we can hit contextual diagnostics
5423-
// about it in case re-typecheck fails.
5424-
Type exprType = withoutContextual.size() == 1 ? *withoutContextual.begin() : Type();
5425-
return diagnoseContextualConversionError(callExpr, contextualType, CTP,
5426-
exprType);
5427-
}
5414+
if (withContextual.empty())
5415+
return diagnoseContextualConversionError(callExpr, contextualType, CTP);
54285416

54295417
// If call produces a single type when type-checked with contextual
54305418
// expression, it means that the problem is elsewhere, any other
@@ -5443,15 +5431,15 @@ static bool shouldTypeCheckFunctionExpr(TypeChecker &TC, DeclContext *DC,
54435431
if (!isa<UnresolvedDotExpr>(fnExpr))
54445432
return true;
54455433

5446-
SmallPtrSet<TypeBase *, 4> fnTypes;
5434+
SmallVector<Type, 4> fnTypes;
54475435
TC.getPossibleTypesOfExpressionWithoutApplying(fnExpr, DC, fnTypes,
54485436
FreeTypeVariableBinding::UnresolvedType);
54495437

54505438
if (fnTypes.size() == 1) {
54515439
// Some member types depend on the arguments to produce a result type,
54525440
// type-checking such expressions without associated arguments is
54535441
// going to produce unrelated diagnostics.
5454-
if (auto fn = (*fnTypes.begin())->getAs<AnyFunctionType>()) {
5442+
if (auto fn = fnTypes[0]->getAs<AnyFunctionType>()) {
54555443
auto resultType = fn->getResult();
54565444
if (resultType->hasUnresolvedType() || resultType->hasTypeVariable())
54575445
return false;
@@ -5506,7 +5494,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
55065494
isa<UnresolvedDotExpr>(callExpr->getFn())) {
55075495
fnExpr = callExpr->getFn();
55085496

5509-
SmallPtrSet<TypeBase *, 4> types;
5497+
SmallVector<Type, 4> types;
55105498
CS.TC.getPossibleTypesOfExpressionWithoutApplying(fnExpr, CS.DC, types);
55115499

55125500
auto isFunctionType = [getFuncType](Type type) -> bool {

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ getTypeOfExpressionWithoutApplying(Expr *&expr, DeclContext *dc,
19941994
}
19951995

19961996
void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
1997-
Expr *&expr, DeclContext *dc, SmallPtrSetImpl<TypeBase *> &types,
1997+
Expr *&expr, DeclContext *dc, SmallVectorImpl<Type> &types,
19981998
FreeTypeVariableBinding allowFreeTypeVariables,
19991999
ExprTypeCheckListener *listener) {
20002000
PrettyStackTraceExpr stackTrace(Context, "type-checking", expr);
@@ -2028,7 +2028,7 @@ void TypeChecker::getPossibleTypesOfExpressionWithoutApplying(
20282028
for (auto &solution : viable) {
20292029
auto exprType = solution.simplifyType(cs.getType(expr));
20302030
assert(exprType && !exprType->hasTypeVariable());
2031-
types.insert(exprType.getPointer());
2031+
types.push_back(exprType);
20322032
}
20332033
}
20342034

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1743,7 +1743,7 @@ class TypeChecker final : public LazyResolver {
17431743
ExprTypeCheckListener *listener = nullptr);
17441744

17451745
void getPossibleTypesOfExpressionWithoutApplying(
1746-
Expr *&expr, DeclContext *dc, SmallPtrSetImpl<TypeBase *> &types,
1746+
Expr *&expr, DeclContext *dc, SmallVectorImpl<Type> &types,
17471747
FreeTypeVariableBinding allowFreeTypeVariables =
17481748
FreeTypeVariableBinding::Disallow,
17491749
ExprTypeCheckListener *listener = nullptr);

test/Constraints/rdar40002266.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)