pub struct WriteTransforming;
Expand description
A pass to rewrite assignments to array accesses and struct accesses.
This pass makes variables for members of arrays and structs that are written to, changes assignments to those members into assignments to those variables, and, whenever the arrays or structs are accessed, reconstructs them from the variables. So code like this:
let s = S { a: 1u8, b: [2u8, 3u8] }; s.a = 1u8; s.b[0u8] = 4u8; return s;
will be changed into something like this:
let s_a = 1u8; let s_b_0 = 2u8; let s_b_1 = 3u8; s_b_1 = 4u8; return S { a: s_a, b: [s_b_0, s_b_1] };
The pass requires that the AST is in SSA form (so that sub-expressions are always
variables or literals) and that tuples have been destructured.
Since the pass will create new assignments, SsaForming
must be run again afterwards.
A note on the semantics of the language as implemented by this pass: assignments and definitions in essence copy structs and arrays. Thus if we do
let x = [0u8, 1u8];
let y = x;
y[0u8] = 12u8;
x is still [0u8, 1u8];
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WriteTransforming
impl RefUnwindSafe for WriteTransforming
impl Send for WriteTransforming
impl Sync for WriteTransforming
impl Unpin for WriteTransforming
impl UnwindSafe for WriteTransforming
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more