Skip to content

Commit 3bdbf74

Browse files
committed
Make moving of temporaries do the right thing, use it to optimize
This adds support for dropping cleanups for temporary values when they are moved somewhere else. It then adds wraps most copy operations (return, put in data structure, box, etc) in a way that will fall back to a move when it is safe. This saves a lot of taking/dropping, shaving over a megabyte off the stage2/rustc binary size. In some cases, most notably function returns, we could detect that the returned value is a local variable, and can thus be safely moved even though it is not a temporary. This will require putting some more information in lvals. I did not yet handle function arguments, since the logic for passing them looked too convoluted to touch. I'll probably try that in the near future, since it's bound to be a big win.
1 parent 007a736 commit 3bdbf74

File tree

6 files changed

+177
-144
lines changed

6 files changed

+177
-144
lines changed

src/comp/middle/resolve.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,8 @@ fn lookup_in_mod_strict(&env e, def m, &span sp, &ident name, namespace ns,
864864
}
865865
}
866866

867-
fn lookup_in_mod(&env e, def m, &span sp, &ident name, namespace ns,
868-
dir dr) ->
869-
option::t[def] {
867+
fn lookup_in_mod(&env e, &def m, &span sp, &ident name, namespace ns,
868+
dir dr) -> option::t[def] {
870869
auto defid = ast::def_id_of_def(m);
871870
if (defid._0 != ast::local_crate) {
872871
// examining a module in an external crate
@@ -966,14 +965,9 @@ fn lookup_glob_in_mod(&env e, @indexed_mod info, &span sp, &ident id,
966965
namespace wanted_ns, dir dr) -> option::t[def] {
967966
fn per_ns(&env e, @indexed_mod info, &span sp, &ident id, namespace ns,
968967
dir dr) -> option::t[def] {
969-
fn l_i_m_r(&env e, &def m, &span sp, &ident id, namespace ns, dir dr)
970-
-> option::t[def] {
971-
be lookup_in_mod(e, m, sp, id, ns, dr);
972-
}
973968
auto matches =
974-
vec::filter_map[def,
975-
def](bind l_i_m_r(e, _, sp, id, ns, dr),
976-
{ info.glob_imports });
969+
vec::filter_map(bind lookup_in_mod(e, _, sp, id, ns, dr),
970+
{ info.glob_imports });
977971
if (vec::len(matches) == 0u) {
978972
ret none[def];
979973
} else if (vec::len(matches) == 1u) {

0 commit comments

Comments
 (0)