Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Sep 6, 2024
1 parent 1760535 commit d613758
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions naga/src/proc/constant_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ enum LiteralVector {
}

impl LiteralVector {
#[allow(clippy::pattern_type_mismatch)]
const fn len(&self) -> usize {
#[allow(clippy::pattern_type_mismatch, clippy::missing_const_for_fn)]
fn len(&self) -> usize {
match self {
LiteralVector::F64(v) => v.len(),
LiteralVector::F32(v) => v.len(),
Expand Down Expand Up @@ -441,7 +441,7 @@ impl LiteralVector {
}
}

/// Returns [`ArrayVec`] of [`Literals`]
/// Returns [`ArrayVec`] of [`Literal`]s
fn to_literal_vec(&self) -> ArrayVec<Literal, { crate::VectorSize::MAX }> {
#[allow(clippy::pattern_type_mismatch)]
match self {
Expand All @@ -459,13 +459,16 @@ impl LiteralVector {
}
}

fn to_expr(&self, eval: &mut ConstantEvaluator<'_>) -> Expression {
fn to_expr(
&self,
eval: &mut ConstantEvaluator<'_>,
) -> Result<Expression, ConstantEvaluatorError> {
let lit_vec = self.to_literal_vec();
assert!(!lit_vec.is_empty());
if lit_vec.len() == 1 {
Expression::Literal(lit_vec[0])
Ok(Expression::Literal(lit_vec[0]))
} else {
Expression::Compose {
Ok(Expression::Compose {
ty: eval.types.insert(
Type {
name: None,
Expand All @@ -483,12 +486,9 @@ impl LiteralVector {
),
components: lit_vec
.iter()
.map(|&l| {
eval.expressions
.append(Expression::Literal(l), Span::UNDEFINED)
})
.collect(),
}
.map(|&l| eval.register_evaluated_expr(Expression::Literal(l), Span::UNDEFINED))
.collect::<Result<_, _>>()?,
})
}
}

Expand All @@ -498,7 +498,7 @@ impl LiteralVector {
eval: &mut ConstantEvaluator<'_>,
span: Span,
) -> Result<Handle<Expression>, ConstantEvaluatorError> {
let expr = self.to_expr(eval);
let expr = self.to_expr(eval)?;
eval.register_evaluated_expr(expr, span)
}
}
Expand Down

0 comments on commit d613758

Please sign in to comment.