/// Outer evaluation for an expression which performs caching into `consts`.
Outer evaluation for an expression which performs caching into `consts`.
Outer evaluation for an expression which performs caching into ` consts ` .
pub(crate) fn eval_const(&mut self, ir: &ir::Ir, used: Used) -> Result<ConstValue, IrError> {
        log::trace!("processing constant: {}", self.item);
        if let Some(const_value) = self.consts.get(&self.item) {
            return Ok(const_value);
        }
        if !self.consts.mark(&self.item) {
            return Err(IrError::new(ir, IrErrorKind::ConstCycle));
        }
        let ir_value = match self.eval(ir, used) {
            Ok(ir_value) => ir_value,
            Err(outcome) => match outcome {
                IrEvalOutcome::Error(error) => {
                    return Err(error);
                }
                IrEvalOutcome::NotConst(span) => {
                    return Err(IrError::new(span, IrErrorKind::NotConst))
                }
                IrEvalOutcome::Break(span, _) => {
                    return Err(IrError::new(span, IrErrorKind::BreakOutsideOfLoop))
                }
            },
        };
        let const_value = ir_value.into_const(ir)?;
        if self
            .consts
            .insert(self.item.clone(), const_value.clone())
            .is_some()
        {
            return Err(IrError::new(ir, IrErrorKind::ConstCycle));
        }
        Ok(const_value)
    }
pub ( crate ) fn eval_const ( & mut self , ir : & ir :: Ir , used : Used ) -> Result < ConstValue , IrError > { log :: trace ! ( " " self item ) ; if let Some ( const_value ) = self . consts . get ( & self . item ) { return Ok ( const_value ) ; } if ! self . consts . mark ( & self . item ) { return Err ( IrError :: new ( ir , IrErrorKind :: ConstCycle ) ) ; } let ir_value = match self . eval ( ir , used ) { Ok ( ir_value ) => ir_value , Err ( outcome ) => match outcome { IrEvalOutcome :: Error ( error ) => { return Err ( error ) ; } IrEvalOutcome :: NotConst ( span ) => { return Err ( IrError :: new ( span , IrErrorKind :: NotConst ) ) } IrEvalOutcome :: Break ( span , _ ) => { return Err ( IrError :: new ( span , IrErrorKind :: BreakOutsideOfLoop ) ) } } , } ; let const_value = ir_value . into_const ( ir ) ? ; if self . consts . insert ( self . item . clone ( ) , const_value . clone ( ) ) . is_some ( ) { return Err ( IrError :: new ( ir , IrErrorKind :: ConstCycle ) ) ; } Ok ( const_value ) }
Outer evaluation for an expression which performs caching into `consts`.
Outer evaluation for an expression which performs caching into ` consts ` .
&mut self
ir
&ir::Ir
used
Used