Skip to content

Commit 2d17294

Browse files
authored
Merge pull request #78301 from slavapestov/remove-one-way-constraints
Sema: Remove ConstraintKind::OneWayBindParam and ConstraintKind::OneWayEqual
2 parents cace199 + 80a988e commit 2d17294

27 files changed

+194
-1150
lines changed

include/swift/AST/Expr.h

-27
Original file line numberDiff line numberDiff line change
@@ -6413,33 +6413,6 @@ class SingleValueStmtExpr : public Expr {
64136413
}
64146414
};
64156415

6416-
/// Expression node that effects a "one-way" constraint in
6417-
/// the constraint system, allowing type information to flow from the
6418-
/// subexpression outward but not the other way.
6419-
///
6420-
/// One-way expressions are generally implicit and synthetic, introduced by
6421-
/// the type checker. However, there is a built-in expression of the
6422-
/// form \c Builtin.one_way(x) that forms a one-way constraint coming out
6423-
/// of expression `x` that can be used for testing purposes.
6424-
class OneWayExpr : public Expr {
6425-
Expr *SubExpr;
6426-
6427-
public:
6428-
/// Construct an implicit one-way expression from the given subexpression.
6429-
OneWayExpr(Expr *subExpr)
6430-
: Expr(ExprKind::OneWay, /*isImplicit=*/true), SubExpr(subExpr) { }
6431-
6432-
SourceLoc getLoc() const { return SubExpr->getLoc(); }
6433-
SourceRange getSourceRange() const { return SubExpr->getSourceRange(); }
6434-
6435-
Expr *getSubExpr() const { return SubExpr; }
6436-
void setSubExpr(Expr *subExpr) { SubExpr = subExpr; }
6437-
6438-
static bool classof(const Expr *E) {
6439-
return E->getKind() == ExprKind::OneWay;
6440-
}
6441-
};
6442-
64436416
class TypeJoinExpr final : public Expr,
64446417
private llvm::TrailingObjects<TypeJoinExpr, Expr *> {
64456418
friend TrailingObjects;

include/swift/AST/ExprNodes.def

-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ EXPR(KeyPath, Expr)
214214
EXPR(CurrentContextIsolation, Expr)
215215
EXPR(SingleValueStmt, Expr)
216216
UNCHECKED_EXPR(KeyPathDot, Expr)
217-
UNCHECKED_EXPR(OneWay, Expr)
218217
EXPR(Tap, Expr)
219218
UNCHECKED_EXPR(TypeJoin, Expr)
220219
EXPR(MacroExpansion, Expr)

include/swift/Sema/Constraint.h

-11
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:
@@ -826,11 +820,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
826820
/// from the rest of the constraint system.
827821
bool isIsolated() const { return IsIsolated; }
828822

829-
/// Whether this is a one-way constraint.
830-
bool isOneWayConstraint() const {
831-
return Kind == ConstraintKind::OneWayEqual;
832-
}
833-
834823
/// Retrieve the overload choice for an overload-binding constraint.
835824
OverloadChoice getOverloadChoice() const {
836825
assert(Kind == ConstraintKind::BindOverload);

include/swift/Sema/ConstraintGraph.h

-11
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,6 @@ class ConstraintGraph {
332332
/// The constraints in this component.
333333
TinyPtrVector<Constraint *> constraints;
334334

335-
/// The set of components that this component depends on, such that
336-
/// the partial solutions of the those components need to be available
337-
/// before this component can be solved.
338-
///
339-
SmallVector<unsigned, 2> dependencies;
340-
341335
public:
342336
Component(unsigned solutionIndex) : solutionIndex(solutionIndex) { }
343337

@@ -353,11 +347,6 @@ class ConstraintGraph {
353347
return constraints;
354348
}
355349

356-
/// Records a component which this component depends on.
357-
void recordDependency(const Component &component);
358-
359-
ArrayRef<unsigned> getDependencies() const { return dependencies; }
360-
361350
unsigned getNumDisjunctions() const { return numDisjunctions; }
362351
};
363352

include/swift/Sema/ConstraintSystem.h

-7
Original file line numberDiff line numberDiff line change
@@ -4505,7 +4505,6 @@ class ConstraintSystem {
45054505
/// \returns a possibly-sanitized initializer, or null if an error occurred.
45064506
[[nodiscard]]
45074507
Type generateConstraints(Pattern *P, ConstraintLocatorBuilder locator,
4508-
bool bindPatternVarsOneWay,
45094508
PatternBindingDecl *patternBinding,
45104509
unsigned patternIndex);
45114510

@@ -5013,12 +5012,6 @@ class ConstraintSystem {
50135012
TypeMatchOptions flags,
50145013
ConstraintLocatorBuilder locator);
50155014

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

include/swift/Sema/SyntacticElementTarget.h

+17-39
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ class SyntacticElementTarget {
114114
/// Whether the expression result will be discarded at the end.
115115
bool isDiscarded;
116116

117-
/// Whether to bind the variables encountered within the pattern to
118-
/// fresh type variables via one-way constraints.
119-
bool bindPatternVarsOneWay;
120-
121117
union {
122118
struct {
123119
/// The pattern binding declaration for an initialization, if any.
@@ -165,10 +161,9 @@ class SyntacticElementTarget {
165161
ForEachStmt *stmt;
166162
DeclContext *dc;
167163
Pattern *pattern;
168-
bool ignoreWhereClause;
169164
GenericEnvironment *packElementEnv;
170165
ForEachStmtInfo info;
171-
} forEachStmt;
166+
} forEachPreamble;
172167

173168
PatternBindingDecl *patternBinding;
174169
};
@@ -246,35 +241,33 @@ class SyntacticElementTarget {
246241
}
247242

248243
SyntacticElementTarget(ForEachStmt *stmt, DeclContext *dc,
249-
bool ignoreWhereClause,
250244
GenericEnvironment *packElementEnv)
251245
: kind(Kind::forEachPreamble) {
252-
forEachStmt.stmt = stmt;
253-
forEachStmt.dc = dc;
254-
forEachStmt.ignoreWhereClause = ignoreWhereClause;
255-
forEachStmt.packElementEnv = packElementEnv;
246+
forEachPreamble.stmt = stmt;
247+
forEachPreamble.dc = dc;
248+
forEachPreamble.packElementEnv = packElementEnv;
256249
}
257250

258251
/// Form a target for the initialization of a pattern from an expression.
259252
static SyntacticElementTarget
260253
forInitialization(Expr *initializer, DeclContext *dc, Type patternType,
261-
Pattern *pattern, bool bindPatternVarsOneWay);
254+
Pattern *pattern);
262255

263256
/// Form a target for the initialization of a pattern binding entry from
264257
/// an expression.
265258
static SyntacticElementTarget
266259
forInitialization(Expr *initializer, Type patternType,
267260
PatternBindingDecl *patternBinding,
268-
unsigned patternBindingIndex, bool bindPatternVarsOneWay);
261+
unsigned patternBindingIndex);
269262

270263
/// Form an expression target for a ReturnStmt.
271264
static SyntacticElementTarget
272265
forReturn(ReturnStmt *returnStmt, Type contextTy, DeclContext *dc);
273266

274-
/// Form a target for the preamble of a for-in loop, excluding its body.
267+
/// Form a target for the preamble of a for-in loop, excluding its where
268+
/// clause and body.
275269
static SyntacticElementTarget
276270
forForEachPreamble(ForEachStmt *stmt, DeclContext *dc,
277-
bool ignoreWhereClause = false,
278271
GenericEnvironment *packElementEnv = nullptr);
279272

280273
/// Form a target for a property with an attached property wrapper that is
@@ -376,7 +369,7 @@ class SyntacticElementTarget {
376369
}
377370

378371
case Kind::forEachPreamble:
379-
return forEachStmt.dc;
372+
return forEachPreamble.dc;
380373
}
381374
llvm_unreachable("invalid decl context type");
382375
}
@@ -500,16 +493,6 @@ class SyntacticElementTarget {
500493
return false;
501494
}
502495

