Skip to content

Commit a6df4ef

Browse files
authored
Merge pull request #76878 from beccadax/abi-changed-your-name
2 parents e87c1c3 + 413c673 commit a6df4ef

File tree

73 files changed

+2353
-317
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2353
-317
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ BridgedDeclAttribute BridgedDeclAttribute_createSimple(
581581
BridgedASTContext cContext, BridgedDeclAttrKind cKind,
582582
BridgedSourceLoc cAtLoc, BridgedSourceLoc cNameLoc);
583583

584+
SWIFT_NAME("BridgedABIAttr.createParsed(_:atLoc:range:abiDecl:)")
585+
BridgedABIAttr BridgedABIAttr_createParsed(
586+
BridgedASTContext cContext, BridgedSourceLoc atLoc,
587+
BridgedSourceRange range, BridgedNullableDecl abiDecl);
588+
584589
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedAccessLevel {
585590
BridgedAccessLevelPrivate,
586591
BridgedAccessLevelFilePrivate,
@@ -918,8 +923,8 @@ BridgedUnavailableFromAsyncAttr BridgedUnavailableFromAsyncAttr_createParsed(
918923

919924
struct BridgedFingerprint;
920925

921-
SWIFT_NAME("BridgedDecl.setAttrs(self:_:)")
922-
void BridgedDecl_setAttrs(BridgedDecl decl, BridgedDeclAttributes attrs);
926+
SWIFT_NAME("BridgedDecl.attachParsedAttrs(self:_:)")
927+
void BridgedDecl_attachParsedAttrs(BridgedDecl decl, BridgedDeclAttributes attrs);
923928

924929
enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedStaticSpelling {
925930
BridgedStaticSpellingNone,

include/swift/AST/ASTBridgingWrappers.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
// Some of the base classes need to be nullable to allow them to be used as
7070
// optional parameters.
71-
AST_BRIDGING_WRAPPER_NONNULL(Decl)
71+
AST_BRIDGING_WRAPPER_NULLABLE(Decl)
7272
AST_BRIDGING_WRAPPER_NONNULL(DeclContext)
7373
AST_BRIDGING_WRAPPER_NONNULL(SourceFile)
7474
AST_BRIDGING_WRAPPER_NULLABLE(Stmt)

include/swift/AST/ASTContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ namespace llvm {
6767
}
6868

6969
namespace swift {
70+
class ABIAttr;
7071
class AbstractFunctionDecl;
7172
class ASTContext;
7273
enum class Associativity : unsigned char;

include/swift/AST/ASTMangler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ class ASTMangler : public Mangler {
209209
return tryMangleSubstitution(type.getPointer());
210210
}
211211

212+
protected:
213+
using Mangler::addSubstitution;
214+
void addSubstitution(const Decl *decl);
215+
216+
using Mangler::tryMangleSubstitution;
217+
bool tryMangleSubstitution(const Decl *decl);
218+
219+
public:
212220
std::string mangleClosureEntity(const AbstractClosureExpr *closure,
213221
SymbolKind SKind);
214222

include/swift/AST/ASTScope.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
142142
friend class IterableTypeBodyPortion;
143143
friend class ScopeCreator;
144144
friend class ASTSourceFileScope;
145+
friend class ABIAttributeScope;
145146
friend class Lowering::SILGenFunction;
146147

147148
#pragma mark - tree state
@@ -250,12 +251,15 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
250251

251252
void printRange(llvm::raw_ostream &out) const;
252253

254+
void printParents(llvm::raw_ostream &out) const;
255+
253256
protected:
254257
virtual void printSpecifics(llvm::raw_ostream &out) const {}
255258
virtual NullablePtr<const void> addressForPrinting() const;
256259

257260
public:
258261
SWIFT_DEBUG_DUMP;
262+
SWIFT_DEBUG_DUMPER(dumpParents());
259263

260264
void dumpOneScopeMapLocation(std::pair<unsigned, unsigned> lineColumn);
261265

@@ -302,6 +306,9 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
302306
SourceFile *sourceFile, SourceLoc loc,
303307
llvm::function_ref<bool(ASTScope::PotentialMacro)> consume);
304308

309+
static ABIAttr *lookupEnclosingABIAttributeScope(
310+
SourceFile *sourceFile, SourceLoc loc);
311+
305312
static CatchNode lookupCatchNode(ModuleDecl *module, SourceLoc loc);
306313

307314
/// Scopes that cannot bind variables may set this to true to create more
@@ -945,6 +952,40 @@ class CustomAttributeScope final : public ASTScopeImpl {
945952
}
946953
};
947954

955+
/// The scope for ABI attributes and their arguments.
956+
///
957+
/// Source locations for the attribute name and its arguments are in the
958+
/// custom attribute, so lookup is invoked from within the attribute
959+
/// itself.
960+
class ABIAttributeScope final : public ASTScopeImpl {
961+
public:
962+
ABIAttr *attr;
963+
Decl *decl;
964+
965+
ABIAttributeScope(ABIAttr *attr, Decl *decl)
966+
: ASTScopeImpl(ScopeKind::ABIAttribute), attr(attr), decl(decl) {}
967+
virtual ~ABIAttributeScope() {}
968+
969+
protected:
970+
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
971+
972+
public:
973+
SourceRange
974+
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
975+
NullablePtr<const void> addressForPrinting() const override { return decl; }
976+
977+
bool ignoreInDebugInfo() const override { return true; }
978+
979+
private:
980+
AnnotatedInsertionPoint
981+
expandAScopeThatCreatesANewInsertionPoint(ScopeCreator &);
982+
983+
public:
984+
static bool classof(const ASTScopeImpl *scope) {
985+
return scope->getKind() == ScopeKind::ABIAttribute;
986+
}
987+
};
988+
948989
/// PatternBindingDecl's (PBDs) are tricky (See the comment for \c
949990
/// PatternBindingDecl):
950991
///

include/swift/AST/ASTScopeNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ SCOPE_NODE(CaseLabelItem)
8989
SCOPE_NODE(CaseStmtBody)
9090
STMT_SCOPE_NODE(BraceStmt)
9191
EXPR_SCOPE_NODE(Try)
92+
DECL_ATTRIBUTE_SCOPE_NODE(ABIAttribute)
9293

9394
#undef DECL_ATTRIBUTE_SCOPE_NODE
9495
#undef EXPR_SCOPE_NODE

include/swift/AST/Attr.h

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "swift/AST/StorageImpl.h"
3333
#include "swift/Basic/Debug.h"
3434
#include "swift/Basic/EnumTraits.h"
35+
#include "swift/Basic/Feature.h"
3536
#include "swift/Basic/InlineBitfield.h"
3637
#include "swift/Basic/Located.h"
3738
#include "swift/Basic/OptimizationMode.h"
@@ -491,6 +492,8 @@ class DeclAttribute : public AttributeBase {
491492
LLVM_READNONE
492493
static bool canAttributeAppearOnDeclKind(DeclAttrKind DAK, DeclKind DK);
493494

495+
static std::optional<Feature> getRequiredFeature(DeclAttrKind DK);
496+
494497
/// Returns the source name of the attribute, without the @ or any arguments.
495498
StringRef getAttrName() const;
496499

@@ -2875,6 +2878,12 @@ template <typename ATTR, bool AllowInvalid> struct ToAttributeKind {
28752878
return cast<ATTR>(Attr);
28762879
return std::nullopt;
28772880
}
2881+
2882+
std::optional<ATTR *> operator()(DeclAttribute *Attr) {
2883+
if (isa<ATTR>(Attr) && (Attr->isValid() || AllowInvalid))
2884+
return cast<ATTR>(Attr);
2885+
return std::nullopt;
2886+
}
28782887
};
28792888

28802889
/// The @_allowFeatureSuppression(Foo, Bar) attribute. The feature
@@ -2908,6 +2917,31 @@ class AllowFeatureSuppressionAttr final
29082917
UNIMPLEMENTED_CLONE(AllowFeatureSuppressionAttr)
29092918
};
29102919

2920+
/// Defines the @abi attribute.
2921+
class ABIAttr : public DeclAttribute {
2922+
public:
2923+
ABIAttr(Decl *abiDecl, SourceLoc AtLoc, SourceRange Range, bool Implicit)
2924+
: DeclAttribute(DeclAttrKind::ABI, AtLoc, Range, Implicit),
2925+
abiDecl(abiDecl)
2926+
{ }
2927+
2928+
ABIAttr(Decl *abiDecl, bool Implicit)
2929+
: ABIAttr(abiDecl, SourceLoc(), SourceRange(), Implicit) {}
2930+
2931+
/// The declaration which will be used to compute a mangled name.
2932+
///
2933+
/// \note For a \c VarDecl with a parent \c PatternBindingDecl , this should
2934+
/// point to the parent \c PatternBindingDecl . (That accommodates the way
2935+
/// sibling \c VarDecl s share attributes.)
2936+
Decl *abiDecl;
2937+
2938+
static bool classof(const DeclAttribute *DA) {
2939+
return DA->getKind() == DeclAttrKind::ABI;
2940+
}
2941+
2942+
UNIMPLEMENTED_CLONE(ABIAttr)
2943+
};
2944+
29112945
/// Attributes that may be applied to declarations.
29122946
class DeclAttributes {
29132947
/// Linked list of declaration attributes.
@@ -3047,17 +3081,25 @@ class DeclAttributes {
30473081
}
30483082

30493083
public:
3050-
template <typename ATTR, bool AllowInvalid>
3084+
template <typename ATTR, typename Iterator, bool AllowInvalid>
30513085
using AttributeKindRange =
3052-
OptionalTransformRange<iterator_range<const_iterator>,
3086+
OptionalTransformRange<iterator_range<Iterator>,
30533087
ToAttributeKind<ATTR, AllowInvalid>,
3054-
const_iterator>;
3088+
Iterator>;
3089+
3090+
/// Return a range with all attributes in DeclAttributes with AttrKind
3091+
/// ATTR.
3092+
template <typename ATTR, bool AllowInvalid = false>
3093+
AttributeKindRange<ATTR, const_iterator, AllowInvalid> getAttributes() const {
3094+
return AttributeKindRange<ATTR, const_iterator, AllowInvalid>(
3095+
make_range(begin(), end()), ToAttributeKind<ATTR, AllowInvalid>());
3096+
}
30553097

30563098
/// Return a range with all attributes in DeclAttributes with AttrKind
30573099
/// ATTR.
30583100
template <typename ATTR, bool AllowInvalid = false>
3059-
AttributeKindRange<ATTR, AllowInvalid> getAttributes() const {
3060-
return AttributeKindRange<ATTR, AllowInvalid>(
3101+
AttributeKindRange<ATTR, iterator, AllowInvalid> getAttributes() {
3102+
return AttributeKindRange<ATTR, iterator, AllowInvalid>(
30613103
make_range(begin(), end()), ToAttributeKind<ATTR, AllowInvalid>());
30623104
}
30633105

0 commit comments

Comments
 (0)