Skip to content

Commit

Permalink
fixed escape! in last stmt in block
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Sep 23, 2023
1 parent 7a90da4 commit 8308a19
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion luisa_compute/examples/mpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ fn main() {
grid_m.var().atomic_fetch_add(idx, weight * P_MASS);
});
});
let _ = (); // WHAT?
}),
);

Expand Down
12 changes: 10 additions & 2 deletions luisa_compute_track/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,30 @@ use pretty_assertions::assert_eq;
struct TraceVisitor {
trait_path: TokenStream,
flow_path: TokenStream,
is_last_stmt: bool,
}

impl VisitMut for TraceVisitor {
fn visit_block_mut(&mut self, node: &mut Block) {
let len = node.stmts.len();
if len > 0 {
for stmt in node.stmts[0..len - 1].iter_mut() {
let old = self.is_last_stmt;
self.is_last_stmt = false;
self.visit_stmt_mut(stmt);
self.is_last_stmt = old;
}
visit_stmt_mut(self, node.stmts.last_mut().unwrap());
let old = self.is_last_stmt;
self.is_last_stmt = true;
self.visit_stmt_mut(node.stmts.last_mut().unwrap());
self.is_last_stmt = old;
}
}
fn visit_stmt_mut(&mut self, node: &mut Stmt) {
let span = node.span();
match node {
Stmt::Expr(_, semi) => {
if semi.is_none() {
if !self.is_last_stmt && semi.is_none() {
*semi = Some(Token![;](span));
}
}
Expand Down Expand Up @@ -337,6 +344,7 @@ pub fn tracked(

fn track_impl(mut ast: Expr) -> TokenStream {
(TraceVisitor {
is_last_stmt: false,
flow_path: quote!(::luisa_compute::lang::control_flow),
trait_path: quote!(::luisa_compute::lang::ops),
})
Expand Down

0 comments on commit 8308a19

Please sign in to comment.