diff --git a/src/proc/constant_evaluator.rs b/src/proc/constant_evaluator.rs index 249b365c59..88c03bf57f 100644 --- a/src/proc/constant_evaluator.rs +++ b/src/proc/constant_evaluator.rs @@ -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,