Skip to content

Commit 385d66f

Browse files
slavapestovxedin
authored andcommitted
Sema: Remove ConstraintKind::OneWayEqual
1 parent 5071e96 commit 385d66f

File tree

6 files changed

+1
-109
lines changed

6 files changed

+1
-109
lines changed

include/swift/Sema/Constraint.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ enum class ConstraintKind : char {
150150
/// The key path type is chosen based on the selection of overloads for the
151151
/// member references along the path.
152152
KeyPath,
153-
/// The first type will be equal to the second type, but only when the
154-
/// second type has been fully determined (and mapped down to a concrete
155-
/// type). At that point, this constraint will be treated like an `Equal`
156-
/// constraint.
157-
OneWayEqual,
158153
/// If there is no contextual info e.g. `_ = { 42 }` default first type
159154
/// to a second type. This is effectively a `Defaultable` constraint
160155
/// which one significant difference:
@@ -680,7 +675,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
680675
case ConstraintKind::DynamicCallableApplicableFunction:
681676
case ConstraintKind::BindOverload:
682677
case ConstraintKind::OptionalObject:
683-
case ConstraintKind::OneWayEqual:
684678
case ConstraintKind::FallbackType:
685679
case ConstraintKind::UnresolvedMemberChainBase:
686680
case ConstraintKind::PackElementOf:
@@ -828,7 +822,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
828822

829823
/// Whether this is a one-way constraint.
830824
bool isOneWayConstraint() const {
831-
return Kind == ConstraintKind::OneWayEqual;
825+
return false;
832826
}
833827

834828
/// Retrieve the overload choice for an overload-binding constraint.

include/swift/Sema/ConstraintSystem.h

-6
Original file line numberDiff line numberDiff line change
@@ -5011,12 +5011,6 @@ class ConstraintSystem {
50115011
TypeMatchOptions flags,
50125012
ConstraintLocatorBuilder locator);
50135013

5014-
/// Attempt to simplify a one-way constraint.
5015-
SolutionKind simplifyOneWayConstraint(ConstraintKind kind,
5016-
Type first, Type second,
5017-
TypeMatchOptions flags,
5018-
ConstraintLocatorBuilder locator);
5019-
50205014
/// Simplify an equality constraint between result and base types of
50215015
/// an unresolved member chain.
50225016
SolutionKind simplifyUnresolvedMemberChainBaseConstraint(

lib/Sema/CSBindings.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -1949,20 +1949,6 @@ void PotentialBindings::infer(ConstraintSystem &CS,
19491949

19501950
break;
19511951
}
1952-
1953-
case ConstraintKind::OneWayEqual:{
1954-
// Don't produce any bindings if this type variable is on the left-hand
1955-
// side of a one-way binding.
1956-
auto firstType = constraint->getFirstType();
1957-
if (auto *tv = firstType->getAs<TypeVariableType>()) {
1958-
if (tv->getImpl().getRepresentative(nullptr) == TypeVar) {
1959-
DelayedBy.push_back(constraint);
1960-
break;
1961-
}
1962-
}
1963-
1964-
break;
1965-
}
19661952
}
19671953
}
19681954

lib/Sema/CSSimplify.cpp

