-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid implicit copy in ptr::addr_of() #2040
Comments
This is the current behavior. |
What you were seeing here -- with the two different addresses being shown -- is produced by the fact that an immediate value that's not assigned to does not get spilled to the stack. So the calls were doing their own spilling to be able to pass it by reference, each producing a different address. Your & approach helped because passing something by mutable reference counts as assigning to it, forcing it to be spilled. This is all rather confusing. We'll soon be overhauling the way function argument passing works, and in the process will have to rethink the way addr_of takes its arguments as well. |
This does seem like a real issue. C doesn't exhibit this behavior, does it? |
C forces locals to be stack-allocated when you take their address. I'm going to make addr_of something that the compiler knows about as part of the work on #1981. I can take a stab at properly fixing this too. |
Regions let you take the address using the |
That actually sounds like a much better approach. So I guess we'd have addr_of take a reference to some thing? Or do you think we should make a variant of the & operator that returns an unsafe pointer right away? |
I think |
…-float-functions, r=flip1995 Add lint to improve floating-point expressions Looks for floating-point expressions that can be expressed using built-in methods to improve accuracy, performance and/or succinctness. changelog: Add lint `floating_point_improvements`. Fixes rust-lang#4726 Partly addresses [rust-lang#2040](rust-lang/rust-clippy#2040) Currently linted expressions: | Expression | Suggestion | |---------------------------------|------------| | x.log(2.0) | x.log2() | | x.log(10.0) | x.log10() | | x.log(std::f32::consts::E) | x.ln() | | (1 + x).ln() | x.ln_1p() | | (2.0).powf(x) | x.exp2() | | (std::f32::consts::E).powf(x) | x.exp() | | x.powf(1/2) | x.sqrt() | | x.powf(1/3) | x.cbrt() | | x.powf(y), where y is whole | x.powi(y) | | x.exp() - 1 | x.exp_m1() | |x * y + z|x.mul_add(y, z)|
Some accuracy lints for floating point operations This will add some lints for accuracy on floating point operations suggested by @clarfon in rust-lang#2040 (fixes rust-lang#2040). These are the remaining lints: - [x] x.powi(2) => x * x - [x] x.logN() / y.logN() => x.logbase(y) - [x] x.logbase(E) => x.log() - [x] x.logbase(10) => x.log10() - [x] x.logbase(2) => x.log2(). - [x] x * PI / 180 => x.to_radians() - [x] x * 180 / PI => x.to_degrees() - [x] (x + 1).log() => x.log_1p() - [x] sqrt(x * x + y * y) => x.hypot(y) changelog: Included some accuracy lints for floating point operations
Co-authored-by: rahulku <luhark@amazon.com>
I wonder if there is any use for
ptr::addr_of()
to return address of a temporary copied version of its argument, but it seems a bit annoying. E.g. for following code, different address will be printed.Use following version of
addr_of
instead, the address will be consistent.And a real world example:
asound::snd_mixer_selem_id_malloc()
will allocate a buffer and assign the address tosid
。But assid
is implicit copied,sid
remains0
after this function call.Can
ptr::addr_of()
be defined as always pass by reference to avoid implicit copy?The text was updated successfully, but these errors were encountered: