Skip to content

Commit 85537fd

Browse files
committed
Murder ExprHandle in cold blood. NFC
ExprHandle is a relic from a horrible time when expressions made their way into the type system via default arguments. It's been unnecessary for a long time, so get rid of it.
1 parent 4eac3ea commit 85537fd

20 files changed

+23
-112
lines changed

include/swift/AST/AST.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "swift/AST/Builtins.h"
2323
#include "swift/AST/Decl.h"
2424
#include "swift/AST/Expr.h"
25-
#include "swift/AST/ExprHandle.h"
2625
#include "swift/AST/Initializer.h"
2726
#include "swift/AST/Module.h"
2827
#include "swift/AST/ParameterList.h"

include/swift/AST/Decl.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "swift/AST/ClangNode.h"
2222
#include "swift/AST/ConcreteDeclRef.h"
2323
#include "swift/AST/DefaultArgumentKind.h"
24-
#include "swift/AST/ExprHandle.h"
2524
#include "swift/AST/GenericSignature.h"
2625
#include "swift/AST/LazyResolver.h"
2726
#include "swift/AST/TypeAlignments.h"
@@ -4277,7 +4276,7 @@ class ParamDecl : public VarDecl {
42774276
SourceLoc LetVarInOutLoc;
42784277

42794278
/// The default value, if any, along with whether this is varargs.
4280-
llvm::PointerIntPair<ExprHandle *, 1, bool> DefaultValueAndIsVariadic;
4279+
llvm::PointerIntPair<Expr *, 1> DefaultValueAndIsVariadic;
42814280

42824281
/// True if the type is implicitly specified in the source, but this has an
42834282
/// apparently valid typeRepr. This is used in accessors, which look like:
@@ -4323,10 +4322,10 @@ class ParamDecl : public VarDecl {
43234322
defaultArgumentKind = K;
43244323
}
43254324

4326-
void setDefaultValue(ExprHandle *H) {
4327-
DefaultValueAndIsVariadic.setPointer(H);
4325+
void setDefaultValue(Expr *E) {
4326+
DefaultValueAndIsVariadic.setPointer(E);
43284327
}
4329-
ExprHandle *getDefaultValue() const {
4328+
Expr *getDefaultValue() const {
43304329
return DefaultValueAndIsVariadic.getPointer();
43314330
}
43324331

include/swift/AST/ExprHandle.h

Lines changed: 0 additions & 63 deletions
This file was deleted.

include/swift/AST/TypeRepr.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace swift {
3232
class DeclContext;
3333
class IdentTypeRepr;
3434
class ValueDecl;
35-
class ExprHandle;
3635
class NamedTypeRepr;
3736

3837
enum class TypeReprKind : uint8_t {

include/swift/AST/Types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ namespace swift {
4242
class AssociatedTypeDecl;
4343
class ASTContext;
4444
class ClassDecl;
45-
class ExprHandle;
4645
class GenericTypeParamDecl;
4746
class GenericTypeParamType;
4847
class GenericParamList;

include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ class Parser {
970970
TypeRepr *Type = nullptr;
971971

972972
/// The default argument for this parameter.
973-
ExprHandle *DefaultArg = nullptr;
973+
Expr *DefaultArg = nullptr;
974974

975975
/// True if we emitted a parse error about this parameter.
976976
bool isInvalid = false;

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "swift/AST/ConcreteDeclRef.h"
2323
#include "swift/AST/DiagnosticEngine.h"
2424
#include "swift/AST/DiagnosticsSema.h"
25-
#include "swift/AST/ExprHandle.h"
2625
#include "swift/AST/ForeignErrorConvention.h"
2726
#include "swift/AST/GenericEnvironment.h"
2827
#include "swift/AST/KnownProtocols.h"
@@ -3663,15 +3662,6 @@ CanType ArchetypeType::getAnyOpened(Type existential) {
36633662
return ArchetypeType::getOpened(existential);
36643663
}
36653664

3666-
void *ExprHandle::operator new(size_t Bytes, ASTContext &C,
3667-
unsigned Alignment) {
3668-
return C.Allocate(Bytes, Alignment);
3669-
}
3670-
3671-
ExprHandle *ExprHandle::get(ASTContext &Context, Expr *E) {
3672-
return new (Context) ExprHandle(E);
3673-
}
3674-
36753665
void TypeLoc::setInvalidType(ASTContext &C) {
36763666
TAndValidBit.setPointerAndInt(ErrorType::get(C), true);
36773667
}

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ namespace {
831831

832832
if (auto init = P->getDefaultValue()) {
833833
OS << " expression=\n";
834-
printRec(init->getExpr());
834+
printRec(init);
835835
}
836836

837837
OS << ')';

lib/AST/ASTWalker.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555

5656
#include "swift/AST/ASTWalker.h"
5757
#include "swift/AST/ASTVisitor.h"
58-
#include "swift/AST/ExprHandle.h"
5958
#include "swift/AST/ParameterList.h"
6059
#include "swift/AST/PrettyStackTrace.h"
6160
using namespace swift;
@@ -899,9 +898,9 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
899898
return true;
900899

901900
if (auto *E = P->getDefaultValue()) {
902-
auto res = doIt(E->getExpr());
901+
auto res = doIt(E);
903902
if (!res) return true;
904-
E->setExpr(res, E->alreadyChecked());
903+
P->setDefaultValue(res);
905904
}
906905
}
907906

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3823,7 +3823,7 @@ SourceRange ParamDecl::getSourceRange() const {
38233823
// but we don't have that location info. Extend the back of the range to the
38243824
// location of the default argument, or the typeloc if they are valid.
38253825
if (auto expr = getDefaultValue()) {
3826-
auto endLoc = expr->getExpr()->getEndLoc();
3826+
auto endLoc = expr->getEndLoc();
38273827
if (endLoc.isValid())
38283828
return SourceRange(range.Start, endLoc);
38293829
}

lib/AST/Parameter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "swift/AST/ParameterList.h"
1919
#include "swift/AST/ASTContext.h"
2020
#include "swift/AST/Expr.h"
21-
#include "swift/AST/ExprHandle.h"
2221
using namespace swift;
2322

2423
/// TODO: unique and reuse the () parameter list in ASTContext, it is common to

lib/AST/TypeRepr.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "swift/AST/TypeRepr.h"
1919
#include "swift/AST/ASTContext.h"
2020
#include "swift/AST/ASTVisitor.h"
21-
#include "swift/AST/ExprHandle.h"
2221
#include "swift/AST/Expr.h"
2322
#include "swift/AST/Module.h"
2423
#include "swift/AST/Types.h"

lib/Parse/ParsePattern.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "swift/Parse/CodeCompletionCallbacks.h"
1818
#include "swift/Parse/Parser.h"
1919
#include "swift/AST/ASTWalker.h"
20-
#include "swift/AST/ExprHandle.h"
2120
#include "swift/Basic/StringExtras.h"
2221
#include "llvm/ADT/SmallString.h"
2322
#include "llvm/ADT/StringMap.h"
@@ -26,11 +25,11 @@ using namespace swift;
2625

2726
/// \brief Determine the kind of a default argument given a parsed
2827
/// expression that has not yet been type-checked.
29-
static DefaultArgumentKind getDefaultArgKind(ExprHandle *init) {
30-
if (!init || !init->getExpr())
28+
static DefaultArgumentKind getDefaultArgKind(Expr *init) {
29+
if (!init)
3130
return DefaultArgumentKind::None;
3231

33-
auto magic = dyn_cast<MagicIdentifierLiteralExpr>(init->getExpr());
32+
auto magic = dyn_cast<MagicIdentifierLiteralExpr>(init);
3433
if (!magic)
3534
return DefaultArgumentKind::Normal;
3635

@@ -58,7 +57,7 @@ void Parser::DefaultArgumentInfo::setFunctionContext(DeclContext *DC) {
5857
static ParserStatus parseDefaultArgument(Parser &P,
5958
Parser::DefaultArgumentInfo *defaultArgs,
6059
unsigned argIndex,
61-
ExprHandle *&init,
60+
Expr *&init,
6261
Parser::ParameterContextKind paramContext) {
6362
SourceLoc equalLoc = P.consumeToken(tok::equal);
6463

@@ -119,7 +118,7 @@ static ParserStatus parseDefaultArgument(Parser &P,
119118
if (initR.isNull())
120119
return makeParserError();
121120

122-
init = ExprHandle::get(P.Context, initR.get());
121+
init = initR.get();
123122
return ParserStatus();
124123
}
125124

@@ -352,7 +351,7 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
352351
if (param.EllipsisLoc.isValid() && param.DefaultArg) {
353352
// The range of the complete default argument.
354353
SourceRange defaultArgRange;
355-
if (auto init = param.DefaultArg->getExpr())
354+
if (auto init = param.DefaultArg)
356355
defaultArgRange = SourceRange(param.EllipsisLoc, init->getEndLoc());
357356

358357
diagnose(EqualLoc, diag::parameter_vararg_default)

lib/Parse/ParseType.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "swift/Parse/Parser.h"
1818
#include "swift/AST/Attr.h"
19-
#include "swift/AST/ExprHandle.h"
2019
#include "swift/AST/TypeLoc.h"
2120
#include "swift/Parse/Lexer.h"
2221
#include "swift/Parse/CodeCompletionCallbacks.h"

lib/SILGen/SILGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,9 @@ void SILGenModule::emitDefaultArgGenerators(SILDeclRef::Loc decl,
10231023
unsigned index = 0;
10241024
for (auto paramList : paramLists) {
10251025
for (auto param : *paramList) {
1026-
if (auto handle = param->getDefaultValue())
1026+
if (auto defaultArg = param->getDefaultValue())
10271027
emitDefaultArgGenerator(SILDeclRef::getDefaultArgGenerator(decl, index),
1028-
handle->getExpr());
1028+
defaultArg);
10291029
++index;
10301030
}
10311031
}

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class FindCapturedVars : public ASTWalker {
400400
for (auto *paramList : AFD->getParameterLists())
401401
for (auto param : *paramList) {
402402
if (auto E = param->getDefaultValue())
403-
E->getExpr()->walk(*this);
403+
E->walk(*this);
404404
}
405405
return false;
406406
}

lib/Sema/TypeCheckPattern.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "TypeChecker.h"
1919
#include "GenericTypeResolver.h"
2020
#include "swift/Basic/StringExtras.h"
21-
#include "swift/AST/ExprHandle.h"
2221
#include "swift/AST/ASTWalker.h"
2322
#include "swift/AST/ASTVisitor.h"
2423
#include "swift/AST/NameLookup.h"

lib/Sema/TypeCheckStmt.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "swift/Subsystems.h"
2020
#include "swift/AST/ASTWalker.h"
2121
#include "swift/AST/ASTVisitor.h"
22-
#include "swift/AST/ExprHandle.h"
2322
#include "swift/AST/Identifier.h"
2423
#include "swift/AST/NameLookup.h"
2524
#include "swift/AST/PrettyStackTrace.h"
@@ -1212,8 +1211,7 @@ static void checkDefaultArguments(TypeChecker &tc, ParameterList *params,
12121211
param->getType()->is<ErrorType>())
12131212
continue;
12141213

1215-
auto defaultValueHandle = param->getDefaultValue();
1216-
Expr *e = defaultValueHandle->getExpr();
1214+
Expr *e = param->getDefaultValue();
12171215

12181216
// Re-use an existing initializer context if possible.
12191217
auto existingContext = e->findExistingInitializerContext();
@@ -1230,12 +1228,10 @@ static void checkDefaultArguments(TypeChecker &tc, ParameterList *params,
12301228
}
12311229

12321230
// Type-check the initializer, then flag that we did so.
1233-
if (tc.typeCheckExpression(e, initContext,
1234-
TypeLoc::withoutLoc(param->getType()),
1235-
CTP_DefaultParameter))
1236-
defaultValueHandle->setExpr(defaultValueHandle->getExpr(), true);
1237-
else
1238-
defaultValueHandle->setExpr(e, true);
1231+
if (!tc.typeCheckExpression(e, initContext,
1232+
TypeLoc::withoutLoc(param->getType()),
1233+
CTP_DefaultParameter))
1234+
param->setDefaultValue(e);
12391235

12401236
tc.checkInitializerErrorHandling(initContext, e);
12411237

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "swift/Strings.h"
2323
#include "swift/AST/ASTVisitor.h"
2424
#include "swift/AST/ASTWalker.h"
25-
#include "swift/AST/ExprHandle.h"
2625
#include "swift/AST/ForeignErrorConvention.h"
2726
#include "swift/AST/NameLookup.h"
2827
#include "swift/AST/PrettyStackTrace.h"

lib/Sema/TypeChecker.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "swift/AST/ASTWalker.h"
2121
#include "swift/AST/ASTVisitor.h"
2222
#include "swift/AST/Attr.h"
23-
#include "swift/AST/ExprHandle.h"
2423
#include "swift/AST/Identifier.h"
2524
#include "swift/AST/ModuleLoader.h"
2625
#include "swift/AST/NameLookup.h"

0 commit comments

Comments
 (0)