Actually wanna talk about the history of this function since it's had a sorta interesting journey.https://twitter.com/Gankro/status/909484632294526977 …
-
Show this thread
-
v. simple: returns whether dropping a type would have an interesting effect. i32 or Option<i32>? false. Vec<i32> or Option<Vec<i32>>? true.
1 reply 0 retweets 5 likesShow this thread -
The purpose of this function is to perform optimizations. For instance, Vec<T> needs to iter+drop contents, but avoidable if T !needs_drop.
1 reply 0 retweets 4 likesShow this thread -
However for a looong time we didn't bother with such an optimization, since llvm *very* reliably optimized all the work away regardless!
1 reply 0 retweets 5 likesShow this thread -
But not in debug, which was the impetus to start doing these optimizations. Also static branches should be faster for an optimizer to solve.
1 reply 0 retweets 5 likesShow this thread -
So all of Rust's collections grew needs_drop branches, because it was a nice and simple win. Not things like Box tho. No real point.
2 replies 0 retweets 3 likesShow this thread -
Replying to @Gankro
But why can't the compiler just infer this? Why not just move the optimization into the front end of the compiler instead of growing libstd?
1 reply 0 retweets 0 likes -
Replying to @BRIAN_____ @Gankro
didn't have much of an optimization framework back then. does now, but would be a lot of work.
1 reply 0 retweets 1 like -
Replying to @ManishEarth @BRIAN_____
Yeah it relies on either an effect system or heavy inlining to determine there are no side effects, in general.
1 reply 0 retweets 1 like -
Replying to @Gankro @ManishEarth
In this case, the inliner would just need to optimize empty statements as function bodies and maybe empty statements as loop bodies.
1 reply 0 retweets 0 likes
The cost of such recognition seems low and it's debugger-friendly since no *executable* code actually gets transformed in any way.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.