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.
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:
Most helpful comment
The following also works:
(yes, performing the same operation twice)