Skip to content

Commit 2778d8e

Browse files
committed
Revert "[5.8] Introduce if/switch expressions"
1 parent 62b24df commit 2778d8e

File tree

74 files changed

+412
-6011
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+412
-6011
lines changed

include/swift/AST/ASTScope.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,6 @@ class PatternEntryInitializerScope final : public AbstractPatternEntryScope {
955955

956956
protected:
957957
bool lookupLocalsOrMembers(DeclConsumer) const override;
958-
bool isLabeledStmtLookupTerminator() const override;
959958
};
960959

961960
/// The scope introduced by a conditional clause initializer in an

include/swift/AST/ASTTypeIDZone.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ SWIFT_TYPEID(Fingerprint)
2626
SWIFT_TYPEID(GenericSignature)
2727
SWIFT_TYPEID(ImplicitImportList)
2828
SWIFT_TYPEID(ImplicitMemberAction)
29-
SWIFT_TYPEID(IsSingleValueStmtResult)
3029
SWIFT_TYPEID(ParamSpecifier)
3130
SWIFT_TYPEID(PropertyWrapperAuxiliaryVariables)
3231
SWIFT_TYPEID(PropertyWrapperInitializerInfo)

include/swift/AST/ASTTypeIDs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class GenericParamList;
4141
class GenericSignature;
4242
class GenericTypeParamType;
4343
class InfixOperatorDecl;
44-
class IsSingleValueStmtResult;
4544
class IterableDeclContext;
4645
class ModuleDecl;
4746
struct ImplicitImportList;

include/swift/AST/CASTBridging.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ void *SwiftVarDecl_create(void *ctx, BridgedIdentifier _Nullable name,
169169
void *initExpr, void *loc, _Bool isStatic,
170170
_Bool isLet, void *dc);
171171

172-
void *SingleValueStmtExpr_createWithWrappedBranches(void *ctx, void *S,
173-
void *DC, _Bool mustBeExpr);
174-
175172
void *IfStmt_create(void *ctx, void *ifLoc, void *cond, void *_Nullable then,
176173
void *_Nullable elseLoc, void *_Nullable elseStmt);
177174

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,29 +1080,6 @@ ERROR(ternary_expr_cases_mismatch,none,
10801080
"result values in '? :' expression have mismatching types %0 and %1",
10811081
(Type, Type))
10821082

1083-
// Statements as expressions
1084-
ERROR(single_value_stmt_branches_mismatch,none,
1085-
"branches have mismatching types %0 and %1",
1086-
(Type, Type))
1087-
ERROR(single_value_stmt_out_of_place,none,
1088-
"'%0' may only be used as expression in return, throw, or as the source "
1089-
"of an assignment",
1090-
(StmtKind))
1091-
ERROR(single_value_stmt_must_be_unlabeled,none,
1092-
"'%0' cannot have a jump label when used as expression",
1093-
(StmtKind))
1094-
ERROR(if_expr_must_be_syntactically_exhaustive,none,
1095-
"'if' must have an unconditional 'else' to be used as expression",
1096-
())
1097-
ERROR(single_value_stmt_branch_must_end_in_throw,none,
1098-
"non-expression branch of '%0' expression may only end with a 'throw'",
1099-
(StmtKind))
1100-
ERROR(cannot_jump_in_single_value_stmt,none,
1101-
"cannot '%0' in '%1' when used as expression",
1102-
(StmtKind, StmtKind))
1103-
ERROR(effect_marker_on_single_value_stmt,none,
1104-
"'%0' may not be used on '%1' expression", (StringRef, StmtKind))
1105-
11061083
ERROR(did_not_call_function_value,none,
11071084
"function value was used as a property; add () to call it",
11081085
())

include/swift/AST/Expr.h

Lines changed: 3 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -4350,10 +4350,6 @@ class OpaqueValueExpr : public Expr {
43504350
Bits.OpaqueValueExpr.IsPlaceholder = isPlaceholder;
43514351
}
43524352

4353-
static OpaqueValueExpr *
4354-
createImplicit(ASTContext &ctx, Type Ty, bool isPlaceholder = false,
4355-
AllocationArena arena = AllocationArena::Permanent);
4356-
43574353
/// Whether this opaque value expression represents a placeholder that
43584354
/// is injected before type checking to act as a placeholder for some
43594355
/// value to be specified later.
@@ -5969,63 +5965,6 @@ class KeyPathDotExpr : public Expr {
59695965
}
59705966
};
59715967

