Skip to content

Commit ce953d9

Browse files
committed
test type checking
1 parent 3cc9f84 commit ce953d9

30 files changed

+274
-203
lines changed

examples/error-examples/thread_idx_offset.desc renamed to examples/error-examples/thread_idx_offset.desc.off

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ fn npu_vec_add<r: prv, n: nat>(
2121
) -[grid: npu.grid<X<64>, X<1024>>]-> () {
2222
sched block in grid {
2323
sched thread in block {
24-
let a_ref = &uniq (*a_array).to_view.grp::<1024>[[block]][[thread + offset]];
25-
*a_ref = *a_ref + (*b_array).to_view.grp::<1024>[[block]][[thread + offset]]
24+
let a = thread + offset;
25+
let b = thread + offset;
26+
let a_ref = &uniq (*a_array).to_view.grp::<1024>[[block]][[a]];
27+
*a_ref = *a_ref + (*b_array).to_view.grp::<1024>[[block]][[b]]
2628
}
2729
}
2830
}

src/ast/internal.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,19 @@ impl PlaceCtx {
170170
PlaceCtx::Hole => PlaceCtx::Hole,
171171
PlaceCtx::Proj(pl_ctx, i) => {
172172
if let PlaceCtx::Hole = **pl_ctx {
173-
panic!("There must be an innermost deref context as created by PlaceExpr.to_pl_ctx_and_most_specif_pl.")
173+
panic!(
174+
"There must be an innermost deref context as created by PlaceExpr.to_pl_ctx_and_most_specif_pl."
175+
)
174176
} else {
175177
let inner_ctx = pl_ctx.without_innermost_deref();
176178
PlaceCtx::Proj(Box::new(inner_ctx), *i)
177179
}
178180
}
179181
PlaceCtx::FieldProj(pl_ctx, field_name) => {
180182
if let PlaceCtx::Hole = **pl_ctx {
181-
panic!("There must be an innermost deref context as created by PlaceExpr.to_pl_ctx_and_most_specif_pl.")
183+
panic!(
184+
"There must be an innermost deref context as created by PlaceExpr.to_pl_ctx_and_most_specif_pl."
185+
)
182186
} else {
183187
let inner_ctx = pl_ctx.without_innermost_deref();
184188
PlaceCtx::FieldProj(Box::new(inner_ctx), field_name.clone())

src/ast/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,13 +1649,11 @@ impl NatCtx {
16491649
}
16501650

16511651
pub fn find(&self, name: &str) -> Option<usize> {
1652-
self.frames.iter().flatten().rev().find_map(|(i, n)| {
1653-
if i.as_ref() == name {
1654-
Some(*n)
1655-
} else {
1656-
None
1657-
}
1658-
})
1652+
self.frames
1653+
.iter()
1654+
.flatten()
1655+
.rev()
1656+
.find_map(|(i, n)| if i.as_ref() == name { Some(*n) } else { None })
16591657
}
16601658

16611659
pub fn push_empty_frame(&mut self) -> &mut Self {

src/ast/span.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl From<Span> for miette::SourceSpan {
2424
fn from(span: Span) -> Self {
2525
miette::SourceSpan::new(
2626
miette::SourceOffset::from(span.begin as usize),
27-
(span.end - span.begin) as usize
27+
(span.end - span.begin) as usize,
2828
)
2929
}
3030
}

src/ast/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::ast::visit::walk_list;
21
use crate::ast::visit::Visit;
2+
use crate::ast::visit::walk_list;
33
use crate::ast::visit_mut::VisitMut;
44
use crate::ast::{
5-
visit, visit_mut, ArgKinded, BaseExec, DataTy, DataTyKind, Dim, ExecExpr, ExecTy, Expr,
6-
ExprKind, FnTy, FunDef, Ident, IdentExec, IdentKinded, Kind, Memory, Nat, ParamSig, Provenance,
7-
Ty, TyKind,
5+
ArgKinded, BaseExec, DataTy, DataTyKind, Dim, ExecExpr, ExecTy, Expr, ExprKind, FnTy, FunDef,
6+
Ident, IdentExec, IdentKinded, Kind, Memory, Nat, ParamSig, Provenance, Ty, TyKind, visit,
7+
visit_mut,
88
};
99
use std::collections::{HashMap, HashSet};
1010
use std::sync::atomic::{AtomicI32, Ordering};

src/codegen/mlir/builder/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
//! All functions return `Result<T, MlirError>` for proper error handling.
2020
2121
use super::super::error::{
22-
missing_result_error, operation_build_error, type_parse_error, MlirError,
22+
MlirError, missing_result_error, operation_build_error, type_parse_error,
2323
};
2424
use melior::{
25+
Context,
2526
dialect::{arith, scf},
2627
ir::{
28+
BlockLike, BlockRef, Location, Type, Value,
2729
attribute::{FloatAttribute, IntegerAttribute},
2830
operation::OperationBuilder,
2931
r#type::IntegerType,
30-
BlockLike, BlockRef, Location, Type, Value,
3132
},
32-
Context,
3333
};
3434
use std::collections::HashMap;
3535

src/codegen/mlir/builder/control_flow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use melior::{
44
};
55

66
use super::super::error::MlirError;
7-
use super::context::{append_yield, MlirContext};
7+
use super::context::{MlirContext, append_yield};
88
use super::expr::build_expr;
99
use crate::ast as desc;
1010

src/codegen/mlir/builder/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use melior::ir::Value;
22

3-
use super::super::error::{missing_result_error, MlirError};
3+
use super::super::error::{MlirError, missing_result_error};
44
use super::context::MlirContext;
55
use super::control_flow::{build_if, build_if_else};
66
use super::literal::build_literal;
@@ -154,7 +154,7 @@ where
154154
ExprKind::App(ident, _gen_args, args) => {
155155
use melior::{
156156
dialect::func,
157-
ir::{attribute::FlatSymbolRefAttribute, BlockLike, Type},
157+
ir::{BlockLike, Type, attribute::FlatSymbolRefAttribute},
158158
};
159159

160160
// Lower operands

src/codegen/mlir/builder/literal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use melior::ir::{attribute::IntegerAttribute, r#type::IntegerType, Value};
1+
use melior::ir::{Value, attribute::IntegerAttribute, r#type::IntegerType};
22

33
use super::super::error::MlirError;
4-
use super::context::{create_constant, create_float_constant, create_int_constant, MlirContext};
4+
use super::context::{MlirContext, create_constant, create_float_constant, create_int_constant};
55
use crate::ast as desc;
66

77
/// Build a literal constant

0 commit comments

Comments
 (0)