Coverage Report

Created: 2026-04-09 08:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wasmtime/crates/environ/src/component/dfg.rs
Line
Count
Source
1
//! A dataflow-graph-like intermediate representation of a component
2
//!
3
//! This module contains `ComponentDfg` which is an intermediate step towards
4
//! becoming a full-fledged `Component`. The main purpose for the existence of
5
//! this representation of a component is to track dataflow between various
6
//! items within a component and support edits to them after the initial inlined
7
//! translation of a component.
8
//!
9
//! Currently fused adapters are represented with a core WebAssembly module
10
//! which gets "injected" into the final component as-if the component already
11
//! bundled it. In doing so the adapter modules need to be partitioned and
12
//! inserted into the final sequence of modules to instantiate. While this is
13
//! possible to do with a flat `GlobalInitializer` list it gets unwieldy really
14
//! quickly especially when other translation features are added.
15
//!
16
//! This module is largely a duplicate of the `component::info` module in this
17
//! crate. The hierarchy here uses `*Id` types instead of `*Index` types to
18
//! represent that they don't have any necessary implicit ordering. Additionally
19
//! nothing is kept in an ordered list and instead this is worked with in a
20
//! general dataflow fashion where dependencies are walked during processing.
21
//!
22
//! The `ComponentDfg::finish` method will convert the dataflow graph to a
23
//! linearized `GlobalInitializer` list which is intended to not be edited after
24
//! it's created.
25
//!
26
//! The `ComponentDfg` is created as part of the `component::inline` phase of
27
//! translation where the dataflow performed there allows identification of
28
//! fused adapters, what arguments make their way to core wasm modules, etc.
29
30
use crate::component::*;
31
use crate::error::Result;
32
use crate::prelude::*;
33
use crate::{EntityIndex, EntityRef, ModuleInternedTypeIndex, PrimaryMap, WasmValType};
34
use cranelift_entity::packed_option::PackedOption;
35
use indexmap::IndexMap;
36
use info::LinearMemoryOptions;
37
use std::collections::HashMap;
38
use std::hash::Hash;
39
use std::ops::Index;
40
use wasmparser::component_types::ComponentCoreModuleTypeId;
41
42
/// High-level representation of a component as a "data-flow graph".
43
#[derive(Default)]
44
pub struct ComponentDfg {
45
    /// Same as `Component::import_types`
46
    pub import_types: PrimaryMap<ImportIndex, (String, TypeDef)>,
47
48
    /// Same as `Component::imports`
49
    pub imports: PrimaryMap<RuntimeImportIndex, (ImportIndex, Vec<String>)>,
50
51
    /// Same as `Component::exports`
52
    pub exports: IndexMap<String, Export>,
53
54
    /// All trampolines and their type signature which will need to get
55
    /// compiled by Cranelift.
56
    pub trampolines: Intern<TrampolineIndex, (ModuleInternedTypeIndex, Trampoline)>,
57
58
    /// A map from `UnsafeIntrinsic::index()` to that intrinsic's
59
    /// module-interned type.
60
    pub unsafe_intrinsics: [PackedOption<ModuleInternedTypeIndex>; UnsafeIntrinsic::len() as usize],
61
62
    /// Know reallocation functions which are used by `lowerings` (e.g. will be
63
    /// used by the host)
64
    pub reallocs: Intern<ReallocId, CoreDef>,
65
66
    /// Same as `reallocs`, but for async-lifted functions.
67
    pub callbacks: Intern<CallbackId, CoreDef>,
68
69
    /// Same as `reallocs`, but for post-return.
70
    pub post_returns: Intern<PostReturnId, CoreDef>,
71
72
    /// Same as `reallocs`, but for memories.
73
    pub memories: Intern<MemoryId, CoreExport<MemoryIndex>>,
74
75
    /// Same as `reallocs`, but for tables.
76
    pub tables: Intern<TableId, CoreExport<TableIndex>>,
77
78
    /// Metadata about identified fused adapters.
79
    ///
80
    /// Note that this list is required to be populated in-order where the
81
    /// "left" adapters cannot depend on "right" adapters. Currently this falls
82
    /// out of the inlining pass of translation.
83
    pub adapters: Intern<AdapterId, Adapter>,
84
85
    /// Metadata about all known core wasm instances created.
86
    ///
87
    /// This is mostly an ordered list and is not deduplicated based on contents
88
    /// unlike the items above. Creation of an `Instance` is side-effectful and
89
    /// all instances here are always required to be created. These are
90
    /// considered "roots" in dataflow.
91
    pub instances: PrimaryMap<InstanceId, Instance>,
92
93
    /// Number of component instances that were created during the inlining
94
    /// phase (this is not edited after creation).
95
    pub num_runtime_component_instances: u32,
96
97
    /// Known adapter modules and how they are instantiated.
98
    ///
99
    /// This map is not filled in on the initial creation of a `ComponentDfg`.
100
    /// Instead these modules are filled in by the `inline::adapt` phase where
101
    /// adapter modules are identified and filled in here.
102
    ///
103
    /// The payload here is the static module index representing the core wasm
104
    /// adapter module that was generated as well as the arguments to the
105
    /// instantiation of the adapter module.
106
    pub adapter_modules: PrimaryMap<AdapterModuleId, (StaticModuleIndex, Vec<CoreDef>)>,
107
108
    /// Metadata about where adapters can be found within their respective
109
    /// adapter modules.
110
    ///
111
    /// Like `adapter_modules` this is not filled on the initial creation of
112
    /// `ComponentDfg` but rather is created alongside `adapter_modules` during
113
    /// the `inline::adapt` phase of translation.
114
    ///
115
    /// The values here are the module that the adapter is present within along
116
    /// as the core wasm index of the export corresponding to the lowered
117
    /// version of the adapter.
118
    pub adapter_partitionings: PrimaryMap<AdapterId, (AdapterModuleId, EntityIndex)>,
119
120
    /// Defined resources in this component sorted by index with metadata about
121
    /// each resource.
122
    ///
123
    /// Note that each index here is a unique resource, and that may mean it was
124
    /// the same component instantiated twice for example.
125
    pub resources: PrimaryMap<DefinedResourceIndex, Resource>,
126
127
    /// Metadata about all imported resources into this component. This records
128
    /// both how many imported resources there are (the size of this map) along
129
    /// with what the corresponding runtime import is.
130
    pub imported_resources: PrimaryMap<ResourceIndex, RuntimeImportIndex>,
131
132
    /// The total number of future tables that will be used by this component.
133
    pub num_future_tables: usize,
134
135
    /// The total number of stream tables that will be used by this component.
136
    pub num_stream_tables: usize,
137
138
    /// The total number of error-context tables that will be used by this
139
    /// component.
140
    pub num_error_context_tables: usize,
141
142
    /// An ordered list of side effects induced by instantiating this component.
143
    ///
144
    /// Currently all side effects are either instantiating core wasm modules or
145
    /// declaring a resource. These side effects affect the dataflow processing
146
    /// of this component by idnicating what order operations should be
147
    /// performed during instantiation.
148
    pub side_effects: Vec<SideEffect>,
149
150
    /// Interned map of id-to-`CanonicalOptions`, or all sets-of-options used by
151
    /// this component.
152
    pub options: Intern<OptionsId, CanonicalOptions>,
153
}
154
155
/// Possible side effects that are possible with instantiating this component.
156
pub enum SideEffect {
157
    /// A core wasm instance was created.
158
    ///
159
    /// Instantiation is side-effectful due to the presence of constructs such
160
    /// as traps and the core wasm `start` function which may call component
161
    /// imports. Instantiation order from the original component must be done in
162
    /// the same order.
163
    Instance(InstanceId, RuntimeComponentInstanceIndex),
164
165
    /// A resource was declared in this component.
166
    ///
167
    /// This is a bit less side-effectful than instantiation but this serves as
168
    /// the order in which resources are initialized in a component with their
169
    /// destructors. Destructors are loaded from core wasm instances (or
170
    /// lowerings) which are produced by prior side-effectful operations.
171
    Resource(DefinedResourceIndex),
172
}
173
174
/// A sound approximation of a particular module's set of instantiations.
175
///
176
/// This type forms a simple lattice that we can use in static analyses that in
177
/// turn let us specialize a module's compilation to exactly the imports it is
178
/// given.
179
#[derive(Clone, Copy, Default)]
180
pub enum AbstractInstantiations<'a> {
181
    /// The associated module is instantiated many times.
182
    Many,
183
184
    /// The module is instantiated exactly once, with the given definitions as
185
    /// arguments to that instantiation.
186
    One(&'a [info::CoreDef]),
187
188
    /// The module is never instantiated.
189
    #[default]
190
    None,
191
}
192
193
impl AbstractInstantiations<'_> {
194
    /// Join two facts about a particular module's instantiation together.
195
    ///
196
    /// This is the least-upper-bound operation on the lattice.
197
22.5k
    pub fn join(&mut self, other: Self) {
198
22.5k
        *self = match (*self, other) {
199
65
            (Self::Many, _) | (_, Self::Many) => Self::Many,
200
4.45k
            (Self::One(a), Self::One(b)) if a == b => Self::One(a),
201
150
            (Self::One(_), Self::One(_)) => Self::Many,
202
18.0k
            (Self::One(a), Self::None) | (Self::None, Self::One(a)) => Self::One(a),
203
0
            (Self::None, Self::None) => Self::None,
204
        }
205
22.5k
    }
206
}
207
208
macro_rules! id {
209
    ($(pub struct $name:ident(u32);)*) => ($(
210
        #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
211
        #[expect(missing_docs, reason = "tedious to document")]
212
        pub struct $name(u32);
213
        cranelift_entity::entity_impl!($name);
214
    )*)
215
}
216
217
id! {
218
    pub struct InstanceId(u32);
219
    pub struct MemoryId(u32);
220
    pub struct TableId(u32);
221
    pub struct ReallocId(u32);
222
    pub struct CallbackId(u32);
223
    pub struct AdapterId(u32);
224
    pub struct PostReturnId(u32);
225
    pub struct AdapterModuleId(u32);
226
    pub struct OptionsId(u32);
227
}
228
229
/// Same as `info::InstantiateModule`
230
#[expect(missing_docs, reason = "tedious to document variants")]
231
pub enum Instance {
232
    Static(StaticModuleIndex, Box<[CoreDef]>),
233
    Import(
234
        RuntimeImportIndex,
235
        IndexMap<String, IndexMap<String, CoreDef>>,
236
    ),
237
}
238
239
/// Same as `info::Export`
240
#[expect(missing_docs, reason = "tedious to document variants")]
241
pub enum Export {
242
    LiftedFunction {
243
        ty: TypeFuncIndex,
244
        func: CoreDef,
245
        options: OptionsId,
246
    },
247
    ModuleStatic {
248
        ty: ComponentCoreModuleTypeId,
249
        index: StaticModuleIndex,
250
    },
251
    ModuleImport {
252
        ty: TypeModuleIndex,
253
        import: RuntimeImportIndex,
254
    },
255
    Instance {
256
        ty: TypeComponentInstanceIndex,
257
        exports: IndexMap<String, Export>,
258
    },
259
    Type(TypeDef),
260
}
261
262
/// Same as `info::CoreDef`, except has an extra `Adapter` variant.
263
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
264
#[expect(missing_docs, reason = "tedious to document variants")]
265
pub enum CoreDef {
266
    Export(CoreExport<EntityIndex>),
267
    InstanceFlags(RuntimeComponentInstanceIndex),
268
    Trampoline(TrampolineIndex),
269
    UnsafeIntrinsic(ModuleInternedTypeIndex, UnsafeIntrinsic),
270
    TaskMayBlock,
271
272
    /// This is a special variant not present in `info::CoreDef` which
273
    /// represents that this definition refers to a fused adapter function. This
274
    /// adapter is fully processed after the initial translation and
275
    /// identification of adapters.
276
    ///
277
    /// During translation into `info::CoreDef` this variant is erased and
278
    /// replaced by `info::CoreDef::Export` since adapters are always
279
    /// represented as the exports of a core wasm instance.
280
    Adapter(AdapterId),
281
}
282
283
impl<T> From<CoreExport<T>> for CoreDef
284
where
285
    EntityIndex: From<T>,
