Skip to content

Commit 08d4a93

Browse files
authored
[AST] More static_asserts for non-destroyed bump-allocated AST types (#19670)
Attributes, ParameterLists, GenericParamLists, Patterns, Types, and TypeReprs. Thanks, Rintaro!
1 parent b956043 commit 08d4a93

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

lib/AST/Attr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828
#include "llvm/ADT/StringSwitch.h"
2929
using namespace swift;
3030

31+
#define DECL_ATTR(_, Id, ...) \
32+
static_assert(IsTriviallyDestructible<Id##Attr>::value, \
33+
"Attrs are BumpPtrAllocated; the destructor is never called");
34+
#include "swift/AST/Attr.def"
35+
static_assert(IsTriviallyDestructible<DeclAttributes>::value,
36+
"DeclAttributes are BumpPtrAllocated; the d'tor is never called");
37+
static_assert(IsTriviallyDestructible<TypeAttributes>::value,
38+
"TypeAttributes are BumpPtrAllocated; the d'tor is never called");
39+
3140

3241
// Only allow allocation of attributes using the allocator in ASTContext.
3342
void *AttributeBase::operator new(size_t Bytes, ASTContext &C,

lib/AST/Decl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ STATISTIC(NumLazyGenericEnvironmentsLoaded,
7272
IsTriviallyDestructible<Id##Decl>::value, \
7373
"Decls are BumpPtrAllocated; the destructor is never called");
7474
#include "swift/AST/DeclNodes.def"
75+
static_assert(IsTriviallyDestructible<ParameterList>::value,
76+
"ParameterLists are BumpPtrAllocated; the d'tor is never called");
77+
static_assert(IsTriviallyDestructible<GenericParamList>::value,
78+
"GenericParamLists are BumpPtrAllocated; the d'tor isn't called");
7579

7680
const clang::MacroInfo *ClangNode::getAsMacro() const {
7781
if (auto MM = getAsModuleMacro())

lib/AST/Pattern.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
#include "llvm/Support/raw_ostream.h"
2626
using namespace swift;
2727

28+
#define PATTERN(Id, _) \
29+
static_assert(IsTriviallyDestructible<Id##Pattern>::value, \
30+
"Patterns are BumpPtrAllocated; the d'tor is never called");
31+
#include "swift/AST/PatternNodes.def"
32+
2833
/// Diagnostic printing of PatternKinds.
2934
llvm::raw_ostream &swift::operator<<(llvm::raw_ostream &OS, PatternKind kind) {
3035
switch (kind) {

lib/AST/Type.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
#include <iterator>
4343
using namespace swift;
4444

45+
#define TYPE(Id, _) \
46+
static_assert(IsTriviallyDestructible<Id##Type>::value, \
47+
"Types are BumpPtrAllocated; the destructor is never called");
48+
#include "swift/AST/TypeNodes.def"
49+
4550
Type QueryTypeSubstitutionMap::operator()(SubstitutableType *type) const {
4651
auto key = type->getCanonicalType()->castTo<SubstitutableType>();
4752
auto known = substitutions.find(key);

lib/AST/TypeRepr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#include "llvm/Support/raw_ostream.h"
2929
using namespace swift;
3030

31+
#define TYPEREPR(Id, _) \
32+
static_assert(IsTriviallyDestructible<Id##TypeRepr>::value, \
33+
"TypeReprs are BumpPtrAllocated; the d'tor is never called");
34+
#include "swift/AST/TypeReprNodes.def"
35+
3136
SourceLoc TypeRepr::getLoc() const {
3237
switch (getKind()) {
3338
#define TYPEREPR(CLASS, PARENT) \

0 commit comments

Comments
 (0)