Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added error.rs
Empty file.
1 change: 1 addition & 0 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ impl Dim {
}

#[derive(PartialEq, Eq, PartialOrd, Hash, Debug, Copy, Clone)]
// Dimension Component
pub enum DimCompo {
X,
Y,
Expand Down
11 changes: 8 additions & 3 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,6 @@ peg::parser! {
mod tests {
use super::*;


#[test]
fn nat_literal() {
assert_eq!(descend::nat("0"), Ok(Nat::Lit(0)), "cannot parse 0");
Expand Down Expand Up @@ -2471,12 +2470,18 @@ mod tests {
#[test]
fn empty_annotate_snippet() {
let source = SourceCode::new("fn\n".to_string());
assert!(parse(&source).is_err(), "Expected a parsing error and specifically not a panic!");
assert!(
parse(&source).is_err(),
"Expected a parsing error and specifically not a panic!"
);
}

#[test]
fn empty_annotate_snippet2() {
let source = SourceCode::new("fn ".to_string());
assert!(parse(&source).is_err(), "Expected a parsing error and specifically not a panic!");
assert!(
parse(&source).is_err(),
"Expected a parsing error and specifically not a panic!"
);
}
}
112 changes: 104 additions & 8 deletions src/ty_check/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use super::Ty;
use crate::ast::internal::Place;
use crate::ast::printer::PrintState;
use crate::ast::{BaseExec, DataTy, Expr, Ident, NatEvalError, Ownership, PlaceExpr, TyKind};
use crate::ast::{
BaseExec, BinOp, DataTy, DataTyKind, DimCompo, ExecTy, ExecTyKind, Expr, FnTy, Ident, Memory,
NatEvalError, Ownership, PlaceExpr, RefDty, TyKind,
};
use crate::error;
use crate::error::{default_format, ErrorReported};
use crate::parser::SourceCode;
Expand Down Expand Up @@ -36,6 +39,7 @@ pub enum TyError {
SplittingNonViewArray,
// Expected a different type
ExpectedTupleType(TyKind, PlaceExpr),
ExpectedStructType(TyKind, PlaceExpr),
// Trying to borrow uniquely but place is not mutable
ConstBorrow(PlaceExpr),
// The borrowed view type is at least paritally dead
Expand All @@ -50,7 +54,9 @@ pub enum TyError {
CouldNotInferProvenance,
// The annotated or inferred type of the pattern does not fit the pattern.
PatternAndTypeDoNotMatch,
UnexpectedType,
UnexpectedType(Ty),
UnexpectedFnTy(FnTy),
UnexpectedDataType(DataTy),
// The thread hierarchy dimension referred to does not exist
IllegalDimension,
UnifyError(UnifyError),
Expand All @@ -60,14 +66,103 @@ pub enum TyError {
UnsafeRequired,
// TODO remove as soon as possible
String(String),

// Newly added errors
// Index, Array/Tuplegit Length
IndexOutOfBounds(usize, usize),
// The indexed expression is not an array or a tuple
CannotIndex,
// The expression is not a reference
CannotDereference(DereferenceError),
// Struct does not have given field
FieldProjError(Ident),
// Select must be applied to an array or a view.
SelectError(PlaceExpr),
ExecError(ExecError),
SyncError(SyncError),
InvalidIterable(RefDty),
NotCopyable,
Moved(PlaceExpr, Moved),
LoopError(LoopError),
IfElseError(IfElseError),
ArrayError(ArrayError),
BinOpError(BinOp, Ty, Ty),
// Cannot cast from [0] to [1]
CastError(CastError),
}

impl<'a> FromIterator<TyError> for TyError {
fn from_iter<T: IntoIterator<Item = TyError>>(iter: T) -> Self {
TyError::MultiError(iter.into_iter().collect())
}
#[derive(Debug)]
pub enum Moved {
Partially,
Entirely,
}

#[derive(Debug)]
pub enum SyncError {
InvalidResourceType,
SplitResource,
NothingToSync,
}

#[derive(Debug)]
pub enum ExecError {
UnexpectedResourceType(ExecTyKind),
DimensionNotFound(DimCompo, ExecTyKind),
ExecToWarpError(ExecToWarpError),
InvalidSplit(ExecTyKind),
}

#[derive(Debug)]
pub enum ExecToWarpError {
MultipleDimensions(ExecTyKind),
DimNotDivBy32(ExecTyKind),
InvalidResourceType(ExecTyKind),
}

#[derive(Debug)]
pub enum DereferenceError {
// Trying to dereference a function (that is the only case).
InvalidTyKind(TyKind),
// Trying to dereference something that is not a reference
InvalidDataTyKind(DataTyKind),
// Trying to dereference a shrd reference
InvalidOwnership,
// Trying to dereference something that is not in the current resource
NotInExecRes(Memory, ExecTyKind),
}

#[derive(Debug)]
pub enum LoopError {
InvalidBlockType(DataTy),
InvalidConditionType(Ty),
ScopeError,
}

#[derive(Debug)]
pub enum IfElseError {
InvalidConditionType(Ty),
InvalidIfBlockType(Ty),
InvalidElseBlockType(Ty),
}

#[derive(Debug)]
pub enum ArrayError {
DifferentTypes(Ty, Ty),
}

#[derive(Debug)]
pub enum CastError {
FromTo(Ty, DataTy),
From(Ty),
}

// TODO: use this
// impl<'a> FromIterator<TyError> for TyError {
// fn from_iter<T: IntoIterator<Item = TyError>>(iter: T) -> Self {
// TyError::MultiError(iter.into_iter().collect())
// }
// }

impl TyError {
pub fn emit(&self, source: &SourceCode) -> ErrorReported {
match &self {
Expand Down Expand Up @@ -181,7 +276,8 @@ impl TyError {
eprintln!("{:?}", conflict)
}
BorrowingError::ConflictingOwnership => eprintln!("{:?}", conflict),
BorrowingError::ConflictingAccess => eprintln!("{:?}", conflict),
// TODO: better error message for conflicting access
BorrowingError::ConflictingAccess(_, _) => eprintln!("{:?}", conflict),
BorrowingError::CtxError(ctx_err) => eprintln!("{:?}", ctx_err),
BorrowingError::WrongDevice(under, from) => {
eprintln!("error: wrong device\nunder:{:?}\nfrom:{:?}", under, from)
Expand Down Expand Up @@ -317,7 +413,7 @@ pub enum BorrowingError {
// loan with {} capability.",
// checked_own, ref_own
ConflictingOwnership,
ConflictingAccess,
ConflictingAccess(Ownership, Ownership),
// The borrowing place is not in the reborrow list
BorrowNotInReborrowList(Place),
TemporaryConflictingBorrow(String),
Expand Down
52 changes: 26 additions & 26 deletions src/ty_check/exec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
BaseExec, BinOpNat, Dim, Dim1d, Dim2d, DimCompo, ExecExpr, ExecPathElem, ExecTy, ExecTyKind,
IdentExec, Nat, TyCtx, TyError, TyResult,
error::ExecError, BaseExec, BinOpNat, Dim, Dim1d, Dim2d, DimCompo, ExecExpr, ExecPathElem,
ExecTy, ExecTyKind, IdentExec, Nat, TyCtx, TyError, TyResult,
};
use crate::ast::{LeftOrRight, NatCtx};

Expand Down Expand Up @@ -71,10 +71,10 @@ fn ty_check_exec_to_threads(d: DimCompo, exec_ty: &ExecTyKind) -> TyResult<ExecT
Box::new(b.0),
)))),
_ => {
return Err(TyError::String(format!(
"Provided dimension {} does not exist",
d
)))
return Err(TyError::ExecError(ExecError::DimensionNotFound(
d,
exec_ty.clone(),
)));
}
};
match (rest_gdim, rest_bdim) {
Expand All @@ -85,19 +85,22 @@ fn ty_check_exec_to_threads(d: DimCompo, exec_ty: &ExecTyKind) -> TyResult<ExecT
_ => unimplemented!(),
}
} else {
Err(TyError::UnexpectedType)
Err(TyError::ExecError(ExecError::UnexpectedResourceType(
exec_ty.clone(),
)))
}
}

fn ty_check_exec_to_warps(nat_ctx: &NatCtx, exec_ty: &ExecTyKind) -> TyResult<ExecTyKind> {
use super::ExecToWarpError::*;
use ExecError::*;
match exec_ty {
ExecTyKind::GpuBlock(dim) => match dim.clone() {
Dim::X(d) => {
if d.0.eval(nat_ctx)? % 32 != 0 {
Err(TyError::String(format!(
"Size of GpuBlock needs to be evenly divisible by 32 to create warps, instead got: {:?}",
exec_ty
)))
Err(TyError::ExecError(ExecToWarpError(DimNotDivBy32(
exec_ty.clone(),
))))
} else {
Ok(ExecTyKind::GpuWarpGrp(Nat::BinOp(
BinOpNat::Div,
Expand All @@ -106,15 +109,13 @@ fn ty_check_exec_to_warps(nat_ctx: &NatCtx, exec_ty: &ExecTyKind) -> TyResult<Ex
)))
}
}
_ => Err(TyError::String(format!(
"GpuBlock needs to be one-dimensional to create warps, instead got: {:?}",
exec_ty
))),
_ => Err(TyError::ExecError(ExecToWarpError(MultipleDimensions(
exec_ty.clone(),
)))),
},
_ => Err(TyError::String(format!(
"Trying to create warps from {:?}",
exec_ty
))),
_ => Err(TyError::ExecError(ExecToWarpError(InvalidResourceType(
exec_ty.clone(),
)))),
}
}

Expand Down Expand Up @@ -159,13 +160,17 @@ fn ty_check_exec_forall(d: DimCompo, exec_ty: &ExecTyKind) -> TyResult<ExecTyKin
}
}
ex @ ExecTyKind::CpuThread | ex @ ExecTyKind::GpuThread | ex @ ExecTyKind::Any => {
return Err(TyError::String(format!("Cannot schedule over {:?}", ex)))
return Err(TyError::ExecError(ExecError::UnexpectedResourceType(
ex.clone(),
)))
}
};
Ok(res_ty)
}

