Skip to content

Commit 2c00271

Browse files
authored
perf: fix implementation of move constructors and move assignment ope… (leanprover#4700)
…rators Right now those constructors result in a copy instead of the desired move. We've measured that expr copying and assignment by itself uses around 10% of total runtime on our workloads. See leanprover#4698 for details.
1 parent b07384a commit 2c00271

File tree

14 files changed

+64
-64
lines changed

14 files changed

+64
-64
lines changed

src/kernel/declaration.h

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class constant_val : public object_ref {
6363
public:
6464
constant_val(name const & n, names const & lparams, expr const & type);
6565
constant_val(constant_val const & other):object_ref(other) {}
66-
constant_val(constant_val && other):object_ref(other) {}
66+
constant_val(constant_val && other):object_ref(std::move(other)) {}
6767
constant_val & operator=(constant_val const & other) { object_ref::operator=(other); return *this; }
68-
constant_val & operator=(constant_val && other) { object_ref::operator=(other); return *this; }
68+
constant_val & operator=(constant_val && other) { object_ref::operator=(std::move(other)); return *this; }
6969
name const & get_name() const { return static_cast<name const &>(cnstr_get_ref(*this, 0)); }
7070
names const & get_lparams() const { return static_cast<names const &>(cnstr_get_ref(*this, 1)); }
7171
expr const & get_type() const { return static_cast<expr const &>(cnstr_get_ref(*this, 2)); }
@@ -79,9 +79,9 @@ class axiom_val : public object_ref {
7979
public:
8080
axiom_val(name const & n, names const & lparams, expr const & type, bool is_unsafe);
8181
axiom_val(axiom_val const & other):object_ref(other) {}
82-
axiom_val(axiom_val && other):object_ref(other) {}
82+
axiom_val(axiom_val && other):object_ref(std::move(other)) {}
8383
axiom_val & operator=(axiom_val const & other) { object_ref::operator=(other); return *this; }
84-
axiom_val & operator=(axiom_val && other) { object_ref::operator=(other); return *this; }
84+
axiom_val & operator=(axiom_val && other) { object_ref::operator=(std::move(other)); return *this; }
8585
constant_val const & to_constant_val() const { return static_cast<constant_val const &>(cnstr_get_ref(*this, 0)); }
8686
name const & get_name() const { return to_constant_val().get_name(); }
8787
names const & get_lparams() const { return to_constant_val().get_lparams(); }
@@ -105,9 +105,9 @@ class definition_val : public object_ref {
105105
public:
106106
definition_val(name const & n, names const & lparams, expr const & type, expr const & val, reducibility_hints const & hints, definition_safety safety, names const & all);
107107
definition_val(definition_val const & other):object_ref(other) {}
108-
definition_val(definition_val && other):object_ref(other) {}
108+
definition_val(definition_val && other):object_ref(std::move(other)) {}
109109
definition_val & operator=(definition_val const & other) { object_ref::operator=(other); return *this; }
110-
definition_val & operator=(definition_val && other) { object_ref::operator=(other); return *this; }
110+
definition_val & operator=(definition_val && other) { object_ref::operator=(std::move(other)); return *this; }
111111
constant_val const & to_constant_val() const { return static_cast<constant_val const &>(cnstr_get_ref(*this, 0)); }
112112
name const & get_name() const { return to_constant_val().get_name(); }
113113
names const & get_lparams() const { return to_constant_val().get_lparams(); }
@@ -128,9 +128,9 @@ class theorem_val : public object_ref {
128128
public:
129129
theorem_val(name const & n, names const & lparams, expr const & type, expr const & val, names const & all);
130130
theorem_val(theorem_val const & other):object_ref(other) {}
131-
theorem_val(theorem_val && other):object_ref(other) {}
131+
theorem_val(theorem_val && other):object_ref(std::move(other)) {}
132132
theorem_val & operator=(theorem_val const & other) { object_ref::operator=(other); return *this; }
133-
theorem_val & operator=(theorem_val && other) { object_ref::operator=(other); return *this; }
133+
theorem_val & operator=(theorem_val && other) { object_ref::operator=(std::move(other)); return *this; }
134134
constant_val const & to_constant_val() const { return static_cast<constant_val const &>(cnstr_get_ref(*this, 0)); }
135135
name const & get_name() const { return to_constant_val().get_name(); }
136136
names const & get_lparams() const { return to_constant_val().get_lparams(); }
@@ -148,9 +148,9 @@ class opaque_val : public object_ref {
148148
public:
149149
opaque_val(name const & n, names const & lparams, expr const & type, expr const & val, bool is_unsafe, names const & all);
150150
opaque_val(opaque_val const & other):object_ref(other) {}
151-
opaque_val(opaque_val && other):object_ref(other) {}
151+
opaque_val(opaque_val && other):object_ref(std::move(other)) {}
152152
opaque_val & operator=(opaque_val const & other) { object_ref::operator=(other); return *this; }
153-
opaque_val & operator=(opaque_val && other) { object_ref::operator=(other); return *this; }
153+
opaque_val & operator=(opaque_val && other) { object_ref::operator=(std::move(other)); return *this; }
154154
constant_val const & to_constant_val() const { return static_cast<constant_val const &>(cnstr_get_ref(*this, 0)); }
155155
name const & get_name() const { return to_constant_val().get_name(); }
156156
names const & get_lparams() const { return to_constant_val().get_lparams(); }
@@ -179,9 +179,9 @@ class inductive_type : public object_ref {
179179
public:
180180
inductive_type(name const & id, expr const & type, constructors const & cnstrs);
181181
inductive_type(inductive_type const & other):object_ref(other) {}
182-
inductive_type(inductive_type && other):object_ref(other) {}
182+
inductive_type(inductive_type && other):object_ref(std::move(other)) {}
183183
inductive_type & operator=(inductive_type const & other) { object_ref::operator=(other); return *this; }
184-
inductive_type & operator=(inductive_type && other) { object_ref::operator=(other); return *this; }
184+
inductive_type & operator=(inductive_type && other) { object_ref::operator=(std::move(other)); return *this; }
185185
name const & get_name() const { return static_cast<name const &>(cnstr_get_ref(*this, 0)); }
186186
expr const & get_type() const { return static_cast<expr const &>(cnstr_get_ref(*this, 1)); }
187187
constructors const & get_cnstrs() const { return static_cast<constructors const &>(cnstr_get_ref(*this, 2)); }
@@ -205,15 +205,15 @@ class declaration : public object_ref {
205205
public:
206206
declaration();
207207
declaration(declaration const & other):object_ref(other) {}
208-
declaration(declaration && other):object_ref(other) {}
208+
declaration(declaration && other):object_ref(std::move(other)) {}
209209
/* low-level constructors */
210210
explicit declaration(object * o):object_ref(o) {}
211211
explicit declaration(b_obj_arg o, bool b):object_ref(o, b) {}
212212
explicit declaration(object_ref const & o):object_ref(o) {}
213213
declaration_kind kind() const { return static_cast<declaration_kind>(obj_tag(raw())); }
214214

215215
declaration & operator=(declaration const & other) { object_ref::operator=(other); return *this; }
216-
declaration & operator=(declaration && other) { object_ref::operator=(other); return *this; }
216+
declaration & operator=(declaration && other) { object_ref::operator=(std::move(other)); return *this; }
217217

218218
friend bool is_eqp(declaration const & d1, declaration const & d2) { return d1.raw() == d2.raw(); }
219219

@@ -263,10 +263,10 @@ declaration mk_axiom_inferring_unsafe(environment const & env, name const & n,
263263
class inductive_decl : public object_ref {
264264
public:
265265
inductive_decl(inductive_decl const & other):object_ref(other) {}
266-
inductive_decl(inductive_decl && other):object_ref(other) {}
266+
inductive_decl(inductive_decl && other):object_ref(std::move(other)) {}
267267
inductive_decl(declaration const & d):object_ref(d) { lean_assert(d.is_inductive()); }
268268
inductive_decl & operator=(inductive_decl const & other) { object_ref::operator=(other); return *this; }
269-
inductive_decl & operator=(inductive_decl && other) { object_ref::operator=(other); return *this; }
269+
inductive_decl & operator=(inductive_decl && other) { object_ref::operator=(std::move(other)); return *this; }
270270
names const & get_lparams() const { return static_cast<names const &>(cnstr_get_ref(raw(), 0)); }
271271
nat const & get_nparams() const { return static_cast<nat const &>(cnstr_get_ref(raw(), 1)); }
272272
inductive_types const & get_types() const { return static_cast<inductive_types const &>(cnstr_get_ref(raw(), 2)); }
@@ -290,9 +290,9 @@ class inductive_val : public object_ref {
290290
inductive_val(name const & n, names const & lparams, expr const & type, unsigned nparams,
291291
unsigned nindices, names const & all, names const & cnstrs, unsigned nnested, bool is_rec, bool is_unsafe, bool is_reflexive);
292292
inductive_val(inductive_val const & other):object_ref(other) {}
293-
inductive_val(inductive_val && other):object_ref(other) {}
293+
inductive_val(inductive_val && other):object_ref(std::move(other)) {}
294294
inductive_val & operator=(inductive_val const & other) { object_ref::operator=(other); return *this; }
295-
inductive_val & operator=(inductive_val && other) { object_ref::operator=(other); return *this; }
295+
inductive_val & operator=(inductive_val && other) { object_ref::operator=(std::move(other)); return *this; }
296296
constant_val const & to_constant_val() const { return static_cast<constant_val const &>(cnstr_get_ref(*this, 0)); }
297297
unsigned get_nparams() const { return static_cast<nat const &>(cnstr_get_ref(*this, 1)).get_small_value(); }
298298
unsigned get_nindices() const { return static_cast<nat const &>(cnstr_get_ref(*this, 2)).get_small_value(); }
@@ -317,9 +317,9 @@ class constructor_val : public object_ref {
317317
public:
318318
constructor_val(name const & n, names const & lparams, expr const & type, name const & induct, unsigned cidx, unsigned nparams, unsigned nfields, bool is_unsafe);
319319
constructor_val(constructor_val const & other):object_ref(other) {}
320-
constructor_val(constructor_val && other):object_ref(other) {}
320+
constructor_val(constructor_val && other):object_ref(std::move(other)) {}
321321
constructor_val & operator=(constructor_val const & other) { object_ref::operator=(other); return *this; }
322-
constructor_val & operator=(constructor_val && other) { object_ref::operator=(other); return *this; }
322+
constructor_val & operator=(constructor_val && other) { object_ref::operator=(std::move(other)); return *this; }
323323
constant_val const & to_constant_val() const { return static_cast<constant_val const &>(cnstr_get_ref(*this, 0)); }
324324
name const & get_induct() const { return static_cast<name const &>(cnstr_get_ref(*this, 1)); }
325325
unsigned get_cidx() const { return static_cast<nat const &>(cnstr_get_ref(*this, 2)).get_small_value(); }
@@ -338,9 +338,9 @@ class recursor_rule : public object_ref {
338338
public:
339339
recursor_rule(name const & cnstr, unsigned nfields, expr const & rhs);
340340
recursor_rule(recursor_rule const & other):object_ref(other) {}
341-
recursor_rule(recursor_rule && other):object_ref(other) {}
341+
recursor_rule(recursor_rule && other):object_ref(std::move(other)) {}
342342
recursor_rule & operator=(recursor_rule const & other) { object_ref::operator=(other); return *this; }
343-
recursor_rule & operator=(recursor_rule && other) { object_ref::operator=(other); return *this; }
343+
recursor_rule & operator=(recursor_rule && other) { object_ref::operator=(std::move(other)); return *this; }
344344
name const & get_cnstr() const { return static_cast<name const &>(cnstr_get_ref(*this, 0)); }
345345
unsigned get_nfields() const { return static_cast<nat const &>(cnstr_get_ref(*this, 1)).get_small_value(); }
346346
expr const & get_rhs() const { return static_cast<expr const &>(cnstr_get_ref(*this, 2)); }
@@ -365,9 +365,9 @@ class recursor_val : public object_ref {
365365
names const & all, unsigned nparams, unsigned nindices, unsigned nmotives,
366366
unsigned nminors, recursor_rules const & rules, bool k, bool is_unsafe);
367367
recursor_val(recursor_val const & other):object_ref(other) {}
368-
recursor_val(recursor_val && other):object_ref(other) {}
368+
recursor_val(recursor_val && other):object_ref(std::move(other)) {}
369369
recursor_val & operator=(recursor_val const & other) { object_ref::operator=(other); return *this; }
370-
recursor_val & operator=(recursor_val && other) { object_ref::operator=(other); return *this; }
370+
recursor_val & operator=(recursor_val && other) { object_ref::operator=(std::move(other)); return *this; }
371371
constant_val const & to_constant_val() const { return static_cast<constant_val const &>(cnstr_get_ref(*this, 0)); }
372372
name const & get_name() const { return to_constant_val().get_name(); }
373373
name const & get_induct() const { return get_name().get_prefix(); }
@@ -398,9 +398,9 @@ class quot_val : public object_ref {
398398
public:
399399
quot_val(name const & n, names const & lparams, expr const & type, quot_kind k);
400400
quot_val(quot_val const & other):object_ref(other) {}
401-
quot_val(quot_val && other):object_ref(other) {}
401+
quot_val(quot_val && other):object_ref(std::move(other)) {}
402402
quot_val & operator=(quot_val const & other) { object_ref::operator=(other); return *this; }
403-
quot_val & operator=(quot_val && other) { object_ref::operator=(other); return *this; }
403+
quot_val & operator=(quot_val && other) { object_ref::operator=(std::move(other)); return *this; }
404404
constant_val const & to_constant_val() const { return static_cast<constant_val const &>(cnstr_get_ref(*this, 0)); }
405405
name const & get_name() const { return to_constant_val().get_name(); }
406406
names const & get_lparams() const { return to_constant_val().get_lparams(); }
@@ -434,14 +434,14 @@ class constant_info : public object_ref {
434434
constant_info(constructor_val const & v);
435435
constant_info(recursor_val const & v);
436436
constant_info(constant_info const & other):object_ref(other) {}
437-
constant_info(constant_info && other):object_ref(other) {}
437+
constant_info(constant_info && other):object_ref(std::move(other)) {}
438438
explicit constant_info(b_obj_arg o, bool b):object_ref(o, b) {}
439439
explicit constant_info(obj_arg o):object_ref(o) {}
440440

441441
constant_info_kind kind() const { return static_cast<constant_info_kind>(cnstr_tag(raw())); }
442442

443443
constant_info & operator=(constant_info const & other) { object_ref::operator=(other); return *this; }
444-
constant_info & operator=(constant_info && other) { object_ref::operator=(other); return *this; }
444+
constant_info & operator=(constant_info && other) { object_ref::operator=(std::move(other)); return *this; }
445445

446446
friend bool is_eqp(constant_info const & d1, constant_info const & d2) { return d1.raw() == d2.raw(); }
447447

src/kernel/expr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ class literal : public object_ref {
5050
explicit literal(nat const & v);
5151
literal():literal(0u) {}
5252
literal(literal const & other):object_ref(other) {}
53-
literal(literal && other):object_ref(other) {}
53+
literal(literal && other):object_ref(std::move(other)) {}
5454
literal & operator=(literal const & other) { object_ref::operator=(other); return *this; }
55-
literal & operator=(literal && other) { object_ref::operator=(other); return *this; }
55+
literal & operator=(literal && other) { object_ref::operator=(std::move(other)); return *this; }
5656

5757
static literal_kind kind(object * o) { return static_cast<literal_kind>(cnstr_tag(o)); }
5858
literal_kind kind() const { return kind(raw()); }
@@ -100,14 +100,14 @@ class expr : public object_ref {
100100
public:
101101
expr();
102102
expr(expr const & other):object_ref(other) {}
103-
expr(expr && other):object_ref(other) {}
103+
expr(expr && other):object_ref(std::move(other)) {}
104104
explicit expr(b_obj_arg o, bool b):object_ref(o, b) {}
105105
explicit expr(obj_arg o):object_ref(o) {}
106106
static expr_kind kind(object * o) { return static_cast<expr_kind>(cnstr_tag(o)); }
107107
expr_kind kind() const { return kind(raw()); }
108108

109109
expr & operator=(expr const & other) { object_ref::operator=(other); return *this; }
110-
expr & operator=(expr && other) { object_ref::operator=(other); return *this; }
110+
expr & operator=(expr && other) { object_ref::operator=(std::move(other)); return *this; }
111111

112112
friend bool is_eqp(expr const & e1, expr const & e2) { return e1.raw() == e2.raw(); }
113113
};

src/kernel/level.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ class level : public object_ref {
4343
explicit level(obj_arg o):object_ref(o) {}
4444
explicit level(b_obj_arg o, bool b):object_ref(o, b) {}
4545
level(level const & other):object_ref(other) {}
46-
level(level && other):object_ref(other) {}
46+
level(level && other):object_ref(std::move(other)) {}
4747
level_kind kind() const {
4848
return lean_is_scalar(raw()) ? level_kind::Zero : static_cast<level_kind>(lean_ptr_tag(raw()));
4949
}
5050
unsigned hash() const;
5151

5252
level & operator=(level const & other) { object_ref::operator=(other); return *this; }
53-
level & operator=(level && other) { object_ref::operator=(other); return *this; }
53+
level & operator=(level && other) { object_ref::operator=(std::move(other)); return *this; }
5454

5555
friend bool is_eqp(level const & l1, level const & l2) { return l1.raw() == l2.raw(); }
5656

src/kernel/local_ctx.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class local_decl : public object_ref {
2727
public:
2828
local_decl();
2929
local_decl(local_decl const & other):object_ref(other) {}
30-
local_decl(local_decl && other):object_ref(other) {}
30+
local_decl(local_decl && other):object_ref(std::move(other)) {}
3131
local_decl(obj_arg o):object_ref(o) {}
3232
local_decl(b_obj_arg o, bool):object_ref(o, true) {}
3333
local_decl & operator=(local_decl const & other) { object_ref::operator=(other); return *this; }
34-
local_decl & operator=(local_decl && other) { object_ref::operator=(other); return *this; }
34+
local_decl & operator=(local_decl && other) { object_ref::operator=(std::move(other)); return *this; }
3535
friend bool is_eqp(local_decl const & d1, local_decl const & d2) { return d1.raw() == d2.raw(); }
3636
unsigned get_idx() const { return static_cast<nat const &>(cnstr_get_ref(raw(), 0)).get_small_value(); }
3737
name const & get_name() const { return static_cast<name const &>(cnstr_get_ref(raw(), 1)); }
@@ -54,9 +54,9 @@ class local_ctx : public object_ref {
5454
explicit local_ctx(obj_arg o):object_ref(o) {}
5555
local_ctx(b_obj_arg o, bool):object_ref(o, true) {}
5656
local_ctx(local_ctx const & other):object_ref(other) {}
57-
local_ctx(local_ctx && other):object_ref(other) {}
57+
local_ctx(local_ctx && other):object_ref(std::move(other)) {}
5858
local_ctx & operator=(local_ctx const & other) { object_ref::operator=(other); return *this; }
59-
local_ctx & operator=(local_ctx && other) { object_ref::operator=(other); return *this; }
59+
local_ctx & operator=(local_ctx && other) { object_ref::operator=(std::move(other)); return *this; }
6060

6161
bool empty() const;
6262

src/library/compiler/specialize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ class spec_info : public object_ref {
9292
object_ref(mk_cnstr(0, ns, ks)) {}
9393
spec_info():spec_info(names(), spec_arg_kinds()) {}
9494
spec_info(spec_info const & other):object_ref(other) {}
95-
spec_info(spec_info && other):object_ref(other) {}
95+
spec_info(spec_info && other):object_ref(std::move(other)) {}
9696
spec_info(b_obj_arg o, bool b):object_ref(o, b) {}
9797
spec_info & operator=(spec_info const & other) { object_ref::operator=(other); return *this; }
98-
spec_info & operator=(spec_info && other) { object_ref::operator=(other); return *this; }
98+
spec_info & operator=(spec_info && other) { object_ref::operator=(std::move(other)); return *this; }
9999
names const & get_mutual_decls() const { return static_cast<names const &>(cnstr_get_ref(*this, 0)); }
100100
spec_arg_kinds const & get_arg_kinds() const { return static_cast<spec_arg_kinds const &>(cnstr_get_ref(*this, 1)); }
101101
};

0 commit comments

Comments
 (0)