Skip to content

Commit

Permalink
use local const ctx
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Jan 23, 2025
1 parent 11e5e8b commit 8650618
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ impl<'a, 'temp> StatementContext<'a, 'temp, '_> {
}
}

#[allow(dead_code)]
fn as_global(&mut self) -> GlobalContext<'a, '_, '_> {
GlobalContext {
ast_expressions: self.ast_expressions,
Expand Down Expand Up @@ -1617,7 +1618,6 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {

let uint =
resolve_inner!(ectx, selector).scalar_kind() == Some(crate::ScalarKind::Uint);
block.extend(emitter.finish(&ctx.function.expressions));

let cases = cases
.iter()
Expand All @@ -1626,8 +1626,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
value: match case.value {
ast::SwitchValue::Expr(expr) => {
let span = ctx.ast_expressions.get_span(expr);
let expr =
self.expression(expr, &mut ctx.as_global().as_const())?;
let expr = self
.expression(expr, &mut ctx.as_const(block, &mut emitter))?;
match ctx.module.to_ctx().eval_expr_to_literal(expr) {
Some(crate::Literal::I32(value)) if !uint => {
crate::SwitchValue::I32(value)
Expand All @@ -1648,6 +1648,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
})
.collect::<Result<_, _>>()?;

block.extend(emitter.finish(&ctx.function.expressions));

crate::Statement::Switch { selector, cases }
}
ast::StatementKind::Loop {
Expand Down Expand Up @@ -2936,7 +2938,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {

let offset = args
.next()
.map(|arg| self.expression(arg, &mut ctx.as_global().as_const()))
.map(|arg| self.expression(arg, &mut ctx.as_const()))
.ok()
.transpose()?;

Expand Down

0 comments on commit 8650618

Please sign in to comment.