Skip to content

Commit ded4004

Browse files
committed
fix formatting and compilation issue due to dfg structs
1 parent 0a837ee commit ded4004

File tree

8 files changed

+120
-103
lines changed

8 files changed

+120
-103
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/environ/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ semver = { workspace = true, optional = true, features = ['serde'] }
3939
smallvec = { workspace = true, features = ['serde'] }
4040
# Needed for the binary digest of modules in the instantiation graph
4141
hex = "0.4.3"
42-
sha2 = "0.10.9"
42+
sha2 = "0.10.2"
4343

4444
[dev-dependencies]
4545
clap = { workspace = true, features = ['default'] }

crates/environ/src/component.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ pub const PREPARE_ASYNC_WITH_RESULT: u32 = u32::MAX - 1;
5252
pub const START_FLAG_ASYNC_CALLEE: i32 = 1 << 0;
5353

5454
mod artifacts;
55-
mod info;
55+
/// Expose the generated component internals
56+
///
57+
pub mod info;
58+
5659
mod intrinsic;
5760
mod names;
5861
mod types;

crates/environ/src/component/dfg.rs

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use anyhow::Result;
3434
use cranelift_entity::packed_option::PackedOption;
3535
use indexmap::IndexMap;
3636
use info::LinearMemoryOptions;
37-
use serde_derive::{Deserialize, Serialize};
3837
use std::collections::HashMap;
3938
use std::hash::Hash;
4039
use std::ops::Index;
@@ -153,91 +152,7 @@ pub struct ComponentDfg {
153152
pub options: Intern<OptionsId, CanonicalOptions>,
154153

155154
/// Structure describing the component internal layout, useful for debugging, attestation, etc...
156-
pub instantiation_graph: RootComponentInstanceStructure,
157-
}
158-
159-
/// A view over the runtime interactions between the subcomponents of a webassembly application.
160-
/// The elements within [`Self::instances`] correspond to the runtime component
161-
/// instances which directly instantiate core modules. Each element should contain the information
162-
/// needed to identify the source of their imports. Specific information about how that is
163-
/// implemented is available in [`dfg::RuntimeComponentInstanceStructure`]
164-
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
165-
pub struct RootComponentInstanceStructure {
166-
/// Subcomponent instances that instantiate core modules directly. The keys are the [`RuntimeComponentInstanceStructure.path`]
167-
pub instances: HashMap<String, RuntimeComponentInstanceStructure>,
168-
169-
/// Re-mapping table from the [`RuntimeComponentInstanceIndex`] to [`RuntimeComponentInstanceStructure.path`]
170-
pub table: HashMap<u32, String>,
171-
}
172-
173-
impl RootComponentInstanceStructure {
174-
pub(crate) fn runtime_instances_mut(
175-
&mut self,
176-
) -> &mut HashMap<String, RuntimeComponentInstanceStructure> {
177-
&mut self.instances
178-
}
179-
180-
pub(crate) fn table_mut(&mut self) -> &mut HashMap<u32, String> {
181-
&mut self.table
182-
}
183-
}
184-
185-
/// Part of the instantiation graph, it represents a core instance of a component instance
186-
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
187-
pub struct CoreInstanceStructure {
188-
/// Hex encoded sha256 digest of the core module binary.
189-
pub module_code_digest: String,
190-
/// Exported items from this core instance
191-
pub core_exports: HashMap<u32, String>,
192-
/// Imported items by this core instance
193-
pub core_imports: HashMap<u32, String>,
194-
/// The sources of the imported items
195-
pub sources: HashMap<u32, Source>,
196-
}
197-
198-
/// Represents a core export definition in the instantiation graph, used to track the source of
199-
/// core module imports or the source of component exports
200-
#[derive(Serialize, Deserialize, Clone, Debug)]
201-
pub struct Source {
202-
/// Dot [`.`] separated indices to identify a component instance entry in the instantiation graph
203-
pub path: String,
204-
/// Index of the referenced core instance within the instance represented by the path
205-
pub core_instance: u32,
206-
/// Index of the referenced export entry
207-
pub export: u32,
208-
}
209-
210-
impl Source {
211-
/// Associates imports with the host as the source.
212-
pub fn host() -> Source {
213-
Source {
214-
path: "host".to_string(),
215-
core_instance: 0,
216-
export: 0,
217-
}
218-
}
219-
220-
/// Full path through the instantiation graph to a core export entry
221-
pub fn full_path(self) -> String {
222-
format!("{}.{}.{}", self.path, self.core_instance, self.export)
223-
}
224-
}
225-
226-
/// Part of the instantiation graph. Represents a component instance which instantiates *statically*
227-
/// known modules. Corresponds to a [`RuntimeComponentInstanceIndex`].
228-
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
229-
pub struct RuntimeComponentInstanceStructure {
230-
/// The path of this runtime component instance starting from the root.
231-
/// E.g. `0.1.4` where each number corresponds to the instance index in the
232-
/// previous component index space. So instance 4 of instance 1 of .
233-
pub path: String,
234-
235-
/// Maps to the core definitions that are being exported by this component.
236-
pub component_exports: HashMap<u32, Source>,
237-
238-
/// Map of the core instances associated with this component instance.
239-
/// The index represents the core instance index within the index space of this component.
240-
pub core_instances: HashMap<u32, CoreInstanceStructure>,
155+
pub instantiation_graph: info::RootComponentInstanceStructure,
241156
}
242157