-45
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,6 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
21782178
case ConstraintKind::ValueMember:
21792179
case ConstraintKind::ValueWitness:
21802180
case ConstraintKind::BridgingConversion:
2181-
case ConstraintKind::OneWayEqual:
21822181
case ConstraintKind::FallbackType:
21832182
case ConstraintKind::UnresolvedMemberChainBase:
21842183
case ConstraintKind::PropertyWrapper:
@@ -2549,7 +2548,6 @@ static bool matchFunctionRepresentations(FunctionType::ExtInfo einfo1,
25492548
case ConstraintKind::UnresolvedValueMember:
25502549
case ConstraintKind::ValueMember:
25512550
case ConstraintKind::ValueWitness:
2552-
case ConstraintKind::OneWayEqual:
25532551
case ConstraintKind::FallbackType:
25542552
case ConstraintKind::UnresolvedMemberChainBase:
25552553
case ConstraintKind::PropertyWrapper:
@@ -3193,7 +3191,6 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
31933191
case ConstraintKind::ValueMember:
31943192
case ConstraintKind::ValueWitness:
31953193
case ConstraintKind::BridgingConversion:
3196-
case ConstraintKind::OneWayEqual:
31973194
case ConstraintKind::FallbackType:
31983195
case ConstraintKind::UnresolvedMemberChainBase:
31993196
case ConstraintKind::PropertyWrapper:
@@ -7128,7 +7125,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
71287125
case ConstraintKind::UnresolvedValueMember:
71297126
case ConstraintKind::ValueMember:
71307127
case ConstraintKind::ValueWitness:
7131-
case ConstraintKind::OneWayEqual:
71327128
case ConstraintKind::FallbackType:
71337129
case ConstraintKind::UnresolvedMemberChainBase:
71347130
case ConstraintKind::PropertyWrapper:
@@ -11561,38 +11557,6 @@ ConstraintSystem::simplifyPropertyWrapperConstraint(
1156111557
return SolutionKind::Solved;
1156211558
}
1156311559

11564-
ConstraintSystem::SolutionKind
11565-
ConstraintSystem::simplifyOneWayConstraint(
11566-
ConstraintKind kind,
11567-
Type first, Type second, TypeMatchOptions flags,
11568-
ConstraintLocatorBuilder locator) {
11569-
// Determine whether the second type can be fully simplified. Only then
11570-
// will this constraint be resolved.
11571-
Type secondSimplified = simplifyType(second);
11572-
if (secondSimplified->hasTypeVariable()) {
11573-
if (flags.contains(TMF_GenerateConstraints)) {
11574-
addUnsolvedConstraint(
11575-
Constraint::create(*this, kind, first, second,
11576-
getConstraintLocator(locator)));
11577-
return SolutionKind::Solved;
11578-
}
11579-
11580-
return SolutionKind::Unsolved;
11581-
}
11582-
11583-
// Propagate holes through one-way constraints.
11584-
if (secondSimplified->isPlaceholder()) {
11585-
recordAnyTypeVarAsPotentialHole(first);
11586-
return SolutionKind::Solved;
11587-
}
11588-
11589-
// Translate this constraint into an equality or bind-parameter constraint,
11590-
// as appropriate.
11591-
ASSERT(kind == ConstraintKind::OneWayEqual);
11592-
return matchTypes(first, secondSimplified, ConstraintKind::Equal, flags,
11593-
locator);
11594-
}
11595-
1159611560
ConstraintSystem::SolutionKind
1159711561
ConstraintSystem::simplifyUnresolvedMemberChainBaseConstraint(
1159811562
Type first, Type second, TypeMatchOptions flags,
@@ -15724,9 +15688,6 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
1572415688
case ConstraintKind::PropertyWrapper:
1572515689
return simplifyPropertyWrapperConstraint(first, second, subflags, locator);
1572615690

15727-
case ConstraintKind::OneWayEqual:
15728-
return simplifyOneWayConstraint(kind, first, second, subflags, locator);
15729-
1573015691
case ConstraintKind::UnresolvedMemberChainBase:
1573115692
return simplifyUnresolvedMemberChainBaseConstraint(first, second, subflags,
1573215693
locator);
@@ -16304,12 +16265,6 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1630416265
// See {Dis, Con}junctionStep class in CSStep.cpp for solving
1630516266
return SolutionKind::Unsolved;
1630616267

16307-
case ConstraintKind::OneWayEqual:
16308-
return simplifyOneWayConstraint(
16309-
constraint.getKind(), constraint.getFirstType(),
16310-
constraint.getSecondType(),
16311-
/*flags*/ std::nullopt, constraint.getLocator());
16312-
1631316268
case ConstraintKind::UnresolvedMemberChainBase:
1631416269
return simplifyUnresolvedMemberChainBaseConstraint(
1631516270
constraint.getFirstType(), constraint.getSecondType(),

lib/Sema/Constraint.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
7474
case ConstraintKind::EscapableFunctionOf:
7575
case ConstraintKind::OpenedExistentialOf:
7676
case ConstraintKind::OptionalObject:
77-
case ConstraintKind::OneWayEqual:
7877
case ConstraintKind::UnresolvedMemberChainBase:
7978
case ConstraintKind::PropertyWrapper:
8079
case ConstraintKind::BindTupleOfFunctionParams:
@@ -162,7 +161,6 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second, Type Third,
162161
case ConstraintKind::BindOverload:
163162
case ConstraintKind::Disjunction:
164163
case ConstraintKind::Conjunction:
165-
case ConstraintKind::OneWayEqual:
166164
case ConstraintKind::FallbackType:
167165
case ConstraintKind::UnresolvedMemberChainBase:
168166
case ConstraintKind::PropertyWrapper:
@@ -395,7 +393,6 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm,
395393
case ConstraintKind::DynamicTypeOf: Out << " dynamicType type of "; break;
396394
case ConstraintKind::EscapableFunctionOf: Out << " @escaping type of "; break;
397395
case ConstraintKind::OpenedExistentialOf: Out << " opened archetype of "; break;
398-
case ConstraintKind::OneWayEqual: Out << " one-way bind to "; break;
399396
case ConstraintKind::FallbackType:
400397
Out << " can fallback to ";
401398
break;
@@ -675,7 +672,6 @@ gatherReferencedTypeVars(Constraint *constraint,
675672
case ConstraintKind::ConformsTo:
676673
case ConstraintKind::LiteralConformsTo:
677674
case ConstraintKind::TransitivelyConformsTo:
678-
case ConstraintKind::OneWayEqual:
679675
case ConstraintKind::FallbackType:
680676
case ConstraintKind::UnresolvedMemberChainBase:
681677
case ConstraintKind::PropertyWrapper:

lib/Sema/ConstraintSystem.cpp

-33
Original file line numberDiff line numberDiff line change
@@ -1837,39 +1837,6 @@ Type Solution::simplifyTypeForCodeCompletion(Type Ty) const {
18371837
return typeVar;
18381838
});
18391839

1840-
// Logic to determine the contextual type inside buildBlock result builders:
1841-
//
1842-
// When completing inside a result builder, the result builder
1843-
// @ViewBuilder var body: some View {
1844-
// Text("Foo")
1845-
// #^COMPLETE^#
1846-
// }
1847-
// gets rewritten to
1848-
// @ViewBuilder var body: some View {
1849-
// let $__builder2: Text
1850-
// let $__builder0 = Text("Foo")
1851-
// let $__builder1 = #^COMPLETE^#
1852-
// $__builder2 = ViewBuilder.buildBlock($__builder0, $__builder1)
1853-
// return $__builder2
1854-
// }
1855-
// Inside the constraint system
1856-
// let $__builder1 = #^COMPLETE^#
1857-
// gets type checked without context, so we can't know the contextual type for
1858-
// the code completion token. But we know that $__builder1 (and thus the type
1859-
// of #^COMPLETE^#) is used as the second argument to ViewBuilder.buildBlock,
1860-
// so we can extract the contextual type from that call. To do this, figure
1861-
// out the type variable that is used for $__builder1 in the buildBlock call.
1862-
// This type variable is connected to the type variable of $__builder1's
1863-
// definition by a one-way constraint.
1864-
if (auto TV = Ty->getAs<TypeVariableType>()) {
1865-
for (auto constraint : CS.getConstraintGraph()[TV].getConstraints()) {
1866-
if (constraint->getKind() == ConstraintKind::OneWayEqual &&
1867-
constraint->getSecondType()->isEqual(TV)) {
1868-
return simplifyTypeForCodeCompletion(constraint->getFirstType());
1869-
}
1870-
}
1871-
}
1872-
18731840
// Remove any remaining type variables and placeholders
18741841
Ty = simplifyType(Ty);
18751842

0 commit comments

Comments
 (0)