286
{
287
78.1k
    fn from(export: CoreExport<T>) -> CoreDef {
288
78.1k
        CoreDef::Export(export.map_index(|i| i.into()))
<wasmtime_environ::component::dfg::CoreDef as core::convert::From<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::EntityIndex>>>::from::{closure#0}
Line
Count
Source
288
69.2k
        CoreDef::Export(export.map_index(|i| i.into()))
<wasmtime_environ::component::dfg::CoreDef as core::convert::From<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::MemoryIndex>>>::from::{closure#0}
Line
Count
Source
288
8.79k
        CoreDef::Export(export.map_index(|i| i.into()))
289
78.1k
    }
<wasmtime_environ::component::dfg::CoreDef as core::convert::From<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::EntityIndex>>>::from
Line
Count
Source
287
69.3k
    fn from(export: CoreExport<T>) -> CoreDef {
288
69.3k
        CoreDef::Export(export.map_index(|i| i.into()))
289
69.3k
    }
<wasmtime_environ::component::dfg::CoreDef as core::convert::From<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::MemoryIndex>>>::from
Line
Count
Source
287
8.79k
    fn from(export: CoreExport<T>) -> CoreDef {
288
8.79k
        CoreDef::Export(export.map_index(|i| i.into()))
289
8.79k
    }
290
}
291
292
/// Same as `info::CoreExport`
293
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
294
#[expect(missing_docs, reason = "self-describing fields")]
295
pub struct CoreExport<T> {
296
    pub instance: InstanceId,
297
    pub item: ExportItem<T>,
298
}
299
300
impl<T> CoreExport<T> {
301
    #[expect(missing_docs, reason = "self-describing function")]
302
107k
    pub fn map_index<U>(self, f: impl FnOnce(T) -> U) -> CoreExport<U> {
303
        CoreExport {
304
107k
            instance: self.instance,
305
107k
            item: match self.item {
306
107k
                ExportItem::Index(i) => ExportItem::Index(f(i)),
307
35
                ExportItem::Name(s) => ExportItem::Name(s),
308
            },
309
        }
310
107k
    }
<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::EntityIndex>>::map_index::<wasmtime_environ::types::EntityIndex, <wasmtime_environ::component::dfg::CoreDef as core::convert::From<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::EntityIndex>>>::from::{closure#0}>
Line
Count
Source
302
69.3k
    pub fn map_index<U>(self, f: impl FnOnce(T) -> U) -> CoreExport<U> {
303
        CoreExport {
304
69.3k
            instance: self.instance,
305
69.3k
            item: match self.item {
306
69.2k
                ExportItem::Index(i) => ExportItem::Index(f(i)),
307
31
                ExportItem::Name(s) => ExportItem::Name(s),
308
            },
309
        }
310
69.3k
    }
<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::EntityIndex>>::map_index::<wasmtime_environ::types::TableIndex, <wasmtime_environ::component::translate::inline::Inliner>::initializer::{closure#3}>
Line
Count
Source
302
5
    pub fn map_index<U>(self, f: impl FnOnce(T) -> U) -> CoreExport<U> {
303
        CoreExport {
304
5
            instance: self.instance,
305
5
            item: match self.item {
306
5
                ExportItem::Index(i) => ExportItem::Index(f(i)),
307
0
                ExportItem::Name(s) => ExportItem::Name(s),
308
            },
309
        }
310
5
    }
<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::EntityIndex>>::map_index::<wasmtime_environ::types::MemoryIndex, <wasmtime_environ::component::translate::inline::Inliner>::memory::{closure#0}>
Line
Count
Source
302
22.5k
    pub fn map_index<U>(self, f: impl FnOnce(T) -> U) -> CoreExport<U> {
303
        CoreExport {
304
22.5k
            instance: self.instance,
305
22.5k
            item: match self.item {
306
22.5k
                ExportItem::Index(i) => ExportItem::Index(f(i)),
307
4
                ExportItem::Name(s) => ExportItem::Name(s),
308
            },
309
        }
310
22.5k
    }
<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::EntityIndex>>::map_index::<wasmtime_environ::types::MemoryIndex, wasmtime_environ::component::translate::adapt::fact_import_to_core_def::unwrap_memory::{closure#0}>
Line
Count
Source
302
6.51k
    pub fn map_index<U>(self, f: impl FnOnce(T) -> U) -> CoreExport<U> {
303
        CoreExport {
304
6.51k
            instance: self.instance,
305
6.51k
            item: match self.item {
306
6.51k
                ExportItem::Index(i) => ExportItem::Index(f(i)),
307
0
                ExportItem::Name(s) => ExportItem::Name(s),
308
            },
309
        }
310
6.51k
    }
<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::MemoryIndex>>::map_index::<wasmtime_environ::types::EntityIndex, <wasmtime_environ::component::dfg::CoreDef as core::convert::From<wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::MemoryIndex>>>::from::{closure#0}>
Line
Count
Source
302
8.79k
    pub fn map_index<U>(self, f: impl FnOnce(T) -> U) -> CoreExport<U> {
303
        CoreExport {
304
8.79k
            instance: self.instance,
305
8.79k
            item: match self.item {
306
8.79k
                ExportItem::Index(i) => ExportItem::Index(f(i)),
307
0
                ExportItem::Name(s) => ExportItem::Name(s),
308
            },
309
        }
310
8.79k
    }
311
}
312
313
/// Same as `info::Trampoline`
314
#[derive(Clone, PartialEq, Eq, Hash)]
315
#[expect(missing_docs, reason = "self-describing fields")]
316
pub enum Trampoline {
317
    LowerImport {
318
        import: RuntimeImportIndex,
319
        options: OptionsId,
320
        lower_ty: TypeFuncIndex,
321
    },
322
    Transcoder {
323
        op: Transcode,
324
        from: MemoryId,
325
        from64: bool,
326
        to: MemoryId,
327
        to64: bool,
328
    },
329
    ResourceNew {
330
        instance: RuntimeComponentInstanceIndex,
331
        ty: TypeResourceTableIndex,
332
    },
333
    ResourceRep {
334
        instance: RuntimeComponentInstanceIndex,
335
        ty: TypeResourceTableIndex,
336
    },
337
    ResourceDrop {
338
        instance: RuntimeComponentInstanceIndex,
339
        ty: TypeResourceTableIndex,
340
    },
341
    BackpressureInc {
342
        instance: RuntimeComponentInstanceIndex,
343
    },
344
    BackpressureDec {
345
        instance: RuntimeComponentInstanceIndex,
346
    },
347
    TaskReturn {
348
        instance: RuntimeComponentInstanceIndex,
349
        results: TypeTupleIndex,
350
        options: OptionsId,
351
    },
352
    TaskCancel {
353
        instance: RuntimeComponentInstanceIndex,
354
    },
355
    WaitableSetNew {
356
        instance: RuntimeComponentInstanceIndex,
357
    },
358
    WaitableSetWait {
359
        instance: RuntimeComponentInstanceIndex,
360
        options: OptionsId,
361
    },
362
    WaitableSetPoll {
363
        instance: RuntimeComponentInstanceIndex,
364
        options: OptionsId,
365
    },
366
    WaitableSetDrop {
367
        instance: RuntimeComponentInstanceIndex,
368
    },
369
    WaitableJoin {
370
        instance: RuntimeComponentInstanceIndex,
371
    },
372
    ThreadYield {
373
        instance: RuntimeComponentInstanceIndex,
374
        cancellable: bool,
375
    },
376
    SubtaskDrop {
377
        instance: RuntimeComponentInstanceIndex,
378
    },
379
    SubtaskCancel {
380
        instance: RuntimeComponentInstanceIndex,
381
        async_: bool,
382
    },
383
    StreamNew {
384
        instance: RuntimeComponentInstanceIndex,
385
        ty: TypeStreamTableIndex,
386
    },
387
    StreamRead {
388
        instance: RuntimeComponentInstanceIndex,
389
        ty: TypeStreamTableIndex,
390
        options: OptionsId,
391
    },
392
    StreamWrite {
393
        instance: RuntimeComponentInstanceIndex,
394
        ty: TypeStreamTableIndex,
395
        options: OptionsId,
396
    },
397
    StreamCancelRead {
398
        instance: RuntimeComponentInstanceIndex,
399
        ty: TypeStreamTableIndex,
400
        async_: bool,
401
    },
402
    StreamCancelWrite {
403
        instance: RuntimeComponentInstanceIndex,
404
        ty: TypeStreamTableIndex,
405
        async_: bool,
406
    },
407
    StreamDropReadable {
408
        instance: RuntimeComponentInstanceIndex,
409
        ty: TypeStreamTableIndex,
410
    },
411
    StreamDropWritable {
412
        instance: RuntimeComponentInstanceIndex,
413
        ty: TypeStreamTableIndex,
414
    },
415
    FutureNew {
416
        instance: RuntimeComponentInstanceIndex,
417
        ty: TypeFutureTableIndex,
418
    },
419
    FutureRead {
420
        instance: RuntimeComponentInstanceIndex,
421
        ty: TypeFutureTableIndex,
422
        options: OptionsId,
423
    },
424
    FutureWrite {
425
        instance: RuntimeComponentInstanceIndex,
426
        ty: TypeFutureTableIndex,
427
        options: OptionsId,
428
    },
429
    FutureCancelRead {
430
        instance: RuntimeComponentInstanceIndex,
431
        ty: TypeFutureTableIndex,
432
        async_: bool,
433
    },
434
    FutureCancelWrite {
435
        instance: RuntimeComponentInstanceIndex,
436
        ty: TypeFutureTableIndex,
437
        async_: bool,
438
    },
439
    FutureDropReadable {
440
        instance: RuntimeComponentInstanceIndex,
441
        ty: TypeFutureTableIndex,
442
    },
443
    FutureDropWritable {
444
        instance: RuntimeComponentInstanceIndex,
445
        ty: TypeFutureTableIndex,
446
    },
447
    ErrorContextNew {
448
        instance: RuntimeComponentInstanceIndex,
449
        ty: TypeComponentLocalErrorContextTableIndex,
450
        options: OptionsId,
451
    },
452
    ErrorContextDebugMessage {
453
        instance: RuntimeComponentInstanceIndex,
454
        ty: TypeComponentLocalErrorContextTableIndex,
455
        options: OptionsId,
456
    },
457
    ErrorContextDrop {
458
        instance: RuntimeComponentInstanceIndex,
459
        ty: TypeComponentLocalErrorContextTableIndex,
460
    },
461
    ResourceTransferOwn,
462
    ResourceTransferBorrow,
463
    PrepareCall {
464
        memory: Option<MemoryId>,
465
    },
466
    SyncStartCall {
467
        callback: Option<CallbackId>,
468
    },
469
    AsyncStartCall {
470
        callback: Option<CallbackId>,
471
        post_return: Option<PostReturnId>,
472
    },
473
    FutureTransfer,
474
    StreamTransfer,
475
    ErrorContextTransfer,
476
    Trap,
477
    EnterSyncCall,
478
    ExitSyncCall,
479
    ContextGet {
480
        instance: RuntimeComponentInstanceIndex,
481
        slot: u32,
482
    },
483
    ContextSet {
484
        instance: RuntimeComponentInstanceIndex,
485
        slot: u32,
486
    },
487
    ThreadIndex,
488
    ThreadNewIndirect {
489
        instance: RuntimeComponentInstanceIndex,
490
        start_func_ty_idx: ComponentTypeIndex,
491
        start_func_table_id: TableId,
492
    },
493
    ThreadSuspendToSuspended {
494
        instance: RuntimeComponentInstanceIndex,
495
        cancellable: bool,
496
    },
497
    ThreadSuspend {
498
        instance: RuntimeComponentInstanceIndex,
499
        cancellable: bool,
500
    },
501
    ThreadSuspendTo {
502
        instance: RuntimeComponentInstanceIndex,
503
        cancellable: bool,
504
    },
505
    ThreadUnsuspend {
506
        instance: RuntimeComponentInstanceIndex,
507
    },
508
    ThreadYieldToSuspended {
509
        instance: RuntimeComponentInstanceIndex,
510
        cancellable: bool,
511
    },
512
}
513
514
#[derive(Copy, Clone, Hash, Eq, PartialEq)]
515
#[expect(missing_docs, reason = "self-describing fields")]
516
pub struct FutureInfo {
517
    pub instance: RuntimeComponentInstanceIndex,
518
    pub payload_type: Option<InterfaceType>,
519
}
520
521
#[derive(Copy, Clone, Hash, Eq, PartialEq)]
522
#[expect(missing_docs, reason = "self-describing fields")]
523
pub struct StreamInfo {
524
    pub instance: RuntimeComponentInstanceIndex,
525
    pub payload_type: InterfaceType,
526
}
527
528
/// Same as `info::CanonicalOptionsDataModel`.
529
#[derive(Clone, Hash, Eq, PartialEq)]
530
#[expect(missing_docs, reason = "self-describing fields")]
531
pub enum CanonicalOptionsDataModel {
532
    Gc {},
533
    LinearMemory {
534
        memory: Option<MemoryId>,
535
        realloc: Option<ReallocId>,
536
    },
537
}
538
539
/// Same as `info::CanonicalOptions`
540
#[derive(Clone, Hash, Eq, PartialEq)]
541
#[expect(missing_docs, reason = "self-describing fields")]
542
pub struct CanonicalOptions {
543
    pub instance: RuntimeComponentInstanceIndex,
544
    pub string_encoding: StringEncoding,
545
    pub callback: Option<CallbackId>,
546
    pub post_return: Option<PostReturnId>,
547
    pub async_: bool,
548
    pub cancellable: bool,
549
    pub core_type: ModuleInternedTypeIndex,
550
    pub data_model: CanonicalOptionsDataModel,
551
}
552
553
/// Same as `info::Resource`
554
#[expect(missing_docs, reason = "self-describing fields")]
555
pub struct Resource {
556
    pub rep: WasmValType,
557
    pub dtor: Option<CoreDef>,
558
    pub instance: RuntimeComponentInstanceIndex,
559
}
560
561
/// A helper structure to "intern" and deduplicate values of type `V` with an
562
/// identifying key `K`.
563
///
564
/// Note that this can also be used where `V` can't be intern'd to represent a
565
/// flat list of items.
566
pub struct Intern<K: EntityRef, V> {
567
    intern_map: HashMap<V, K>,
568
    key_map: PrimaryMap<K, V>,
569
}
570
571
impl<K, V> Intern<K, V>
572
where
573
    K: EntityRef,
574
{
575
    /// Inserts the `value` specified into this set, returning either a fresh
576
    /// key `K` if this value hasn't been seen before or otherwise returning the
577
    /// previous `K` used to represent value.
578
    ///
579
    /// Note that this should only be used for component model items where the
580
    /// creation of `value` is not side-effectful.
581
76.7k
    pub fn push(&mut self, value: V) -> K
582
76.7k
    where
583
76.7k
        V: Hash + Eq + Clone,
584
    {
585
76.7k
        *self
586
76.7k
            .intern_map
587
76.7k
            .entry(value.clone())
588
76.7k
            .or_insert_with(|| self.key_map.push(value))
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::CallbackId, wasmtime_environ::component::dfg::CoreDef>>::push::{closure#0}
Line
Count
Source
588
2.66k
            .or_insert_with(|| self.key_map.push(value))
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::PostReturnId, wasmtime_environ::component::dfg::CoreDef>>::push::{closure#0}
Line
Count
Source
588
30
            .or_insert_with(|| self.key_map.push(value))
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::TableId, wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::TableIndex>>>::push::{closure#0}
Line
Count
Source
588
5
            .or_insert_with(|| self.key_map.push(value))
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::MemoryId, wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::MemoryIndex>>>::push::{closure#0}
Line
Count
Source
588
8.58k
            .or_insert_with(|| self.key_map.push(value))
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::AdapterId, wasmtime_environ::component::translate::adapt::Adapter>>::push::{closure#0}
Line
Count
Source
588
4.98k
            .or_insert_with(|| self.key_map.push(value))
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::OptionsId, wasmtime_environ::component::dfg::CanonicalOptions>>::push::{closure#0}
Line
Count
Source
588
14.3k
            .or_insert_with(|| self.key_map.push(value))
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::ReallocId, wasmtime_environ::component::dfg::CoreDef>>::push::{closure#0}
Line
Count
Source
588
8.50k
            .or_insert_with(|| self.key_map.push(value))
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::types::TrampolineIndex, (wasmtime_environ::types::ModuleInternedTypeIndex, wasmtime_environ::component::dfg::Trampoline)>>::push::{closure#0}
Line
Count
Source
588
24.9k
            .or_insert_with(|| self.key_map.push(value))
589
76.7k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::CallbackId, wasmtime_environ::component::dfg::CoreDef>>::push
Line
Count
Source
581
2.77k
    pub fn push(&mut self, value: V) -> K
582
2.77k
    where
583
2.77k
        V: Hash + Eq + Clone,
584
    {
585
2.77k
        *self
586
2.77k
            .intern_map
587
2.77k
            .entry(value.clone())
588
2.77k
            .or_insert_with(|| self.key_map.push(value))
589
2.77k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::PostReturnId, wasmtime_environ::component::dfg::CoreDef>>::push
Line
Count
Source
581
30
    pub fn push(&mut self, value: V) -> K
582
30
    where
583
30
        V: Hash + Eq + Clone,
584
    {
585
30
        *self
586
30
            .intern_map
587
30
            .entry(value.clone())
588
30
            .or_insert_with(|| self.key_map.push(value))
589
30
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::TableId, wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::TableIndex>>>::push
Line
Count
Source
581
5
    pub fn push(&mut self, value: V) -> K
582
5
    where
583
5
        V: Hash + Eq + Clone,
584
    {
585
5
        *self
586
5
            .intern_map
587
5
            .entry(value.clone())
588
5
            .or_insert_with(|| self.key_map.push(value))
589
5
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::MemoryId, wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::MemoryIndex>>>::push
Line
Count
Source
581
20.3k
    pub fn push(&mut self, value: V) -> K
582
20.3k
    where
583
20.3k
        V: Hash + Eq + Clone,
584
    {
585
20.3k
        *self
586
20.3k
            .intern_map
587
20.3k
            .entry(value.clone())
588
20.3k
            .or_insert_with(|| self.key_map.push(value))
589
20.3k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::AdapterId, wasmtime_environ::component::translate::adapt::Adapter>>::push
Line
Count
Source
581
4.98k
    pub fn push(&mut self, value: V) -> K
582
4.98k
    where
583
4.98k
        V: Hash + Eq + Clone,
584
    {
585
4.98k
        *self
586
4.98k
            .intern_map
587
4.98k
            .entry(value.clone())
588
4.98k
            .or_insert_with(|| self.key_map.push(value))
589
4.98k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::OptionsId, wasmtime_environ::component::dfg::CanonicalOptions>>::push
Line
Count
Source
581
14.5k
    pub fn push(&mut self, value: V) -> K
582
14.5k
    where
583
14.5k
        V: Hash + Eq + Clone,
584
    {
585
14.5k
        *self
586
14.5k
            .intern_map
587
14.5k
            .entry(value.clone())
588
14.5k
            .or_insert_with(|| self.key_map.push(value))
589
14.5k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::ReallocId, wasmtime_environ::component::dfg::CoreDef>>::push
Line
Count
Source
581
8.51k
    pub fn push(&mut self, value: V) -> K
582
8.51k
    where
583
8.51k
        V: Hash + Eq + Clone,
584
    {
585
8.51k
        *self
586
8.51k
            .intern_map
587
8.51k
            .entry(value.clone())
588
8.51k
            .or_insert_with(|| self.key_map.push(value))
589
8.51k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::types::TrampolineIndex, (wasmtime_environ::types::ModuleInternedTypeIndex, wasmtime_environ::component::dfg::Trampoline)>>::push
Line
Count
Source
581
25.6k
    pub fn push(&mut self, value: V) -> K
582
25.6k
    where
583
25.6k
        V: Hash + Eq + Clone,
584
    {
585
25.6k
        *self
586
25.6k
            .intern_map
587
25.6k
            .entry(value.clone())
588
25.6k
            .or_insert_with(|| self.key_map.push(value))
589
25.6k
    }
590
591
    /// Returns an iterator of all the values contained within this set.
592
4.74k
    pub fn iter(&self) -> impl Iterator<Item = (K, &V)> {
593
4.74k
        self.key_map.iter()
594
4.74k
    }
595
}
596
597
impl<K: EntityRef, V> Index<K> for Intern<K, V> {
598
    type Output = V;
599
64.0k
    fn index(&self, key: K) -> &V {
600
64.0k
        &self.key_map[key]
601
64.0k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::CallbackId, wasmtime_environ::component::dfg::CoreDef> as core::ops::index::Index<wasmtime_environ::component::dfg::CallbackId>>::index
Line
Count
Source
599
2.66k
    fn index(&self, key: K) -> &V {
600
2.66k
        &self.key_map[key]
601
2.66k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::PostReturnId, wasmtime_environ::component::dfg::CoreDef> as core::ops::index::Index<wasmtime_environ::component::dfg::PostReturnId>>::index
Line
Count
Source
599
30
    fn index(&self, key: K) -> &V {
600
30
        &self.key_map[key]
601
30
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::TableId, wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::TableIndex>> as core::ops::index::Index<wasmtime_environ::component::dfg::TableId>>::index
Line
Count
Source
599
5
    fn index(&self, key: K) -> &V {
600
5
        &self.key_map[key]
601
5
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::MemoryId, wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::MemoryIndex>> as core::ops::index::Index<wasmtime_environ::component::dfg::MemoryId>>::index
Line
Count
Source
599
8.58k
    fn index(&self, key: K) -> &V {
600
8.58k
        &self.key_map[key]
601
8.58k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::AdapterId, wasmtime_environ::component::translate::adapt::Adapter> as core::ops::index::Index<wasmtime_environ::component::dfg::AdapterId>>::index
Line
Count
Source
599
4.98k
    fn index(&self, key: K) -> &V {
600
4.98k
        &self.key_map[key]
601
4.98k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::OptionsId, wasmtime_environ::component::dfg::CanonicalOptions> as core::ops::index::Index<wasmtime_environ::component::dfg::OptionsId>>::index
Line
Count
Source
599
14.3k
    fn index(&self, key: K) -> &V {
600
14.3k
        &self.key_map[key]
601
14.3k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::ReallocId, wasmtime_environ::component::dfg::CoreDef> as core::ops::index::Index<wasmtime_environ::component::dfg::ReallocId>>::index
Line
Count
Source
599
8.50k
    fn index(&self, key: K) -> &V {
600
8.50k
        &self.key_map[key]
601
8.50k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::types::TrampolineIndex, (wasmtime_environ::types::ModuleInternedTypeIndex, wasmtime_environ::component::dfg::Trampoline)> as core::ops::index::Index<wasmtime_environ::component::types::TrampolineIndex>>::index
Line
Count
Source
599
24.9k
    fn index(&self, key: K) -> &V {
600
24.9k
        &self.key_map[key]
601
24.9k
    }
602
}
603
604
impl<K: EntityRef, V> Default for Intern<K, V> {
605
38.1k
    fn default() -> Intern<K, V> {
606
38.1k
        Intern {
607
38.1k
            intern_map: HashMap::new(),
608
38.1k
            key_map: PrimaryMap::new(),
609
38.1k
        }
610
38.1k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::CallbackId, wasmtime_environ::component::dfg::CoreDef> as core::default::Default>::default
Line
Count
Source
605
4.77k
    fn default() -> Intern<K, V> {
606
4.77k
        Intern {
607
4.77k
            intern_map: HashMap::new(),
608
4.77k
            key_map: PrimaryMap::new(),
609
4.77k
        }
610
4.77k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::PostReturnId, wasmtime_environ::component::dfg::CoreDef> as core::default::Default>::default
Line
Count
Source
605
4.77k
    fn default() -> Intern<K, V> {
606
4.77k
        Intern {
607
4.77k
            intern_map: HashMap::new(),
608
4.77k
            key_map: PrimaryMap::new(),
609
4.77k
        }
610
4.77k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::TableId, wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::TableIndex>> as core::default::Default>::default
Line
Count
Source
605
4.77k
    fn default() -> Intern<K, V> {
606
4.77k
        Intern {
607
4.77k
            intern_map: HashMap::new(),
608
4.77k
            key_map: PrimaryMap::new(),
609
4.77k
        }
610
4.77k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::MemoryId, wasmtime_environ::component::dfg::CoreExport<wasmtime_environ::types::MemoryIndex>> as core::default::Default>::default
Line
Count
Source
605
4.77k
    fn default() -> Intern<K, V> {
606
4.77k
        Intern {
607
4.77k
            intern_map: HashMap::new(),
608
4.77k
            key_map: PrimaryMap::new(),
609
4.77k
        }
610
4.77k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::AdapterId, wasmtime_environ::component::translate::adapt::Adapter> as core::default::Default>::default
Line
Count
Source
605
4.77k
    fn default() -> Intern<K, V> {
606
4.77k
        Intern {
607
4.77k
            intern_map: HashMap::new(),
608
4.77k
            key_map: PrimaryMap::new(),
609
4.77k
        }
610
4.77k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::OptionsId, wasmtime_environ::component::dfg::CanonicalOptions> as core::default::Default>::default
Line
Count
Source
605
4.77k
    fn default() -> Intern<K, V> {
606
4.77k
        Intern {
607
4.77k
            intern_map: HashMap::new(),
608
4.77k
            key_map: PrimaryMap::new(),
609
4.77k
        }
610
4.77k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::dfg::ReallocId, wasmtime_environ::component::dfg::CoreDef> as core::default::Default>::default
Line
Count
Source
605
4.77k
    fn default() -> Intern<K, V> {
606
4.77k
        Intern {
607
4.77k
            intern_map: HashMap::new(),
608
4.77k
            key_map: PrimaryMap::new(),
609
4.77k
        }
610
4.77k
    }
<wasmtime_environ::component::dfg::Intern<wasmtime_environ::component::types::TrampolineIndex, (wasmtime_environ::types::ModuleInternedTypeIndex, wasmtime_environ::component::dfg::Trampoline)> as core::default::Default>::default
Line
Count
Source
605
4.77k
    fn default() -> Intern<K, V> {
606
4.77k
        Intern {
607
4.77k
            intern_map: HashMap::new(),
608
4.77k
            key_map: PrimaryMap::new(),
609
4.77k
        }
610
4.77k
    }
611
}
612
613
impl ComponentDfg {
614
    /// Consumes the intermediate `ComponentDfg` to produce a final `Component`
615
    /// with a linear initializer list.
616
4.74k
    pub fn finish(
617
4.74k
        self,
618
4.74k
        wasmtime_types: &mut ComponentTypesBuilder,
619
4.74k
        wasmparser_types: wasmparser::types::TypesRef<'_>,
620
4.74k
    ) -> Result<ComponentTranslation> {
621
4.74k
        let mut linearize = LinearizeDfg {
622
4.74k
            dfg: &self,
623
4.74k
            initializers: Vec::new(),
624
4.74k
            runtime_memories: Default::default(),
625
4.74k
            runtime_tables: Default::default(),
626
4.74k
            runtime_post_return: Default::default(),
627
4.74k
            runtime_reallocs: Default::default(),
628
4.74k
            runtime_callbacks: Default::default(),
629
4.74k
            runtime_instances: Default::default(),
630
4.74k
            num_lowerings: 0,
631
4.74k
            unsafe_intrinsics: Default::default(),
632
4.74k
            trampolines: Default::default(),
633
4.74k
            trampoline_defs: Default::default(),
634
4.74k
            trampoline_map: Default::default(),
635
4.74k
            options: Default::default(),
636
4.74k
            options_map: Default::default(),
637
4.74k
        };
638
639
        // Handle all side effects of this component in the order that they're
640
        // defined. This will, for example, process all instantiations necessary
641
        // of core wasm modules.
642
18.0k
        for item in linearize.dfg.side_effects.iter() {
643
18.0k
            linearize.side_effect(item);
644
18.0k
        }
645
646
        // Next the exports of the instance are handled which will likely end up
647
        // creating some lowered imports, perhaps some saved modules, etc.
648
4.74k
        let mut export_items = PrimaryMap::new();
649
4.74k
        let mut exports = NameMap::default();
650
4.74k
        for (name, export) in self.exports.iter() {
651
4.59k
            let export =
652
4.59k
                linearize.export(export, &mut export_items, wasmtime_types, wasmparser_types)?;
653
4.59k
            exports.insert(name, &mut NameMapNoIntern, false, export)?;
654
        }
655
656
        // With all those pieces done the results of the dataflow-based
657
        // linearization are recorded into the `Component`. The number of
658
        // runtime values used for each index space is used from the `linearize`
659
        // result.
660
        Ok(ComponentTranslation {
661
4.74k
            trampolines: linearize.trampoline_defs,
662
            component: Component {
663
4.74k
                exports,
664
4.74k
                export_items,
665
4.74k
                initializers: linearize.initializers,
666
4.74k
                unsafe_intrinsics: linearize.unsafe_intrinsics,
667
4.74k
                trampolines: linearize.trampolines,
668
4.74k
                num_lowerings: linearize.num_lowerings,
669
4.74k
                options: linearize.options,
670
671
4.74k
                num_runtime_memories: linearize.runtime_memories.len() as u32,
672
4.74k
                num_runtime_tables: linearize.runtime_tables.len() as u32,
673
4.74k
                num_runtime_post_returns: linearize.runtime_post_return.len() as u32,
674
4.74k
                num_runtime_reallocs: linearize.runtime_reallocs.len() as u32,
675
4.74k
                num_runtime_callbacks: linearize.runtime_callbacks.len() as u32,
676
4.74k
                num_runtime_instances: linearize.runtime_instances.len() as u32,
677
4.74k
                imports: self.imports,
678
4.74k
                import_types: self.import_types,
679
4.74k
                num_runtime_component_instances: self.num_runtime_component_instances,
680
4.74k
                num_future_tables: self.num_future_tables,
681
4.74k
                num_stream_tables: self.num_stream_tables,
682
4.74k
                num_error_context_tables: self.num_error_context_tables,
683
4.74k
                num_resources: (self.resources.len() + self.imported_resources.len()) as u32,
684
4.74k
                imported_resources: self.imported_resources,
685
4.74k
                defined_resource_instances: self
686
4.74k
                    .resources
687
4.74k
                    .iter()
688
4.74k
                    .map(|(_, r)| r.instance)
689
4.74k
                    .collect(),
690
            },
691
        })
692
4.74k
    }
693
694
    /// Converts the provided defined index into a normal index, adding in the
695
    /// number of imported resources.
696
23
    pub fn resource_index(&self, defined: DefinedResourceIndex) -> ResourceIndex {
697
23
        ResourceIndex::from_u32(defined.as_u32() + (self.imported_resources.len() as u32))
698
23
    }
699
}
700
701
struct LinearizeDfg<'a> {
702
    dfg: &'a ComponentDfg,
703
    initializers: Vec<GlobalInitializer>,
704
    unsafe_intrinsics: [PackedOption<ModuleInternedTypeIndex>; UnsafeIntrinsic::len() as usize],
705
    trampolines: PrimaryMap<TrampolineIndex, ModuleInternedTypeIndex>,
706
    trampoline_defs: PrimaryMap<TrampolineIndex, info::Trampoline>,
707
    options: PrimaryMap<OptionsIndex, info::CanonicalOptions>,
708
    trampoline_map: HashMap<TrampolineIndex, TrampolineIndex>,
709
    runtime_memories: HashMap<MemoryId, RuntimeMemoryIndex>,
710
    runtime_tables: HashMap<TableId, RuntimeTableIndex>,
711
    runtime_reallocs: HashMap<ReallocId, RuntimeReallocIndex>,
712
    runtime_callbacks: HashMap<CallbackId, RuntimeCallbackIndex>,
713
    runtime_post_return: HashMap<PostReturnId, RuntimePostReturnIndex>,
714
    runtime_instances: HashMap<RuntimeInstance, RuntimeInstanceIndex>,
715
    options_map: HashMap<OptionsId, OptionsIndex>,
716
    num_lowerings: u32,
717
}
718
719
#[derive(Copy, Clone, Hash, Eq, PartialEq)]
720
enum RuntimeInstance {
721
    Normal(InstanceId),
722
    Adapter(AdapterModuleId),
723
}
724
725
impl LinearizeDfg<'_> {
726
18.0k
    fn side_effect(&mut self, effect: &SideEffect) {
727
18.0k
        match effect {
728
18.0k
            SideEffect::Instance(i, ci) => {
729
18.0k
                self.instantiate(*i, &self.dfg.instances[*i], *ci);
730
18.0k
            }
731
23
            SideEffect::Resource(i) => {
732
23
                self.resource(*i, &self.dfg.resources[*i]);
733
23
            }
734
        }
735
18.0k
    }
736
737
18.0k
    fn instantiate(
738
18.0k
        &mut self,
739
18.0k
        instance: InstanceId,
740
18.0k
        args: &Instance,
741
18.0k
        component_instance: RuntimeComponentInstanceIndex,
742
18.0k
    ) {
743
18.0k
        log::trace!("creating instance {instance:?}");
744
18.0k
        let instantiation = match args {
745
18.0k
            Instance::Static(index, args) => InstantiateModule::Static(
746
18.0k
                *index,
747
33.2k
                args.iter().map(|def| self.core_def(def)).collect(),
748
            ),
749
19
            Instance::Import(index, args) => InstantiateModule::Import(
750
19
                *index,
751
19
                args.iter()
752
19
                    .map(|(module, values)| {
753
6
                        let values = values
754
6
                            .iter()
755
16
                            .map(|(name, def)| (name.clone(), self.core_def(def)))
756
6
                            .collect();
757
6
                        (module.clone(), values)
758
6
                    })
759
19
                    .collect(),
760
            ),
761
        };
762
18.0k
        let index = RuntimeInstanceIndex::new(self.runtime_instances.len());
763
18.0k
        self.initializers.push(GlobalInitializer::InstantiateModule(
764
18.0k
            instantiation,
765
18.0k
            Some(component_instance),
766
18.0k
        ));
767
18.0k
        let prev = self
768
18.0k
            .runtime_instances
769
18.0k
            .insert(RuntimeInstance::Normal(instance), index);
770
18.0k
        assert!(prev.is_none());
771
18.0k
    }
772
773
23
    fn resource(&mut self, index: DefinedResourceIndex, resource: &Resource) {
774
23
        let dtor = resource.dtor.as_ref().map(|dtor| self.core_def(dtor));
775
23
        self.initializers
776
23
            .push(GlobalInitializer::Resource(info::Resource {
777
23
                dtor,
778
23
                index,
779
23
                rep: resource.rep,
780
23
                instance: resource.instance,
781
23
            }));
782
23
    }
783
784
4.62k
    fn export(
785
4.62k
        &mut self,
786
4.62k
        export: &Export,
787
4.62k
        items: &mut PrimaryMap<ExportIndex, info::Export>,
788
4.62k
        wasmtime_types: &mut ComponentTypesBuilder,
789
4.62k
        wasmparser_types: wasmparser::types::TypesRef<'_>,
790
4.62k
    ) -> Result<ExportIndex> {
791
4.62k
        let item = match export {
792
4.55k
            Export::LiftedFunction { ty, func, options } => {
793
4.55k
                let func = self.core_def(func);
794
4.55k
                let options = self.options(*options);
795
4.55k
                info::Export::LiftedFunction {
796
4.55k
                    ty: *ty,
797
4.55k
                    func,
798
4.55k
                    options,
799
4.55k
                }
800
            }
801
11
            Export::ModuleStatic { ty, index } => info::Export::ModuleStatic {
802
11
                ty: wasmtime_types.convert_module(wasmparser_types, *ty)?,
803
11
                index: *index,
804
            },
805
0
            Export::ModuleImport { ty, import } => info::Export::ModuleImport {
806
0
                ty: *ty,
807
0
                import: *import,
808
0
            },
809
14
            Export::Instance { ty, exports } => info::Export::Instance {
810
14
                ty: *ty,
811
                exports: {
812
14
                    let mut map = NameMap::default();
813
27
                    for (name, export) in exports {
814
27
                        let export =
815
27
                            self.export(export, items, wasmtime_types, wasmparser_types)?;
816
27
                        map.insert(name, &mut NameMapNoIntern, false, export)?;
817
                    }
818
14
                    map
819
                },
820
            },
821
43
            Export::Type(def) => info::Export::Type(*def),
822
        };
823
4.62k
        Ok(items.push(item))
824
4.62k
    }
825
826
14.5k
    fn options(&mut self, options: OptionsId) -> OptionsIndex {
827
14.5k
        self.intern_no_init(
828
14.5k
            options,
829
            |me| &mut me.options_map,
830
14.3k
            |me, options| me.convert_options(options),
831
        )
832
14.5k
    }
833
834
14.3k
    fn convert_options(&mut self, options: OptionsId) -> OptionsIndex {
835
14.3k
        let options = &self.dfg.options[options];
836
14.3k
        let data_model = match options.data_model {
837
0
            CanonicalOptionsDataModel::Gc {} => info::CanonicalOptionsDataModel::Gc {},
838
14.3k
            CanonicalOptionsDataModel::LinearMemory { memory, realloc } => {
839
                info::CanonicalOptionsDataModel::LinearMemory(LinearMemoryOptions {
840
14.3k
                    memory: memory.map(|mem| self.runtime_memory(mem)),
841
14.3k
                    realloc: realloc.map(|mem| self.runtime_realloc(mem)),
842
                })
843
            }
844
        };
845
14.3k
        let callback = options.callback.map(|mem| self.runtime_callback(mem));
846
14.3k
        let post_return = options.post_return.map(|mem| self.runtime_post_return(mem));
847
14.3k
        let options = info::CanonicalOptions {
848
14.3k
            instance: options.instance,
849
14.3k
            string_encoding: options.string_encoding,
850
14.3k
            callback,
851
14.3k
            post_return,
852
14.3k
            async_: options.async_,
853
14.3k
            cancellable: options.cancellable,
854
14.3k
            core_type: options.core_type,
855
14.3k
            data_model,
856
14.3k
        };
857
14.3k
        self.options.push(options)
858
14.3k
    }
859
860
20.2k
    fn runtime_memory(&mut self, mem: MemoryId) -> RuntimeMemoryIndex {
861
20.2k
        self.intern(
862
20.2k
            mem,
863
            |me| &mut me.runtime_memories,
864
8.58k
            |me, mem| me.core_export(&me.dfg.memories[mem]),
865
8.58k
            |index, export| GlobalInitializer::ExtractMemory(ExtractMemory { index, export }),
866
        )
867
20.2k
    }
868
869
5
    fn runtime_table(&mut self, table: TableId) -> RuntimeTableIndex {
870
5
        self.intern(
871
5
            table,
872
            |me| &mut me.runtime_tables,
873
5
            |me, table| me.core_export(&me.dfg.tables[table]),
874
5
            |index, export| GlobalInitializer::ExtractTable(ExtractTable { index, export }),
875
        )
876
5
    }
877
878
8.51k
    fn runtime_realloc(&mut self, realloc: ReallocId) -> RuntimeReallocIndex {
879
8.51k
        self.intern(
880
8.51k
            realloc,
881
            |me| &mut me.runtime_reallocs,
882
8.50k
            |me, realloc| me.core_def(&me.dfg.reallocs[realloc]),
883
8.50k
            |index, def| GlobalInitializer::ExtractRealloc(ExtractRealloc { index, def }),
884
        )
885
8.51k
    }
886
887
2.67k
    fn runtime_callback(&mut self, callback: CallbackId) -> RuntimeCallbackIndex {
888
2.67k
        self.intern(
889
2.67k
            callback,
890
            |me| &mut me.runtime_callbacks,
891
2.66k
            |me, callback| me.core_def(&me.dfg.callbacks[callback]),
892
2.66k
            |index, def| GlobalInitializer::ExtractCallback(ExtractCallback { index, def }),
893
        )
894
2.67k
    }
895
896
30
    fn runtime_post_return(&mut self, post_return: PostReturnId) -> RuntimePostReturnIndex {
897
30
        self.intern(
898
30
            post_return,
899
            |me| &mut me.runtime_post_return,
900
30
            |me, post_return| me.core_def(&me.dfg.post_returns[post_return]),
901
30
            |index, def| GlobalInitializer::ExtractPostReturn(ExtractPostReturn { index, def }),
902
        )
903
30
    }
904
905
97.9k
    fn core_def(&mut self, def: &CoreDef) -> info::CoreDef {
906
97.9k
        match def {
907
56.6k
            CoreDef::Export(e) => info::CoreDef::Export(self.core_export(e)),
908
9.40k
            CoreDef::InstanceFlags(i) => info::CoreDef::InstanceFlags(*i),
909
4.99k
            CoreDef::Adapter(id) => info::CoreDef::Export(self.adapter(*id)),
910
25.5k
            CoreDef::Trampoline(index) => info::CoreDef::Trampoline(self.trampoline(*index)),
911
0
            CoreDef::UnsafeIntrinsic(ty, i) => {
912
0
                let index = usize::try_from(i.index()).unwrap();
913
0
                if self.unsafe_intrinsics[index].is_none() {
914
0
                    self.unsafe_intrinsics[index] = Some(*ty).into();
915
0
                }
916
0
                info::CoreDef::UnsafeIntrinsic(*i)
917
            }
918
1.31k
            CoreDef::TaskMayBlock => info::CoreDef::TaskMayBlock,
919
        }
920
97.9k
    }
921
922
25.5k
    fn trampoline(&mut self, index: TrampolineIndex) -> TrampolineIndex {
923
25.5k
        if let Some(idx) = self.trampoline_map.get(&index) {
924
657
            return *idx;
925
24.9k
        }
926
24.9k
        let (signature, trampoline) = &self.dfg.trampolines[index];
927
24.9k
        let trampoline = match trampoline {
928
            Trampoline::LowerImport {
929
4.38k
                import,
930
4.38k
                options,
931
4.38k
                lower_ty,
932
            } => {
933
4.38k
                let index = LoweredIndex::from_u32(self.num_lowerings);
934
4.38k
                self.num_lowerings += 1;
935
4.38k
                self.initializers.push(GlobalInitializer::LowerImport {
936
4.38k
                    index,
937
4.38k
                    import: *import,
938
4.38k
                });
939
4.38k
                info::Trampoline::LowerImport {
940
4.38k
                    index,
941
4.38k
                    options: self.options(*options),
942
4.38k
                    lower_ty: *lower_ty,
943
4.38k
                }
944
            }
945
            Trampoline::Transcoder {
946
1.73k
                op,
947
1.73k
                from,
948
1.73k
                from64,
949
1.73k
                to,
950
1.73k
                to64,
951
1.73k
            } => info::Trampoline::Transcoder {
952
1.73k
                op: *op,
953
1.73k
                from: self.runtime_memory(*from),
954
1.73k
                from64: *from64,
955
1.73k
                to: self.runtime_memory(*to),
956
1.73k
                to64: *to64,
957
1.73k
            },
958
15
            Trampoline::ResourceNew { instance, ty } => info::Trampoline::ResourceNew {
959
15
                instance: *instance,
960
15
                ty: *ty,
961
15
            },
962
50
            Trampoline::ResourceDrop { instance, ty } => info::Trampoline::ResourceDrop {
963
50
                instance: *instance,
964
50
                ty: *ty,
965
50
            },
966
5
            Trampoline::ResourceRep { instance, ty } => info::Trampoline::ResourceRep {
967
5
                instance: *instance,
968
5
                ty: *ty,
969
5
            },
970
2
            Trampoline::BackpressureInc { instance } => info::Trampoline::BackpressureInc {
971
2
                instance: *instance,
972
2
            },
973
1
            Trampoline::BackpressureDec { instance } => info::Trampoline::BackpressureDec {
974
1
                instance: *instance,
975
1
            },
976
            Trampoline::TaskReturn {
977
5.44k
                instance,
978
5.44k
                results,
979
5.44k
                options,
980
5.44k
            } => info::Trampoline::TaskReturn {
981
5.44k
                instance: *instance,
982
5.44k
                results: *results,
983
5.44k
                options: self.options(*options),
984
5.44k
            },
985
6
            Trampoline::TaskCancel { instance } => info::Trampoline::TaskCancel {
986
6
                instance: *instance,
987
6
            },
988
121
            Trampoline::WaitableSetNew { instance } => info::Trampoline::WaitableSetNew {
989
121
                instance: *instance,
990
121
            },
991
18
            Trampoline::WaitableSetWait { instance, options } => {
992
18
                info::Trampoline::WaitableSetWait {
993
18
                    instance: *instance,
994
18
                    options: self.options(*options),
995
18
                }
996
            }
997
4
            Trampoline::WaitableSetPoll { instance, options } => {
998
4
                info::Trampoline::WaitableSetPoll {
999
4
                    instance: *instance,
1000
4
                    options: self.options(*options),
1001
4
                }
1002
            }
1003
7
            Trampoline::WaitableSetDrop { instance } => info::Trampoline::WaitableSetDrop {
1004
7
                instance: *instance,
1005
7
            },
1006
116
            Trampoline::WaitableJoin { instance } => info::Trampoline::WaitableJoin {
1007
116
                instance: *instance,
1008
116
            },
1009
            Trampoline::ThreadYield {
1010
7
                instance,
1011
7
                cancellable,
1012
7
            } => info::Trampoline::ThreadYield {
1013
7
                instance: *instance,
1014
7
                cancellable: *cancellable,
1015
7
            },
1016
102
            Trampoline::SubtaskDrop { instance } => info::Trampoline::SubtaskDrop {
1017
102
                instance: *instance,
1018
102
            },
1019
6
            Trampoline::SubtaskCancel { instance, async_ } => info::Trampoline::SubtaskCancel {
1020
6
                instance: *instance,
1021
6
                async_: *async_,
1022
6
            },
1023
30
            Trampoline::StreamNew { instance, ty } => info::Trampoline::StreamNew {
1024
30
                instance: *instance,
1025
30
                ty: *ty,
1026
30
            },
1027
            Trampoline::StreamRead {
1028
27
                instance,
1029
27
                ty,
1030
27
                options,
1031
27
            } => info::Trampoline::StreamRead {
1032
27
                instance: *instance,
1033
27
                ty: *ty,
1034
27
                options: self.options(*options),
1035
27
            },
1036
            Trampoline::StreamWrite {
1037
30
                instance,
1038
30
                ty,
1039
30
                options,
1040
30
            } => info::Trampoline::StreamWrite {
1041
30
                instance: *instance,
1042
30
                ty: *ty,
1043
30
                options: self.options(*options),
1044
30
            },
1045
            Trampoline::StreamCancelRead {
1046
18
                instance,
1047
18
                ty,
1048
18
                async_,
1049
18
            } => info::Trampoline::StreamCancelRead {
1050
18
                instance: *instance,
1051
18
                ty: *ty,
1052
18
                async_: *async_,
1053
18
            },
1054
            Trampoline::StreamCancelWrite {
1055
15
                instance,
1056
15
                ty,
1057
15
                async_,
1058
15
            } => info::Trampoline::StreamCancelWrite {
1059
15
                instance: *instance,
1060
15
                ty: *ty,
1061
15
                async_: *async_,
1062
15
            },
1063
25
            Trampoline::StreamDropReadable { instance, ty } => {
1064
25
                info::Trampoline::StreamDropReadable {
1065
25
                    instance: *instance,
1066
25
                    ty: *ty,
1067
25
                }
1068
            }
1069
29
            Trampoline::StreamDropWritable { instance, ty } => {
1070
29
                info::Trampoline::StreamDropWritable {
1071
29
                    instance: *instance,
1072
29
                    ty: *ty,
1073
29
                }
1074
            }
1075
28
            Trampoline::FutureNew { instance, ty } => info::Trampoline::FutureNew {
1076
28
                instance: *instance,
1077
28
                ty: *ty,
1078
28
            },
1079
            Trampoline::FutureRead {
1080
26
                instance,
1081
26
                ty,
1082
26
                options,
1083
26
            } => info::Trampoline::FutureRead {
1084
26
                instance: *instance,
1085
26
                ty: *ty,
1086
26
                options: self.options(*options),
1087
26
            },
1088
            Trampoline::FutureWrite {
1089
24
                instance,
1090
24
                ty,
1091
24
                options,
1092
24
            } => info::Trampoline::FutureWrite {
1093
24
                instance: *instance,
1094
24
                ty: *ty,
1095
24
                options: self.options(*options),
1096
24
            },
1097
            Trampoline::FutureCancelRead {
1098
7
                instance,
1099
7
                ty,
1100
7
                async_,
1101
7
            } => info::Trampoline::FutureCancelRead {
1102
7
                instance: *instance,
1103
7
                ty: *ty,
1104
7
                async_: *async_,
1105
7
            },
1106
            Trampoline::FutureCancelWrite {
1107
8
                instance,
1108
8
                ty,
1109
8
                async_,
1110
8
            } => info::Trampoline::FutureCancelWrite {
1111
8
                instance: *instance,
1112
8
                ty: *ty,
1113
8
                async_: *async_,
1114
8
            },
1115
14
            Trampoline::FutureDropReadable { instance, ty } => {
1116
14
                info::Trampoline::FutureDropReadable {
1117
14
                    instance: *instance,
1118
14
                    ty: *ty,
1119
14
                }
1120
            }
1121
13
            Trampoline::FutureDropWritable { instance, ty } => {
1122
13
                info::Trampoline::FutureDropWritable {
1123
13
                    instance: *instance,
1124
13
                    ty: *ty,
1125
13
                }
1126
            }
1127
            Trampoline::ErrorContextNew {
1128
5
                instance,
1129
5
                ty,
1130
5
                options,
1131
5
            } => info::Trampoline::ErrorContextNew {
1132
5
                instance: *instance,
1133
5
                ty: *ty,
1134
5
                options: self.options(*options),
1135
5
            },
1136
            Trampoline::ErrorContextDebugMessage {
1137
5
                instance,
1138
5
                ty,
1139
5
                options,
1140
5
            } => info::Trampoline::ErrorContextDebugMessage {
1141
5
                instance: *instance,
1142
5
                ty: *ty,
1143
5
                options: self.options(*options),
1144
5
            },
1145
5
            Trampoline::ErrorContextDrop { instance, ty } => info::Trampoline::ErrorContextDrop {
1146
5
                instance: *instance,
1147
5
                ty: *ty,
1148
5
            },
1149
3
            Trampoline::ResourceTransferOwn => info::Trampoline::ResourceTransferOwn,
1150
4
            Trampoline::ResourceTransferBorrow => info::Trampoline::ResourceTransferBorrow,
1151
3.16k
            Trampoline::PrepareCall { memory } => info::Trampoline::PrepareCall {
1152
3.16k
                memory: memory.map(|v| self.runtime_memory(v)),
1153
            },
1154
1.64k
            Trampoline::SyncStartCall { callback } => info::Trampoline::SyncStartCall {
1155
1.64k
                callback: callback.map(|v| self.runtime_callback(v)),
1156
            },
1157
            Trampoline::AsyncStartCall {
1158
1.70k
                callback,
1159
1.70k
                post_return,
1160
            } => info::Trampoline::AsyncStartCall {
1161
1.70k
                callback: callback.map(|v| self.runtime_callback(v)),
1162
1.70k
                post_return: post_return.map(|v| self.runtime_post_return(v)),
1163
            },
1164
17
            Trampoline::FutureTransfer => info::Trampoline::FutureTransfer,
1165
15
            Trampoline::StreamTransfer => info::Trampoline::StreamTransfer,
1166
0
            Trampoline::ErrorContextTransfer => info::Trampoline::ErrorContextTransfer,
1167
3.24k
            Trampoline::Trap => info::Trampoline::Trap,
1168
1.29k
            Trampoline::EnterSyncCall => info::Trampoline::EnterSyncCall,
1169
1.29k
            Trampoline::ExitSyncCall => info::Trampoline::ExitSyncCall,
1170
96
            Trampoline::ContextGet { instance, slot } => info::Trampoline::ContextGet {
1171
96
                instance: *instance,
1172
96
                slot: *slot,
1173
96
            },
1174
96
            Trampoline::ContextSet { instance, slot } => info::Trampoline::ContextSet {
1175
96
                instance: *instance,
1176
96
                slot: *slot,
1177
96
            },
1178
1
            Trampoline::ThreadIndex => info::Trampoline::ThreadIndex,
1179
            Trampoline::ThreadNewIndirect {
1180
5
                instance,
1181
5
                start_func_ty_idx,
1182
5
                start_func_table_id,
1183
5
            } => info::Trampoline::ThreadNewIndirect {
1184
5
                instance: *instance,
1185
5
                start_func_ty_idx: *start_func_ty_idx,
1186
5
                start_func_table_idx: self.runtime_table(*start_func_table_id),
1187
5
            },
1188
            Trampoline::ThreadSuspendToSuspended {
1189
5
                instance,
1190
5
                cancellable,
1191
5
            } => info::Trampoline::ThreadSuspendToSuspended {
1192
5
                instance: *instance,
1193
5
                cancellable: *cancellable,
1194
5
            },
1195
            Trampoline::ThreadSuspendTo {
1196
0
                instance,
1197
0
                cancellable,
1198
0
            } => info::Trampoline::ThreadSuspendTo {
1199
0
                instance: *instance,
1200
0
                cancellable: *cancellable,
1201
0
            },
1202
            Trampoline::ThreadSuspend {
1203
5
                instance,
1204
5
                cancellable,
1205
5
            } => info::Trampoline::ThreadSuspend {
1206
5
                instance: *instance,
1207
5
                cancellable: *cancellable,
1208
5
            },
1209
4
            Trampoline::ThreadUnsuspend { instance } => info::Trampoline::ThreadUnsuspend {
1210
4
                instance: *instance,
1211
4
            },
1212
            Trampoline::ThreadYieldToSuspended {
1213
5
                instance,
1214
5
                cancellable,
1215
5
            } => info::Trampoline::ThreadYieldToSuspended {
1216
5
                instance: *instance,
1217
5
                cancellable: *cancellable,
1218
5
            },
1219
        };
1220
24.9k
        let i1 = self.trampolines.push(*signature);
1221
24.9k
        let i2 = self.trampoline_defs.push(trampoline);
1222
24.9k
        assert_eq!(i1, i2);
1223
24.9k
        self.trampoline_map.insert(index, i1);
1224
24.9k
        i1
1225
25.5k
    }
1226
1227
65.2k
    fn core_export<T>(&mut self, export: &CoreExport<T>) -> info::CoreExport<T>
1228
65.2k
    where
1229
65.2k
        T: Clone,
1230
    {
1231
65.2k
        let instance = export.instance;
1232
65.2k
        log::trace!("referencing export of {instance:?}");
1233
65.2k
        info::CoreExport {
1234
65.2k
            instance: self.runtime_instances[&RuntimeInstance::Normal(instance)],
1235
65.2k
            item: export.item.clone(),
1236
65.2k
        }
1237
65.2k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::core_export::<wasmtime_environ::types::TableIndex>
Line
Count
Source
1227
5
    fn core_export<T>(&mut self, export: &CoreExport<T>) -> info::CoreExport<T>
1228
5
    where
1229
5
        T: Clone,
1230
    {
1231
5
        let instance = export.instance;
1232
5
        log::trace!("referencing export of {instance:?}");
1233
5
        info::CoreExport {
1234
5
            instance: self.runtime_instances[&RuntimeInstance::Normal(instance)],
1235
5
            item: export.item.clone(),
1236
5
        }
1237
5
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::core_export::<wasmtime_environ::types::EntityIndex>
Line
Count
Source
1227
56.6k
    fn core_export<T>(&mut self, export: &CoreExport<T>) -> info::CoreExport<T>
1228
56.6k
    where
1229
56.6k
        T: Clone,
1230
    {
1231
56.6k
        let instance = export.instance;
1232
56.6k
        log::trace!("referencing export of {instance:?}");
1233
56.6k
        info::CoreExport {
1234
56.6k
            instance: self.runtime_instances[&RuntimeInstance::Normal(instance)],
1235
56.6k
            item: export.item.clone(),
1236
56.6k
        }
1237
56.6k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::core_export::<wasmtime_environ::types::MemoryIndex>
Line
Count
Source
1227
8.58k
    fn core_export<T>(&mut self, export: &CoreExport<T>) -> info::CoreExport<T>
1228
8.58k
    where
1229
8.58k
        T: Clone,
1230
    {
1231
8.58k
        let instance = export.instance;
1232
8.58k
        log::trace!("referencing export of {instance:?}");
1233
8.58k
        info::CoreExport {
1234
8.58k
            instance: self.runtime_instances[&RuntimeInstance::Normal(instance)],
1235
8.58k
            item: export.item.clone(),
1236
8.58k
        }
1237
8.58k
    }
1238
1239
4.99k
    fn adapter(&mut self, adapter: AdapterId) -> info::CoreExport<EntityIndex> {
1240
4.99k
        let (adapter_module, entity_index) = self.dfg.adapter_partitionings[adapter];
1241
1242
        // Instantiates the adapter module if it hasn't already been
1243
        // instantiated or otherwise returns the index that the module was
1244
        // already instantiated at.
1245
4.99k
        let instance = self.adapter_module(adapter_module);
1246
1247
        // This adapter is always an export of the instance.
1248
4.99k
        info::CoreExport {
1249
4.99k
            instance,
1250
4.99k
            item: ExportItem::Index(entity_index),
1251
4.99k
        }
1252
4.99k
    }
1253
1254
4.99k
    fn adapter_module(&mut self, adapter_module: AdapterModuleId) -> RuntimeInstanceIndex {
1255
4.99k
        self.intern(
1256
4.99k
            RuntimeInstance::Adapter(adapter_module),
1257
            |me| &mut me.runtime_instances,
1258
4.56k
            |me, _| {
1259
4.56k
                log::debug!("instantiating {adapter_module:?}");
1260
4.56k
                let (module_index, args) = &me.dfg.adapter_modules[adapter_module];
1261
48.8k
                let args = args.iter().map(|arg| me.core_def(arg)).collect();
1262
4.56k
                let instantiate = InstantiateModule::Static(*module_index, args);
1263
4.56k
                GlobalInitializer::InstantiateModule(instantiate, None)
1264
4.56k
            },
1265
            |_, init| init,
1266
        )
1267
4.99k
    }
1268
1269
    /// Helper function to manage interning of results to avoid duplicate
1270
    /// initializers being inserted into the final list.
1271
    ///
1272
    /// * `key` - the key being referenced which is used to deduplicate.
1273
    /// * `map` - a closure to access the interning map on `Self`
1274
    /// * `gen` - a closure to generate an intermediate value with `Self` from
1275
    ///   `K`. This is only used if `key` hasn't previously been seen. This
1276
    ///   closure can recursively intern other values possibly.
1277
    /// * `init` - a closure to use the result of `gen` to create the final
1278
    ///   initializer now that the index `V` of the runtime item is known.
1279
    ///
1280
    /// This is used by all the other interning methods above to lazily append
1281
    /// initializers on-demand and avoid pushing more than one initializer at a
1282
    /// time.
1283
36.4k
    fn intern<K, V, T>(
1284
36.4k
        &mut self,
1285
36.4k
        key: K,
1286
36.4k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1287
36.4k
        generate: impl FnOnce(&mut Self, K) -> T,
1288
36.4k
        init: impl FnOnce(V, T) -> GlobalInitializer,
1289
36.4k
    ) -> V
1290
36.4k
    where
1291
36.4k
        K: Hash + Eq + Copy,
1292
36.4k
        V: EntityRef,
1293
    {
1294
36.4k
        self.intern_(key, map, generate, |me, key, val| {
1295
24.3k
            me.initializers.push(init(key, val));
1296
24.3k
        })
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::CallbackId, wasmtime_environ::component::types::RuntimeCallbackIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#2}>::{closure#0}
Line
Count
Source
1294
2.66k
        self.intern_(key, map, generate, |me, key, val| {
1295
2.66k
            me.initializers.push(init(key, val));
1296
2.66k
        })
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::PostReturnId, wasmtime_environ::component::types::RuntimePostReturnIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#2}>::{closure#0}
Line
Count
Source
1294
30
        self.intern_(key, map, generate, |me, key, val| {
1295
30
            me.initializers.push(init(key, val));
1296
30
        })
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::RuntimeInstance, wasmtime_environ::component::types::RuntimeInstanceIndex, wasmtime_environ::component::info::GlobalInitializer, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#2}>::{closure#0}
Line
Count
Source
1294
4.56k
        self.intern_(key, map, generate, |me, key, val| {
1295
4.56k
            me.initializers.push(init(key, val));
1296
4.56k
        })
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::TableId, wasmtime_environ::component::types::RuntimeTableIndex, wasmtime_environ::component::info::CoreExport<wasmtime_environ::types::TableIndex>, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#2}>::{closure#0}
Line
Count
Source
1294
5
        self.intern_(key, map, generate, |me, key, val| {
1295
5
            me.initializers.push(init(key, val));
1296
5
        })
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::MemoryId, wasmtime_environ::component::types::RuntimeMemoryIndex, wasmtime_environ::component::info::CoreExport<wasmtime_environ::types::MemoryIndex>, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#2}>::{closure#0}
Line
Count
Source
1294
8.58k
        self.intern_(key, map, generate, |me, key, val| {
1295
8.58k
            me.initializers.push(init(key, val));
1296
8.58k
        })
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::ReallocId, wasmtime_environ::component::types::RuntimeReallocIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#2}>::{closure#0}
Line
Count
Source
1294
8.50k
        self.intern_(key, map, generate, |me, key, val| {
1295
8.50k
            me.initializers.push(init(key, val));
1296
8.50k
        })
1297
36.4k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::CallbackId, wasmtime_environ::component::types::RuntimeCallbackIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#2}>
Line
Count
Source
1283
2.67k
    fn intern<K, V, T>(
1284
2.67k
        &mut self,
1285
2.67k
        key: K,
1286
2.67k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1287
2.67k
        generate: impl FnOnce(&mut Self, K) -> T,
1288
2.67k
        init: impl FnOnce(V, T) -> GlobalInitializer,
1289
2.67k
    ) -> V
1290
2.67k
    where
1291
2.67k
        K: Hash + Eq + Copy,
1292
2.67k
        V: EntityRef,
1293
    {
1294
2.67k
        self.intern_(key, map, generate, |me, key, val| {
1295
            me.initializers.push(init(key, val));
1296
        })
1297
2.67k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::PostReturnId, wasmtime_environ::component::types::RuntimePostReturnIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#2}>
Line
Count
Source
1283
30
    fn intern<K, V, T>(
1284
30
        &mut self,
1285
30
        key: K,
1286
30
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1287
30
        generate: impl FnOnce(&mut Self, K) -> T,
1288
30
        init: impl FnOnce(V, T) -> GlobalInitializer,
1289
30
    ) -> V
1290
30
    where
1291
30
        K: Hash + Eq + Copy,
1292
30
        V: EntityRef,
1293
    {
1294
30
        self.intern_(key, map, generate, |me, key, val| {
1295
            me.initializers.push(init(key, val));
1296
        })
1297
30
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::RuntimeInstance, wasmtime_environ::component::types::RuntimeInstanceIndex, wasmtime_environ::component::info::GlobalInitializer, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#2}>
Line
Count
Source
1283
4.99k
    fn intern<K, V, T>(
1284
4.99k
        &mut self,
1285
4.99k
        key: K,
1286
4.99k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1287
4.99k
        generate: impl FnOnce(&mut Self, K) -> T,
1288
4.99k
        init: impl FnOnce(V, T) -> GlobalInitializer,
1289
4.99k
    ) -> V
1290
4.99k
    where
1291
4.99k
        K: Hash + Eq + Copy,
1292
4.99k
        V: EntityRef,
1293
    {
1294
4.99k
        self.intern_(key, map, generate, |me, key, val| {
1295
            me.initializers.push(init(key, val));
1296
        })
1297
4.99k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::TableId, wasmtime_environ::component::types::RuntimeTableIndex, wasmtime_environ::component::info::CoreExport<wasmtime_environ::types::TableIndex>, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#2}>
Line
Count
Source
1283
5
    fn intern<K, V, T>(
1284
5
        &mut self,
1285
5
        key: K,
1286
5
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1287
5
        generate: impl FnOnce(&mut Self, K) -> T,
1288
5
        init: impl FnOnce(V, T) -> GlobalInitializer,
1289
5
    ) -> V
1290
5
    where
1291
5
        K: Hash + Eq + Copy,
1292
5
        V: EntityRef,
1293
    {
1294
5
        self.intern_(key, map, generate, |me, key, val| {
1295
            me.initializers.push(init(key, val));
1296
        })
1297
5
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::MemoryId, wasmtime_environ::component::types::RuntimeMemoryIndex, wasmtime_environ::component::info::CoreExport<wasmtime_environ::types::MemoryIndex>, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#2}>
Line
Count
Source
1283
20.2k
    fn intern<K, V, T>(
1284
20.2k
        &mut self,
1285
20.2k
        key: K,
1286
20.2k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1287
20.2k
        generate: impl FnOnce(&mut Self, K) -> T,
1288
20.2k
        init: impl FnOnce(V, T) -> GlobalInitializer,
1289
20.2k
    ) -> V
1290
20.2k
    where
1291
20.2k
        K: Hash + Eq + Copy,
1292
20.2k
        V: EntityRef,
1293
    {
1294
20.2k
        self.intern_(key, map, generate, |me, key, val| {
1295
            me.initializers.push(init(key, val));
1296
        })
1297
20.2k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern::<wasmtime_environ::component::dfg::ReallocId, wasmtime_environ::component::types::RuntimeReallocIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#2}>
Line
Count
Source
1283
8.51k
    fn intern<K, V, T>(
1284
8.51k
        &mut self,
1285
8.51k
        key: K,
1286
8.51k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1287
8.51k
        generate: impl FnOnce(&mut Self, K) -> T,
1288
8.51k
        init: impl FnOnce(V, T) -> GlobalInitializer,
1289
8.51k
    ) -> V
1290
8.51k
    where
1291
8.51k
        K: Hash + Eq + Copy,
1292
8.51k
        V: EntityRef,
1293
    {
1294
8.51k
        self.intern_(key, map, generate, |me, key, val| {
1295
            me.initializers.push(init(key, val));
1296
        })
1297
8.51k
    }
1298
1299
14.5k
    fn intern_no_init<K, V, T>(
1300
14.5k
        &mut self,
1301
14.5k
        key: K,
1302
14.5k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1303
14.5k
        generate: impl FnOnce(&mut Self, K) -> T,
1304
14.5k
    ) -> V
1305
14.5k
    where
1306
14.5k
        K: Hash + Eq + Copy,
1307
14.5k
        V: EntityRef,
1308
    {
1309
14.5k
        self.intern_(key, map, generate, |_me, _key, _val| {})
1310
14.5k
    }
1311
1312
50.9k
    fn intern_<K, V, T>(
1313
50.9k
        &mut self,
1314
50.9k
        key: K,
1315
50.9k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1316
50.9k
        generate: impl FnOnce(&mut Self, K) -> T,
1317
50.9k
        init: impl FnOnce(&mut Self, V, T),
1318
50.9k
    ) -> V
1319
50.9k
    where
1320
50.9k
        K: Hash + Eq + Copy,
1321
50.9k
        V: EntityRef,
1322
    {
1323
50.9k
        if let Some(val) = map(self).get(&key) {
1324
12.2k
            return *val;
1325
38.6k
        }
1326
38.6k
        let tmp = generate(self, key);
1327
38.6k
        let index = V::new(map(self).len());
1328
38.6k
        init(self, index, tmp);
1329
38.6k
        let prev = map(self).insert(key, index);
1330
38.6k
        assert!(prev.is_none());
1331
38.6k
        index
1332
50.9k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern_::<wasmtime_environ::component::dfg::CallbackId, wasmtime_environ::component::types::RuntimeCallbackIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::intern<wasmtime_environ::component::dfg::CallbackId, wasmtime_environ::component::types::RuntimeCallbackIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_callback::{closure#2}>::{closure#0}>
Line
Count
Source
1312
2.67k
    fn intern_<K, V, T>(
1313
2.67k
        &mut self,
1314
2.67k
        key: K,
1315
2.67k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1316
2.67k
        generate: impl FnOnce(&mut Self, K) -> T,
1317
2.67k
        init: impl FnOnce(&mut Self, V, T),
1318
2.67k
    ) -> V
1319
2.67k
    where
1320
2.67k
        K: Hash + Eq + Copy,
1321
2.67k
        V: EntityRef,
1322
    {
1323
2.67k
        if let Some(val) = map(self).get(&key) {
1324
4
            return *val;
1325
2.66k
        }
1326
2.66k
        let tmp = generate(self, key);
1327
2.66k
        let index = V::new(map(self).len());
1328
2.66k
        init(self, index, tmp);
1329
2.66k
        let prev = map(self).insert(key, index);
1330
2.66k
        assert!(prev.is_none());
1331
2.66k
        index
1332
2.67k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern_::<wasmtime_environ::component::dfg::PostReturnId, wasmtime_environ::component::types::RuntimePostReturnIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::intern<wasmtime_environ::component::dfg::PostReturnId, wasmtime_environ::component::types::RuntimePostReturnIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_post_return::{closure#2}>::{closure#0}>
Line
Count
Source
1312
30
    fn intern_<K, V, T>(
1313
30
        &mut self,
1314
30
        key: K,
1315
30
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1316
30
        generate: impl FnOnce(&mut Self, K) -> T,
1317
30
        init: impl FnOnce(&mut Self, V, T),
1318
30
    ) -> V
1319
30
    where
1320
30
        K: Hash + Eq + Copy,
1321
30
        V: EntityRef,
1322
    {
1323
30
        if let Some(val) = map(self).get(&key) {
1324
0
            return *val;
1325
30
        }
1326
30
        let tmp = generate(self, key);
1327
30
        let index = V::new(map(self).len());
1328
30
        init(self, index, tmp);
1329
30
        let prev = map(self).insert(key, index);
1330
30
        assert!(prev.is_none());
1331
30
        index
1332
30
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern_::<wasmtime_environ::component::dfg::RuntimeInstance, wasmtime_environ::component::types::RuntimeInstanceIndex, wasmtime_environ::component::info::GlobalInitializer, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::intern<wasmtime_environ::component::dfg::RuntimeInstance, wasmtime_environ::component::types::RuntimeInstanceIndex, wasmtime_environ::component::info::GlobalInitializer, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::adapter_module::{closure#2}>::{closure#0}>
Line
Count
Source
1312
4.99k
    fn intern_<K, V, T>(
1313
4.99k
        &mut self,
1314
4.99k
        key: K,
1315
4.99k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1316
4.99k
        generate: impl FnOnce(&mut Self, K) -> T,
1317
4.99k
        init: impl FnOnce(&mut Self, V, T),
1318
4.99k
    ) -> V
1319
4.99k
    where
1320
4.99k
        K: Hash + Eq + Copy,
1321
4.99k
        V: EntityRef,
1322
    {
1323
4.99k
        if let Some(val) = map(self).get(&key) {
1324
431
            return *val;
1325
4.56k
        }
1326
4.56k
        let tmp = generate(self, key);
1327
4.56k
        let index = V::new(map(self).len());
1328
4.56k
        init(self, index, tmp);
1329
4.56k
        let prev = map(self).insert(key, index);
1330
4.56k
        assert!(prev.is_none());
1331
4.56k
        index
1332
4.99k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern_::<wasmtime_environ::component::dfg::TableId, wasmtime_environ::component::types::RuntimeTableIndex, wasmtime_environ::component::info::CoreExport<wasmtime_environ::types::TableIndex>, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::intern<wasmtime_environ::component::dfg::TableId, wasmtime_environ::component::types::RuntimeTableIndex, wasmtime_environ::component::info::CoreExport<wasmtime_environ::types::TableIndex>, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_table::{closure#2}>::{closure#0}>
Line
Count
Source
1312
5
    fn intern_<K, V, T>(
1313
5
        &mut self,
1314
5
        key: K,
1315
5
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1316
5
        generate: impl FnOnce(&mut Self, K) -> T,
1317
5
        init: impl FnOnce(&mut Self, V, T),
1318
5
    ) -> V
1319
5
    where
1320
5
        K: Hash + Eq + Copy,
1321
5
        V: EntityRef,
1322
    {
1323
5
        if let Some(val) = map(self).get(&key) {
1324
0
            return *val;
1325
5
        }
1326
5
        let tmp = generate(self, key);
1327
5
        let index = V::new(map(self).len());
1328
5
        init(self, index, tmp);
1329
5
        let prev = map(self).insert(key, index);
1330
5
        assert!(prev.is_none());
1331
5
        index
1332
5
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern_::<wasmtime_environ::component::dfg::MemoryId, wasmtime_environ::component::types::RuntimeMemoryIndex, wasmtime_environ::component::info::CoreExport<wasmtime_environ::types::MemoryIndex>, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::intern<wasmtime_environ::component::dfg::MemoryId, wasmtime_environ::component::types::RuntimeMemoryIndex, wasmtime_environ::component::info::CoreExport<wasmtime_environ::types::MemoryIndex>, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_memory::{closure#2}>::{closure#0}>
Line
Count
Source
1312
20.2k
    fn intern_<K, V, T>(
1313
20.2k
        &mut self,
1314
20.2k
        key: K,
1315
20.2k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1316
20.2k
        generate: impl FnOnce(&mut Self, K) -> T,
1317
20.2k
        init: impl FnOnce(&mut Self, V, T),
1318
20.2k
    ) -> V
1319
20.2k
    where
1320
20.2k
        K: Hash + Eq + Copy,
1321
20.2k
        V: EntityRef,
1322
    {
1323
20.2k
        if let Some(val) = map(self).get(&key) {
1324
11.6k
            return *val;
1325
8.58k
        }
1326
8.58k
        let tmp = generate(self, key);
1327
8.58k
        let index = V::new(map(self).len());
1328
8.58k
        init(self, index, tmp);
1329
8.58k
        let prev = map(self).insert(key, index);
1330
8.58k
        assert!(prev.is_none());
1331
8.58k
        index
1332
20.2k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern_::<wasmtime_environ::component::dfg::OptionsId, wasmtime_environ::component::types::OptionsIndex, wasmtime_environ::component::types::OptionsIndex, <wasmtime_environ::component::dfg::LinearizeDfg>::options::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::options::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::intern_no_init<wasmtime_environ::component::dfg::OptionsId, wasmtime_environ::component::types::OptionsIndex, wasmtime_environ::component::types::OptionsIndex, <wasmtime_environ::component::dfg::LinearizeDfg>::options::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::options::{closure#1}>::{closure#0}>
Line
Count
Source
1312
14.5k
    fn intern_<K, V, T>(
1313
14.5k
        &mut self,
1314
14.5k
        key: K,
1315
14.5k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1316
14.5k
        generate: impl FnOnce(&mut Self, K) -> T,
1317
14.5k
        init: impl FnOnce(&mut Self, V, T),
1318
14.5k
    ) -> V
1319
14.5k
    where
1320
14.5k
        K: Hash + Eq + Copy,
1321
14.5k
        V: EntityRef,
1322
    {
1323
14.5k
        if let Some(val) = map(self).get(&key) {
1324
182
            return *val;
1325
14.3k
        }
1326
14.3k
        let tmp = generate(self, key);
1327
14.3k
        let index = V::new(map(self).len());
1328
14.3k
        init(self, index, tmp);
1329
14.3k
        let prev = map(self).insert(key, index);
1330
14.3k
        assert!(prev.is_none());
1331
14.3k
        index
1332
14.5k
    }
<wasmtime_environ::component::dfg::LinearizeDfg>::intern_::<wasmtime_environ::component::dfg::ReallocId, wasmtime_environ::component::types::RuntimeReallocIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::intern<wasmtime_environ::component::dfg::ReallocId, wasmtime_environ::component::types::RuntimeReallocIndex, wasmtime_environ::component::info::CoreDef, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#0}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#1}, <wasmtime_environ::component::dfg::LinearizeDfg>::runtime_realloc::{closure#2}>::{closure#0}>
Line
Count
Source
1312
8.51k
    fn intern_<K, V, T>(
1313
8.51k
        &mut self,
1314
8.51k
        key: K,
1315
8.51k
        map: impl Fn(&mut Self) -> &mut HashMap<K, V>,
1316
8.51k
        generate: impl FnOnce(&mut Self, K) -> T,
1317
8.51k
        init: impl FnOnce(&mut Self, V, T),
1318
8.51k
    ) -> V
1319
8.51k
    where
1320
8.51k
        K: Hash + Eq + Copy,
1321
8.51k
        V: EntityRef,
1322
    {
1323
8.51k
        if let Some(val) = map(self).get(&key) {
1324
7
            return *val;
1325
8.50k
        }
1326
8.50k
        let tmp = generate(self, key);
1327
8.50k
        let index = V::new(map(self).len());
1328
8.50k
        init(self, index, tmp);
1329
8.50k
        let prev = map(self).insert(key, index);
1330
8.50k
        assert!(prev.is_none());
1331
8.50k
        index
1332
8.51k
    }
1333
}