5972-
/// An expression that may wrap a statement which produces a single value.
5973-
class SingleValueStmtExpr : public Expr {
5974-
public:
5975-
enum class Kind {
5976-
If, Switch
5977-
};
5978-
5979-
private:
5980-
Stmt *S;
5981-
DeclContext *DC;
5982-
5983-
SingleValueStmtExpr(Stmt *S, DeclContext *DC)
5984-
: Expr(ExprKind::SingleValueStmt, /*isImplicit*/ true), S(S), DC(DC) {}
5985-
5986-
public:
5987-
/// Creates a new SingleValueStmtExpr wrapping a statement.
5988-
static SingleValueStmtExpr *create(ASTContext &ctx, Stmt *S, DeclContext *DC);
5989-
5990-
/// Creates a new SingleValueStmtExpr wrapping a statement, and recursively
5991-
/// attempts to wrap any branches of that statement that can become single
5992-
/// value statement expressions.
5993-
///
5994-
/// If \p mustBeExpr is true, branches will be eagerly wrapped even if they
5995-
/// may not be valid SingleValueStmtExprs (which Sema will later diagnose).
5996-
static SingleValueStmtExpr *createWithWrappedBranches(ASTContext &ctx,
5997-
Stmt *S,
5998-
DeclContext *DC,
5999-
bool mustBeExpr);
6000-
6001-
/// Attempt to look through valid parent expressions to a child
6002-
/// SingleValueStmtExpr.
6003-
static SingleValueStmtExpr *tryDigOutSingleValueStmtExpr(Expr *E);
6004-
6005-
/// Retrieve the wrapped statement.
6006-
Stmt *getStmt() const { return S; }
6007-
void setStmt(Stmt *newS) { S = newS; }
6008-
6009-
/// Retrieve the kind of statement being wrapped.
6010-
Kind getStmtKind() const;
6011-
6012-
/// Retrieve the complete set of branches for the underlying statement.
6013-
ArrayRef<Stmt *> getBranches(SmallVectorImpl<Stmt *> &scratch) const;
6014-
6015-
/// Retrieve the single expression branches of the statement, excluding
6016-
/// branches that either have multiple expressions, or have statements.
6017-
ArrayRef<Expr *>
6018-
getSingleExprBranches(SmallVectorImpl<Expr *> &scratch) const;
6019-
6020-
DeclContext *getDeclContext() const { return DC; }
6021-
6022-
SourceRange getSourceRange() const;
6023-
6024-
static bool classof(const Expr *E) {
6025-
return E->getKind() == ExprKind::SingleValueStmt;
6026-
}
6027-
};
6028-
60295968
/// Expression node that effects a "one-way" constraint in
60305969
/// the constraint system, allowing type information to flow from the
60315970
/// subexpression outward but not the other way.
@@ -6059,10 +5998,6 @@ class TypeJoinExpr final : public Expr,
60595998

60605999
DeclRefExpr *Var;
60616000

6062-
/// If this is joining the expression branches for a SingleValueStmtExpr,
6063-
/// this holds the expr node. Otherwise, it is \c nullptr.
6064-
SingleValueStmtExpr *SVE;
6065-
60666001
size_t numTrailingObjects() const {
60676002
return getNumElements();
60686003
}
@@ -6071,34 +6006,11 @@ class TypeJoinExpr final : public Expr,
60716006
return { getTrailingObjects<Expr *>(), getNumElements() };
60726007
}
60736008

6074-
TypeJoinExpr(llvm::PointerUnion<DeclRefExpr *, TypeBase *> result,
6075-
ArrayRef<Expr *> elements, SingleValueStmtExpr *SVE);
6076-
6077-
static TypeJoinExpr *
6078-
createImpl(ASTContext &ctx,
6079-
llvm::PointerUnion<DeclRefExpr *, TypeBase *> varOrType,
6080-
ArrayRef<Expr *> elements,
6081-
AllocationArena arena = AllocationArena::Permanent,
6082-
SingleValueStmtExpr *SVE = nullptr);
6009+
TypeJoinExpr(DeclRefExpr *var, ArrayRef<Expr *> elements);
60836010

60846011
public:
6085-
static TypeJoinExpr *
6086-
create(ASTContext &ctx, DeclRefExpr *var, ArrayRef<Expr *> exprs,
6087-
AllocationArena arena = AllocationArena::Permanent) {
6088-
return createImpl(ctx, var, exprs, arena);
6089-
}
6090-
6091-
static TypeJoinExpr *
6092-
create(ASTContext &ctx, Type joinType, ArrayRef<Expr *> exprs,
6093-
AllocationArena arena = AllocationArena::Permanent) {
6094-
return createImpl(ctx, joinType.getPointer(), exprs, arena);
6095-
}
6096-
6097-
/// Create a join for the branch types of a SingleValueStmtExpr.
6098-
static TypeJoinExpr *
6099-
forBranchesOfSingleValueStmtExpr(ASTContext &ctx, Type joinType,
6100-
SingleValueStmtExpr *SVE,
6101-
AllocationArena arena);
6012+
static TypeJoinExpr *create(ASTContext &ctx, DeclRefExpr *var,
6013+
ArrayRef<Expr *> exprs);
61026014

