diff --git a/cranelift/wasm/src/sections_translator.rs b/cranelift/wasm/src/sections_translator.rs index 967612178a..a762bd0dfb 100644 --- a/cranelift/wasm/src/sections_translator.rs +++ b/cranelift/wasm/src/sections_translator.rs @@ -108,6 +108,7 @@ pub fn parse_import_section<'data>( ImportSectionEntryType::Table(ref tab) => { environ.declare_table_import( Table { + wasm_ty: tab.element_type, ty: match tabletype_to_type(tab.element_type, environ)? { Some(t) => TableElementType::Val(t), None => TableElementType::Func, @@ -157,6 +158,7 @@ pub fn parse_table_section( for entry in tables { let table = entry?; environ.declare_table(Table { + wasm_ty: table.element_type, ty: match tabletype_to_type(table.element_type, environ)? { Some(t) => TableElementType::Val(t), None => TableElementType::Func, diff --git a/cranelift/wasm/src/translation_utils.rs b/cranelift/wasm/src/translation_utils.rs index 2b2a7af68f..d799027903 100644 --- a/cranelift/wasm/src/translation_utils.rs +++ b/cranelift/wasm/src/translation_utils.rs @@ -1,5 +1,5 @@ //! Helper functions and structures for the translation. -use crate::environ::{TargetEnvironment, WasmResult}; +use crate::environ::{TargetEnvironment, WasmResult, WasmType}; use crate::state::ModuleTranslationState; use crate::wasm_unsupported; use core::u32; @@ -104,7 +104,9 @@ pub enum GlobalInit { /// WebAssembly table. #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] pub struct Table { - /// The type of data stored in elements of the table. + /// The table elements' Wasm type. + pub wasm_ty: WasmType, + /// The table elements' Cranelift type. pub ty: TableElementType, /// The minimum number of elements in the table. pub minimum: u32, diff --git a/crates/jit/src/imports.rs b/crates/jit/src/imports.rs index cf0f497e15..5694daa36d 100644 --- a/crates/jit/src/imports.rs +++ b/crates/jit/src/imports.rs @@ -201,6 +201,7 @@ fn is_table_compatible(exported: &TablePlan, imported: &TablePlan) -> bool { let TablePlan { table: Table { + wasm_ty: exported_wasm_ty, ty: exported_ty, minimum: exported_minimum, maximum: exported_maximum, @@ -210,6 +211,7 @@ fn is_table_compatible(exported: &TablePlan, imported: &TablePlan) -> bool { let TablePlan { table: Table { + wasm_ty: imported_wasm_ty, ty: imported_ty, minimum: imported_minimum, maximum: imported_maximum, @@ -217,7 +219,8 @@ fn is_table_compatible(exported: &TablePlan, imported: &TablePlan) -> bool { style: _imported_style, } = imported; - is_table_element_type_compatible(*exported_ty, *imported_ty) + exported_wasm_ty == imported_wasm_ty + && is_table_element_type_compatible(*exported_ty, *imported_ty) && imported_minimum <= exported_minimum && (imported_maximum.is_none() || (!exported_maximum.is_none()