Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Jul 10, 2023
1 parent 4e0185d commit 281ce68
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/hugr/typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,42 @@ pub fn typecheck_const(typ: &ClassicType, val: &ConstValue) -> Result<(), ConstT
}
(ClassicType::F64, ConstValue::F64(_)) => Ok(()),
(ty @ ClassicType::Container(c), tm) => match c {
Container::Tuple(row) => if let ConstValue::Tuple(xs) = tm {
if row.len() != xs.len() {
return Err(ConstTypeError::TupleWrongLength);
Container::Tuple(row) => {
if let ConstValue::Tuple(xs) = tm {
if row.len() != xs.len() {
return Err(ConstTypeError::TupleWrongLength);
}
for (ty, tm) in row.iter().zip(xs.iter()) {
match ty {
SimpleType::Classic(ty) => typecheck_const(ty, tm)?,
_ => return Err(ConstTypeError::LinearTypeDisallowed),
}
}
Ok(())
} else {
Err(ConstTypeError::Failed(ty.clone()))
}
for (ty, tm) in row.iter().zip(xs.iter()) {
}
Container::Sum(row) => {
if let ConstValue::Sum { tag, variants, val } = tm {
if tag > &row.len() {
return Err(ConstTypeError::InvalidSumTag);
}
if **row != *variants {
return Err(ConstTypeError::TypeRowMismatch(
*row.clone(),
variants.clone(),
));
}
let ty = variants.get(*tag).unwrap();
match ty {
SimpleType::Classic(ty) => typecheck_const(ty, tm)?,
_ => return Err(ConstTypeError::LinearTypeDisallowed),
SimpleType::Classic(ty) => typecheck_const(ty, val.as_ref()),
_ => Err(ConstTypeError::LinearTypeDisallowed),
}
} else {
Err(ConstTypeError::Failed(ty.clone()))
}
Ok(())
} else {Err(ConstTypeError::Failed(ty.clone()))},
Container::Sum(row) => if let ConstValue::Sum { tag, variants, val } = tm {
if tag > &row.len() {
return Err(ConstTypeError::InvalidSumTag);
}
if **row != *variants {
return Err(ConstTypeError::TypeRowMismatch(
*row.clone(),
variants.clone(),
));
}
let ty = variants.get(*tag).unwrap();
match ty {
SimpleType::Classic(ty) => typecheck_const(ty, val.as_ref()),
_ => Err(ConstTypeError::LinearTypeDisallowed),
}
} else {Err(ConstTypeError::Failed(ty.clone()))},
}
_ => Err(ConstTypeError::Unimplemented(ty.clone())),
},
(ty @ ClassicType::Graph(_), _) => Err(ConstTypeError::Unimplemented(ty.clone())),
Expand Down

0 comments on commit 281ce68

Please sign in to comment.