61036015
SourceLoc getLoc() const { return SourceLoc(); }
61046016
SourceRange getSourceRange() const { return SourceRange(); }
@@ -6122,10 +6034,6 @@ class TypeJoinExpr final : public Expr,
61226034
getMutableElements()[i] = E;
61236035
}
61246036

6125-
/// If this is joining the expression branches for a SingleValueStmtExpr,
6126-
/// this returns the expr node. Otherwise, returns \c nullptr.
6127-
SingleValueStmtExpr *getSingleValueStmtExpr() const { return SVE; }
6128-
61296037
unsigned getNumElements() const { return Bits.TypeJoinExpr.NumElements; }
61306038

61316039
static bool classof(const Expr *E) {

include/swift/AST/ExprNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ EXPR(LazyInitializer, Expr)
204204
EXPR(EditorPlaceholder, Expr)
205205
EXPR(ObjCSelector, Expr)
206206
EXPR(KeyPath, Expr)
207-
EXPR(SingleValueStmt, Expr)
208207
UNCHECKED_EXPR(KeyPathDot, Expr)
209208
UNCHECKED_EXPR(OneWay, Expr)
210209
EXPR(Tap, Expr)

include/swift/AST/Stmt.h

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@ class ASTContext;
3535
class ASTWalker;
3636
class Decl;
3737
class DeclContext;
38-
class Evaluator;
3938
class Expr;
4039
class FuncDecl;
4140
class Pattern;
4241
class PatternBindingDecl;
4342
class VarDecl;
4443
class CaseStmt;
4544
class DoCatchStmt;
46-
class IsSingleValueStmtResult;
4745
class SwitchStmt;
4846

4947
enum class StmtKind {
@@ -135,12 +133,7 @@ class alignas(8) Stmt : public ASTAllocated<Stmt> {
135133

136134
SourceRange getSourceRange() const;
137135
SourceLoc TrailingSemiLoc;
138-
139-
/// Whether the statement can produce a single value, and as such may be
140-
/// treated as an expression.
141-
IsSingleValueStmtResult mayProduceSingleValue(Evaluator &eval) const;
142-
IsSingleValueStmtResult mayProduceSingleValue(ASTContext &ctx) const;
143-
136+
144137
/// isImplicit - Determines whether this statement was implicitly-generated,
145138
/// rather than explicitly written in the AST.
146139
bool isImplicit() const { return Bits.Stmt.Implicit; }
@@ -211,10 +204,6 @@ class BraceStmt final : public Stmt,
211204

212205
ASTNode findAsyncNode();
213206

214-
/// If this brace is wrapping a single expression, returns it. Otherwise
215-
/// returns \c nullptr.
216-
Expr *getSingleExpressionElement() const;
217-
218207
static bool classof(const Stmt *S) { return S->getKind() == StmtKind::Brace; }
219208
};
220209

@@ -722,14 +711,7 @@ class IfStmt : public LabeledConditionalStmt {
722711

723712
Stmt *getElseStmt() const { return Else; }
724713
void setElseStmt(Stmt *s) { Else = s; }
725-
726-
/// Retrieve the complete set of branches for this if statement, including
727-
/// else if statements.
728-
ArrayRef<Stmt *> getBranches(SmallVectorImpl<Stmt *> &scratch) const;
729-
730-
/// Whether the if statement has an unconditional \c else.
731-
bool isSyntacticallyExhaustive() const;
732-
714+
733715
// Implement isa/cast/dyncast/etc.
734716
static bool classof(const Stmt *S) { return S->getKind() == StmtKind::If; }
735717
};
@@ -1301,10 +1283,7 @@ class SwitchStmt final : public LabeledStmt,
13011283
AsCaseStmtRange getCases() const {
13021284
return AsCaseStmtRange(getRawCases(), AsCaseStmtWithSkippingNonCaseStmts());
13031285
}
1304-
1305-
/// Retrieve the complete set of branches for this switch statement.
1306-
ArrayRef<Stmt *> getBranches(SmallVectorImpl<Stmt *> &scratch) const;
1307-
1286+
13081287
static bool classof(const Stmt *S) {
13091288
return S->getKind() == StmtKind::Switch;
13101289
}

0 commit comments

Comments
 (0)