503-
/// Whether to bind the types of any variables within the pattern via
504-
/// one-way constraints.
505-
bool shouldBindPatternVarsOneWay() const {
506-
if (kind == Kind::expression)
507-
return expression.bindPatternVarsOneWay;
508-
if (kind == Kind::forEachPreamble)
509-
return !ignoreForEachWhereClause() && forEachStmt.stmt->getWhere();
510-
return false;
511-
}
512-
513496
/// Whether or not an opaque value placeholder should be injected into the
514497
/// first \c wrappedValue argument of an apply expression so the initializer
515498
/// expression can be turned into a property wrapper generator function.
@@ -555,24 +538,19 @@ class SyntacticElementTarget {
555538
return expression.initialization.patternBindingIndex;
556539
}
557540

558-
bool ignoreForEachWhereClause() const {
559-
assert(isForEachPreamble());
560-
return forEachStmt.ignoreWhereClause;
561-
}
562-
563541
GenericEnvironment *getPackElementEnv() const {
564542
assert(isForEachPreamble());
565-
return forEachStmt.packElementEnv;
543+
return forEachPreamble.packElementEnv;
566544
}
567545

568546
const ForEachStmtInfo &getForEachStmtInfo() const {
569547
assert(isForEachPreamble());
570-
return forEachStmt.info;
548+
return forEachPreamble.info;
571549
}
572550

573551
ForEachStmtInfo &getForEachStmtInfo() {
574552
assert(isForEachPreamble());
575-
return forEachStmt.info;
553+
return forEachPreamble.info;
576554
}
577555

