Skip to content

Commit e3cdd97

Browse files
committed
use wasmparser Map instead of std in environ::component::info
1 parent e19e01c commit e3cdd97

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

crates/environ/src/component/info.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use crate::prelude::*;
5151
use crate::{EntityIndex, ModuleInternedTypeIndex, PrimaryMap, WasmValType};
5252
use cranelift_entity::packed_option::PackedOption;
5353
use serde_derive::{Deserialize, Serialize};
54-
use std::collections::HashMap;
54+
use wasmparser::collections::Map;
5555

5656
/// Metadata as a result of compiling a component.
5757
pub struct ComponentTranslation {
@@ -66,26 +66,24 @@ pub struct ComponentTranslation {
6666
/// The elements within [`Self::instances`] correspond to the runtime component
6767
/// instances which directly instantiate core modules. Each element should contain the information
6868
/// needed to identify the source of their imports. Specific information about how that is
69-
/// implemented is available in [`dfg::RuntimeComponentInstanceStructure`]
69+
/// implemented is available in [`info::RuntimeComponentInstanceStructure`]
7070
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
7171
pub struct RootComponentInstanceStructure {
7272
/// Subcomponent instances that instantiate core modules directly. The keys are the [`RuntimeComponentInstanceStructure.path`]
73-
pub instances: HashMap<String, RuntimeComponentInstanceStructure>,
73+
pub instances: Map<String, RuntimeComponentInstanceStructure>,
7474

7575
/// Re-mapping table from the [`RuntimeComponentInstanceIndex`] to [`RuntimeComponentInstanceStructure.path`]
76-
pub table: HashMap<u32, String>,
76+
pub table: Map<u32, String>,
7777
}
7878

7979
impl RootComponentInstanceStructure {
8080
/// todo:
81-
pub fn runtime_instances_mut(
82-
&mut self,
83-
) -> &mut HashMap<String, RuntimeComponentInstanceStructure> {
81+
pub fn runtime_instances_mut(&mut self) -> &mut Map<String, RuntimeComponentInstanceStructure> {
8482
&mut self.instances
8583
}
8684

8785
/// todo:
88-
pub fn table_mut(&mut self) -> &mut HashMap<u32, String> {
86+
pub fn table_mut(&mut self) -> &mut Map<u32, String> {
8987
&mut self.table
9088
}
9189
}
@@ -96,11 +94,11 @@ pub struct CoreInstanceStructure {
9694
/// Hex encoded sha256 digest of the core module binary.
9795
pub module_code_digest: String,
9896
/// Exported items from this core instance
99-
pub core_exports: HashMap<u32, String>,
97+
pub core_exports: Map<u32, String>,
10098
/// Imported items by this core instance
101-
pub core_imports: HashMap<u32, String>,
99+
pub core_imports: Map<u32, String>,
102100
/// The sources of the imported items
103-
pub sources: HashMap<u32, Source>,
101+
pub sources: Map<u32, Source>,
104102
}
105103

106104
/// Represents a core export definition in the instantiation graph, used to track the source of
@@ -141,11 +139,11 @@ pub struct RuntimeComponentInstanceStructure {
141139
pub path: String,
142140

143141
/// Maps to the core definitions that are being exported by this component.
144-
pub component_exports: HashMap<u32, Source>,
142+
pub component_exports: Map<u32, Source>,
145143

146144
/// Map of the core instances associated with this component instance.
147145
/// The index represents the core instance index within the index space of this component.
148-
pub core_instances: HashMap<u32, CoreInstanceStructure>,
146+
pub core_instances: Map<u32, CoreInstanceStructure>,
149147
}
150148

151149
/// Run-time-type-information about a `Component`, its structure, and how to

crates/environ/src/component/translate/inline.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ use core::str::FromStr;
5252
use sha2::{Digest, Sha256};
5353
use std::borrow::Cow;
5454
use std::ops::Index;
55+
use wasmparser::collections::Map;
5556
use wasmparser::component_types::{ComponentAnyTypeId, ComponentCoreModuleTypeId};
5657

5758
pub(super) fn run(
@@ -377,7 +378,7 @@ fn record_core_def_from_export(
377378
name: &str,
378379
def: ComponentItemDef,
379380
types: &ComponentTypesBuilder,
380-
map: &mut HashMap<String, dfg::CoreDef>,
381+
map: &mut Map<String, dfg::CoreDef>,
381382
) -> Result<()> {
382383
match &def {
383384
ComponentItemDef::Instance(instance) => match instance {
@@ -502,7 +503,7 @@ impl<'a> Inliner<'a> {
502503
exports: &IndexMap<&str, ComponentItemDef>,
503504
fr: &mut InlinerFrame,
504505
) -> Result<()> {
505-
let mut comp_exports: HashMap<String, dfg::CoreDef> = HashMap::new();
506+
let mut comp_exports: Map<String, dfg::CoreDef> = Map::new();
506507
for (name, item) in exports.iter() {
507508
record_core_def_from_export(name, item.clone(), types, &mut comp_exports)?;
508509
}
@@ -1313,8 +1314,8 @@ impl<'a> Inliner<'a> {
13131314
// and an initializer is recorded to indicate that it's being
13141315
// instantiated.
13151316
ModuleInstantiate(module, args) => {
1316-
let mut core_imports: HashMap<u32, String> = Default::default();
1317-
let mut sources: HashMap<u32, Source> = Default::default();
1317+
let mut core_imports: Map<u32, String> = Default::default();
1318+
let mut sources: Map<u32, Source> = Default::default();
13181319

13191320
let (instance_module, init) = match &frame.modules[*module] {
13201321
ModuleDef::Static(idx, _ty) => {
@@ -1386,7 +1387,7 @@ impl<'a> Inliner<'a> {
13861387
match &frame.modules[*module] {
13871388
ModuleDef::Static(midx, _ty) => {
13881389
let core_instance = frame.module_instances.len() as u32;
1389-
let mut core_exports: HashMap<u32, String> = HashMap::new();
1390+
let mut core_exports: Map<u32, String> = Map::new();
13901391
let mut count = 0;
13911392
for (name, &entity) in self.nested_modules[*midx].module.exports.iter() {
13921393
core_exports.insert(count, name.to_string());

0 commit comments

Comments
 (0)