Skip to content

Sema: Remove ConstraintKind::OneWayBindParam and ConstraintKind::OneWayEqual #78301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6413,33 +6413,6 @@ class SingleValueStmtExpr : public Expr {
}
};

/// Expression node that effects a "one-way" constraint in
/// the constraint system, allowing type information to flow from the
/// subexpression outward but not the other way.
///
/// One-way expressions are generally implicit and synthetic, introduced by
/// the type checker. However, there is a built-in expression of the
/// form \c Builtin.one_way(x) that forms a one-way constraint coming out
/// of expression `x` that can be used for testing purposes.
class OneWayExpr : public Expr {
Expr *SubExpr;

public:
/// Construct an implicit one-way expression from the given subexpression.
OneWayExpr(Expr *subExpr)
: Expr(ExprKind::OneWay, /*isImplicit=*/true), SubExpr(subExpr) { }

SourceLoc getLoc() const { return SubExpr->getLoc(); }
SourceRange getSourceRange() const { return SubExpr->getSourceRange(); }

Expr *getSubExpr() const { return SubExpr; }
void setSubExpr(Expr *subExpr) { SubExpr = subExpr; }

static bool classof(const Expr *E) {
return E->getKind() == ExprKind::OneWay;
}
};

class TypeJoinExpr final : public Expr,
private llvm::TrailingObjects<TypeJoinExpr, Expr *> {
friend TrailingObjects;
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/ExprNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ EXPR(KeyPath, Expr)
EXPR(CurrentContextIsolation, Expr)
EXPR(SingleValueStmt, Expr)
UNCHECKED_EXPR(KeyPathDot, Expr)
UNCHECKED_EXPR(OneWay, Expr)
EXPR(Tap, Expr)
UNCHECKED_EXPR(TypeJoin, Expr)
EXPR(MacroExpansion, Expr)
Expand Down
11 changes: 0 additions & 11 deletions include/swift/Sema/Constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ enum class ConstraintKind : char {
/// The key path type is chosen based on the selection of overloads for the
/// member references along the path.
KeyPath,
/// The first type will be equal to the second type, but only when the
/// second type has been fully determined (and mapped down to a concrete
/// type). At that point, this constraint will be treated like an `Equal`
/// constraint.
OneWayEqual,
/// If there is no contextual info e.g. `_ = { 42 }` default first type
/// to a second type. This is effectively a `Defaultable` constraint
/// which one significant difference:
Expand Down Expand Up @@ -680,7 +675,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
case ConstraintKind::DynamicCallableApplicableFunction:
case ConstraintKind::BindOverload:
case ConstraintKind::OptionalObject:
case ConstraintKind::OneWayEqual:
case ConstraintKind::FallbackType:
case ConstraintKind::UnresolvedMemberChainBase:
case ConstraintKind::PackElementOf:
Expand Down Expand Up @@ -826,11 +820,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
/// from the rest of the constraint system.
bool isIsolated() const { return IsIsolated; }

/// Whether this is a one-way constraint.
bool isOneWayConstraint() const {
return Kind == ConstraintKind::OneWayEqual;
}

/// Retrieve the overload choice for an overload-binding constraint.
OverloadChoice getOverloadChoice() const {
assert(Kind == ConstraintKind::BindOverload);
Expand Down
11 changes: 0 additions & 11 deletions include/swift/Sema/ConstraintGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,6 @@ class ConstraintGraph {
/// The constraints in this component.
TinyPtrVector<Constraint *> constraints;

/// The set of components that this component depends on, such that
/// the partial solutions of the those components need to be available
/// before this component can be solved.
///
SmallVector<unsigned, 2> dependencies;

public:
Component(unsigned solutionIndex) : solutionIndex(solutionIndex) { }

Expand All @@ -353,11 +347,6 @@ class ConstraintGraph {
return constraints;
}

/// Records a component which this component depends on.
void recordDependency(const Component &component);

ArrayRef<unsigned> getDependencies() const { return dependencies; }

unsigned getNumDisjunctions() const { return numDisjunctions; }
};

Expand Down
7 changes: 0 additions & 7 deletions include/swift/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -4504,7 +4504,6 @@ class ConstraintSystem {
/// \returns a possibly-sanitized initializer, or null if an error occurred.
[[nodiscard]]
Type generateConstraints(Pattern *P, ConstraintLocatorBuilder locator,
bool bindPatternVarsOneWay,
PatternBindingDecl *patternBinding,
unsigned patternIndex);

Expand Down Expand Up @@ -5012,12 +5011,6 @@ class ConstraintSystem {
TypeMatchOptions flags,
ConstraintLocatorBuilder locator);

/// Attempt to simplify a one-way constraint.
SolutionKind simplifyOneWayConstraint(ConstraintKind kind,
Type first, Type second,
TypeMatchOptions flags,
ConstraintLocatorBuilder locator);

/// Simplify an equality constraint between result and base types of
/// an unresolved member chain.
SolutionKind simplifyUnresolvedMemberChainBaseConstraint(
Expand Down
56 changes: 17 additions & 39 deletions include/swift/Sema/SyntacticElementTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ class SyntacticElementTarget {
/// Whether the expression result will be discarded at the end.
bool isDiscarded;

/// Whether to bind the variables encountered within the pattern to
/// fresh type variables via one-way constraints.
bool bindPatternVarsOneWay;

union {
struct {
/// The pattern binding declaration for an initialization, if any.
Expand Down Expand Up @@ -165,10 +161,9 @@ class SyntacticElementTarget {
ForEachStmt *stmt;
DeclContext *dc;
Pattern *pattern;
bool ignoreWhereClause;
GenericEnvironment *packElementEnv;
ForEachStmtInfo info;
} forEachStmt;
} forEachPreamble;

PatternBindingDecl *patternBinding;
};
Expand Down Expand Up @@ -246,35 +241,33 @@ class SyntacticElementTarget {
}

SyntacticElementTarget(ForEachStmt *stmt, DeclContext *dc,
bool ignoreWhereClause,
GenericEnvironment *packElementEnv)
: kind(Kind::forEachPreamble) {
forEachStmt.stmt = stmt;
forEachStmt.dc = dc;
forEachStmt.ignoreWhereClause = ignoreWhereClause;
forEachStmt.packElementEnv = packElementEnv;
forEachPreamble.stmt = stmt;
forEachPreamble.dc = dc;
forEachPreamble.packElementEnv = packElementEnv;
}

/// Form a target for the initialization of a pattern from an expression.
static SyntacticElementTarget
forInitialization(Expr *initializer, DeclContext *dc, Type patternType,
Pattern *pattern, bool bindPatternVarsOneWay);
Pattern *pattern);

/// Form a target for the initialization of a pattern binding entry from
/// an expression.
static SyntacticElementTarget
forInitialization(Expr *initializer, Type patternType,
PatternBindingDecl *patternBinding,
unsigned patternBindingIndex, bool bindPatternVarsOneWay);
unsigned patternBindingIndex);

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

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

/// Form a target for a property with an attached property wrapper that is
Expand Down Expand Up @@ -376,7 +369,7 @@ class SyntacticElementTarget {
}

case Kind::forEachPreamble:
return forEachStmt.dc;
return forEachPreamble.dc;
}
llvm_unreachable("invalid decl context type");
}
Expand Down Expand Up @@ -500,16 +493,6 @@ class SyntacticElementTarget {
return false;
}

/// Whether to bind the types of any variables within the pattern via
/// one-way constraints.
bool shouldBindPatternVarsOneWay() const {
if (kind == Kind::expression)
return expression.bindPatternVarsOneWay;
if (kind == Kind::forEachPreamble)
return !ignoreForEachWhereClause() && forEachStmt.stmt->getWhere();
return false;
}

/// Whether or not an opaque value placeholder should be injected into the
/// first \c wrappedValue argument of an apply expression so the initializer
/// expression can be turned into a property wrapper generator function.
Expand Down Expand Up @@ -555,24 +538,19 @@ class SyntacticElementTarget {
return expression.initialization.patternBindingIndex;
}

bool ignoreForEachWhereClause() const {
assert(isForEachPreamble());
return forEachStmt.ignoreWhereClause;
}

GenericEnvironment *getPackElementEnv() const {
assert(isForEachPreamble());
return forEachStmt.packElementEnv;
return forEachPreamble.packElementEnv;
}

const ForEachStmtInfo &getForEachStmtInfo() const {
assert(isForEachPreamble());
return forEachStmt.info;
return forEachPreamble.info;
}

ForEachStmtInfo &getForEachStmtInfo() {
assert(isForEachPreamble());
return forEachStmt.info;
return forEachPreamble.info;
}

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

if (kind == Kind::forEachPreamble)
return forEachStmt.pattern;
return forEachPreamble.pattern;

return nullptr;
}
Expand All @@ -612,7 +590,7 @@ class SyntacticElementTarget {
}

if (kind == Kind::forEachPreamble) {
forEachStmt.pattern = pattern;
forEachPreamble.pattern = pattern;
return;
}

Expand Down Expand Up @@ -743,7 +721,7 @@ class SyntacticElementTarget {
return nullptr;

case Kind::forEachPreamble:
return forEachStmt.stmt;
return forEachPreamble.stmt;
}
llvm_unreachable("invalid case label type");
}
Expand Down Expand Up @@ -855,7 +833,7 @@ class SyntacticElementTarget {

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

Expand Down Expand Up @@ -898,7 +876,7 @@ class SyntacticElementTarget {
}

case Kind::forEachPreamble:
return forEachStmt.stmt->getStartLoc();
return forEachPreamble.stmt->getStartLoc();
}
llvm_unreachable("invalid target type");
}
Expand Down
6 changes: 0 additions & 6 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3339,12 +3339,6 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
printFoot();
}

