cairo_lang_sierra/extensions/modules/
squashed_felt252_dict.rs

1use crate::extensions::SpecializationError;
2use crate::extensions::type_specialization_context::TypeSpecializationContext;
3use crate::extensions::types::{
4    GenericTypeArgGenericType, GenericTypeArgGenericTypeWrapper, TypeInfo,
5};
6use crate::ids::GenericTypeId;
7
8/// Type representing a static squashed dictionary from a felt252 to any type of size one.
9#[derive(Default)]
10pub struct SquashedFelt252DictTypeWrapped {}
11impl GenericTypeArgGenericType for SquashedFelt252DictTypeWrapped {
12    const ID: GenericTypeId = GenericTypeId::new_inline("SquashedFelt252Dict");
13
14    fn calc_info(
15        &self,
16        _context: &dyn TypeSpecializationContext,
17        long_id: crate::program::ConcreteTypeLongId,
18        TypeInfo { zero_sized, storable, droppable, .. }: TypeInfo,
19    ) -> Result<TypeInfo, SpecializationError> {
20        // Note: SquashedFelt252Dict is defined as non-duplicatable even if the inner type is
21        // duplicatable to allow libfunc that adds entries to it (treat it similarly to an array).
22        // TODO(Gil): the implementation support values of size 1. Remove when other sizes are
23        // supported.
24        if storable && !zero_sized {
25            Ok(TypeInfo {
26                long_id,
27                storable: true,
28                droppable,
29                duplicatable: false,
30                zero_sized: false,
31            })
32        } else {
33            Err(SpecializationError::UnsupportedGenericArg)
34        }
35    }
36}
37pub type SquashedFelt252DictType = GenericTypeArgGenericTypeWrapper<SquashedFelt252DictTypeWrapped>;