Skip to content

Commit c2c8abf

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 ee34fc0 commit c2c8abf

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
@@ -3732,6 +3732,11 @@ static StorageImplInfo classifyWithHasStorageAttr(VarDecl *var) {
37323732

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

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

lib/Serialization/Deserialization.cpp

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

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

39613962
{

0 commit comments

Comments
 (0)