Skip to content

Commit 6552361

Browse files
committed
Remove 4 constraint solver fixits that were not pulling their weight anymore:
- 3 related to OptionSet migration for Swift 1 -> Swift 2. - 1 related to calling a non-function type, which is now handled by CSDiags.
1 parent 45eb277 commit 6552361

File tree

11 files changed

+9
-296
lines changed

11 files changed

+9
-296
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,6 @@ ERROR(extra_address_of_unsafepointer,none,
672672
ERROR(missing_init_on_metatype_initialization,none,
673673
"initializing from a metatype value must reference 'init' explicitly",
674674
())
675-
ERROR(extra_call_nonfunction,none,
676-
"invalid use of '()' to call a value of non-function type %0",
677-
(Type))
678675
ERROR(extra_argument_labels,none,
679676
"extraneous argument label%select{|s}0 '%1' in %select{call|subscript}2",
680677
(bool, StringRef, bool))
@@ -1802,16 +1799,6 @@ ERROR(optional_used_as_true_boolean,none,
18021799
"optional type %0 cannot be used as a boolean; "
18031800
"test for '== nil' instead", (Type))
18041801

1805-
ERROR(migrate_from_raw_to_init,none,
1806-
"static method 'fromRaw' has been replaced with a failable initializer "
1807-
"'init(rawValue:)'", ())
1808-
ERROR(migrate_from_allZeros,none,
1809-
"static method 'allZeros' has been replaced with the default initializer",
1810-
())
1811-
1812-
ERROR(migrate_to_raw_to_raw_value,none,
1813-
"method 'fromRaw' has been replaced with a property 'rawValue'", ())
1814-
18151802
ERROR(interpolation_missing_proto,none,
18161803
"string interpolation requires the protocol 'StringInterpolationConvertible' to be defined",
18171804
())

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -5888,24 +5888,9 @@ bool ConstraintSystem::applySolutionFix(Expr *expr,
58885888
unsigned fixNo) {
58895889
auto &fix = solution.Fixes[fixNo];
58905890

5891-
// Some fixes need more information from the locator itself, including
5892-
// tweaking the locator. Deal with those now.
5891+
// Some fixes need more information from the locator.
58935892
ConstraintLocator *locator = fix.second;
58945893

5895-
// Removing a nullary call to a non-function requires us to have an
5896-
// 'ApplyFunction', which we strip.
5897-
if (fix.first.getKind() == FixKind::RemoveNullaryCall) {
5898-
auto anchor = locator->getAnchor();
5899-
auto path = locator->getPath();
5900-
if (!path.empty() &&
5901-
path.back().getKind() == ConstraintLocator::ApplyFunction) {
5902-
locator = getConstraintLocator(anchor, path.slice(0, path.size()-1),
5903-
locator->getSummaryFlags());
5904-
} else {
5905-
return false;
5906-
}
5907-
}
5908-
59095894
// Resolve the locator to a specific expression.
59105895
SourceRange range;
59115896
ConstraintLocator *resolved = simplifyLocator(*this, locator, range);
@@ -5932,16 +5917,6 @@ bool ConstraintSystem::applySolutionFix(Expr *expr,
59325917
case FixKind::None:
59335918
llvm_unreachable("no-fix marker should never make it into solution");
59345919

5935-
case FixKind::RemoveNullaryCall:
5936-
if (auto apply = dyn_cast<ApplyExpr>(affected)) {
5937-
auto type = solution.simplifyType(TC, apply->getFn()->getType())
5938-
->getRValueObjectType();
5939-
TC.diagnose(affected->getLoc(), diag::extra_call_nonfunction, type)
5940-
.fixItRemove(apply->getArg()->getSourceRange());
5941-
return true;
5942-
}
5943-
return false;
5944-
59455920
case FixKind::ForceOptional: {
59465921
const Expr *unwrapped = affected->getValueProvidingExpr();
59475922
auto type = solution.simplifyType(TC, affected->getType())
@@ -6085,117 +6060,6 @@ bool ConstraintSystem::applySolutionFix(Expr *expr,
60856060
return true;
60866061
}
60876062

6088-
case FixKind::FromRawToInit: {
6089-
// Chase the parent map to find the reference to 'fromRaw' and
6090-
// the call to it. We'll need these for the Fix-It.
6091-
UnresolvedDotExpr *fromRawRef = nullptr;
6092-
CallExpr *fromRawCall = nullptr;
6093-
auto parentMap = expr->getParentMap();
6094-
Expr *current = affected;
6095-
do {
6096-
if (!fromRawRef) {
6097-
// We haven't found the reference to fromRaw yet, look for it now.
6098-
fromRawRef = dyn_cast<UnresolvedDotExpr>(current);
6099-
if (fromRawRef && fromRawRef->getName() != TC.Context.Id_fromRaw)
6100-
fromRawRef = nullptr;
6101-
6102-
current = parentMap[current];
6103-
continue;
6104-
}
6105-
6106-
// We previously found the reference to fromRaw, so we're
6107-
// looking for the call.
6108-
fromRawCall = dyn_cast<CallExpr>(current);
6109-
if (fromRawCall)
6110-
break;
6111-
6112-
current = parentMap[current];
6113-
continue;
6114-
} while (current);
6115-
6116-
if (fromRawCall) {
6117-
TC.diagnose(fromRawRef->getNameLoc().getBaseNameLoc(),
6118-
diag::migrate_from_raw_to_init)
6119-
.fixItReplace(SourceRange(fromRawRef->getDotLoc(),
6120-
fromRawCall->getArg()->getStartLoc()),
6121-
"(rawValue: ");
6122-
} else {
6123-
// Diagnostic without Fix-It; we couldn't find what we needed.
6124-
TC.diagnose(affected->getLoc(), diag::migrate_from_raw_to_init);
6125-
}
6126-
return true;
6127-
}
6128-
6129-
case FixKind::ToRawToRawValue: {
6130-
// Chase the parent map to find the reference to 'toRaw' and
6131-
// the call to it. We'll need these for the Fix-It.
6132-
UnresolvedDotExpr *toRawRef = nullptr;
6133-
CallExpr *toRawCall = nullptr;
6134-
auto parentMap = expr->getParentMap();
6135-
Expr *current = affected;
6136-
do {
6137-
if (!toRawRef) {
6138-
// We haven't found the reference to toRaw yet, look for it now.
6139-
toRawRef = dyn_cast<UnresolvedDotExpr>(current);
6140-
if (toRawRef && toRawRef->getName() != TC.Context.Id_toRaw)
6141-
toRawRef = nullptr;
6142-
6143-
current = parentMap[current];
6144-
continue;
6145-
}
6146-
6147-
// We previously found the reference to toRaw, so we're
6148-
// looking for the call.
6149-
toRawCall = dyn_cast<CallExpr>(current);
6150-
if (toRawCall)
6151-
break;
6152-
6153-
current = parentMap[current];
6154-
continue;
6155-
} while (current);
6156-
6157-
if (toRawCall) {
6158-
TC.diagnose(toRawRef->getNameLoc(),
6159-
diag::migrate_to_raw_to_raw_value)
6160-
.fixItReplace(SourceRange(toRawRef->getNameLoc().getBaseNameLoc(),
6161-
toRawCall->getArg()->getEndLoc()),
6162-
"rawValue");
6163-
} else {
6164-
TC.diagnose(affected->getLoc(), diag::migrate_to_raw_to_raw_value);
6165-
}
6166-
return true;
6167-
}
6168-
case FixKind::AllZerosToInit: {
6169-
// Chase the parent map to find the reference to 'allZeros' and
6170-
// the call to it. We'll need these for the Fix-It.
6171-
UnresolvedDotExpr *allZerosRef = nullptr;
6172-
auto parentMap = expr->getParentMap();
6173-
Expr *current = affected;
6174-
do {
6175-
// We haven't found the reference to allZeros yet, look for it now.
6176-
if ((allZerosRef = dyn_cast<UnresolvedDotExpr>(current))) {
6177-
if (allZerosRef->getName().isSimpleName(TC.Context.Id_allZeros))
6178-
break;
6179-
allZerosRef = nullptr;
6180-
}
6181-
6182-
current = parentMap[current];
6183-
} while (current);
6184-
6185-
if (allZerosRef) {
6186-
TC.diagnose(allZerosRef->getNameLoc(),
6187-
diag::migrate_from_allZeros)
6188-
.fixItReplace(SourceRange(
6189-
allZerosRef->getDotLoc(),
6190-
allZerosRef->getNameLoc().getSourceRange().End),
6191-
"()");
6192-
} else {
6193-
// Diagnostic without Fix-It; we couldn't find what we needed.
6194-
TC.diagnose(affected->getLoc(), diag::migrate_from_allZeros);
6195-
}
6196-
return true;
6197-
}
6198-
61996063
case FixKind::CoerceToCheckedCast: {
62006064
if (auto *coerceExpr = dyn_cast<CoerceExpr>(locator->getAnchor())) {
62016065
Expr *subExpr = coerceExpr->getSubExpr();

lib/Sema/CSSimplify.cpp

Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,26 +2570,6 @@ ConstraintSystem::simplifyOptionalObjectConstraint(const Constraint &constraint)
25702570
return SolutionKind::Solved;
25712571
}
25722572

2573-
/// If the given type conforms to the RawRepresentable protocol,
2574-
/// return its underlying raw type.
2575-
static Type getRawRepresentableValueType(TypeChecker &tc, DeclContext *dc,
2576-
Type type) {
2577-
auto proto = tc.Context.getProtocol(KnownProtocolKind::RawRepresentable);
2578-
if (!proto)
2579-
return nullptr;
2580-
2581-
if (type->hasTypeVariable())
2582-
return nullptr;
2583-
2584-
ProtocolConformance *conformance = nullptr;
2585-
if (!tc.conformsToProtocol(type, proto, dc,
2586-
ConformanceCheckFlags::InExpression, &conformance))
2587-
return nullptr;
2588-
2589-
return tc.getWitnessType(type, proto, conformance, tc.Context.Id_RawValue,
2590-
diag::broken_raw_representable_requirement);
2591-
}
2592-
25932573
/// Retrieve the argument labels that are provided for a member
25942574
/// reference at the given locator.
25952575
static Optional<ArrayRef<Identifier>>
@@ -3139,7 +3119,6 @@ ConstraintSystem::simplifyMemberConstraint(const Constraint &constraint) {
31393119
baseTy, constraint.getLocator(),
31403120
/*includeInaccessibleMembers*/false);
31413121

3142-
DeclName name = constraint.getMember();
31433122
Type memberTy = constraint.getSecondType();
31443123

31453124
switch (result.OverallResult) {
@@ -3193,62 +3172,6 @@ ConstraintSystem::simplifyMemberConstraint(const Constraint &constraint) {
31933172
instanceTy = MTT->getInstanceType();
31943173

31953174
// Value member lookup has some hacks too.
3196-
Type rawValueType;
3197-
if (shouldAttemptFixes() && name == TC.Context.Id_fromRaw &&
3198-
(rawValueType = getRawRepresentableValueType(TC, DC, instanceTy))) {
3199-
// Replace a reference to ".fromRaw" with a reference to init(rawValue:).
3200-
// FIXME: This is temporary.
3201-
3202-
// Record this fix.
3203-
if (recordFix(FixKind::FromRawToInit, constraint.getLocator()))
3204-
return SolutionKind::Error;
3205-
3206-
// Form the type that "fromRaw" would have had and bind the
3207-
// member type to it.
3208-
Type fromRawType = FunctionType::get(ParenType::get(TC.Context,
3209-
rawValueType),
3210-
OptionalType::get(instanceTy));
3211-
addConstraint(ConstraintKind::Bind, memberTy, fromRawType,
3212-
constraint.getLocator());
3213-
3214-
return SolutionKind::Solved;
3215-
}
3216-
3217-
if (shouldAttemptFixes() && name == TC.Context.Id_toRaw &&
3218-
(rawValueType = getRawRepresentableValueType(TC, DC, instanceTy))) {
3219-
// Replace a call to "toRaw" with a reference to rawValue.
3220-
// FIXME: This is temporary.
3221-
3222-
// Record this fix.
3223-
if (recordFix(FixKind::ToRawToRawValue, constraint.getLocator()))
3224-
return SolutionKind::Error;
3225-
3226-
// Form the type that "toRaw" would have had and bind the member
3227-
// type to it.
3228-
Type toRawType = FunctionType::get(TupleType::getEmpty(TC.Context),
3229-
rawValueType);
3230-
addConstraint(ConstraintKind::Bind, memberTy, toRawType,
3231-
constraint.getLocator());
3232-
3233-
return SolutionKind::Solved;
3234-
}
3235-
3236-
if (shouldAttemptFixes() && name.isSimpleName(getASTContext().Id_allZeros) &&
3237-
(rawValueType = getRawRepresentableValueType(TC, DC, instanceTy))) {
3238-
// Replace a reference to "X.allZeros" with a reference to X().
3239-
// FIXME: This is temporary.
3240-
3241-
// Record this fix.
3242-
if (recordFix(FixKind::AllZerosToInit, constraint.getLocator()))
3243-
return SolutionKind::Error;
3244-
3245-
// Form the type that "allZeros" would have had and bind the
3246-
// member type to it.
3247-
addConstraint(ConstraintKind::Bind, memberTy, rawValueType,
3248-
constraint.getLocator());
3249-
return SolutionKind::Solved;
3250-
}
3251-
32523175
if (shouldAttemptFixes() && baseObjTy->getOptionalObjectType()) {
32533176
// If the base type was an optional, look through it.
32543177

@@ -3504,20 +3427,6 @@ ConstraintSystem::simplifyApplicableFnConstraint(const Constraint &constraint) {
35043427
goto retry;
35053428
}
35063429

3507-
// If this is a '()' call, drop the call.
3508-
if (func1->getInput()->isEqual(TupleType::getEmpty(getASTContext()))) {
3509-
// We don't bother with a 'None' case, because at this point we won't get
3510-
// a better diagnostic from that case.
3511-
if (recordFix(FixKind::RemoveNullaryCall, getConstraintLocator(locator)))
3512-
return SolutionKind::Error;
3513-
3514-
return matchTypes(func1->getResult(), type2,
3515-
TypeMatchKind::BindType,
3516-
flags | TMF_ApplyingFix | TMF_GenerateConstraints,
3517-
locator.withPathElement(
3518-
ConstraintLocator::FunctionResult));
3519-
}
3520-
35213430
return SolutionKind::Error;
35223431
}
35233432

@@ -4251,24 +4160,18 @@ bool ConstraintSystem::recordFix(Fix fix, ConstraintLocatorBuilder locator) {
42514160
}
42524161

42534162
ConstraintSystem::SolutionKind
4254-
ConstraintSystem::simplifyFixConstraint(Fix fix,
4255-
Type type1, Type type2,
4256-
TypeMatchKind matchKind,
4257-
unsigned flags,
4163+
ConstraintSystem::simplifyFixConstraint(Fix fix, Type type1, Type type2,
4164+
TypeMatchKind matchKind, unsigned flags,
42584165
ConstraintLocatorBuilder locator) {
4259-
if (recordFix(fix, locator)) {
4166+
if (recordFix(fix, locator))
42604167
return SolutionKind::Error;
4261-
}
42624168

42634169
// Try with the fix.
42644170
unsigned subFlags = flags | TMF_ApplyingFix | TMF_GenerateConstraints;
42654171
switch (fix.getKind()) {
42664172
case FixKind::None:
42674173
return matchTypes(type1, type2, matchKind, subFlags, locator);
42684174

4269-
case FixKind::RemoveNullaryCall:
4270-
llvm_unreachable("Always applied directly");
4271-
42724175
case FixKind::ForceOptional:
42734176
// Assume that '!' was applied to the first type.
42744177
return matchTypes(type1->getRValueObjectType()->getOptionalObjectType(),
@@ -4288,10 +4191,7 @@ ConstraintSystem::simplifyFixConstraint(Fix fix,
42884191
// The actual semantics are handled elsewhere.
42894192
return SolutionKind::Solved;
42904193

4291-
case FixKind::FromRawToInit:
4292-
case FixKind::ToRawToRawValue:
42934194
case FixKind::CoerceToCheckedCast:
4294-
case FixKind::AllZerosToInit:
42954195
llvm_unreachable("handled elsewhere");
42964196
}
42974197
}

lib/Sema/Constraint.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,16 +431,8 @@ StringRef Fix::getName(FixKind kind) {
431431
return "fix: force downcast";
432432
case FixKind::AddressOf:
433433
return "fix: add address-of";
434-
case FixKind::RemoveNullaryCall:
435-
return "fix: remove nullary call";
436434
case FixKind::OptionalToBoolean:
437435
return "fix: convert optional to boolean";
438-
case FixKind::FromRawToInit:
439-
return "fix: fromRaw(x) to init(rawValue:x)";
440-
case FixKind::AllZerosToInit:
441-
return "fix: x.allZeros to x()";
442-
case FixKind::ToRawToRawValue:
443-
return "fix: toRaw() to rawValue";
444436
case FixKind::CoerceToCheckedCast:
445437
return "fix: as to as!";
446438
}

lib/Sema/Constraint.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,21 +240,9 @@ enum class FixKind : uint8_t {
240240

241241
/// Introduce a '&' to take the address of an lvalue.
242242
AddressOf,
243-
244-
/// Remove a no-argument call to something that is not a function.
245-
RemoveNullaryCall,
246243

247244
/// Introduce a '!= nil' to convert an Optional to a Boolean expression.
248245
OptionalToBoolean,
249-
250-
/// Replace a use of 'fromRaw' with an initializer requirement.
251-
FromRawToInit,
252-
253-
/// Replace a call of 'toRaw' with a reference to 'rawValue'.
254-
ToRawToRawValue,
255-
256-
/// Replace a call of 'X.allZeros' with a reference to 'X()'.
257-
AllZerosToInit,
258246

259247
/// Replace a coercion ('as') with a forced checked cast ('as!').
260248
CoerceToCheckedCast,

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ _ = { $0 } // expected-error {{unable to infer closure return type in current c
271271

272272

273273

274-
_ = 4() // expected-error {{invalid use of '()' to call a value of non-function type 'Int'}} {{6-8=}}
274+
_ = 4() // expected-error {{cannot call value of non-function type 'Int'}}
275275
_ = 4(1) // expected-error {{cannot call value of non-function type 'Int'}}
276276

277277

0 commit comments

Comments
 (0)