Skip to content

Commit a49521c

Browse files
committed
Review feedback.
1 parent d592c51 commit a49521c

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

crates/cranelift/src/func_environ.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2540,7 +2540,7 @@ impl FuncEnvironment<'_> {
25402540
builder: &mut FunctionBuilder<'_>,
25412541
tag_index: TagIndex,
25422542
exn_ref: ir::Value,
2543-
) -> WasmResult<Vec<ir::Value>> {
2543+
) -> WasmResult<SmallVec<[ir::Value; 4]>> {
25442544
gc::translate_exn_unbox(self, builder, tag_index, exn_ref)
25452545
}
25462546

crates/cranelift/src/func_environ/gc/enabled.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use cranelift_codegen::{
1010
};
1111
use cranelift_entity::packed_option::ReservedValue;
1212
use cranelift_frontend::FunctionBuilder;
13-
use smallvec::SmallVec;
13+
use smallvec::{SmallVec, smallvec};
1414
use wasmtime_environ::{
1515
Collector, GcArrayLayout, GcLayout, GcStructLayout, I31_DISCRIMINANT, ModuleInternedTypeIndex,
1616
PtrSize, TagIndex, TypeIndex, VMGcKind, WasmCompositeInnerType, WasmHeapTopType, WasmHeapType,
@@ -414,7 +414,7 @@ pub fn translate_exn_unbox(
414414
builder: &mut FunctionBuilder<'_>,
415415
tag_index: TagIndex,
416416
exn_ref: ir::Value,
417-
) -> WasmResult<Vec<ir::Value>> {
417+
) -> WasmResult<SmallVec<[ir::Value; 4]>> {
418418
log::trace!("translate_exn_unbox({tag_index:?} {exn_ref:?})");
419419

420420
// We know that the `exn_ref` is not null because we reach this
@@ -433,12 +433,12 @@ pub fn translate_exn_unbox(
433433
// Gather accesses first because these require a borrow on
434434
// `func_env`, which we later mutate below via
435435
// `prepare_gc_ref_access()`.
436-
let mut accesses = vec![];
436+
let mut accesses: SmallVec<[_; 4]> = smallvec![];
437437
for (field_ty, field_layout) in exception_ty.fields.iter().zip(exn_layout.fields.iter()) {
438438
accesses.push((field_layout.offset, field_ty.element_type));
439439
}
440440

441-
let mut result = vec![];
441+
let mut result = smallvec![];
442442
for (field_offset, field_ty) in accesses {
443443
let field_size = wasmtime_environ::byte_size_of_wasm_ty_in_gc_heap(&field_ty);
444444
assert!(field_offset + field_size <= exn_size);

crates/wasmtime/src/runtime/code_memory.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ impl CodeMemory {
188188

189189
// Ensure that the exception table is well-formed. This parser
190190
// construction is cheap: it reads the header and validates
191-
// ranges but nothing else.
191+
// ranges but nothing else. We do this only in debug-assertion
192+
// builds because we otherwise require for safety that the
193+
// compiled artifact is as-produced-by this version of
194+
// Wasmtime, and we should always produce a correct exception
195+
// table (i.e., we are not expecting untrusted data here).
196+
#[cfg(debug_assertions)]
192197
let _ = ExceptionTable::parse(&mmap[exception_data.clone()])?;
193198

194199
Ok(Self {

crates/wasmtime/src/runtime/vm/gc/disabled.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ impl VMGcRef {
2626
}
2727

2828
impl From<VMStructRef> for VMGcRef {
29-
fn from(_s: VMStructRef) -> VMGcRef {
30-
unreachable!()
29+
fn from(s: VMStructRef) -> VMGcRef {
30+
match s {}
3131
}
3232
}
3333

3434
impl From<VMExnRef> for VMGcRef {
35-
fn from(_e: VMExnRef) -> VMGcRef {
36-
unreachable!()
35+
fn from(e: VMExnRef) -> VMGcRef {
36+
match e {}
3737
}
3838
}
3939

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ mod test_vmtag_import {
355355
offset_of!(VMTagImport, from),
356356
usize::from(offsets.vmtag_import_from())
357357
);
358+
assert_eq!(
359+
offset_of!(VMTagImport, vmctx),
360+
usize::from(offsets.vmtag_import_vmctx())
361+
);
362+
assert_eq!(
363+
offset_of!(VMTagImport, index),
364+
usize::from(offsets.vmtag_import_index())
365+
);
358366
}
359367
}
360368

0 commit comments

Comments
 (0)