@@ -2089,11 +2089,11 @@ impl TypeTrace for Tag {
2089
2089
#[ expect( missing_docs, reason = "self-describing functions" ) ]
2090
2090
pub trait TypeConvert {
2091
2091
/// Converts a wasmparser table type into a wasmtime type
2092
- fn convert_global_type ( & self , ty : & wasmparser:: GlobalType ) -> Global {
2093
- Global {
2094
- wasm_ty : self . convert_valtype ( ty. content_type ) ,
2092
+ fn convert_global_type ( & self , ty : & wasmparser:: GlobalType ) -> WasmResult < Global > {
2093
+ Ok ( Global {
2094
+ wasm_ty : self . convert_valtype ( ty. content_type ) ? ,
2095
2095
mutability : ty. mutable ,
2096
- }
2096
+ } )
2097
2097
}
2098
2098
2099
2099
/// Converts a wasmparser table type into a wasmtime type
@@ -2109,37 +2109,40 @@ pub trait TypeConvert {
2109
2109
Ok ( Table {
2110
2110
idx_type,
2111
2111
limits,
2112
- ref_type : self . convert_ref_type ( ty. element_type ) ,
2112
+ ref_type : self . convert_ref_type ( ty. element_type ) ? ,
2113
2113
} )
2114
2114
}
2115
2115
2116
- fn convert_sub_type ( & self , ty : & wasmparser:: SubType ) -> WasmSubType {
2117
- WasmSubType {
2116
+ fn convert_sub_type ( & self , ty : & wasmparser:: SubType ) -> WasmResult < WasmSubType > {
2117
+ Ok ( WasmSubType {
2118
2118
is_final : ty. is_final ,
2119
2119
supertype : ty. supertype_idx . map ( |i| self . lookup_type_index ( i. unpack ( ) ) ) ,
2120
- composite_type : self . convert_composite_type ( & ty. composite_type ) ,
2121
- }
2120
+ composite_type : self . convert_composite_type ( & ty. composite_type ) ? ,
2121
+ } )
2122
2122
}
2123
2123
2124
- fn convert_composite_type ( & self , ty : & wasmparser:: CompositeType ) -> WasmCompositeType {
2124
+ fn convert_composite_type (
2125
+ & self ,
2126
+ ty : & wasmparser:: CompositeType ,
2127
+ ) -> WasmResult < WasmCompositeType > {
2125
2128
let inner = match & ty. inner {
2126
2129
wasmparser:: CompositeInnerType :: Func ( f) => {
2127
- WasmCompositeInnerType :: Func ( self . convert_func_type ( f) )
2130
+ WasmCompositeInnerType :: Func ( self . convert_func_type ( f) ? )
2128
2131
}
2129
2132
wasmparser:: CompositeInnerType :: Array ( a) => {
2130
- WasmCompositeInnerType :: Array ( self . convert_array_type ( a) )
2133
+ WasmCompositeInnerType :: Array ( self . convert_array_type ( a) ? )
2131
2134
}
2132
2135
wasmparser:: CompositeInnerType :: Struct ( s) => {
2133
- WasmCompositeInnerType :: Struct ( self . convert_struct_type ( s) )
2136
+ WasmCompositeInnerType :: Struct ( self . convert_struct_type ( s) ? )
2134
2137
}
2135
2138
wasmparser:: CompositeInnerType :: Cont ( c) => {
2136
2139
WasmCompositeInnerType :: Cont ( self . convert_cont_type ( c) )
2137
2140
}
2138
2141
} ;
2139
- WasmCompositeType {
2142
+ Ok ( WasmCompositeType {
2140
2143
inner,
2141
2144
shared : ty. shared ,
2142
- }
2145
+ } )
2143
2146
}
2144
2147
2145
2148
/// Converts a wasmparser continuation type to a wasmtime type
@@ -2151,73 +2154,73 @@ pub trait TypeConvert {
2151
2154
}
2152
2155
}
2153
2156
2154
- fn convert_struct_type ( & self , ty : & wasmparser:: StructType ) -> WasmStructType {
2155
- WasmStructType {
2157
+ fn convert_struct_type ( & self , ty : & wasmparser:: StructType ) -> WasmResult < WasmStructType > {
2158
+ Ok ( WasmStructType {
2156
2159
fields : ty
2157
2160
. fields
2158
2161
. iter ( )
2159
2162
. map ( |f| self . convert_field_type ( f) )
2160
- . collect ( ) ,
2161
- }
2163
+ . collect :: < WasmResult < _ > > ( ) ? ,
2164
+ } )
2162
2165
}
2163
2166
2164
- fn convert_array_type ( & self , ty : & wasmparser:: ArrayType ) -> WasmArrayType {
2165
- WasmArrayType ( self . convert_field_type ( & ty. 0 ) )
2167
+ fn convert_array_type ( & self , ty : & wasmparser:: ArrayType ) -> WasmResult < WasmArrayType > {
2168
+ Ok ( WasmArrayType ( self . convert_field_type ( & ty. 0 ) ? ) )
2166
2169
}
2167
2170
2168
- fn convert_field_type ( & self , ty : & wasmparser:: FieldType ) -> WasmFieldType {
2169
- WasmFieldType {
2170
- element_type : self . convert_storage_type ( & ty. element_type ) ,
2171
+ fn convert_field_type ( & self , ty : & wasmparser:: FieldType ) -> WasmResult < WasmFieldType > {
2172
+ Ok ( WasmFieldType {
2173
+ element_type : self . convert_storage_type ( & ty. element_type ) ? ,
2171
2174
mutable : ty. mutable ,
2172
- }
2175
+ } )
2173
2176
}
2174
2177
2175
- fn convert_storage_type ( & self , ty : & wasmparser:: StorageType ) -> WasmStorageType {
2176
- match ty {
2178
+ fn convert_storage_type ( & self , ty : & wasmparser:: StorageType ) -> WasmResult < WasmStorageType > {
2179
+ Ok ( match ty {
2177
2180
wasmparser:: StorageType :: I8 => WasmStorageType :: I8 ,
2178
2181
wasmparser:: StorageType :: I16 => WasmStorageType :: I16 ,
2179
- wasmparser:: StorageType :: Val ( v) => WasmStorageType :: Val ( self . convert_valtype ( * v) ) ,
2180
- }
2182
+ wasmparser:: StorageType :: Val ( v) => WasmStorageType :: Val ( self . convert_valtype ( * v) ? ) ,
2183
+ } )
2181
2184
}
2182
2185
2183
2186
/// Converts a wasmparser function type to a wasmtime type
2184
- fn convert_func_type ( & self , ty : & wasmparser:: FuncType ) -> WasmFuncType {
2187
+ fn convert_func_type ( & self , ty : & wasmparser:: FuncType ) -> WasmResult < WasmFuncType > {
2185
2188
let params = ty
2186
2189
. params ( )
2187
2190
. iter ( )
2188
2191
. map ( |t| self . convert_valtype ( * t) )
2189
- . collect ( ) ;
2192
+ . collect :: < WasmResult < _ > > ( ) ? ;
2190
2193
let results = ty
2191
2194
. results ( )
2192
2195
. iter ( )
2193
2196
. map ( |t| self . convert_valtype ( * t) )
2194
- . collect ( ) ;
2195
- WasmFuncType :: new ( params, results)
2197
+ . collect :: < WasmResult < _ > > ( ) ? ;
2198
+ Ok ( WasmFuncType :: new ( params, results) )
2196
2199
}
2197
2200
2198
2201
/// Converts a wasmparser value type to a wasmtime type
2199
- fn convert_valtype ( & self , ty : wasmparser:: ValType ) -> WasmValType {
2200
- match ty {
2202
+ fn convert_valtype ( & self , ty : wasmparser:: ValType ) -> WasmResult < WasmValType > {
2203
+ Ok ( match ty {
2201
2204
wasmparser:: ValType :: I32 => WasmValType :: I32 ,
2202
2205
wasmparser:: ValType :: I64 => WasmValType :: I64 ,
2203
2206
wasmparser:: ValType :: F32 => WasmValType :: F32 ,
2204
2207
wasmparser:: ValType :: F64 => WasmValType :: F64 ,
2205
2208
wasmparser:: ValType :: V128 => WasmValType :: V128 ,
2206
- wasmparser:: ValType :: Ref ( t) => WasmValType :: Ref ( self . convert_ref_type ( t) ) ,
2207
- }
2209
+ wasmparser:: ValType :: Ref ( t) => WasmValType :: Ref ( self . convert_ref_type ( t) ? ) ,
2210
+ } )
2208
2211
}
2209
2212
2210
2213
/// Converts a wasmparser reference type to a wasmtime type
2211
- fn convert_ref_type ( & self , ty : wasmparser:: RefType ) -> WasmRefType {
2212
- WasmRefType {
2214
+ fn convert_ref_type ( & self , ty : wasmparser:: RefType ) -> WasmResult < WasmRefType > {
2215
+ Ok ( WasmRefType {
2213
2216
nullable : ty. is_nullable ( ) ,
2214
- heap_type : self . convert_heap_type ( ty. heap_type ( ) ) ,
2215
- }
2217
+ heap_type : self . convert_heap_type ( ty. heap_type ( ) ) ? ,
2218
+ } )
2216
2219
}
2217
2220
2218
2221
/// Converts a wasmparser heap type to a wasmtime type
2219
- fn convert_heap_type ( & self , ty : wasmparser:: HeapType ) -> WasmHeapType {
2220
- match ty {
2222
+ fn convert_heap_type ( & self , ty : wasmparser:: HeapType ) -> WasmResult < WasmHeapType > {
2223
+ Ok ( match ty {
2221
2224
wasmparser:: HeapType :: Concrete ( i) => self . lookup_heap_type ( i) ,
2222
2225
wasmparser:: HeapType :: Abstract { ty, shared : false } => match ty {
2223
2226
wasmparser:: AbstractHeapType :: Extern => WasmHeapType :: Extern ,
@@ -2235,11 +2238,11 @@ pub trait TypeConvert {
2235
2238
| wasmparser:: AbstractHeapType :: NoExn
2236
2239
| wasmparser:: AbstractHeapType :: Cont
2237
2240
| wasmparser:: AbstractHeapType :: NoCont => {
2238
- unimplemented ! ( "unsupported heap type {ty:?}" ) ;
2241
+ return Err ( wasm_unsupported ! ( "unsupported heap type {ty:?}" ) )
2239
2242
}
2240
2243
} ,
2241
- _ => unimplemented ! ( "unsupported heap type {ty:?}" ) ,
2242
- }
2244
+ _ => return Err ( wasm_unsupported ! ( "unsupported heap type {ty:?}" ) ) ,
2245
+ } )
2243
2246
}
2244
2247
2245
2248
/// Converts the specified type index from a heap type into a canonicalized
0 commit comments