Skip to content

Commit 123447d

Browse files
committed
Don’t add HasStorageAttr to ABI-only decls
It’s unnecessary, shouldn’t be serialized into module interfaces, and Swift doesn’t know how to compute it for an ABI-only decl since it doesn’t have accessors or an initial value. No tests because enforcement isn’t in yet.
1 parent 63be84a commit 123447d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3733,6 +3733,11 @@ static StorageImplInfo classifyWithHasStorageAttr(VarDecl *var) {
37333733

37343734
bool HasStorageRequest::evaluate(Evaluator &evaluator,
37353735
AbstractStorageDecl *storage) const {
3736+
// ABI decl inherits this from API.
3737+
auto abiRole = ABIRoleInfo(storage);
3738+
if (!abiRole.providesAPI() && abiRole.getCounterpart())
3739+
return abiRole.getCounterpart()->hasStorage();
3740+
37363741
// Parameters are always stored.
37373742
if (isa<ParamDecl>(storage))
37383743
return true;
@@ -3818,7 +3823,11 @@ void HasStorageRequest::cacheResult(bool hasStorage) const {
38183823
return;
38193824

38203825
if (auto varDecl = dyn_cast<VarDecl>(decl)) {
3821-
if (hasStorage && !varDecl->getAttrs().hasAttribute<HasStorageAttr>())
3826+
auto abiRole = ABIRoleInfo(varDecl);
3827+
bool abiOnly = !abiRole.providesAPI() && abiRole.getCounterpart();
3828+
3829+
if (hasStorage && !abiOnly &&
3830+
!varDecl->getAttrs().hasAttribute<HasStorageAttr>())
38223831
varDecl->getAttrs().add(new (varDecl->getASTContext())
38233832
HasStorageAttr(/*isImplicit=*/true));
38243833
}

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4025,7 +4025,8 @@ class DeclDeserializer {
40254025
AddAttribute(new (ctx) OverrideAttr(SourceLoc()));
40264026

40274027
// Add the @_hasStorage attribute if this var has storage.
4028-
if (var->hasStorage())
4028+
// (Unless it's an ABI-only decl--they shouldn't have a HasStorageAttr.)
4029+
if (var->hasStorage() && ABIDeclCounterpartID == 0)
40294030
AddAttribute(new (ctx) HasStorageAttr(/*isImplicit:*/true));
40304031

40314032
{

0 commit comments

Comments
 (0)