pub fn resolve_struct_def_with_fetcher<'txn, F: ModuleFetcher>(
        &'txn self,
        module: &LoadedModule,
        idx: StructDefinitionIndex,
        gas_meter: &GasMeter,
        fetcher: &F,
    ) -> VMResult<Option<StructDef>> {
        if let Some(def) = module.cached_struct_def_at(idx) {
            return Ok(Some(def));
        }
        let def = {
            let struct_def = module.struct_def_at(idx);
            let struct_handle = module.struct_handle_at(struct_def.struct_handle);
            let type_context =
                TypeContext::identity_mapping(struct_handle.type_formals.len() as u16);
            match &struct_def.field_information {
                // TODO we might want a more informative error here
                StructFieldInformation::Native => {
                    return Err(VMStatus::new(StatusCode::LINKER_ERROR))
                }
                StructFieldInformation::Declared {
                    field_count,
                    fields,
                } => {
                    let mut field_types = vec![];
                    for field in module.field_def_range(*field_count, *fields) {
                        let ty = self.resolve_signature_token_with_fetcher(
                            module,
                            &module.type_signature_at(field.signature).0,
                            &type_context,
                            gas_meter,
                            fetcher,
                        )?;
                        if let Some(t) = ty {
                            // `field_types` is initally empty, a single element is pushed
                            // per loop iteration and the number of iterations is bound to
                            // the max size of `module.field_def_range()`.
                            // MIRAI cannot currently check this bound in terms of
                            // `field_count`.
                            assume!(field_types.len() < usize::max_value());
                            field_types.push(t);
                        } else {
                            return Ok(None);
                        }
                    }
                    StructDef::new(field_types)
                }
            }
        };
        // If multiple writers write to def at the same time, the last one will win. It's possible
        // to have multiple copies of a struct def floating around, but that probably isn't going
        // to be a big deal.
        module.cache_struct_def(idx, def.clone());
        Ok(Some(def))
    }
/// Resolve a StructDefinition into a StructDef recursively in either the cache or the
/// `fetcher`.
Resolve a StructDefinition into a StructDef recursively in either the cache or the
`fetcher`.
Resolve a StructDefinition into a StructDef recursively in either the cache or the ` fetcher ` .
pub fn resolve_struct_def_with_fetcher<'txn, F: ModuleFetcher>(
        &'txn self,
        module: &LoadedModule,
        idx: StructDefinitionIndex,
        gas_meter: &GasMeter,
        fetcher: &F,
    ) -> VMResult<Option<StructDef>> {
        if let Some(def) = module.cached_struct_def_at(idx) {
            return Ok(Some(def));
        }
        let def = {
            let struct_def = module.struct_def_at(idx);
            let struct_handle = module.struct_handle_at(struct_def.struct_handle);
            let type_context =
                TypeContext::identity_mapping(struct_handle.type_formals.len() as u16);
            match &struct_def.field_information {
                // TODO we might want a more informative error here
                StructFieldInformation::Native => {
                    return Err(VMStatus::new(StatusCode::LINKER_ERROR))
                }
                StructFieldInformation::Declared {
                    field_count,
                    fields,
                } => {
                    let mut field_types = vec![];
                    for field in module.field_def_range(*field_count, *fields) {
                        let ty = self.resolve_signature_token_with_fetcher(
                            module,
                            &module.type_signature_at(field.signature).0,
                            &type_context,
                            gas_meter,
                            fetcher,
                        )?;
                        if let Some(t) = ty {
                            // `field_types` is initally empty, a single element is pushed
                            // per loop iteration and the number of iterations is bound to
                            // the max size of `module.field_def_range()`.
                            // MIRAI cannot currently check this bound in terms of
                            // `field_count`.
                            assume!(field_types.len() < usize::max_value());
                            field_types.push(t);
                        } else {
                            return Ok(None);
                        }
                    }
                    StructDef::new(field_types)
                }
            }
        };
        // If multiple writers write to def at the same time, the last one will win. It's possible
        // to have multiple copies of a struct def floating around, but that probably isn't going
        // to be a big deal.
        module.cache_struct_def(idx, def.clone());
        Ok(Some(def))
    }
pub fn resolve_struct_def_with_fetcher < ' txn , F : ModuleFetcher > ( & ' txn self , module : & LoadedModule , idx : StructDefinitionIndex , gas_meter : & GasMeter , fetcher : & F , ) -> VMResult < Option < StructDef > > { if let Some ( def ) = module . cached_struct_def_at ( idx ) { return Ok ( Some ( def ) ) ; } let def = { let struct_def = module . struct_def_at ( idx ) ; let struct_handle = module . struct_handle_at ( struct_def . struct_handle ) ; let type_context = TypeContext :: identity_mapping ( struct_handle . type_formals . len ( ) as u16 ) ; match & struct_def . field_information { // TODO we might want a more informative error here StructFieldInformation :: Native => { return Err ( VMStatus :: new ( StatusCode :: LINKER_ERROR ) ) } StructFieldInformation :: Declared { field_count , fields , } => { let mut field_types = vec ! [ ] ; for field in module . field_def_range ( * field_count , * fields ) { let ty = self . resolve_signature_token_with_fetcher ( module , & module . type_signature_at ( field . signature ) . 0 , & type_context , gas_meter , fetcher , ) ? ; if let Some ( t ) = ty { // `field_types` is initally empty, a single element is pushed // per loop iteration and the number of iterations is bound to // the max size of `module.field_def_range()`. // MIRAI cannot currently check this bound in terms of // `field_count`. assume ! ( field_types len ( ) usize max_value ( ) ) ; field_types . push ( t ) ; } else { return Ok ( None ) ; } } StructDef :: new ( field_types ) } } } ; // If multiple writers write to def at the same time, the last one will win. It's possible // to have multiple copies of a struct def floating around, but that probably isn't going // to be a big deal. module . cache_struct_def ( idx , def . clone ( ) ) ; Ok ( Some ( def ) ) }
Resolve a StructDefinition into a StructDef recursively in either the cache or the
`fetcher`.
Resolve a StructDefinition into a StructDef recursively in either the cache or the ` fetcher ` .
&'txn self
module
&LoadedModule
idx
StructDefinitionIndex
gas_meter
&GasMeter
fetcher
&F