243158
/// Possible side effects that are possible with instantiating this component.

crates/environ/src/component/info.rs

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +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 wasmparser::collections::Map;
5455

5556
/// Metadata as a result of compiling a component.
5657
pub struct ComponentTranslation {
@@ -61,6 +62,91 @@ pub struct ComponentTranslation {
6162
pub trampolines: PrimaryMap<TrampolineIndex, Trampoline>,
6263
}
6364

65+
/// A view over the runtime interactions between the subcomponents of a webassembly application.
66+
/// The elements within [`Self::instances`] correspond to the runtime component
67+
/// instances which directly instantiate core modules. Each element should contain the information
68+
/// needed to identify the source of their imports. Specific information about how that is
69+
/// implemented is available in [`info::RuntimeComponentInstanceStructure`]
70+
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
71+
pub struct RootComponentInstanceStructure {
72+
/// Subcomponent instances that instantiate core modules directly. The keys are the [`RuntimeComponentInstanceStructure.path`]
73+
pub instances: Map<String, RuntimeComponentInstanceStructure>,
74+
75+
/// Re-mapping table from the [`RuntimeComponentInstanceIndex`] to [`RuntimeComponentInstanceStructure.path`]
76+
pub table: Map<u32, String>,
77+
}
78+
79+
impl RootComponentInstanceStructure {
80+
/// Returns a mutable reference to the map of runtime component instances
81+
/// contained within this root component.
82+
pub fn runtime_instances_mut(&mut self) -> &mut Map<String, RuntimeComponentInstanceStructure> {
83+
&mut self.instances
84+
}
85+
86+
/// Returns a mutable reference to the component table associated with this root component.
87+
pub fn table_mut(&mut self) -> &mut Map<u32, String> {
88+
&mut self.table
89+
}
90+
}
91+
92+
/// Part of the instantiation graph, it represents a core instance of a component instance
93+
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
94+
pub struct CoreInstanceStructure {
95+
/// Hex encoded sha256 digest of the core module binary.
96+
pub module_code_digest: String,
97+
/// Exported items from this core instance
98+
pub core_exports: Map<u32, String>,
99+
/// Imported items by this core instance
100+
pub core_imports: Map<u32, String>,
101+
/// The sources of the imported items
102+
pub sources: Map<u32, Source>,
103+
}
104+
105+
/// Represents a core export definition in the instantiation graph, used to track the source of
106+
/// core module imports or the source of component exports
107+
#[derive(Serialize, Deserialize, Clone, Debug)]
108+
pub struct Source {
109+
/// Dot [`.`] separated indices to identify a component instance entry in the instantiation graph
110+
pub path: String,
111+
/// Index of the referenced core instance within the instance represented by the path
112+
pub core_instance: u32,
113+
/// Index of the referenced export entry
114+
pub export: u32,
115+
}
116+
117+
impl Source {
118+
/// Associates imports with the host as the source.
119+
pub fn host() -> Source {
120+
Source {
121+
path: "host".to_string(),
122+
core_instance: 0,
123+
export: 0,
124+
}
125+
}
126+
127+
/// Full path through the instantiation graph to a core export entry
128+
pub fn full_path(self) -> String {
129+
format!("{}.{}.{}", self.path, self.core_instance, self.export)
130+
}
131+
}
132+
133+
/// Part of the instantiation graph. Represents a component instance which instantiates *statically*
134+
/// known modules. Corresponds to a [`RuntimeComponentInstanceIndex`].
135+
#[derive(Serialize, Deserialize, Default, Clone, Debug)]
136+
pub struct RuntimeComponentInstanceStructure {
137+
/// The path of this runtime component instance starting from the root.
138+
/// E.g. `0.1.4` where each number corresponds to the instance index in the
139+
/// previous component index space. So instance 4 of instance 1 of .
140+
pub path: String,
141+
142+
/// Maps to the core definitions that are being exported by this component.
143+
pub component_exports: Map<u32, Source>,
144+
145+
/// Map of the core instances associated with this component instance.
146+
/// The index represents the core instance index within the index space of this component.
147+
pub core_instances: Map<u32, CoreInstanceStructure>,
148+
}
149+
64150
/// Run-time-type-information about a `Component`, its structure, and how to
65151
/// instantiate it.
66152
///
@@ -73,7 +159,7 @@ pub struct ComponentTranslation {
73159
#[derive(Default, Debug, Serialize, Deserialize)]
74160
pub struct Component {
75161
/// Component Structure keeping track of the runtime instances dependency graph
76-
pub instantiation_graph: dfg::RootComponentInstanceStructure,
162+
pub instantiation_graph: RootComponentInstanceStructure,
77163

78164
/// A list of typed values that this component imports.
79165
///

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@
4545
//! side-effectful initializers are emitted to the `GlobalInitializer` list in the
4646
//! final `Component`.
4747
48-
use crate::component::dfg::{CoreInstanceStructure, RuntimeComponentInstanceStructure, Source};
48+
pub use self::info::*;
4949
use crate::component::translate::*;
5050
use crate::{EntityType, IndexType};
5151
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 {
@@ -491,24 +492,28 @@ impl<'a> Inliner<'a> {
491492
}
492493
}
493494

494-
/// Records the runtime sources for each component export,
495-
/// so the instantiation graph later knows which
495+
/// Records the runtime sources for each component export,
496+
/// so the instantiation graph later knows which
496497
/// core definitions they depend on.
497-
/// Here internal component exports are recorded in addition to the
498-
/// exports recoreded for the top level component.
498+
/// Here internal component exports are recorded in addition to the
499+
/// exports recorded for the top level component.
499500
fn add_component_exports(
500501
&mut self,
501502
types: &mut ComponentTypesBuilder,
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
}
509510
let mut count = 0;
510511
for (_, func) in comp_exports {
511-
let source = self.core_def_to_sources.get(&func).unwrap_or(&Source::host()).clone();
512+
let source = self
513+
.core_def_to_sources
514+
.get(&func)
515+
.unwrap_or(&Source::host())
516+
.clone();
512517
fr.instance_structure
513518
.component_exports
514519
.insert(count, source);
@@ -1309,8 +1314,8 @@ impl<'a> Inliner<'a> {
13091314
// and an initializer is recorded to indicate that it's being
13101315
// instantiated.
13111316
ModuleInstantiate(module, args) => {
1312-
let mut core_imports: HashMap<u32, String> = Default::default();
1313-
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();
13141319

13151320
let (instance_module, init) = match &frame.modules[*module] {
13161321
ModuleDef::Static(idx, _ty) => {
@@ -1382,7 +1387,7 @@ impl<'a> Inliner<'a> {
13821387
match &frame.modules[*module] {
13831388
ModuleDef::Static(midx, _ty) => {
13841389
let core_instance = frame.module_instances.len() as u32;
1385-
let mut core_exports: HashMap<u32, String> = HashMap::new();
1390+
let mut core_exports: Map<u32, String> = Map::new();
13861391
let mut count = 0;
13871392
for (name, &entity) in self.nested_modules[*midx].module.exports.iter() {
13881393
core_exports.insert(count, name.to_string());

crates/wasmtime/src/runtime/component/component.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::path::Path;
1818
use wasmtime_environ::component::{
1919
CompiledComponentInfo, ComponentArtifacts, ComponentTypes, CoreDef, Export, ExportIndex,
2020
GlobalInitializer, InstantiateModule, NameMapNoIntern, OptionsIndex, StaticModuleIndex,
21-
TrampolineIndex, TypeComponentIndex, TypeFuncIndex, UnsafeIntrinsic, VMComponentOffsets, dfg,
21+
TrampolineIndex, TypeComponentIndex, TypeFuncIndex, UnsafeIntrinsic, VMComponentOffsets, info,
2222
};
2323
use wasmtime_environ::{Abi, CompiledFunctionsTable, FuncKey, TypeTrace};
2424
use wasmtime_environ::{FunctionLoc, HostPtr, ObjectKind, PrimaryMap};
@@ -882,7 +882,7 @@ impl Component {
882882
}
883883

884884
/// Returns the Instantiation Graph.
885-
pub fn instantiation_graph(&self) -> &dfg::RootComponentInstanceStructure {
885+
pub fn instantiation_graph(&self) -> &info::RootComponentInstanceStructure {
886886
&self.inner.info.component.instantiation_graph
887887
}
888888
}

crates/wasmtime/src/runtime/component/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ pub use self::func::{
131131
};
132132
pub use self::has_data::*;
133133
pub use self::instance::{Instance, InstanceExportLookup, InstancePre};
134-
pub use self::linker::{Linker, LinkerInstance};
135134
#[cfg(feature = "caller")]
136135
pub use self::linker::CallerInstance;
136+
pub use self::linker::{Linker, LinkerInstance};
137137
pub use self::resource_table::{ResourceTable, ResourceTableError};
138138
pub use self::resources::{Resource, ResourceAny, ResourceDynamic};
139139
pub use self::types::{ResourceType, Type};

0 commit comments

Comments
 (0)