578556
/// Whether this context infers an opaque return type.
@@ -599,7 +577,7 @@ class SyntacticElementTarget {
599577
return getInitializationPattern();
600578

601579
if (kind == Kind::forEachPreamble)
602-
return forEachStmt.pattern;
580+
return forEachPreamble.pattern;
603581

604582
return nullptr;
605583
}
@@ -612,7 +590,7 @@ class SyntacticElementTarget {
612590
}
613591

614592
if (kind == Kind::forEachPreamble) {
615-
forEachStmt.pattern = pattern;
593+
forEachPreamble.pattern = pattern;
616594
return;
617595
}
618596

@@ -743,7 +721,7 @@ class SyntacticElementTarget {
743721
return nullptr;
744722

745723
case Kind::forEachPreamble:
746-
return forEachStmt.stmt;
724+
return forEachPreamble.stmt;
747725
}
748726
llvm_unreachable("invalid case label type");
749727
}
@@ -855,7 +833,7 @@ class SyntacticElementTarget {
855833

856834
// For-in preamble target doesn't cover the body.
857835
case Kind::forEachPreamble:
858-
auto *stmt = forEachStmt.stmt;
836+
auto *stmt = forEachPreamble.stmt;
859837
SourceLoc startLoc = stmt->getForLoc();
860838
SourceLoc endLoc = stmt->getParsedSequence()->getEndLoc();
861839

@@ -898,7 +876,7 @@ class SyntacticElementTarget {
898876
}
899877

900878
case Kind::forEachPreamble:
901-
return forEachStmt.stmt->getStartLoc();
879+
return forEachPreamble.stmt->getStartLoc();
902880
}
903881
llvm_unreachable("invalid target type");
904882
}

lib/AST/ASTDumper.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -3343,12 +3343,6 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
33433343
printFoot();
33443344
}
33453345

3346-
void visitOneWayExpr(OneWayExpr *E, StringRef label) {
3347-
printCommon(E, "one_way_expr", label);
3348-
printRec(E->getSubExpr());
3349-
printFoot();
3350-
}
3351-
33523346
void visitTapExpr(TapExpr *E, StringRef label) {
33533347
printCommon(E, "tap_expr", label);
33543348
printDeclRefField(E->getVar(), "var");

lib/AST/ASTPrinter.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -4888,10 +4888,6 @@ void PrintAST::visitCoerceExpr(CoerceExpr *expr) {
48884888
printType(expr->getCastType());
48894889
}
48904890

4891-
void PrintAST::visitOneWayExpr(OneWayExpr *expr) {
4892-
llvm_unreachable("Not representable in source code");
4893-
}
4894-
48954891
void PrintAST::printClosure(AbstractClosureExpr *closure, CaptureListExpr *captureList) {
48964892

48974893
}

lib/AST/ASTWalker.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -1332,18 +1332,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
13321332
return E;
13331333
}
13341334

1335-
Expr *visitOneWayExpr(OneWayExpr *E) {
1336-
if (auto oldSubExpr = E->getSubExpr()) {
1337-
if (auto subExpr = doIt(oldSubExpr)) {
1338-
E->setSubExpr(subExpr);
1339-
} else {
1340-
return nullptr;
1341-
}
1342-
}
1343-
1344-
return E;
1345-
}
1346-
13471335
Expr *visitTapExpr(TapExpr *E) {
13481336
if (auto oldSubExpr = E->getSubExpr()) {
13491337
if (auto subExpr = doIt(oldSubExpr)) {

lib/AST/Expr.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ ConcreteDeclRef Expr::getReferencedDecl(bool stopAtParenExpr) const {
461461
NO_REFERENCE(KeyPath);
462462
NO_REFERENCE(KeyPathDot);
463463
PASS_THROUGH_REFERENCE(CurrentContextIsolation, getActor);
464-
PASS_THROUGH_REFERENCE(OneWay, getSubExpr);
465464
NO_REFERENCE(Tap);
466465
NO_REFERENCE(TypeJoin);
467466
SIMPLE_REFERENCE(MacroExpansion, getMacroRef);
@@ -662,7 +661,6 @@ bool Expr::canAppendPostfixExpression(bool appendingPostfixOperator) const {
662661
case ExprKind::Error:
663662
case ExprKind::CodeCompletion:
664663
case ExprKind::LazyInitializer:
665-
case ExprKind::OneWay:
666664
return false;
667665

668666
case ExprKind::NilLiteral:
@@ -1037,7 +1035,6 @@ bool Expr::isValidParentOfTypeExpr(Expr *typeExpr) const {
10371035
case ExprKind::ObjCSelector:
10381036
case ExprKind::KeyPath:
10391037
case ExprKind::KeyPathDot:
1040-
case ExprKind::OneWay:
10411038
case ExprKind::Tap:
10421039
case ExprKind::SingleValueStmt:
10431040
case ExprKind::TypeJoin:

0 commit comments

Comments
 (0)