Currently
Produces a Cast expression from a 128 bit wide 3 to int[32]. This loosely follow a document on how Rust treats literals in the first levels of compilation. We recently introduced storing the value of x in a table of const values. We store this Cast expression. This then has to be parsed to extract the value 3 when it is used later.
This Cast should either be avoided, or immediately reduced to a Literal of type int[32]. In particular, the Cast should never appear in the ASG (or any other persistent structure). This does not change the semantics of the program, and simplifies using the table of const values.
This would allow us, for example, to avoid this match arm:
|
impl TryFrom<&TExpr> for u32 { |
|
type Error = TryFromU32Error; |
|
fn try_from(value: &TExpr) -> Result<Self, TryFromU32Error> { |
|
match &value.expression { |
|
Expr::Cast(thecast) => { |
|
match **thecast { |
|
Cast { |
|
operand: |
|
TExpr { |
|
expression: |
|
Expr::Literal(Literal::Int(IntLiteral { |
|
value: int_value, |
|
sign: true, |
|
})), |
|
ty: _, // Type::Int(_, _), |
|
}, |
|
typ: _, // Type::Int(_, _), |
|
} => u32::try_from(int_value).map_err(|_| TryFromU32Error), |
|
_ => Err(TryFromU32Error), |
|
} |
|
} |
|
_ => Err(TryFromU32Error), |
|
} |
|
} |
|
} |
Currently
Produces a
Castexpression from a 128 bit wide3toint[32]. This loosely follow a document on how Rust treats literals in the first levels of compilation. We recently introduced storing the value ofxin a table ofconstvalues. We store thisCastexpression. This then has to be parsed to extract the value3when it is used later.This
Castshould either be avoided, or immediately reduced to aLiteralof typeint[32]. In particular, theCastshould never appear in the ASG (or any other persistent structure). This does not change the semantics of the program, and simplifies using the table ofconstvalues.This would allow us, for example, to avoid this match arm:
openqasm3_parser/crates/oq3_semantics/src/asg.rs
Lines 169 to 193 in 02a7c6b