Skip to content

Commit 7e58d82

Browse files
authored
Merge pull request #79619 from slavapestov/cleanups-from-optimize-optional-conversion
Small cleanups from "optimize optional conversion"
2 parents d452c40 + 8be3bee commit 7e58d82

16 files changed

+45
-61
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7523,13 +7523,6 @@ ERROR(result_builder_buildpartialblock_accumulated_not_accessible,none,
75237523
"expression shuffles the elements of this tuple; "
75247524
"this behavior is deprecated", ())
75257525

7526-
//------------------------------------------------------------------------------
7527-
// MARK: Implicit conversion diagnostics
7528-
//------------------------------------------------------------------------------
7529-
ERROR(cannot_implicitly_convert_in_optional_context,none,
7530-
"cannot implicitly convert value of type %0 to expected type %1",
7531-
(Type, Type))
7532-
75337526
//------------------------------------------------------------------------------
75347527
// MARK: marker protocol diagnostics
75357528
//------------------------------------------------------------------------------

include/swift/AST/SimpleRequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ enum class RequestFlags {
5757
/// incremental dependency pair and defines a new dependency scope.
5858
///
5959
/// This bit is optional. High-level requests
60-
/// (e.g. \c TypeCheckSourceFileRequest) will require it.
60+
/// (e.g. \c TypeCheckPrimaryFileRequest) will require it.
6161
///
6262
/// For further discussion on incremental dependencies
6363
/// see DependencyAnalysis.md.

include/swift/AST/TypeCheckRequests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,9 +3300,9 @@ class ApplyAccessNoteRequest
33003300
void cacheResult(evaluator::SideEffect value) const;
33013301
};
33023302