void visitOneWayExpr(OneWayExpr *E, StringRef label) {
printCommon(E, "one_way_expr", label);
printRec(E->getSubExpr());
printFoot();
}

void visitTapExpr(TapExpr *E, StringRef label) {
printCommon(E, "tap_expr", label);
printDeclRefField(E->getVar(), "var");
Expand Down
4 changes: 0 additions & 4 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4884,10 +4884,6 @@ void PrintAST::visitCoerceExpr(CoerceExpr *expr) {
printType(expr->getCastType());
}

void PrintAST::visitOneWayExpr(OneWayExpr *expr) {
llvm_unreachable("Not representable in source code");
}

void PrintAST::printClosure(AbstractClosureExpr *closure, CaptureListExpr *captureList) {

}
Expand Down
12 changes: 0 additions & 12 deletions lib/AST/ASTWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,18 +1332,6 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
return E;
}

Expr *visitOneWayExpr(OneWayExpr *E) {
if (auto oldSubExpr = E->getSubExpr()) {
if (auto subExpr = doIt(oldSubExpr)) {
E->setSubExpr(subExpr);
} else {
return nullptr;
}
}

return E;
}

Expr *visitTapExpr(TapExpr *E) {
if (auto oldSubExpr = E->getSubExpr()) {
if (auto subExpr = doIt(oldSubExpr)) {
Expand Down
3 changes: 0 additions & 3 deletions lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ ConcreteDeclRef Expr::getReferencedDecl(bool stopAtParenExpr) const {
NO_REFERENCE(KeyPath);
NO_REFERENCE(KeyPathDot);
PASS_THROUGH_REFERENCE(CurrentContextIsolation, getActor);
PASS_THROUGH_REFERENCE(OneWay, getSubExpr);
NO_REFERENCE(Tap);
NO_REFERENCE(TypeJoin);
SIMPLE_REFERENCE(MacroExpansion, getMacroRef);
Expand Down Expand Up @@ -662,7 +661,6 @@ bool Expr::canAppendPostfixExpression(bool appendingPostfixOperator) const {
case ExprKind::Error:
case ExprKind::CodeCompletion:
case ExprKind::LazyInitializer:
case ExprKind::OneWay:
return false;

case ExprKind::NilLiteral:
Expand Down Expand Up @@ -1037,7 +1035,6 @@ bool Expr::isValidParentOfTypeExpr(Expr *typeExpr) const {
case ExprKind::ObjCSelector:
case ExprKind::KeyPath:
case ExprKind::KeyPathDot:
case ExprKind::OneWay:
case ExprKind::Tap:
case ExprKind::SingleValueStmt:
case ExprKind::TypeJoin:
Expand Down
Loading