Skip to content

Removing code for 'initializes' and 'accesses' attributes old syntax #68073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions include/swift/AST/Attr.def
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,6 @@ SIMPLE_DECL_ATTR(_marker, Marker,
SIMPLE_DECL_ATTR(reasync, AtReasync,
OnProtocol | ConcurrencyOnly | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
110)
DECL_ATTR(initializes, Initializes,
OnAccessor | ABIStableToAdd | ABIStableToRemove | APIBreakingToAdd | APIBreakingToRemove,
111)
DECL_ATTR(accesses, Accesses,
OnAccessor | ABIStableToAdd | ABIStableToRemove | APIBreakingToAdd | APIBreakingToRemove,
113)
SIMPLE_DECL_ATTR(_unsafeInheritExecutor, UnsafeInheritExecutor,
OnFunc | UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIBreakingToRemove,
114)
Expand Down
62 changes: 0 additions & 62 deletions include/swift/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1555,68 +1555,6 @@ class SpecializeAttr final
}
};

class InitializesAttr final
: public DeclAttribute,
private llvm::TrailingObjects<InitializesAttr, Identifier> {
friend TrailingObjects;

size_t numProperties;

InitializesAttr(SourceLoc atLoc, SourceRange range,
ArrayRef<Identifier> properties);

public:
static InitializesAttr *create(ASTContext &ctx,
SourceLoc atLoc, SourceRange range,
ArrayRef<Identifier> properties);

size_t numTrailingObjects(OverloadToken<Identifier>) const {
return numProperties;
}

unsigned getNumProperties() const { return numProperties; }

ArrayRef<Identifier> getProperties() const {
return {getTrailingObjects<Identifier>(), numProperties};
}

ArrayRef<VarDecl *> getPropertyDecls(AccessorDecl *attachedTo) const;

static bool classof(const DeclAttribute *DA) {
return DA->getKind() == DAK_Initializes;
}
};

class AccessesAttr final
: public DeclAttribute,
private llvm::TrailingObjects<AccessesAttr, Identifier> {
friend TrailingObjects;

size_t numProperties;

AccessesAttr(SourceLoc atLoc, SourceRange range,
ArrayRef<Identifier> properties);

public:
static AccessesAttr *create(ASTContext &ctx,
SourceLoc atLoc, SourceRange range,
ArrayRef<Identifier> properties);

size_t numTrailingObjects(OverloadToken<Identifier>) const {
return numProperties;
}

ArrayRef<Identifier> getProperties() const {
return {getTrailingObjects<Identifier>(), numProperties};
}

ArrayRef<VarDecl *> getPropertyDecls(AccessorDecl *attachedTo) const;

static bool classof(const DeclAttribute *DA) {
return DA->getKind() == DAK_Accesses;
}
};

