Skip to content
Snippets Groups Projects

Misc. improvements

Merged rarbore2 requested to merge misc into main
Files
3
+ 34
0
@@ -708,6 +708,40 @@ impl Constant {
}
}
// A zero constant may need to return constants that don't exist yet, so we
// need mutable access to the constants array.
pub fn try_product_fields(
&self,
types: &[Type],
constants: &mut Vec<Constant>,
) -> Option<Vec<ConstantID>> {
match self {
Constant::Product(_, fields) => Some(fields.iter().map(|x| *x).collect()),
Constant::Zero(ty) => match types[ty.idx()] {
Type::Product(ref fields) => Some(
fields
.iter()
.map(|field_ty| {
let field_constant = Constant::Zero(*field_ty);
if let Some(idx) = constants
.iter()
.position(|constant| *constant == field_constant)
{
ConstantID::new(idx)
} else {
let id = ConstantID::new(constants.len());
constants.push(field_constant);
id
}
})
.collect(),
),
_ => None,
},
_ => None,
}
}
pub fn try_array_type(&self, types: &[Type]) -> Option<TypeID> {
// Need types, since zero initializer may be for a collection type, ro
// not.
Loading