Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document some parts of ConstantEvaluator. #2489

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/proc/constant_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,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 @@ -786,6 +790,13 @@ impl ConstantEvaluator<'_> {
Ok(self.register_constant(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