class StorageRestrictionsAttr final
: public DeclAttribute,
private llvm::TrailingObjects<StorageRestrictionsAttr, Identifier> {
Expand Down
6 changes: 0 additions & 6 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -7397,12 +7397,6 @@ ERROR(init_accessor_can_refer_only_to_properties,none,
" to stored properties",
(DescriptiveDeclKind, DeclNameRef))

ERROR(init_accessor_initializes_attribute_on_other_declaration,none,
"initializes(...) attribute could only be used with init accessors",
())
ERROR(init_accessor_accesses_attribute_on_other_declaration,none,
"accesses(...) attribute could only be used with init accessors",
())
ERROR(storage_restrictions_attribute_not_on_init_accessor,none,
"@storageRestrictions attribute could only be used with init accessors",
())
Expand Down
4 changes: 0 additions & 4 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1274,10 +1274,6 @@ class Parser {
AccessorKind currentKind,
SourceLoc const& currentLoc);

ParserStatus parseInitAccessorEffects(ParsedAccessors &accessors,
AccessorKind currentKind,
DeclAttributes &Attributes);

/// Parse accessors provided as a separate list, for use in macro
/// expansions.
void parseTopLevelAccessors(
Expand Down
56 changes: 0 additions & 56 deletions lib/AST/Attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1661,10 +1661,6 @@ StringRef DeclAttribute::getAttrName() const {
return "<<synthesized protocol>>";
case DAK_Specialize:
return "_specialize";
case DAK_Initializes:
return "initializes";
case DAK_Accesses:
return "accesses";
case DAK_StorageRestrictions:
return "storageRestrictions";
case DAK_Implements:
Expand Down Expand Up @@ -2450,38 +2446,6 @@ TransposeAttr *TransposeAttr::create(ASTContext &context, bool implicit,
std::move(originalName), parameterIndices);
}

InitializesAttr::InitializesAttr(SourceLoc atLoc, SourceRange range,
ArrayRef<Identifier> properties)
: DeclAttribute(DAK_Initializes, atLoc, range, /*implicit*/false),
numProperties(properties.size()) {
std::uninitialized_copy(properties.begin(), properties.end(),
getTrailingObjects<Identifier>());
}

InitializesAttr *
InitializesAttr::create(ASTContext &ctx, SourceLoc atLoc, SourceRange range,
ArrayRef<Identifier> properties) {
unsigned size = totalSizeToAlloc<Identifier>(properties.size());
void *mem = ctx.Allocate(size, alignof(InitializesAttr));
return new (mem) InitializesAttr(atLoc, range, properties);
}

AccessesAttr::AccessesAttr(SourceLoc atLoc, SourceRange range,
ArrayRef<Identifier> properties)
: DeclAttribute(DAK_Accesses, atLoc, range, /*implicit*/false),
numProperties(properties.size()) {
std::uninitialized_copy(properties.begin(), properties.end(),
getTrailingObjects<Identifier>());
}

AccessesAttr *
AccessesAttr::create(ASTContext &ctx, SourceLoc atLoc, SourceRange range,
ArrayRef<Identifier> properties) {
unsigned size = totalSizeToAlloc<Identifier>(properties.size());
void *mem = ctx.Allocate(size, alignof(AccessesAttr));
return new (mem) AccessesAttr(atLoc, range, properties);
}

StorageRestrictionsAttr::StorageRestrictionsAttr(
SourceLoc AtLoc, SourceRange Range, ArrayRef<Identifier> initializes,
ArrayRef<Identifier> accesses, bool Implicit)
Expand Down Expand Up @@ -2663,26 +2627,6 @@ DeclAttributes::getEffectiveSendableAttr() const {
return assumedAttr;
}

ArrayRef<VarDecl *>
InitializesAttr::getPropertyDecls(AccessorDecl *attachedTo) const {
auto &ctx = attachedTo->getASTContext();
return evaluateOrDefault(
ctx.evaluator,
InitAccessorReferencedVariablesRequest{
const_cast<InitializesAttr *>(this), attachedTo, getProperties()},
{});
}

ArrayRef<VarDecl *>
AccessesAttr::getPropertyDecls(AccessorDecl *attachedTo) const {
auto &ctx = attachedTo->getASTContext();
return evaluateOrDefault(
ctx.evaluator,
InitAccessorReferencedVariablesRequest{const_cast<AccessesAttr *>(this),
attachedTo, getProperties()},
{});
}

ArrayRef<VarDecl *> StorageRestrictionsAttr::getInitializesProperties(
AccessorDecl *attachedTo) const {
auto &ctx = attachedTo->getASTContext();
Expand Down
8 changes: 0 additions & 8 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9567,10 +9567,6 @@ ArrayRef<VarDecl *> AccessorDecl::getInitializedProperties() const {
if (auto *SR = getAttrs().getAttribute<StorageRestrictionsAttr>())
return SR->getInitializesProperties(const_cast<AccessorDecl *>(this));

// Fallback to old effect style declaration.
if (auto *initAttr = getAttrs().getAttribute<InitializesAttr>())
return initAttr->getPropertyDecls(const_cast<AccessorDecl *>(this));

return {};
}

Expand All @@ -9580,10 +9576,6 @@ ArrayRef<VarDecl *> AccessorDecl::getAccessedProperties() const {
if (auto *SR = getAttrs().getAttribute<StorageRestrictionsAttr>())
return SR->getAccessesProperties(const_cast<AccessorDecl *>(this));

// Fallback to old effect style declaration.
if (auto *accessAttr = getAttrs().getAttribute<AccessesAttr>())
return accessAttr->getPropertyDecls(const_cast<AccessorDecl *>(this));

return {};
}

Expand Down
74 changes: 0 additions & 74 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3523,14 +3523,6 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
break;
}

case DAK_Initializes: {
llvm_unreachable("InitializesAttr not yet implemented");
}

case DAK_Accesses: {
llvm_unreachable("AccessesAttr not yet implemented");
}

case DAK_StorageRestrictions: {
ParserResult<StorageRestrictionsAttr> Attr =
parseStorageRestrictionsAttribute(AtLoc, Loc);
Expand Down Expand Up @@ -7446,71 +7438,6 @@ ParserStatus Parser::parseGetEffectSpecifier(ParsedAccessors &accessors,
return Status;
}

template <typename EffectAttr>
static ParserStatus parseInitAccessorEffect(Parser &P,
DeclAttributes &attributes,
StringRef attrName) {
ParserStatus status;

if (P.Tok.isContextualKeyword(attrName)) {
auto effectLoc = P.consumeToken();
if (!P.Tok.is(tok::l_paren)) {
P.diagnose(P.Tok.getLoc(), diag::attr_expected_lparen,
attrName, true);
status.setIsParseError();
return status;
}

// Consume '('
P.consumeToken();

bool hasNextProperty = false;
// Consume the identifier list
SmallVector<Identifier, 4> properties;
do {
Identifier propertyName;
SourceLoc propertyNameLoc;
if (P.parseIdentifier(propertyName, propertyNameLoc,
diag::init_accessor_expected_name,
/*diagnoseDollarPrefix=*/true)) {
status.setIsParseError();
return status;
}

properties.push_back(propertyName);

// Parse the comma, if the list continues.
hasNextProperty = P.consumeIf(tok::comma);
} while (hasNextProperty);

if (!P.Tok.is(tok::r_paren)) {
P.diagnose(P.Tok.getLoc(), diag::attr_expected_rparen,
attrName, true);
status.setIsParseError();
return status;
}

// Consume ')'
SourceLoc rParenLoc = P.consumeToken();

auto *attr = EffectAttr::create(P.Context, SourceLoc(),
SourceRange(effectLoc, rParenLoc),
properties);
attributes.add(attr);
}

return status;
}

ParserStatus Parser::parseInitAccessorEffects(ParsedAccessors &accessors,
AccessorKind currentKind,
DeclAttributes &attrs) {
ParserStatus status;
status |= parseInitAccessorEffect<InitializesAttr>(*this, attrs, "initializes");
status |= parseInitAccessorEffect<AccessesAttr>(*this, attrs, "accesses");
return status;
}

bool Parser::parseAccessorAfterIntroducer(
SourceLoc Loc, AccessorKind Kind, ParsedAccessors &accessors,
bool &hasEffectfulGet, ParameterList *Indices, bool &parsingLimitedSyntax,
Expand All @@ -7525,7 +7452,6 @@ bool Parser::parseAccessorAfterIntroducer(
SourceLoc throwsLoc;
Status |= parseGetEffectSpecifier(accessors, asyncLoc, throwsLoc,
hasEffectfulGet, Kind, Loc);
Status |= parseInitAccessorEffects(accessors, Kind, Attributes);

// Set up a function declaration.
auto accessor =
Expand Down
40 changes: 0 additions & 40 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
void visitDiscardableResultAttr(DiscardableResultAttr *attr);
void visitDynamicReplacementAttr(DynamicReplacementAttr *attr);
void visitTypeEraserAttr(TypeEraserAttr *attr);
void visitInitializesAttr(InitializesAttr *attr);
void visitAccessesAttr(AccessesAttr *attr);
void visitStorageRestrictionsAttr(StorageRestrictionsAttr *attr);
void visitImplementsAttr(ImplementsAttr *attr);
void visitNoMetadataAttr(NoMetadataAttr *attr);
Expand Down Expand Up @@ -3573,44 +3571,6 @@ void AttributeChecker::visitTypeEraserAttr(TypeEraserAttr *attr) {
(void)attr->hasViableTypeEraserInit(cast<ProtocolDecl>(D));
}

void AttributeChecker::visitInitializesAttr(InitializesAttr *attr) {
auto *accessor = dyn_cast<AccessorDecl>(D);
if (!accessor || accessor->getAccessorKind() != AccessorKind::Init) {
diagnose(attr->getLocation(),
diag::init_accessor_initializes_attribute_on_other_declaration);
return;
}

(void)attr->getPropertyDecls(accessor);
}

void AttributeChecker::visitAccessesAttr(AccessesAttr *attr) {
auto *accessor = dyn_cast<AccessorDecl>(D);
if (!accessor || accessor->getAccessorKind() != AccessorKind::Init) {
diagnose(attr->getLocation(),
diag::init_accessor_accesses_attribute_on_other_declaration);
return;
}

// Check whether there are any intersections between initializes(...) and
// accesses(...) attributes.

llvm::Optional<ArrayRef<VarDecl *>> initializedProperties;
if (auto *initAttr = D->getAttrs().getAttribute<InitializesAttr>()) {
initializedProperties.emplace(initAttr->getPropertyDecls(accessor));
}

if (initializedProperties) {
for (auto *property : attr->getPropertyDecls(accessor)) {
if (llvm::is_contained(*initializedProperties, property)) {
diagnose(attr->getLocation(),
diag::init_accessor_property_both_init_and_accessed,
property->getName());
}
}
}
}

void AttributeChecker::visitStorageRestrictionsAttr(StorageRestrictionsAttr *attr) {
auto *accessor = dyn_cast<AccessorDecl>(D);
if (!accessor || accessor->getAccessorKind() != AccessorKind::Init) {
Expand Down
2 changes: 0 additions & 2 deletions lib/Sema/TypeCheckDeclOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1577,8 +1577,6 @@ namespace {
UNINTERESTING_ATTR(ObjCMembers)
UNINTERESTING_ATTR(ObjCRuntimeName)
UNINTERESTING_ATTR(RestatedObjCConformance)
UNINTERESTING_ATTR(Initializes)
UNINTERESTING_ATTR(Accesses)
UNINTERESTING_ATTR(StorageRestrictions)
UNINTERESTING_ATTR(Implements)
UNINTERESTING_ATTR(StaticInitializeObjCMetadata)
Expand Down
30 changes: 0 additions & 30 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5584,36 +5584,6 @@ llvm::Error DeclDeserializer::deserializeDeclCommon() {
break;
}

case decls_block::Initializes_DECL_ATTR: {
ArrayRef<uint64_t> rawPropertyIDs;
serialization::decls_block::InitializesDeclAttrLayout::
readRecord(scratch, rawPropertyIDs);

SmallVector<Identifier, 4> properties;
for (auto rawID : rawPropertyIDs) {
properties.push_back(MF.getIdentifier(rawID));
}

Attr = InitializesAttr::create(ctx, SourceLoc(), SourceRange(),
properties);
break;
}

case decls_block::Accesses_DECL_ATTR: {
ArrayRef<uint64_t> rawPropertyIDs;
serialization::decls_block::AccessesDeclAttrLayout::
readRecord(scratch, rawPropertyIDs);

SmallVector<Identifier, 4> properties;
for (auto rawID : rawPropertyIDs) {
properties.push_back(MF.getIdentifier(rawID));
}

Attr = AccessesAttr::create(ctx, SourceLoc(), SourceRange(),
properties);
break;
}

case decls_block::StorageRestrictions_DECL_ATTR: {
unsigned numInitializesProperties;
ArrayRef<uint64_t> rawPropertyIDs;
Expand Down
Loading