pub fn remove_dim(dim: &Dim, dim_compo: DimCompo) -> TyResult<(Option<Dim>, Dim)> {
// given (dimension, dimension component)
// return (left over dimension, dimension from removing the specific dimension component)
match (dim, dim_compo) {
(Dim::XYZ(dim3d), DimCompo::X) => Ok((
Some(Dim::YZ(Box::new(Dim2d(
Expand Down Expand Up @@ -264,12 +269,7 @@ fn ty_check_exec_take_range(
panic!("GpuToThreads is not well-formed.")
}
}
ex => {
return Err(TyError::String(format!(
"Trying to split non-splittable execution resource: {:?}",
ex
)))
}
ex => return Err(TyError::ExecError(ExecError::InvalidSplit(ex.clone()))),
};
Ok(if proj == LeftOrRight::Left {
lexec_ty
Expand Down
2 changes: 1 addition & 1 deletion src/ty_check/infer_kinded_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::collections::HashMap;
// instantiation of a bound identifier
pub fn infer_kinded_args(poly_fn_ty: &FnTy, mono_fn_ty: &FnTy) -> TyResult<Vec<ArgKinded>> {
if poly_fn_ty.param_sigs.len() != mono_fn_ty.param_sigs.len() {
panic!("Unexpected difference in amount of paramters.")
panic!("Unexpected difference in amount of parameters.")
}
let mut res_map = HashMap::new();
for (subst_ty, mono_ty) in poly_fn_ty.param_sigs.iter().zip(&mono_fn_ty.param_sigs) {
Expand Down
Loading