Enum naga::back::continue_forward::Nesting

source ·
enum Nesting {
    Loop,
    Switch {
        variable: Rc<String>,
        continue_encountered: bool,
    },
}
Expand description

A summary of the code surrounding a statement.

Variants§

§

Loop

Currently nested in at least one Loop statement.

Continue should apply to the innermost loop.

When this entry is on the top of the stack:

  • When entering an inner Loop statement, push a Loop state onto the stack.

  • When entering a nested Switch statement, push a Switch state onto the stack with a new variable name. Before the generated switch, introduce a bool local with that name, initialized to false.

When exiting the Loop for which this entry was pushed, pop it from the stack.

§

Switch

Currently nested in at least one Switch that may need to forward Continues.

This includes Switches rendered as do {} while(false) loops, but doesn’t need to include regular Switches in backends that can support continue within switches.

Continue should be forwarded to the innermost surrounding Loop.

When this entry is on the top of the stack:

  • When entering a nested Loop, push a Loop state onto the stack.

  • When entering a nested Switch, push a Switch state onto the stack with a clone of the introduced bool variable’s name.

  • When encountering a Continue statement, render it as code to set the introduced bool local (whose name is held in variable) to true, and then break. Set continue_encountered to true to record that the Switch contains a Continue.

  • When exiting this Switch, pop its entry from the stack. If continue_encountered is set, then we have rendered Continue statements as break statements that jump to this point. Generate code to check variable, and if it is true:

    • If there is another Switch left on top of the stack, set its continue_encountered flag, and generate a break. (Both Switches are within the same Loop and share the same introduced variable, so there’s no need to set another flag to continue to exit the switches.)

    • Otherwise, continue.

When we exit the Switch for which this entry was pushed, pop it.

Fields

§variable: Rc<String>
§continue_encountered: bool

Set if we’ve generated code for a Continue statement with this entry on the top of the stack.

If this is still clear when we finish rendering the Switch, then we know we don’t need to generate branch forwarding code. Omitting that may make it easier for drivers to tell that the bool we introduced ahead of the Switch is actually unused.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.