Skip to content

Commit

Permalink
fixup! use LocalVariable init
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Oct 9, 2023
1 parent 3ba1ad8 commit 4eeeb49
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let mut typifier = Typifier::default();
let mut body = self.block(
&f.body,
true,
StatementContext {
local_table: &mut local_table,
globals: ctx.globals,
Expand Down Expand Up @@ -1056,12 +1057,13 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
fn block(
&mut self,
b: &ast::Block<'source>,
is_fn_body: bool,
mut ctx: StatementContext<'source, '_, '_>,
) -> Result<crate::Block, Error<'source>> {
let mut block = crate::Block::default();

for stmt in b.stmts.iter() {
self.statement(stmt, &mut block, ctx.reborrow())?;
self.statement(stmt, &mut block, is_fn_body, ctx.reborrow())?;
}

Ok(block)
Expand All @@ -1071,11 +1073,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
&mut self,
stmt: &ast::Statement<'source>,
block: &mut crate::Block,
is_fn_body: bool,
mut ctx: StatementContext<'source, '_, '_>,
) -> Result<(), Error<'source>> {
let out = match stmt.kind {
ast::StatementKind::Block(ref block) => {
let block = self.block(block, ctx.reborrow())?;
let block = self.block(block, false, ctx.reborrow())?;
crate::Statement::Block(block)
}
ast::StatementKind::LocalDecl(ref decl) => match *decl {
Expand Down Expand Up @@ -1160,7 +1163,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
let (const_initializer, initializer) = {
match initializer {
Some(init) if ctx.expression_constness.is_const(init) => {
(Some(init), None)
(Some(init), (!is_fn_body).then_some(init))
}
Some(init) => (None, Some(init)),
None => (None, None),
Expand Down Expand Up @@ -1210,8 +1213,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
self.expression(condition, ctx.as_expression(block, &mut emitter))?;
block.extend(emitter.finish(ctx.naga_expressions));

let accept = self.block(accept, ctx.reborrow())?;
let reject = self.block(reject, ctx.reborrow())?;
let accept = self.block(accept, false, ctx.reborrow())?;
let reject = self.block(reject, false, ctx.reborrow())?;

crate::Statement::If {
condition,
Expand Down Expand Up @@ -1256,7 +1259,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
ast::SwitchValue::Default => crate::SwitchValue::Default,
},
body: self.block(&case.body, ctx.reborrow())?,
body: self.block(&case.body, false, ctx.reborrow())?,
fall_through: case.fall_through,
})
})
Expand All @@ -1269,8 +1272,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
ref continuing,
break_if,
} => {
let body = self.block(body, ctx.reborrow())?;
let mut continuing = self.block(continuing, ctx.reborrow())?;
let body = self.block(body, false, ctx.reborrow())?;
let mut continuing = self.block(continuing, false, ctx.reborrow())?;

let mut emitter = Emitter::default();
emitter.start(ctx.naga_expressions);
Expand Down
2 changes: 2 additions & 0 deletions tests/out/spv/atomicCompareExchange.spvasm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ OpBranch %43
%47 = OpAccessChain %46 %22 %45
%48 = OpAtomicLoad %4 %47 %49 %50
OpStore %29 %48
OpStore %32 %23
OpBranch %51
%51 = OpLabel
OpLoopMerge %52 %54 None
Expand Down Expand Up @@ -153,6 +154,7 @@ OpBranch %92
%96 = OpAccessChain %95 %78 %94
%97 = OpAtomicLoad %3 %96 %49 %50
OpStore %80 %97
OpStore %82 %23
OpBranch %98
%98 = OpLabel
OpLoopMerge %99 %101 None
Expand Down
2 changes: 2 additions & 0 deletions tests/out/wgsl/atomicCompareExchange.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn test_atomic_compare_exchange_i32_() {
let _e6 = i;
let _e8 = atomicLoad((&arr_i32_[_e6]));
old = _e8;
exchanged = false;
loop {
let _e12 = exchanged;
if !(_e12) {
Expand Down Expand Up @@ -62,6 +63,7 @@ fn test_atomic_compare_exchange_u32_() {
let _e6 = i_1;
let _e8 = atomicLoad((&arr_u32_[_e6]));
old_1 = _e8;
exchanged_1 = false;
loop {
let _e12 = exchanged_1;
if !(_e12) {
Expand Down

0 comments on commit 4eeeb49

Please sign in to comment.