Document some parts of ConstantEvaluator. (#2489)

This commit is contained in:
Jim Blandy authored and Teodor Tanasoaia committed 2023-10-12 13:13:26 +02:00
1 parent ca69a6b372
commit 44ca6ac5b3
1 file changed
+11
+11
View File
@@ -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)
}
}
@@ -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>,