3303-
class TypeCheckSourceFileRequest
3303+
class TypeCheckPrimaryFileRequest
33043304
: public SimpleRequest<
3305-
TypeCheckSourceFileRequest, evaluator::SideEffect(SourceFile *),
3305+
TypeCheckPrimaryFileRequest, evaluator::SideEffect(SourceFile *),
33063306
RequestFlags::SeparatelyCached | RequestFlags::DependencySource> {
33073307
public:
33083308
using SimpleRequest::SimpleRequest;

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ SWIFT_REQUEST(TypeChecker, HasDefaultInitRequest,
424424
bool(NominalTypeDecl *), Cached, NoLocationInfo)
425425
SWIFT_REQUEST(TypeChecker, SynthesizeDefaultInitRequest,
426426
ConstructorDecl *(NominalTypeDecl *), Cached, NoLocationInfo)
427-
SWIFT_REQUEST(TypeChecker, TypeCheckSourceFileRequest,
427+
SWIFT_REQUEST(TypeChecker, TypeCheckPrimaryFileRequest,
428428
bool(SouceFile *), SeparatelyCached, NoLocationInfo)
429429
SWIFT_REQUEST(TypeChecker, ConformanceAccessScopeRequest,
430430
ConformanceAccessScope(DeclContext *, ProtocolDecl *),

include/swift/Sema/ConstraintLocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ class ConstraintLocatorBuilder {
12751275

12761276
auto last = std::find_if(
12771277
path.rbegin(), path.rend(), [](LocatorPathElt &elt) -> bool {
1278-
return elt.getKind() != ConstraintLocator::OptionalPayload &&
1278+
return elt.getKind() != ConstraintLocator::OptionalInjection &&
12791279
elt.getKind() != ConstraintLocator::GenericArgument;
12801280
});
12811281

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ CUSTOM_LOCATOR_PATH_ELT(OpenedGeneric)
153153
/// type at the base of the locator.
154154
CUSTOM_LOCATOR_PATH_ELT(OpenedOpaqueArchetype)
155155

156-
/// An optional payload.
157-
SIMPLE_LOCATOR_PATH_ELT(OptionalPayload)
156+
/// The optional payload in an optional injection, ie a T -> T? conversion.
157+
SIMPLE_LOCATOR_PATH_ELT(OptionalInjection)
158158

159159
/// The parent of a nested type.
160160
SIMPLE_LOCATOR_PATH_ELT(ParentType)

lib/AST/TypeCheckRequests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,24 +1655,24 @@ void RenamedDeclRequest::cacheResult(ValueDecl *value) const {
16551655
}
16561656

16571657
//----------------------------------------------------------------------------//
1658-
// TypeCheckSourceFileRequest computation.
1658+
// TypeCheckPrimaryFileRequest computation.
16591659
//----------------------------------------------------------------------------//
16601660

1661-
evaluator::DependencySource TypeCheckSourceFileRequest::readDependencySource(
1661+
evaluator::DependencySource TypeCheckPrimaryFileRequest::readDependencySource(
16621662
const evaluator::DependencyRecorder &e) const {
16631663
return std::get<0>(getStorage());
16641664
}
16651665

16661666
std::optional<evaluator::SideEffect>
1667-
TypeCheckSourceFileRequest::getCachedResult() const {
1667+
TypeCheckPrimaryFileRequest::getCachedResult() const {
16681668
auto *SF = std::get<0>(getStorage());
16691669
if (SF->ASTStage == SourceFile::TypeChecked)
16701670
return std::make_tuple<>();
16711671

16721672
return std::nullopt;
16731673
}
16741674

1675-
void TypeCheckSourceFileRequest::cacheResult(evaluator::SideEffect) const {
1675+
void TypeCheckPrimaryFileRequest::cacheResult(evaluator::SideEffect) const {
16761676
auto *SF = std::get<0>(getStorage());
16771677

16781678
// Verify that we've checked types correctly.

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ bool GenericArgumentsMismatchFailure::diagnoseAsError() {
940940

941941
while (!path.empty()) {
942942
auto last = path.back();
943-
if (last.is<LocatorPathElt::OptionalPayload>() ||
943+
if (last.is<LocatorPathElt::OptionalInjection>() ||
944944
last.is<LocatorPathElt::GenericType>() ||
945945
last.is<LocatorPathElt::GenericArgument>()) {
946946
path = path.drop_back();
@@ -2837,22 +2837,6 @@ bool ContextualFailure::diagnoseAsError() {
28372837
break;
28382838
}
28392839

2840-
case ConstraintLocator::OptionalPayload: {
2841-
// If this is an attempt at a Double <-> CGFloat conversion
2842-
// through optional chaining, let's produce a tailored diagnostic.
2843-
if (isExpr<OptionalEvaluationExpr>(getAnchor())) {
2844-
if ((fromType->isDouble() || fromType->isCGFloat()) &&
2845-
(toType->isDouble() || toType->isCGFloat())) {
2846-
fromType = OptionalType::get(fromType);
2847-
toType = OptionalType::get(toType);
2848-
diagnostic = diag::cannot_implicitly_convert_in_optional_context;
2849-
break;
2850-
}
2851-
}
2852-
2853-
return false;
2854-
}
2855-
28562840
case ConstraintLocator::EnumPatternImplicitCastMatch: {
28572841
// In this case, the types are reversed, as we are checking whether we
28582842
// can convert the pattern type to the context type.

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4673,7 +4673,7 @@ generateForEachStmtConstraints(ConstraintSystem &cs, DeclContext *dc,
46734673
// Add a conversion constraint between the element type of the sequence
46744674
// and the type of the element pattern.
46754675
auto *elementTypeLoc = cs.getConstraintLocator(
4676-
elementLocator, ConstraintLocator::OptionalPayload);
4676+
elementLocator, ConstraintLocator::OptionalInjection);
46774677
auto elementType = cs.createTypeVariable(elementTypeLoc,
46784678
/*flags=*/0);
46794679
{

lib/Sema/CSSimplify.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,11 +3323,11 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
33233323
SmallVector<LocatorPathElt, 4> path;
33243324
locator.getLocatorParts(path);
33253325

3326-
// Find the last path element, skipping OptionalPayload elements
3326+
// Find the last path element, skipping OptionalInjection elements
33273327
// so that we allow this exception in cases of optional injection.
33283328
auto last = std::find_if(
33293329
path.rbegin(), path.rend(), [](LocatorPathElt &elt) -> bool {
3330-
return elt.getKind() != ConstraintLocator::OptionalPayload;
3330+
return elt.getKind() != ConstraintLocator::OptionalInjection;
33313331
});
33323332

33333333
auto &ctx = getASTContext();
@@ -3431,12 +3431,12 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
34313431

34323432
// Find the last path element, skipping GenericArgument elements
34333433
// so that we allow this exception in cases of optional types, and
3434-
// skipping OptionalPayload elements so that we allow this
3434+
// skipping OptionalInjection elements so that we allow this
34353435
// exception in cases of optional injection.
34363436
auto last = std::find_if(
34373437
path.rbegin(), path.rend(), [](LocatorPathElt &elt) -> bool {
34383438
return elt.getKind() != ConstraintLocator::GenericArgument &&
3439-
elt.getKind() != ConstraintLocator::OptionalPayload;
3439+
elt.getKind() != ConstraintLocator::OptionalInjection;
34403440
});
34413441

34423442
if (last != path.rend()) {
@@ -3484,7 +3484,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
34843484
//
34853485
// func foo(_: ((Int, Int) -> Void)?) {}
34863486
// _ = foo { _ in } <- missing second closure parameter.
3487-
if (loc->isLastElement<LocatorPathElt::OptionalPayload>()) {
3487+
if (loc->isLastElement<LocatorPathElt::OptionalInjection>()) {
34883488
auto path = loc->getPath();
34893489
loc = getConstraintLocator(loc->getAnchor(), path.drop_back());
34903490
}
@@ -4144,7 +4144,7 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
41444144
// `value-to-optional` or `optional-to-optional` conversion
41454145
// associated with them (expected argument is `AnyObject?`).
41464146
if (!path.empty() &&
4147-
(path.back().is<LocatorPathElt::OptionalPayload>() ||
4147+
(path.back().is<LocatorPathElt::OptionalInjection>() ||
41484148
path.back().is<LocatorPathElt::GenericArgument>()))
41494149
path.pop_back();
41504150

@@ -4200,7 +4200,7 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
42004200
// If the path ends at `optional payload` it means that this
42014201
// check is part of an implicit value-to-optional conversion,
42024202
// and it could be safely dropped.
4203-
if (!path.empty() && path.back().is<LocatorPathElt::OptionalPayload>())
4203+
if (!path.empty() && path.back().is<LocatorPathElt::OptionalInjection>())
42044204
path.pop_back();
42054205

42064206
// Determine whether this conformance mismatch is
@@ -6495,7 +6495,7 @@ bool ConstraintSystem::repairFailures(
64956495
// If the mismatch is a part of either optional-to-optional or
64966496
// value-to-optional conversions, let's allow fix refer to a complete
64976497
// top level type and not just a part of it.
6498-
if (tupleLocator->findLast<LocatorPathElt::OptionalPayload>())
6498+
if (tupleLocator->findLast<LocatorPathElt::OptionalInjection>())
64996499
break;
65006500

65016501
if (tupleLocator->isForContextualType()) {
@@ -6636,7 +6636,7 @@ bool ConstraintSystem::repairFailures(
66366636
break;
66376637
}
66386638

6639-
case ConstraintLocator::OptionalPayload: {
6639+
case ConstraintLocator::OptionalInjection: {
66406640
if (lhs->isPlaceholder() || rhs->isPlaceholder())
66416641
return true;
66426642

@@ -7446,7 +7446,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
74467446
// Look through all value-to-optional promotions to allow
74477447
// conversions like Double -> CGFloat?? and vice versa.
74487448
// T -> Optional<T>
7449-
if (location.endsWith<LocatorPathElt::OptionalPayload>() ||
7449+
if (location.endsWith<LocatorPathElt::OptionalInjection>() ||
74507450
location.endsWith<LocatorPathElt::GenericArgument>()) {
74517451
SmallVector<LocatorPathElt, 4> path;
74527452
auto anchor = location.getLocatorParts(path);
@@ -7456,7 +7456,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
74567456
path.erase(llvm::remove_if(
74577457
path,
74587458
[](const LocatorPathElt &elt) {
7459-
return elt.is<LocatorPathElt::OptionalPayload>() ||
7459+
return elt.is<LocatorPathElt::OptionalInjection>() ||
74607460
elt.is<LocatorPathElt::GenericArgument>();
74617461
}),
74627462
path.end());
@@ -14608,7 +14608,7 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
1460814608
if (generic2->getDecl()->isOptionalDecl()) {
1460914609
auto result = matchTypes(
1461014610
type1, generic2->getGenericArgs()[0], matchKind, subflags,
14611-
locator.withPathElement(ConstraintLocator::OptionalPayload));
14611+
locator.withPathElement(ConstraintLocator::OptionalInjection));
1461214612

1461314613
if (!(shouldAttemptFixes() && result.isFailure()))
1461414614
return result;

0 commit comments

Comments
 (0)