Skip to content

Commit 158c782

Browse files
committed
[AST] Promote isNoImplicitCopy to Decl.
Move the predicate up from ParamDecl to Decl and use it everywhere in place of hasAttribute<NoImplicitCopyAttr>.
1 parent 477461b commit 158c782

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
986986
/// Check if this is a declaration defined at the top level of the Swift module
987987
bool isStdlibDecl() const;
988988

989+
bool isNoImplicitCopy() const {
990+
return getAttrs().hasAttribute<NoImplicitCopyAttr>();
991+
}
992+
989993
AvailabilityContext getAvailabilityForLinkage() const;
990994

991995
/// Whether this declaration or one of its outer contexts has the
@@ -5783,10 +5787,6 @@ class ParamDecl : public VarDecl {
57835787
setDefaultArgumentKind(K.argumentKind);
57845788
}
57855789

5786-
bool isNoImplicitCopy() const {
5787-
return getAttrs().hasAttribute<NoImplicitCopyAttr>();
5788-
}
5789-
57905790
/// Whether this parameter has a default argument expression available.
57915791
///
57925792
/// Note that this will return false for deserialized declarations, which only

lib/AST/ASTDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ namespace {
979979
break;
980980
}
981981

982-
if (P->getAttrs().hasAttribute<NoImplicitCopyAttr>())
982+
if (P->isNoImplicitCopy())
983983
OS << " noImplicitCopy";
984984

985985
if (P->getDefaultArgumentKind() != DefaultArgumentKind::None) {

lib/SILGen/SILGenDecl.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ class LetValueInitialization : public Initialization {
450450
LetValueInitialization(VarDecl *vd, SILGenFunction &SGF) : vd(vd) {
451451
const TypeLowering *lowering = nullptr;
452452
if (SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) &&
453-
vd->getAttrs().hasAttribute<NoImplicitCopyAttr>()) {
453+
vd->isNoImplicitCopy()) {
454454
lowering = &SGF.getTypeLowering(
455455
SILMoveOnlyWrappedType::get(vd->getType()->getCanonicalType()));
456456
} else {
@@ -487,8 +487,7 @@ class LetValueInitialization : public Initialization {
487487
// Make sure that we have a non-address only type when binding a
488488
// @_noImplicitCopy let.
489489
if (SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) &&
490-
lowering->isAddressOnly() &&
491-
vd->getAttrs().hasAttribute<NoImplicitCopyAttr>()) {
490+
lowering->isAddressOnly() && vd->isNoImplicitCopy()) {
492491
auto d = diag::noimplicitcopy_used_on_generic_or_existential;
493492
diagnose(SGF.getASTContext(), vd->getLoc(), d);
494493
}
@@ -569,8 +568,7 @@ class LetValueInitialization : public Initialization {
569568
// ... and we don't have a no implicit copy trivial type, just return
570569
// value.
571570
if (!SGF.getASTContext().LangOpts.Features.count(Feature::MoveOnly) ||
572-
!vd->getAttrs().hasAttribute<NoImplicitCopyAttr>() ||
573-
!value->getType().isTrivial(SGF.F))
571+
!vd->isNoImplicitCopy() || !value->getType().isTrivial(SGF.F))
574572
return value;
575573

576574
// Otherwise, we have a no implicit copy trivial type, so wrap it in the
@@ -626,7 +624,7 @@ class LetValueInitialization : public Initialization {
626624

627625
// Otherwise, if we do not have a no implicit copy variable, just follow
628626
// the "normal path": perform a lexical borrow if the lifetime is lexical.
629-
if (!vd->getAttrs().hasAttribute<NoImplicitCopyAttr>()) {
627+
if (!vd->isNoImplicitCopy()) {
630628
if (SGF.F.getLifetime(vd, value->getType()).isLexical())
631629
return SGF.B.createBeginBorrow(PrologueLoc, value, /*isLexical*/ true);
632630
else

0 commit comments

Comments
 (0)