Skip to content

Commit

Permalink
Document some parts of ConstantEvaluator. (#2489)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblandy committed Oct 7, 2023
1 parent e2a764e commit 5267b58
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/proc/constant_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ impl ConstantEvaluator<'_> {
| Expression::Compose { .. }
| Expression::Splat { .. } => Ok(expr),
Expression::Constant(c) => {
// Are we working in a function's expression arena, or the
// module's constant expression arena?
if let Some(const_expressions) = self.const_expressions {
// Deep-copy the constant's value into our arena.
self.copy_from(self.constants[c].init, const_expressions)
} else {
// "See through" the constant and use its initializer.
Ok(self.constants[c].init)
}
}
Expand Down Expand Up @@ -783,6 +787,13 @@ impl ConstantEvaluator<'_> {
Ok(self.register_evaluated_expr(expr, span))
}

/// Deep copy `expr` from `expressions` into `self.expressions`.
///
/// Return the root of the new copy.
///
/// This is used when we're evaluating expressions in a function's
/// expression arena that refer to a constant: we need to copy the
/// constant's value into the function's arena so we can operate on it.
fn copy_from(
&mut self,
handle: Handle<Expression>,
Expand Down

0 comments on commit 5267b58

Please sign in to comment.