Skip to content

Commit 0a18000

Browse files
authored
Rename VMTableImport to VMTable (#10506)
In #10499, I used the `struct VMTableImport` to hold the necessary pointers for accessing a core WebAssembly table from a component. Since `VMTableImport` no longer was exclusively used for imported tables, it seems reasonable to rename it to something less specific: `VMTable`. This changes all the functions referencing `vmtable_import*` as well except those that are specifically dealing with imported tables.
1 parent b91f504 commit 0a18000

File tree

11 files changed

+53
-62
lines changed

11 files changed

+53
-62
lines changed

crates/cranelift/src/func_environ.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
807807
.unwrap();
808808
(vmctx, base_offset, current_elements_offset)
809809
} else {
810-
let from_offset = self.offsets.vmctx_vmtable_import_from(index);
810+
let from_offset = self.offsets.vmctx_vmtable_from(index);
811811
let table = func.create_global_value(ir::GlobalValueData::Load {
812812
base: vmctx,
813813
offset: Offset32::new(i32::try_from(from_offset).unwrap()),

crates/environ/src/component/vmcomponent_offsets.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// trampoline_func_refs: [VMFuncRef; component.num_trampolines],
99
// lowerings: [VMLowering; component.num_lowerings],
1010
// memories: [*mut VMMemoryDefinition; component.num_runtime_memories],
11-
// tables: [VMTableImport; component.num_runtime_tables],
11+
// tables: [VMTable; component.num_runtime_tables],
1212
// reallocs: [*mut VMFuncRef; component.num_runtime_reallocs],
1313
// post_returns: [*mut VMFuncRef; component.num_runtime_post_returns],
1414
// resource_destructors: [*mut VMFuncRef; component.num_resources],
@@ -151,7 +151,7 @@ impl<P: PtrSize> VMComponentOffsets<P> {
151151
size(trampoline_func_refs) = cmul(ret.num_trampolines, ret.ptr.size_of_vm_func_ref()),
152152
size(lowerings) = cmul(ret.num_lowerings, ret.ptr.size() * 2),
153153
size(memories) = cmul(ret.num_runtime_memories, ret.ptr.size()),
154-
size(tables) = cmul(ret.num_runtime_tables, ret.size_of_vmtable_import()),
154+
size(tables) = cmul(ret.num_runtime_tables, ret.size_of_vmtable()),
155155
size(reallocs) = cmul(ret.num_runtime_reallocs, ret.ptr.size()),
156156
size(callbacks) = cmul(ret.num_runtime_callbacks, ret.ptr.size()),
157157
size(post_returns) = cmul(ret.num_runtime_post_returns, ret.ptr.size()),
@@ -279,13 +279,13 @@ impl<P: PtrSize> VMComponentOffsets<P> {
279279
#[inline]
280280
pub fn runtime_table(&self, index: RuntimeTableIndex) -> u32 {
281281
assert!(index.as_u32() < self.num_runtime_tables);
282-
self.runtime_tables() + index.as_u32() * u32::from(self.size_of_vmtable_import())
282+
self.runtime_tables() + index.as_u32() * u32::from(self.size_of_vmtable())
283283
}
284284

285-
/// Return the size of `VMTableImport`, used here to hold the pointers to
286-
/// the `VMTableDefinition` and `VMContext` (not because this is an import).
285+
/// Return the size of `VMTable`, used here to hold the pointers to
286+
/// the `VMTableDefinition` and `VMContext`.
287287
#[inline]
288-
pub fn size_of_vmtable_import(&self) -> u8 {
288+
pub fn size_of_vmtable(&self) -> u8 {
289289
2 * self.pointer_size()
290290
}
291291

crates/environ/src/vmoffsets.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// memories: [*mut VMMemoryDefinition; module.num_defined_memories],
2828
// owned_memories: [VMMemoryDefinition; module.num_owned_memories],
2929
// imported_functions: [VMFunctionImport; module.num_imported_functions],
30-
// imported_tables: [VMTableImport; module.num_imported_tables],
30+
// imported_tables: [VMTable; module.num_imported_tables],
3131
// imported_globals: [VMGlobalImport; module.num_imported_globals],
3232
// imported_tags: [VMTagImport; module.num_imported_tags],
3333
// tables: [VMTableDefinition; module.num_defined_tables],
@@ -520,7 +520,7 @@ impl<P: PtrSize> From<VMOffsetsFields<P>> for VMOffsets<P> {
520520
size(imported_functions)
521521
= cmul(ret.num_imported_functions, ret.size_of_vmfunction_import()),
522522
size(imported_tables)
523-
= cmul(ret.num_imported_tables, ret.size_of_vmtable_import()),
523+
= cmul(ret.num_imported_tables, ret.size_of_vmtable()),
524524
size(imported_globals)
525525
= cmul(ret.num_imported_globals, ret.size_of_vmglobal_import()),
526526
size(imported_tags)
@@ -578,23 +578,23 @@ impl<P: PtrSize> VMOffsets<P> {
578578
}
579579
}
580580

581-
/// Offsets for `VMTableImport`.
581+
/// Offsets for `VMTable`.
582582
impl<P: PtrSize> VMOffsets<P> {
583583
/// The offset of the `from` field.
584584
#[inline]
585-
pub fn vmtable_import_from(&self) -> u8 {
585+
pub fn vmtable_from(&self) -> u8 {
586586
0 * self.pointer_size()
587587
}
588588

589589
/// The offset of the `vmctx` field.
590590
#[inline]
591-
pub fn vmtable_import_vmctx(&self) -> u8 {
591+
pub fn vmtable_vmctx(&self) -> u8 {
592592
1 * self.pointer_size()
593593
}
594594

595-
/// Return the size of `VMTableImport`.
595+
/// Return the size of `VMTable`.
596596
#[inline]
597-
pub fn size_of_vmtable_import(&self) -> u8 {
597+
pub fn size_of_vmtable(&self) -> u8 {
598598
2 * self.pointer_size()
599599
}
600600
}
@@ -767,12 +767,11 @@ impl<P: PtrSize> VMOffsets<P> {
767767
+ index.as_u32() * u32::from(self.size_of_vmfunction_import())
768768
}
769769

770-
/// Return the offset to `VMTableImport` index `index`.
770+
/// Return the offset to `VMTable` index `index`.
771771
#[inline]
772772
pub fn vmctx_vmtable_import(&self, index: TableIndex) -> u32 {
773773
assert!(index.as_u32() < self.num_imported_tables);
774-
self.vmctx_imported_tables_begin()
775-
+ index.as_u32() * u32::from(self.size_of_vmtable_import())
774+
self.vmctx_imported_tables_begin() + index.as_u32() * u32::from(self.size_of_vmtable())
776775
}
777776

778777
/// Return the offset to `VMMemoryImport` index `index`.
@@ -863,10 +862,11 @@ impl<P: PtrSize> VMOffsets<P> {
863862
self.vmctx_vmfunction_import(index) + u32::from(self.vmfunction_import_vmctx())
864863
}
865864

866-
/// Return the offset to the `from` field in `VMTableImport` index `index`.
865+
/// Return the offset to the `from` field in the imported `VMTable` at index
866+
/// `index`.
867867
#[inline]
868-
pub fn vmctx_vmtable_import_from(&self, index: TableIndex) -> u32 {
869-
self.vmctx_vmtable_import(index) + u32::from(self.vmtable_import_from())
868+
pub fn vmctx_vmtable_from(&self, index: TableIndex) -> u32 {
869+
self.vmctx_vmtable_import(index) + u32::from(self.vmtable_from())
870870
}
871871

872872
/// Return the offset to the `base` field in `VMTableDefinition` index `index`.

crates/wasmtime/src/runtime/externals/table.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ impl Table {
414414
&data[self.0].table
415415
}
416416

417-
pub(crate) fn vmimport(&self, store: &StoreOpaque) -> crate::runtime::vm::VMTableImport {
417+
pub(crate) fn vmimport(&self, store: &StoreOpaque) -> crate::runtime::vm::VMTable {
418418
let export = &store[self.0];
419-
crate::runtime::vm::VMTableImport {
419+
crate::runtime::vm::VMTable {
420420
from: export.definition.into(),
421421
vmctx: export.vmctx.into(),
422422
}

crates/wasmtime/src/runtime/instance.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::linker::{Definition, DefinitionType};
22
use crate::prelude::*;
33
use crate::runtime::vm::{
44
Imports, InstanceAllocationRequest, ModuleRuntimeInfo, StorePtr, VMFuncRef, VMFunctionImport,
5-
VMGlobalImport, VMMemoryImport, VMOpaqueContext, VMTableImport, VMTagImport,
5+
VMGlobalImport, VMMemoryImport, VMOpaqueContext, VMTable, VMTagImport,
66
};
77
use crate::store::{InstanceId, StoreOpaque, Stored};
88
use crate::types::matching;
@@ -656,7 +656,7 @@ impl Instance {
656656

657657
pub(crate) struct OwnedImports {
658658
functions: PrimaryMap<FuncIndex, VMFunctionImport>,
659-
tables: PrimaryMap<TableIndex, VMTableImport>,
659+
tables: PrimaryMap<TableIndex, VMTable>,
660660
memories: PrimaryMap<MemoryIndex, VMMemoryImport>,
661661
globals: PrimaryMap<GlobalIndex, VMGlobalImport>,
662662
tags: PrimaryMap<TagIndex, VMTagImport>,
@@ -739,7 +739,7 @@ impl OwnedImports {
739739
});
740740
}
741741
crate::runtime::vm::Export::Table(t) => {
742-
self.tables.push(VMTableImport {
742+
self.tables.push(VMTable {
743743
from: t.definition.into(),
744744
vmctx: t.vmctx.into(),
745745
});

crates/wasmtime/src/runtime/vm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub use crate::runtime::vm::vmcontext::VMTableDefinition;
9595
pub use crate::runtime::vm::vmcontext::{
9696
VMArrayCallFunction, VMArrayCallHostFuncContext, VMContext, VMFuncRef, VMFunctionBody,
9797
VMFunctionImport, VMGlobalDefinition, VMGlobalImport, VMMemoryDefinition, VMMemoryImport,
98-
VMOpaqueContext, VMStoreContext, VMTableImport, VMTagImport, VMWasmCallFunction, ValRaw,
98+
VMOpaqueContext, VMStoreContext, VMTable, VMTagImport, VMWasmCallFunction, ValRaw,
9999
};
100100
pub use send_sync_ptr::SendSyncPtr;
101101

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use crate::prelude::*;
1010
use crate::runtime::vm::{
1111
SendSyncPtr, VMArrayCallFunction, VMContext, VMFuncRef, VMGlobalDefinition, VMMemoryDefinition,
12-
VMOpaqueContext, VMStore, VMStoreRawPtr, VMTableDefinition, VMTableImport, VMWasmCallFunction,
12+
VMOpaqueContext, VMStore, VMStoreRawPtr, VMTable, VMTableDefinition, VMWasmCallFunction,
1313
ValRaw, VmPtr, VmSafe,
1414
};
1515
use alloc::alloc::Layout;
@@ -295,12 +295,9 @@ impl ComponentInstance {
295295
///
296296
/// This can only be called after `idx` has been initialized at runtime
297297
/// during the instantiation process of a component.
298-
///
299-
/// Note that we use a `VMTableImport` here because of its structure, not
300-
/// because these tables are actually imports.
301-
pub fn runtime_table(&self, idx: RuntimeTableIndex) -> VMTableImport {
298+
pub fn runtime_table(&self, idx: RuntimeTableIndex) -> VMTable {
302299
unsafe {
303-
let ret = *self.vmctx_plus_offset::<VMTableImport>(self.offsets.runtime_table(idx));
300+
let ret = *self.vmctx_plus_offset::<VMTable>(self.offsets.runtime_table(idx));
304301
debug_assert!(ret.from.as_ptr() as usize != INVALID_PTR);
305302
debug_assert!(ret.vmctx.as_ptr() as usize != INVALID_PTR);
306303
ret
@@ -436,14 +433,11 @@ impl ComponentInstance {
436433
ptr: NonNull<VMTableDefinition>,
437434
vmctx: NonNull<VMContext>,
438435
) {
439-
// Note that we use a `VMTableImport` here because of its structure, not
440-
// because these tables are actually imports.
441436
unsafe {
442-
let storage =
443-
self.vmctx_plus_offset_mut::<VMTableImport>(self.offsets.runtime_table(idx));
437+
let storage = self.vmctx_plus_offset_mut::<VMTable>(self.offsets.runtime_table(idx));
444438
debug_assert!((*storage).vmctx.as_ptr() as usize == INVALID_PTR);
445439
debug_assert!((*storage).from.as_ptr() as usize == INVALID_PTR);
446-
*storage = VMTableImport {
440+
*storage = VMTable {
447441
vmctx: vmctx.into(),
448442
from: ptr.into(),
449443
};

crates/wasmtime/src/runtime/vm/imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::runtime::vm::vmcontext::{
2-
VMFunctionImport, VMGlobalImport, VMMemoryImport, VMTableImport, VMTagImport,
2+
VMFunctionImport, VMGlobalImport, VMMemoryImport, VMTable, VMTagImport,
33
};
44

55
/// Resolved import pointers.
@@ -19,7 +19,7 @@ pub struct Imports<'a> {
1919
pub functions: &'a [VMFunctionImport],
2020

2121
/// Resolved addresses for imported tables.
22-
pub tables: &'a [VMTableImport],
22+
pub tables: &'a [VMTable],
2323

2424
/// Resolved addresses for imported memories.
2525
pub memories: &'a [VMMemoryImport],

crates/wasmtime/src/runtime/vm/instance.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::runtime::vm::memory::{Memory, RuntimeMemoryCreator};
88
use crate::runtime::vm::table::{Table, TableElement, TableElementType};
99
use crate::runtime::vm::vmcontext::{
1010
VMBuiltinFunctionsArray, VMContext, VMFuncRef, VMFunctionImport, VMGlobalDefinition,
11-
VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMOpaqueContext, VMStoreContext,
12-
VMTableDefinition, VMTableImport, VMTagDefinition, VMTagImport,
11+
VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMOpaqueContext, VMStoreContext, VMTable,
12+
VMTableDefinition, VMTagDefinition, VMTagImport,
1313
};
1414
use crate::runtime::vm::{
1515
ExportFunction, ExportGlobal, ExportMemory, ExportTable, ExportTag, GcStore, Imports,
@@ -428,8 +428,8 @@ impl Instance {
428428
unsafe { &*self.vmctx_plus_offset(self.offsets().vmctx_vmfunction_import(index)) }
429429
}
430430

431-
/// Return the index `VMTableImport`.
432-
fn imported_table(&self, index: TableIndex) -> &VMTableImport {
431+
/// Return the index `VMTable`.
432+
fn imported_table(&self, index: TableIndex) -> &VMTable {
433433
unsafe { &*self.vmctx_plus_offset(self.offsets().vmctx_vmtable_import(index)) }
434434
}
435435

crates/wasmtime/src/runtime/vm/vmcontext.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ mod test_vmfunction_body {
144144
/// imported from another instance.
145145
#[derive(Debug, Copy, Clone)]
146146
#[repr(C)]
147-
pub struct VMTableImport {
147+
pub struct VMTable {
148148
/// A pointer to the imported table description.
149149
pub from: VmPtr<VMTableDefinition>,
150150

@@ -153,46 +153,43 @@ pub struct VMTableImport {
153153
}
154154

155155
// SAFETY: the above structure is repr(C) and only contains `VmSafe` fields.
156-
unsafe impl VmSafe for VMTableImport {}
156+
unsafe impl VmSafe for VMTable {}
157157

158158
#[cfg(test)]
159-
mod test_vmtable_import {
160-
use super::VMTableImport;
159+
mod test_vmtable {
160+
use super::VMTable;
161161
use core::mem::offset_of;
162162
use std::mem::size_of;
163163
use wasmtime_environ::component::{Component, VMComponentOffsets};
164164
use wasmtime_environ::{HostPtr, Module, VMOffsets};
165165

166166
#[test]
167-
fn check_vmtable_import_offsets() {
167+
fn check_vmtable_offsets() {
168168
let module = Module::new();
169169
let offsets = VMOffsets::new(HostPtr, &module);
170+
assert_eq!(size_of::<VMTable>(), usize::from(offsets.size_of_vmtable()));
170171
assert_eq!(
171-
size_of::<VMTableImport>(),
172-
usize::from(offsets.size_of_vmtable_import())
172+
offset_of!(VMTable, from),
173+
usize::from(offsets.vmtable_from())
173174
);
174175
assert_eq!(
175-
offset_of!(VMTableImport, from),
176-
usize::from(offsets.vmtable_import_from())
177-
);
178-
assert_eq!(
179-
offset_of!(VMTableImport, vmctx),
180-
usize::from(offsets.vmtable_import_vmctx())
176+
offset_of!(VMTable, vmctx),
177+
usize::from(offsets.vmtable_vmctx())
181178
);
182179
}
183180

184181
#[test]
185182
fn ensure_sizes_match() {
186-
// Because we use `VMTableImport` for recording tables used by
187-
// components, we want to make sure that the size calculations between
188-
// `VMOffsets` and `VMComponentOffsets` stay the same.
183+
// Because we use `VMTable` for recording tables used by components, we
184+
// want to make sure that the size calculations between `VMOffsets` and
185+
// `VMComponentOffsets` stay the same.
189186
let module = Module::new();
190187
let vm_offsets = VMOffsets::new(HostPtr, &module);
191188
let component = Component::default();
192189
let vm_component_offsets = VMComponentOffsets::new(HostPtr, &component);
193190
assert_eq!(
194-
vm_offsets.size_of_vmtable_import(),
195-
vm_component_offsets.size_of_vmtable_import()
191+
vm_offsets.size_of_vmtable(),
192+
vm_component_offsets.size_of_vmtable()
196193
);
197194
}
198195
}

0 commit comments

Comments
 (0)