Skip to content

Commit c22711a

Browse files
authored
[AST] static_assert that Decls, Stmts, and Exprs don't need cleanup (#19667)
These types are all allocated on the ASTContext's BumpPtrAllocator, and by default their destructors are never called. (ModuleDecl is the exception; it registers its destructor with the ASTContext on construction.) No functionality change.
1 parent e014950 commit c22711a

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/AST/Decl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ STATISTIC(NumLazyGenericEnvironments,
6767
STATISTIC(NumLazyGenericEnvironmentsLoaded,
6868
"# of lazily-deserialized generic environments loaded");
6969

70+
#define DECL(Id, _) \
71+
static_assert((DeclKind::Id == DeclKind::Module) ^ \
72+
IsTriviallyDestructible<Id##Decl>::value, \
73+
"Decls are BumpPtrAllocated; the destructor is never called");
74+
#include "swift/AST/DeclNodes.def"
75+
7076
const clang::MacroInfo *ClangNode::getAsMacro() const {
7177
if (auto MM = getAsModuleMacro())
7278
return MM->getMacroInfo();

lib/AST/Expr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
#include "llvm/ADT/Twine.h"
3333
using namespace swift;
3434

35+
#define EXPR(Id, _) \
36+
static_assert(IsTriviallyDestructible<Id##Expr>::value, \
37+
"Exprs are BumpPtrAllocated; the destructor is never called");
38+
#include "swift/AST/ExprNodes.def"
39+
3540
StringRef swift::getFunctionRefKindStr(FunctionRefKind refKind) {
3641
switch (refKind) {
3742
case FunctionRefKind::Unapplied:

lib/AST/Stmt.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424

2525
using namespace swift;
2626

27+
#define STMT(Id, _) \
28+
static_assert(IsTriviallyDestructible<Id##Stmt>::value, \
29+
"Stmts are BumpPtrAllocated; the destructor is never called");
30+
#include "swift/AST/StmtNodes.def"
31+
2732
//===----------------------------------------------------------------------===//
2833
// Stmt methods.
2934
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)