When storing a temporary value (something that's not a variable or part of a data structure, for example function return values or the result of operators) somewhere, it is usually not necessary to copy it -- a temporary is only accessible in a single place, so there is no risk of other code using it later. I submitted a patch today that uses this fact to avoid a lot of taking and dropping [1], shaving a megabyte off of the size of stage2/rustc.
[1]: https://github.com/graydon/rust/commit/3bdbf74d4703771571fdee1733b7b3d919b5ede8 One of the effects this patch has is that if you now do @foo(x), the result of foo will be moved into the box, rather than copied. If foo is a resource constructor, that expression used to cause an error (you can't copy a resource). With my change, it works. That's nice, in this case. But it's a semantic difference coming out of an optimization, which is usually a Bad Thing. Shall we specify that temporary values, when put into a data structure, are moved, rather than copied? For non-temporary values, this usually not what you want, so we should provide an explicit operator to specify that we want to move those. Furthermore, it seems we can do the same for by-value function arguments. I didn't implement that yet (since the argument passing logic is somewhat hairy), but it seems like a sane optimization. Thoughts? _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
