Skip to content

Commit 522f4e4

Browse files
committed
AST: Replace recently-added IsInOut bit with simpler check, NFC
Thanks to @lattner for the suggestion.
1 parent 045bc16 commit 522f4e4

File tree

6 files changed

+6
-22
lines changed

6 files changed

+6
-22
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,6 @@ class alignas(1 << DeclAlignInBits) Decl {
288288
/// once (either in its declaration, or once later), making it immutable.
289289
unsigned IsLet : 1;
290290

291-
/// \brief Whether this is an 'inout' parameter; this is preferable
292-
/// to checking if the parameter type is an InOutType, because invalid
293-
/// inout parameters have an error type.
294-
unsigned IsInOut : 1;
295-
296291
/// \brief Whether this vardecl has an initial value bound to it in a way
297292
/// that isn't represented in the AST with an initializer in the pattern
298293
/// binding. This happens in cases like "for i in ...", switch cases, etc.
@@ -306,7 +301,7 @@ class alignas(1 << DeclAlignInBits) Decl {
306301
/// a.storage for lazy var a is a decl that cannot be accessed.
307302
unsigned IsUserAccessible : 1;
308303
};
309-
enum { NumVarDeclBits = NumAbstractStorageDeclBits + 6 };
304+
enum { NumVarDeclBits = NumAbstractStorageDeclBits + 5 };
310305
static_assert(NumVarDeclBits <= 32, "fits in an unsigned");
311306

312307
class EnumElementDeclBitfields {
@@ -4250,7 +4245,6 @@ class VarDecl : public AbstractStorageDecl {
42504245
VarDeclBits.IsUserAccessible = true;
42514246
VarDeclBits.IsStatic = IsStatic;
42524247
VarDeclBits.IsLet = IsLet;
4253-
VarDeclBits.IsInOut = false;
42544248
VarDeclBits.IsDebuggerVar = false;
42554249
VarDeclBits.HasNonPatternBindingInit = false;
42564250
setType(Ty);
@@ -4348,10 +4342,6 @@ class VarDecl : public AbstractStorageDecl {
43484342
bool isLet() const { return VarDeclBits.IsLet; }
43494343
void setLet(bool IsLet) { VarDeclBits.IsLet = IsLet; }
43504344

4351-
/// Is this an 'inout' parameter?
4352-
bool isInOut() const { return VarDeclBits.IsInOut; }
4353-
void setInOut(bool InOut) { VarDeclBits.IsInOut = InOut; }
4354-
43554345
/// Return true if this vardecl has an initial value bound to it in a way
43564346
/// that isn't represented in the AST with an initializer in the pattern
43574347
/// binding. This happens in cases like "for i in ...", switch cases, etc.

lib/Parse/ParsePattern.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,8 @@ mapParsedParameters(Parser &parser,
387387
// If a type was provided, create the type for the parameter.
388388
if (auto type = paramInfo.Type) {
389389
// If 'inout' was specified, turn the type into an in-out type.
390-
if (specifierKind == Parser::ParsedParameter::InOut) {
390+
if (specifierKind == Parser::ParsedParameter::InOut)
391391
type = new (ctx) InOutTypeRepr(type, paramInfo.LetVarInOutLoc);
392-
param->setInOut(true);
393-
}
394392

395393
param->getTypeLoc() = TypeLoc(type);
396394
} else if (paramContext != Parser::ParameterContextKind::Closure) {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,6 @@ Type swift::configureImplicitSelf(TypeChecker &tc,
11211121
// 'self' is 'let' for reference types (i.e., classes) or when 'self' is
11221122
// neither inout.
11231123
selfDecl->setLet(!selfTy->is<InOutType>());
1124-
selfDecl->setInOut(selfTy->is<InOutType>());
11251124
selfDecl->overwriteType(selfTy);
11261125

11271126
// Install the self type on the Parameter that contains it. This ensures that

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ static bool validateParameterType(ParamDecl *decl, DeclContext *DC,
781781
// If the param is not a 'let' and it is not an 'inout'.
782782
// It must be a 'var'. Provide helpful diagnostics like a shadow copy
783783
// in the function body to fix the 'var' attribute.
784-
if (!decl->isLet() && !decl->isInOut()) {
784+
if (!decl->isLet() && !Ty->is<InOutType>() && !hadError) {
785785
auto func = dyn_cast_or_null<AbstractFunctionDecl>(DC);
786786
diagnoseAndMigrateVarParameterToBody(decl, func, TC);
787787
decl->setInvalid();
@@ -829,7 +829,6 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL, DeclContext *DC,
829829

830830
checkTypeModifyingDeclAttributes(param);
831831
if (param->getType()->is<InOutType>()) {
832-
param->setInOut(true);
833832
param->setLet(false);
834833
}
835834
}
@@ -1101,7 +1100,6 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
11011100

11021101
checkTypeModifyingDeclAttributes(var);
11031102
if (type->is<InOutType>()) {
1104-
NP->getDecl()->setInOut(true);
11051103
NP->getDecl()->setLet(false);
11061104
}
11071105
if (var->getAttrs().hasAttribute<OwnershipAttr>())
@@ -1563,7 +1561,6 @@ bool TypeChecker::coerceParameterListToType(ParameterList *P, DeclContext *DC,
15631561

15641562
if (!ty->isMaterializable()) {
15651563
if (ty->is<InOutType>()) {
1566-
param->setInOut(true);
15671564
param->setLet(false);
15681565
} else if (param->hasName()) {
15691566
diagnose(param->getStartLoc(),

validation-test/IDE/crashers/069-swift-typechecker-typecheckparameterlist.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
func b(e:({#^A^#var e){

0 commit comments

Comments
 (0)