Rust: mem::replace don't actually mutate the destination on Android

Created on 22 Mar 2018  ·  3Comments  ·  Source: rust-lang/rust

I have a branch of Servo which crashes when run on Android because a key use of mem::replace does not actually cause the destination to change values. When I add println!("{:?}", self.pending_line) before and after the mem::replace, on desktop the values are updated as expected, but on Android the original value remains.

When I use either of the following instead:

self.pending_line = Line::new(self.floats.writing_mode, &self.minimum_metrics);

or

let mut new_line = Line::new(self.floats.writing_mode, &self.minimum_metrics);
mem::swap(&mut self.pending_line, &mut new_line);

then self.pending is updated as expected and Servo does not crash on Android.

A-codegen A-simd C-bug O-android T-compiler

Most helpful comment

The following also works:

        mem::replace(&mut self.pending_line,
                     Line::new(self.floats.writing_mode, &self.minimum_metrics));
        mem::replace(&mut self.pending_line,
                     Line::new(self.floats.writing_mode, &self.minimum_metrics));

(yes, performing the same operation twice)

All 3 comments

The following also works:

        mem::replace(&mut self.pending_line,
                     Line::new(self.floats.writing_mode, &self.minimum_metrics));
        mem::replace(&mut self.pending_line,
                     Line::new(self.floats.writing_mode, &self.minimum_metrics));

(yes, performing the same operation twice)

Hmm, it looks like that type is pretty large (https://github.com/jdm/servo/blob/layoutstuff/components/layout/inline.rs#L221-L245) so will be hitting the simd path in swap (https://github.com/rust-lang/rust/blob/master/src/libcore/ptr.rs#L194-L227) that's currently disabled on some other platforms, so I wonder if the bug's in there somewhere...

Triage: Not sure if this is still an issue.

Updated libcore SIMD code:

https://github.com/rust-lang/rust/blob/8ce3f840ae9b735a66531996c32330f24b877cb0/src/libcore/ptr/mod.rs#L418-L465

Was this page helpful?
0 / 5 - 0 ratings