Skip to content

Commit bbd8442

Browse files
Merge pull request #83400 from swiftlang/jepa-main
Address `llvm::PointerUnion::{is,get}` deprecations
2 parents eeda39a + fec049e commit bbd8442

File tree

139 files changed

+655
-600
lines changed

Some content is hidden

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

139 files changed

+655
-600
lines changed

include/swift/AST/ASTNode.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ namespace swift {
4545
enum class PatternKind : uint8_t;
4646
enum class StmtKind;
4747

48-
struct ASTNode
49-
: public llvm::PointerUnion<Expr *, Stmt *, Decl *, Pattern *, TypeRepr *,
50-
StmtConditionElement *, CaseLabelItem *> {
48+
namespace detail {
49+
using ASTNodeBase =
50+
llvm::PointerUnion<Expr *, Stmt *, Decl *, Pattern *, TypeRepr *,
51+
StmtConditionElement *, CaseLabelItem *>;
52+
} // end namespace detail
53+
54+
struct ASTNode : public detail::ASTNodeBase {
55+
using Base = detail::ASTNodeBase;
56+
5157
// Inherit the constructors from PointerUnion.
5258
using PointerUnion::PointerUnion;
5359

@@ -109,6 +115,14 @@ namespace swift {
109115

110116
namespace llvm {
111117
using swift::ASTNode;
118+
119+
/// `isa`, `dyn_cast`, `cast` for `ASTNode`.
120+
template <typename To>
121+
struct CastInfo<To, ASTNode> : public CastInfo<To, ASTNode::Base> {};
122+
template <typename To>
123+
struct CastInfo<To, const ASTNode>
124+
: public CastInfo<To, const ASTNode::Base> {};
125+
112126
template <> struct DenseMapInfo<ASTNode> {
113127
static inline ASTNode getEmptyKey() {
114128
return DenseMapInfo<swift::Expr *>::getEmptyKey();

include/swift/AST/AnyFunctionRef.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ class AnyFunctionRef {
7272
CaptureInfo getCaptureInfo() const {
7373
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
7474
return AFD->getCaptureInfo();
75-
return TheFunction.get<AbstractClosureExpr *>()->getCaptureInfo();
75+
return cast<AbstractClosureExpr *>(TheFunction)->getCaptureInfo();
7676
}
7777

7878
ParameterList *getParameters() const {
7979
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
8080
return AFD->getParameters();
81-
return TheFunction.get<AbstractClosureExpr *>()->getParameters();
81+
return cast<AbstractClosureExpr *>(TheFunction)->getParameters();
8282
}
8383

8484
bool hasExternalPropertyWrapperParameters() const {
@@ -90,7 +90,7 @@ class AnyFunctionRef {
9090
Type getType() const {
9191
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
9292
return AFD->getInterfaceType();
93-
return TheFunction.get<AbstractClosureExpr *>()->getType();
93+
return cast<AbstractClosureExpr *>(TheFunction)->getType();
9494
}
9595

9696
Type getBodyResultType() const {
@@ -99,7 +99,7 @@ class AnyFunctionRef {
9999
return FD->mapTypeIntoContext(FD->getResultInterfaceType());
100100
return TupleType::getEmpty(AFD->getASTContext());
101101
}
102-
return TheFunction.get<AbstractClosureExpr *>()->getResultType();
102+
return cast<AbstractClosureExpr *>(TheFunction)->getResultType();
103103
}
104104

105105
ArrayRef<AnyFunctionType::Yield>
@@ -115,7 +115,7 @@ class AnyFunctionRef {
115115
BraceStmt *getBody() const {
116116
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
117117
return AFD->getBody();
118-
auto *ACE = TheFunction.get<AbstractClosureExpr *>();
118+
auto *ACE = cast<AbstractClosureExpr *>(TheFunction);
119119
if (auto *CE = dyn_cast<ClosureExpr>(ACE))
120120
return CE->getBody();
121121
return cast<AutoClosureExpr>(ACE)->getBody();
@@ -127,7 +127,7 @@ class AnyFunctionRef {
127127
return;
128128
}
129129

130-
auto *ACE = TheFunction.get<AbstractClosureExpr *>();
130+
auto *ACE = cast<AbstractClosureExpr *>(TheFunction);
131131
if (auto *CE = dyn_cast<ClosureExpr>(ACE)) {
132132
CE->setBody(stmt);
133133
CE->setBodyState(ClosureExpr::BodyState::Parsed);
@@ -143,7 +143,7 @@ class AnyFunctionRef {
143143
return;
144144
}
145145

146-
auto *ACE = TheFunction.get<AbstractClosureExpr *>();
146+
auto *ACE = cast<AbstractClosureExpr *>(TheFunction);
147147
if (auto *CE = dyn_cast<ClosureExpr>(ACE)) {
148148
CE->setBody(stmt);
149149
CE->setBodyState(ClosureExpr::BodyState::TypeChecked);
@@ -168,7 +168,7 @@ class AnyFunctionRef {
168168
DeclContext *getAsDeclContext() const {
169169
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
170170
return AFD;
171-
return TheFunction.get<AbstractClosureExpr *>();
171+
return cast<AbstractClosureExpr *>(TheFunction);
172172
}
173173

174174
AbstractFunctionDecl *getAbstractFunctionDecl() const {

include/swift/AST/AvailabilityDomain.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ class AvailabilityDomain final {
120120
AvailabilityDomain(Storage storage) : storage(storage) {};
121121

122122
std::optional<InlineDomain> getInlineDomain() const {
123-
return storage.is<InlineDomainPtr>()
123+
return isa<InlineDomainPtr>(storage)
124124
? static_cast<std::optional<InlineDomain>>(
125-
storage.get<InlineDomainPtr>())
125+
cast<InlineDomainPtr>(storage))
126126
: std::nullopt;
127127
}
128128

@@ -203,7 +203,7 @@ class AvailabilityDomain final {
203203
/// the domain. Returns `nullptr` otherwise.
204204
const CustomAvailabilityDomain *getCustomDomain() const {
205205
if (isCustom())
206-
return storage.get<const CustomAvailabilityDomain *>();
206+
return cast<const CustomAvailabilityDomain *>(storage);
207207
return nullptr;
208208
}
209209

@@ -401,25 +401,25 @@ class AvailabilityDomainOrIdentifier {
401401
: storage(domain) {};
402402

403403
bool isDomain() const {
404-
return storage.getPointer().is<AvailabilityDomain>();
404+
return isa<AvailabilityDomain>(storage.getPointer());
405405
}
406-
bool isIdentifier() const { return storage.getPointer().is<Identifier>(); }
406+
bool isIdentifier() const { return isa<Identifier>(storage.getPointer()); }
407407

408408
/// Overwrites the existing domain or identifier with the given domain.
409409
void setDomain(AvailabilityDomain domain) { storage = Storage(domain); }
410410

411411
/// Returns the resolved domain, or `std::nullopt` if there isn't one.
412412
std::optional<AvailabilityDomain> getAsDomain() const {
413413
if (isDomain())
414-
return storage.getPointer().get<AvailabilityDomain>();
414+
return cast<AvailabilityDomain>(storage.getPointer());
415415
return std::nullopt;
416416
}
417417

418418
/// Returns the unresolved identifier, or `std::nullopt` if the domain has
419419
/// been resolved.
420420
std::optional<Identifier> getAsIdentifier() const {
421421
if (isIdentifier())
422-
return storage.getPointer().get<Identifier>();
422+
return cast<Identifier>(storage.getPointer());
423423
return std::nullopt;
424424
}
425425

include/swift/AST/CatchNode.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@
2222

2323
namespace swift {
2424

25+
namespace detail {
26+
using CatchNodeBase = llvm::PointerUnion<AbstractFunctionDecl *, ClosureExpr *,
27+
DoCatchStmt *, AnyTryExpr *>;
28+
} // end namespace detail
29+
2530
/// An AST node that represents a point where a thrown error can be caught and
2631
/// or rethrown, which includes functions do...catch statements.
27-
class CatchNode: public llvm::PointerUnion<
28-
AbstractFunctionDecl *, ClosureExpr *, DoCatchStmt *, AnyTryExpr *
29-
> {
32+
class CatchNode : public detail::CatchNodeBase {
3033
public:
34+
using Base = detail::CatchNodeBase;
3135
using PointerUnion::PointerUnion;
3236

3337
/// Determine the thrown error type within the region of this catch node
@@ -62,4 +66,17 @@ SourceLoc extractNearestSourceLoc(CatchNode catchNode);
6266

6367
} // end namespace swift
6468

69+
namespace llvm {
70+
71+
using swift::CatchNode;
72+
73+
/// `isa`, `dyn_cast`, `cast` for `CatchNode`.
74+
template <typename To>
75+
struct CastInfo<To, CatchNode> : public CastInfo<To, CatchNode::Base> {};
76+
template <typename To>
77+
struct CastInfo<To, const CatchNode>
78+
: public CastInfo<To, const CatchNode::Base> {};
79+
80+
} // end namespace llvm
81+
6582
#endif // SWIFT_AST_CATCHNODE_H

include/swift/AST/ClangNode.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_CLANGNODE_H
1515

1616
#include "swift/Basic/Debug.h"
17+
#include "swift/Basic/LLVM.h"
1718
#include "llvm/ADT/PointerUnion.h"
1819

1920
namespace clang {
@@ -76,16 +77,16 @@ class ClangNode {
7677
}
7778

7879
const clang::Decl *castAsDecl() const {
79-
return Ptr.get<Box<clang::Decl>>().value;
80+
return cast<Box<clang::Decl>>(Ptr).value;
8081
}
8182
const clang::MacroInfo *castAsMacroInfo() const {
82-
return Ptr.get<Box<clang::MacroInfo>>().value;
83+
return cast<Box<clang::MacroInfo>>(Ptr).value;
8384
}
8485
const clang::ModuleMacro *castAsModuleMacro() const {
85-
return Ptr.get<Box<clang::ModuleMacro>>().value;
86+
return cast<Box<clang::ModuleMacro>>(Ptr).value;
8687
}
8788
const clang::Module *castAsModule() const {
88-
return Ptr.get<Box<clang::Module>>().value;
89+
return cast<Box<clang::Module>>(Ptr).value;
8990
}
9091

9192
// Get the MacroInfo for a local definition, one imported from a

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl>, public Swi
10211021
if (auto dc = Context.dyn_cast<DeclContext *>())
10221022
return dc->getASTContext();
10231023

1024-
return *Context.get<ASTContext *>();
1024+
return *cast<ASTContext *>(Context);
10251025
}
10261026

10271027
const DeclAttributes &getAttrs() const {

include/swift/AST/Identifier.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class DeclName {
573573
if (auto compound = BaseNameOrCompound.dyn_cast<CompoundDeclName*>())
574574
return compound->BaseName;
575575

576-
return BaseNameOrCompound.get<DeclBaseName>();
576+
return cast<DeclBaseName>(BaseNameOrCompound);
577577
}
578578

579579
/// Assert that the base name is not special and return its identifier.
@@ -597,13 +597,11 @@ class DeclName {
597597
explicit operator bool() const {
598598
if (BaseNameOrCompound.dyn_cast<CompoundDeclName*>())
599599
return true;
600-
return !BaseNameOrCompound.get<DeclBaseName>().empty();
600+
return !cast<DeclBaseName>(BaseNameOrCompound).empty();
601601
}
602602

603603
/// True if this is a simple one-component name.
604-
bool isSimpleName() const {
605-
return BaseNameOrCompound.is<DeclBaseName>();
606-
}
604+
bool isSimpleName() const { return isa<DeclBaseName>(BaseNameOrCompound); }
607605

608606
/// True if this is a compound name.
609607
bool isCompoundName() const {

include/swift/AST/NameLookupRequests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ class OperatorLookupDescriptor final {
651651
DeclContext *getDC() const {
652652
if (auto *module = getModule())
653653
return module;
654-
return fileOrModule.get<FileUnit *>();
654+
return cast<FileUnit *>(fileOrModule);
655655
}
656656

657657
friend llvm::hash_code hash_value(const OperatorLookupDescriptor &desc) {

include/swift/AST/Pattern.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,10 @@ class EnumElementPattern : public Pattern {
617617
}
618618

619619
Expr *getUnresolvedOriginalExpr() const {
620-
return ElementDeclOrUnresolvedOriginalExpr.get<Expr*>();
620+
return cast<Expr *>(ElementDeclOrUnresolvedOriginalExpr);
621621
}
622622
bool hasUnresolvedOriginalExpr() const {
623-
return ElementDeclOrUnresolvedOriginalExpr.is<Expr*>();
623+
return isa<Expr *>(ElementDeclOrUnresolvedOriginalExpr);
624624
}
625625
void setUnresolvedOriginalExpr(Expr *e) {
626626
ElementDeclOrUnresolvedOriginalExpr = e;

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,28 +120,26 @@ class ProtocolConformanceRef {
120120
ProtocolDecl *protocol);
121121

122122
bool isConcrete() const {
123-
return !isInvalid() && Union.is<ProtocolConformance*>();
123+
return !isInvalid() && isa<ProtocolConformance *>(Union);
124124
}
125125
ProtocolConformance *getConcrete() const {
126126
ASSERT(isConcrete());
127-
return Union.get<ProtocolConformance*>();
127+
return cast<ProtocolConformance *>(Union);
128128
}
129129

130-
bool isPack() const {
131-
return !isInvalid() && Union.is<PackConformance*>();
132-
}
130+
bool isPack() const { return !isInvalid() && isa<PackConformance *>(Union); }
133131
PackConformance *getPack() const {
134132
ASSERT(isPack());
135-
return Union.get<PackConformance*>();
133+
return cast<PackConformance *>(Union);
136134
}
137135

138136
bool isAbstract() const {
139-
return !isInvalid() && Union.is<AbstractConformance*>();
137+
return !isInvalid() && isa<AbstractConformance *>(Union);
140138
}
141139

142140
AbstractConformance *getAbstract() const {
143141
ASSERT(isAbstract());
144-
return Union.get<AbstractConformance *>();
142+
return cast<AbstractConformance *>(Union);
145143
}
146144

147145
/// Determine whether this conformance (or a conformance it depends on)

0 commit comments

Comments
 (0)