mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
AST: Replace recently-added IsInOut bit with simpler check, NFC
Thanks to @lattner for the suggestion.
This commit is contained in:
@@ -288,11 +288,6 @@ class alignas(1 << DeclAlignInBits) Decl {
|
|||||||
/// once (either in its declaration, or once later), making it immutable.
|
/// once (either in its declaration, or once later), making it immutable.
|
||||||
unsigned IsLet : 1;
|
unsigned IsLet : 1;
|
||||||
|
|
||||||
/// \brief Whether this is an 'inout' parameter; this is preferable
|
|
||||||
/// to checking if the parameter type is an InOutType, because invalid
|
|
||||||
/// inout parameters have an error type.
|
|
||||||
unsigned IsInOut : 1;
|
|
||||||
|
|
||||||
/// \brief Whether this vardecl has an initial value bound to it in a way
|
/// \brief Whether this vardecl has an initial value bound to it in a way
|
||||||
/// that isn't represented in the AST with an initializer in the pattern
|
/// that isn't represented in the AST with an initializer in the pattern
|
||||||
/// binding. This happens in cases like "for i in ...", switch cases, etc.
|
/// binding. This happens in cases like "for i in ...", switch cases, etc.
|
||||||
@@ -306,7 +301,7 @@ class alignas(1 << DeclAlignInBits) Decl {
|
|||||||
/// a.storage for lazy var a is a decl that cannot be accessed.
|
/// a.storage for lazy var a is a decl that cannot be accessed.
|
||||||
unsigned IsUserAccessible : 1;
|
unsigned IsUserAccessible : 1;
|
||||||
};
|
};
|
||||||
enum { NumVarDeclBits = NumAbstractStorageDeclBits + 6 };
|
enum { NumVarDeclBits = NumAbstractStorageDeclBits + 5 };
|
||||||
static_assert(NumVarDeclBits <= 32, "fits in an unsigned");
|
static_assert(NumVarDeclBits <= 32, "fits in an unsigned");
|
||||||
|
|
||||||
class EnumElementDeclBitfields {
|
class EnumElementDeclBitfields {
|
||||||
@@ -4250,7 +4245,6 @@ protected:
|
|||||||
VarDeclBits.IsUserAccessible = true;
|
VarDeclBits.IsUserAccessible = true;
|
||||||
VarDeclBits.IsStatic = IsStatic;
|
VarDeclBits.IsStatic = IsStatic;
|
||||||
VarDeclBits.IsLet = IsLet;
|
VarDeclBits.IsLet = IsLet;
|
||||||
VarDeclBits.IsInOut = false;
|
|
||||||
VarDeclBits.IsDebuggerVar = false;
|
VarDeclBits.IsDebuggerVar = false;
|
||||||
VarDeclBits.HasNonPatternBindingInit = false;
|
VarDeclBits.HasNonPatternBindingInit = false;
|
||||||
setType(Ty);
|
setType(Ty);
|
||||||
@@ -4348,10 +4342,6 @@ public:
|
|||||||
bool isLet() const { return VarDeclBits.IsLet; }
|
bool isLet() const { return VarDeclBits.IsLet; }
|
||||||
void setLet(bool IsLet) { VarDeclBits.IsLet = IsLet; }
|
void setLet(bool IsLet) { VarDeclBits.IsLet = IsLet; }
|
||||||
|
|
||||||
/// Is this an 'inout' parameter?
|
|
||||||
bool isInOut() const { return VarDeclBits.IsInOut; }
|
|
||||||
void setInOut(bool InOut) { VarDeclBits.IsInOut = InOut; }
|
|
||||||
|
|
||||||
/// Return true if this vardecl has an initial value bound to it in a way
|
/// Return true if this vardecl has an initial value bound to it in a way
|
||||||
/// that isn't represented in the AST with an initializer in the pattern
|
/// that isn't represented in the AST with an initializer in the pattern
|
||||||
/// binding. This happens in cases like "for i in ...", switch cases, etc.
|
/// binding. This happens in cases like "for i in ...", switch cases, etc.
|
||||||
|
|||||||
@@ -387,10 +387,8 @@ mapParsedParameters(Parser &parser,
|
|||||||
// If a type was provided, create the type for the parameter.
|
// If a type was provided, create the type for the parameter.
|
||||||
if (auto type = paramInfo.Type) {
|
if (auto type = paramInfo.Type) {
|
||||||
// If 'inout' was specified, turn the type into an in-out type.
|
// If 'inout' was specified, turn the type into an in-out type.
|
||||||
if (specifierKind == Parser::ParsedParameter::InOut) {
|
if (specifierKind == Parser::ParsedParameter::InOut)
|
||||||
type = new (ctx) InOutTypeRepr(type, paramInfo.LetVarInOutLoc);
|
type = new (ctx) InOutTypeRepr(type, paramInfo.LetVarInOutLoc);
|
||||||
param->setInOut(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
param->getTypeLoc() = TypeLoc(type);
|
param->getTypeLoc() = TypeLoc(type);
|
||||||
} else if (paramContext != Parser::ParameterContextKind::Closure) {
|
} else if (paramContext != Parser::ParameterContextKind::Closure) {
|
||||||
|
|||||||
@@ -1121,7 +1121,6 @@ Type swift::configureImplicitSelf(TypeChecker &tc,
|
|||||||
// 'self' is 'let' for reference types (i.e., classes) or when 'self' is
|
// 'self' is 'let' for reference types (i.e., classes) or when 'self' is
|
||||||
// neither inout.
|
// neither inout.
|
||||||
selfDecl->setLet(!selfTy->is<InOutType>());
|
selfDecl->setLet(!selfTy->is<InOutType>());
|
||||||
selfDecl->setInOut(selfTy->is<InOutType>());
|
|
||||||
selfDecl->overwriteType(selfTy);
|
selfDecl->overwriteType(selfTy);
|
||||||
|
|
||||||
// Install the self type on the Parameter that contains it. This ensures that
|
// Install the self type on the Parameter that contains it. This ensures that
|
||||||
|
|||||||
@@ -781,7 +781,7 @@ static bool validateParameterType(ParamDecl *decl, DeclContext *DC,
|
|||||||
// If the param is not a 'let' and it is not an 'inout'.
|
// If the param is not a 'let' and it is not an 'inout'.
|
||||||
// It must be a 'var'. Provide helpful diagnostics like a shadow copy
|
// It must be a 'var'. Provide helpful diagnostics like a shadow copy
|
||||||
// in the function body to fix the 'var' attribute.
|
// in the function body to fix the 'var' attribute.
|
||||||
if (!decl->isLet() && !decl->isInOut()) {
|
if (!decl->isLet() && !Ty->is<InOutType>() && !hadError) {
|
||||||
auto func = dyn_cast_or_null<AbstractFunctionDecl>(DC);
|
auto func = dyn_cast_or_null<AbstractFunctionDecl>(DC);
|
||||||
diagnoseAndMigrateVarParameterToBody(decl, func, TC);
|
diagnoseAndMigrateVarParameterToBody(decl, func, TC);
|
||||||
decl->setInvalid();
|
decl->setInvalid();
|
||||||
@@ -829,7 +829,6 @@ bool TypeChecker::typeCheckParameterList(ParameterList *PL, DeclContext *DC,
|
|||||||
|
|
||||||
checkTypeModifyingDeclAttributes(param);
|
checkTypeModifyingDeclAttributes(param);
|
||||||
if (param->getType()->is<InOutType>()) {
|
if (param->getType()->is<InOutType>()) {
|
||||||
param->setInOut(true);
|
|
||||||
param->setLet(false);
|
param->setLet(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1101,7 +1100,6 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
|
|||||||
|
|
||||||
checkTypeModifyingDeclAttributes(var);
|
checkTypeModifyingDeclAttributes(var);
|
||||||
if (type->is<InOutType>()) {
|
if (type->is<InOutType>()) {
|
||||||
NP->getDecl()->setInOut(true);
|
|
||||||
NP->getDecl()->setLet(false);
|
NP->getDecl()->setLet(false);
|
||||||
}
|
}
|
||||||
if (var->getAttrs().hasAttribute<OwnershipAttr>())
|
if (var->getAttrs().hasAttribute<OwnershipAttr>())
|
||||||
@@ -1563,7 +1561,6 @@ bool TypeChecker::coerceParameterListToType(ParameterList *P, DeclContext *DC,
|
|||||||
|
|
||||||
if (!ty->isMaterializable()) {
|
if (!ty->isMaterializable()) {
|
||||||
if (ty->is<InOutType>()) {
|
if (ty->is<InOutType>()) {
|
||||||
param->setInOut(true);
|
|
||||||
param->setLet(false);
|
param->setLet(false);
|
||||||
} else if (param->hasName()) {
|
} else if (param->hasName()) {
|
||||||
diagnose(param->getStartLoc(),
|
diagnose(param->getStartLoc(),
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
|
|
||||||
// REQUIRES: asserts
|
|
||||||
func b(e:({#^A^#var e){
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
|
||||||
|
// REQUIRES: asserts
|
||||||
|
func b(e:({#^A^#var e){
|
||||||
Reference in New Issue
Block a user