@@ -3091,34 +3091,6 @@ bool AbstractStorageDecl::isSetterMutating() const {
3091
3091
IsSetterMutatingRequest{const_cast <AbstractStorageDecl *>(this )}, {});
3092
3092
}
3093
3093
3094
- StorageMutability
3095
- AbstractStorageDecl::mutability (const DeclContext *useDC,
3096
- const DeclRefExpr *base) const {
3097
- if (auto vd = dyn_cast<VarDecl>(this ))
3098
- return vd->mutability (useDC, base);
3099
-
3100
- auto sd = cast<SubscriptDecl>(this );
3101
- return sd->supportsMutation () ? StorageMutability::Mutable
3102
- : StorageMutability::Immutable;
3103
- }
3104
-
3105
- // / Determine the mutability of this storage declaration when
3106
- // / accessed from a given declaration context in Swift.
3107
- // /
3108
- // / This method differs only from 'mutability()' in its handling of
3109
- // / 'optional' storage requirements, which lack support for direct
3110
- // / writes in Swift.
3111
- StorageMutability
3112
- AbstractStorageDecl::mutabilityInSwift (const DeclContext *useDC,
3113
- const DeclRefExpr *base) const {
3114
- // TODO: Writing to an optional storage requirement is not supported in Swift.
3115
- if (getAttrs ().hasAttribute <OptionalAttr>()) {
3116
- return StorageMutability::Immutable;
3117
- }
3118
-
3119
- return mutability (useDC, base);
3120
- }
3121
-
3122
3094
OpaqueReadOwnership AbstractStorageDecl::getOpaqueReadOwnership () const {
3123
3095
ASTContext &ctx = getASTContext ();
3124
3096
return evaluateOrDefault (ctx.evaluator ,
@@ -7289,39 +7261,32 @@ Type VarDecl::getTypeInContext() const {
7289
7261
return getDeclContext ()->mapTypeIntoContext (getInterfaceType ());
7290
7262
}
7291
7263
7292
- // / Translate an "is mutable" bit into a StorageMutability value.
7293
- static StorageMutability storageIsMutable (bool isMutable) {
7294
- return isMutable ? StorageMutability::Mutable
7295
- : StorageMutability::Immutable;
7296
- }
7297
-
7298
7264
// / Returns whether the var is settable in the specified context: this
7299
7265
// / is either because it is a stored var, because it has a custom setter, or
7300
7266
// / is a let member in an initializer.
7301
- StorageMutability
7302
- VarDecl::mutability (const DeclContext *UseDC,
7303
- const DeclRefExpr *base) const {
7267
+ bool VarDecl::isSettable (const DeclContext *UseDC,
7268
+ const DeclRefExpr *base) const {
7304
7269
// Parameters are settable or not depending on their ownership convention.
7305
7270
if (auto *PD = dyn_cast<ParamDecl>(this ))
7306
- return storageIsMutable ( !PD->isImmutableInFunctionBody () );
7271
+ return !PD->isImmutableInFunctionBody ();
7307
7272
7308
7273
// If this is a 'var' decl, then we're settable if we have storage or a
7309
7274
// setter.
7310
7275
if (!isLet ()) {
7311
7276
if (hasInitAccessor ()) {
7312
7277
if (auto *ctor = dyn_cast_or_null<ConstructorDecl>(UseDC)) {
7313
7278
if (base && ctor->getImplicitSelfDecl () != base->getDecl ())
7314
- return storageIsMutable ( supportsMutation () );
7315
- return StorageMutability::Initializable ;
7279
+ return supportsMutation ();
7280
+ return true ;
7316
7281
}
7317
7282
}
7318
7283
7319
- return storageIsMutable ( supportsMutation () );
7284
+ return supportsMutation ();
7320
7285
}
7321
7286
7322
7287
// Static 'let's are always immutable.
7323
7288
if (isStatic ()) {
7324
- return StorageMutability::Immutable ;
7289
+ return false ;
7325
7290
}
7326
7291
7327
7292
//
@@ -7331,11 +7296,11 @@ VarDecl::mutability(const DeclContext *UseDC,
7331
7296
7332
7297
// Debugger expression 'let's are initialized through a side-channel.
7333
7298
if (isDebuggerVar ())
7334
- return StorageMutability::Immutable ;
7299
+ return false ;
7335
7300
7336
7301
// 'let's are only ever settable from a specific DeclContext.
7337
7302
if (UseDC == nullptr )
7338
- return StorageMutability::Immutable ;
7303
+ return false ;
7339
7304
7340
7305
// 'let' properties in structs/classes are only ever settable in their
7341
7306
// designated initializer(s) or by init accessors.
@@ -7347,64 +7312,61 @@ VarDecl::mutability(const DeclContext *UseDC,
7347
7312
// Check whether this property is part of `initializes` list,
7348
7313
// and allow assignment/mutation if so. DI would be responsible
7349
7314
// for checking for re-assignment.
7350
- if ( accessor->isInitAccessor () &&
7315
+ return accessor->isInitAccessor () &&
7351
7316
llvm::is_contained (accessor->getInitializedProperties (),
7352
- const_cast <VarDecl *>(this )))
7353
- return StorageMutability::Initializable;
7354
-
7355
- return StorageMutability::Immutable;
7317
+ const_cast <VarDecl *>(this ));
7356
7318
}
7357
7319
7358
7320
auto *CD = dyn_cast<ConstructorDecl>(UseDC);
7359
- if (!CD) return StorageMutability::Immutable ;
7360
-
7321
+ if (!CD) return false ;
7322
+
7361
7323
auto *CDC = CD->getDeclContext ();
7362
7324
7363
7325
// 'let' properties are not valid inside protocols.
7364
7326
if (CDC->getExtendedProtocolDecl ())
7365
- return StorageMutability::Immutable ;
7327
+ return false ;
7366
7328
7367
7329
// If this init is defined inside of the same type (or in an extension
7368
7330
// thereof) as the let property, then it is mutable.
7369
7331
if (CDC->getSelfNominalTypeDecl () !=
7370
7332
getDeclContext ()->getSelfNominalTypeDecl ())
7371
- return StorageMutability::Immutable ;
7333
+ return false ;
7372
7334
7373
7335
if (base && CD->getImplicitSelfDecl () != base->getDecl ())
7374
- return StorageMutability::Immutable ;
7336
+ return false ;
7375
7337
7376
7338
// If this is a convenience initializer (i.e. one that calls
7377
7339
// self.init), then let properties are never mutable in it. They are
7378
7340
// only mutable in designated initializers.
7379
7341
auto initKindAndExpr = CD->getDelegatingOrChainedInitKind ();
7380
7342
if (initKindAndExpr.initKind == BodyInitKind::Delegating)
7381
- return StorageMutability::Immutable ;
7343
+ return false ;
7382
7344
7383
- return StorageMutability::Initializable ;
7345
+ return true ;
7384
7346
}
7385
7347
7386
7348
// If the 'let' has a value bound to it but has no PBD, then it is
7387
7349
// already initializedand not settable.
7388
7350
if (getParentPatternBinding () == nullptr )
7389
- return StorageMutability::Immutable ;
7351
+ return false ;
7390
7352
7391
7353
// If the 'let' has an explicitly written initializer with a pattern binding,
7392
7354
// then it isn't settable.
7393
7355
if (isParentInitialized ())
7394
- return StorageMutability::Immutable ;
7356
+ return false ;
7395
7357
7396
7358
// Normal lets (e.g. globals) are only mutable in the context of the
7397
7359
// declaration. To handle top-level code properly, we look through
7398
7360
// the TopLevelCode decl on the use (if present) since the vardecl may be
7399
7361
// one level up.
7400
7362
if (getDeclContext () == UseDC)
7401
- return StorageMutability::Initializable ;
7363
+ return true ;
7402
7364
7403
7365
if (isa<TopLevelCodeDecl>(UseDC) &&
7404
7366
getDeclContext () == UseDC->getParent ())
7405
- return StorageMutability::Initializable ;
7367
+ return true ;
7406
7368
7407
- return StorageMutability::Immutable ;
7369
+ return false ;
7408
7370
}
7409
7371
7410
7372
bool VarDecl::isLazilyInitializedGlobal () const {
0 commit comments