@@ -51,6 +51,7 @@ use crate::prelude::*;
5151use crate :: { EntityIndex , ModuleInternedTypeIndex , PrimaryMap , WasmValType } ;
5252use cranelift_entity:: packed_option:: PackedOption ;
5353use serde_derive:: { Deserialize , Serialize } ;
54+ use wasmparser:: collections:: Map ;
5455
5556/// Metadata as a result of compiling a component.
5657pub 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 ) ]
74160pub 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 ///
0 commit comments