Skip to content

Commit 4898a15

Browse files
committed
shrink ast's app by 8 bytes on 64-bit platforms when number of args > 0
1 parent b2d5c24 commit 4898a15

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

src/ast/ast.cpp

+6-27
Original file line numberDiff line numberDiff line change
@@ -319,26 +319,6 @@ func_decl::func_decl(symbol const & name, unsigned arity, sort * const * domain,
319319
//
320320
// -----------------------------------
321321

322-
static app_flags mk_const_flags() {
323-
app_flags r;
324-
r.m_depth = 1;
325-
r.m_ground = true;
326-
r.m_has_quantifiers = false;
327-
r.m_has_labels = false;
328-
return r;
329-
}
330-
331-
static app_flags mk_default_app_flags() {
332-
app_flags r;
333-
r.m_depth = 1;
334-
r.m_ground = true;
335-
r.m_has_quantifiers = false;
336-
r.m_has_labels = false;
337-
return r;
338-
}
339-
340-
app_flags app::g_constant_flags = mk_const_flags();
341-
342322
app::app(func_decl * decl, unsigned num_args, expr * const * args):
343323
expr(AST_APP),
344324
m_decl(decl),
@@ -1762,8 +1742,7 @@ ast * ast_manager::register_node_core(ast * n) {
17621742
inc_ref(t->get_decl());
17631743
unsigned num_args = t->get_num_args();
17641744
if (num_args > 0) {
1765-
app_flags * f = t->flags();
1766-
*f = mk_default_app_flags();
1745+
app_flags * f = &t->m_flags;
17671746
SASSERT(t->is_ground());
17681747
SASSERT(!t->has_quantifiers());
17691748
SASSERT(!t->has_labels());
@@ -1776,13 +1755,13 @@ ast * ast_manager::register_node_core(ast * n) {
17761755
unsigned arg_depth = 0;
17771756
switch (arg->get_kind()) {
17781757
case AST_APP: {
1779-
app_flags * arg_flags = to_app(arg)->flags();
1780-
arg_depth = arg_flags->m_depth;
1781-
if (arg_flags->m_has_quantifiers)
1758+
app *app = to_app(arg);
1759+
arg_depth = app->get_depth();
1760+
if (app->has_quantifiers())
17821761
f->m_has_quantifiers = true;
1783-
if (arg_flags->m_has_labels)
1762+
if (app->has_labels())
17841763
f->m_has_labels = true;
1785-
if (!arg_flags->m_ground)
1764+
if (!app->is_ground())
17861765
f->m_ground = false;
17871766
break;
17881767
}

src/ast/ast.h

+7-10
Original file line numberDiff line numberDiff line change
@@ -704,26 +704,23 @@ struct app_flags {
704704
unsigned m_ground:1; // application does not have free variables or nested quantifiers.
705705
unsigned m_has_quantifiers:1; // application has nested quantifiers.
706706
unsigned m_has_labels:1; // application has nested labels.
707+
app_flags() : m_depth(1), m_ground(1), m_has_quantifiers(0), m_has_labels(0) {}
707708
};
708709

709710
class app : public expr {
710711
friend class ast_manager;
711712

712713
func_decl * m_decl;
713714
unsigned m_num_args;
715+
app_flags m_flags;
714716
expr * m_args[0];
715717

716-
static app_flags g_constant_flags;
717-
718-
// remark: store term depth in the end of the app. the depth is only stored if the num_args > 0
719718
static unsigned get_obj_size(unsigned num_args) {
720-
return num_args == 0 ? sizeof(app) : sizeof(app) + num_args * sizeof(expr *) + sizeof(app_flags);
719+
return sizeof(app) + num_args * sizeof(expr *);
721720
}
722721

723722
friend class tmp_app;
724723

725-
app_flags * flags() const { return m_num_args == 0 ? &g_constant_flags : reinterpret_cast<app_flags*>(const_cast<expr**>(m_args + m_num_args)); }
726-
727724
app(func_decl * decl, unsigned num_args, expr * const * args);
728725
public:
729726
func_decl * get_decl() const { return m_decl; }
@@ -744,10 +741,10 @@ class app : public expr {
744741
expr * const * end() const { return m_args + m_num_args; }
745742
sort * _get_sort() const { return get_decl()->get_range(); }
746743

747-
unsigned get_depth() const { return flags()->m_depth; }
748-
bool is_ground() const { return flags()->m_ground; }
749-
bool has_quantifiers() const { return flags()->m_has_quantifiers; }
750-
bool has_labels() const { return flags()->m_has_labels; }
744+
unsigned get_depth() const { return m_flags.m_depth; }
745+
bool is_ground() const { return m_flags.m_ground; }
746+
bool has_quantifiers() const { return m_flags.m_has_quantifiers; }
747+
bool has_labels() const { return m_flags.m_has_labels; }
751748
};
752749

753750
// -----------------------------------

0 commit comments

Comments
 (0)