| 102 | /// over there for documentation and rationale. |
| 103 | #[repr(C)] |
| 104 | pub struct ComponentInstance { |
| 105 | /// The index within the store of where to find this component instance. |
| 106 | id: ComponentInstanceId, |
| 107 | |
| 108 | /// Size and offset information for the trailing `VMComponentContext`. |
| 109 | offsets: VMComponentOffsets<HostPtr>, |
| 110 | |
| 111 | /// The component that this instance was created from. |
| 112 | // |
| 113 | // NB: in the future if necessary it would be possible to avoid storing an |
| 114 | // entire `Component` here and instead storing only information such as: |
| 115 | // |
| 116 | // * Some reference to `Arc<ComponentTypes>` |
| 117 | // * Necessary references to closed-over modules which are exported from the |
| 118 | // component itself. |
| 119 | // |
| 120 | // Otherwise the full guts of this component should only ever be used during |
| 121 | // the instantiation of this instance, meaning that after instantiation much |
| 122 | // of the component can be thrown away (theoretically). |
| 123 | // |
| 124 | // SAFETY: this field cannot be overwritten after an instance is created. It |
| 125 | // must contain this exact same value for the entire lifetime of this |
| 126 | // instance. This enables borrowing the component and this instance at the |
| 127 | // same time (instance mutably, component not). Additionally it enables |
| 128 | // borrowing a store mutably at the same time as a contained instance. |
| 129 | component: Component, |
| 130 | |
| 131 | /// Contains state specific to each (sub-)component instance within this |
| 132 | /// top-level instance. |
| 133 | instance_states: TryPrimaryMap<RuntimeComponentInstanceIndex, InstanceState>, |
| 134 | |
| 135 | /// What all compile-time-identified core instances are mapped to within the |
| 136 | /// `Store` that this component belongs to. |
| 137 | instances: TryPrimaryMap<RuntimeInstanceIndex, InstanceId>, |
| 138 | |
| 139 | /// Storage for the type information about resources within this component |
| 140 | /// instance. |
| 141 | resource_types: Arc<TryPrimaryMap<ResourceIndex, ResourceType>>, |
| 142 | |
| 143 | /// Arguments that this instance used to be instantiated. |
| 144 | /// |
| 145 | /// Strong references are stored to these arguments since pointers are saved |
| 146 | /// into the structures such as functions within the |
| 147 | /// `OwnedComponentInstance` but it's our job to keep them alive. |
| 148 | /// |
| 149 | /// One purpose of this storage is to enable embedders to drop a `Linker`, |
| 150 | /// for example, after a component is instantiated. In that situation if the |
| 151 | /// arguments weren't held here then they might be dropped, and structures |
| 152 | /// such as `.lowering()` which point back into the original function would |
| 153 | /// become stale and use-after-free conditions when used. By preserving the |
| 154 | /// entire list here though we're guaranteed that nothing is lost for the |
| 155 | /// duration of the lifetime of this instance. |
| 156 | imports: Arc<PrimaryMap<RuntimeImportIndex, RuntimeImport>>, |
| 157 | |
| 158 | /// Self-pointer back to `Store<T>` and its functions. |
| 159 | store: VMStoreRawPtr, |
| 160 | |
| 161 | /// Required by `InstanceLayout`, also required to be the last field (with |
no outgoing calls
no test coverage detected