Fold constant slice: if all parts are compile-time constants, emit LOAD_CONST(slice).
(
&mut self,
lower: Option<&ast::Expr>,
upper: Option<&ast::Expr>,
step: Option<&ast::Expr>,
)
| 9503 | |
| 9504 | /// Fold constant slice: if all parts are compile-time constants, emit LOAD_CONST(slice). |
| 9505 | fn try_fold_constant_slice( |
| 9506 | &mut self, |
| 9507 | lower: Option<&ast::Expr>, |
| 9508 | upper: Option<&ast::Expr>, |
| 9509 | step: Option<&ast::Expr>, |
| 9510 | ) -> CompileResult<bool> { |
| 9511 | let to_const = |expr: Option<&ast::Expr>, this: &mut Self| -> CompileResult<_> { |
| 9512 | match expr { |
| 9513 | None => Ok(Some(ConstantData::None)), |
| 9514 | Some(expr) => this.try_fold_constant_expr(expr), |
| 9515 | } |
| 9516 | }; |
| 9517 | |
| 9518 | let (Some(start), Some(stop), Some(step_val)) = ( |
| 9519 | to_const(lower, self)?, |
| 9520 | to_const(upper, self)?, |
| 9521 | to_const(step, self)?, |
| 9522 | ) else { |
| 9523 | return Ok(false); |
| 9524 | }; |
| 9525 | |
| 9526 | self.emit_load_const(ConstantData::Slice { |
| 9527 | elements: Box::new([start, stop, step_val]), |
| 9528 | }); |
| 9529 | Ok(true) |
| 9530 | } |
| 9531 | |
| 9532 | fn emit_return_const(&mut self, constant: ConstantData) { |
| 9533 | self.emit_load_const(constant); |
no test coverage detected