@@ -113,8 +113,8 @@ use wasmtime_runtime::{
113113/// // Here we need to define the type signature of our `Double` function and
114114/// // then wrap it up in a `Func`
115115/// let double_type = wasmtime::FuncType::new(
116- /// Box::new( [wasmtime::ValType::I32]),
117- /// Box::new( [wasmtime::ValType::I32])
116+ /// [wasmtime::ValType::I32].iter().cloned( ),
117+ /// [wasmtime::ValType::I32].iter().cloned(),
118118/// );
119119/// let double = Func::new(&store, double_type, |_, params, results| {
120120/// let mut value = params[0].unwrap_i32();
@@ -163,7 +163,7 @@ macro_rules! getters {
163163 // Verify all the paramers match the expected parameters, and that
164164 // there are no extra parameters...
165165 let ty = self . ty( ) ;
166- let mut params = ty. params( ) . iter ( ) . cloned ( ) ;
166+ let mut params = ty. params( ) ;
167167 let n = 0 ;
168168 $(
169169 let n = n + 1 ;
@@ -173,7 +173,7 @@ macro_rules! getters {
173173 ensure!( params. next( ) . is_none( ) , "Type mismatch: too many arguments (expected {})" , n) ;
174174
175175 // ... then do the same for the results...
176- let mut results = ty. results( ) . iter ( ) . cloned ( ) ;
176+ let mut results = ty. results( ) ;
177177 R :: matches( & mut results)
178178 . context( "Type mismatch in return type" ) ?;
179179 ensure!( results. next( ) . is_none( ) , "Type mismatch: too many return values (expected 1)" ) ;
@@ -274,7 +274,7 @@ impl Func {
274274 let mut args: SmallVec < [ Val ; STACK_ARGS ] > =
275275 SmallVec :: with_capacity ( ty_clone. params ( ) . len ( ) ) ;
276276 let store = Store :: upgrade ( & store_weak) . unwrap ( ) ;
277- for ( i, ty) in ty_clone. params ( ) . iter ( ) . enumerate ( ) {
277+ for ( i, ty) in ty_clone. params ( ) . enumerate ( ) {
278278 unsafe {
279279 let val = Val :: read_value_from ( & store, values_vec. add ( i) , ty) ;
280280 args. push ( val) ;
@@ -298,7 +298,7 @@ impl Func {
298298 // produces the wrong number or wrong types of values, and we need
299299 // to catch that here.
300300 for ( i, ( ret, ty) ) in returns. into_iter ( ) . zip ( ty_clone. results ( ) ) . enumerate ( ) {
301- if ret. ty ( ) != * ty {
301+ if ret. ty ( ) != ty {
302302 return Err ( Trap :: new (
303303 "function attempted to return an incompatible value" ,
304304 ) ) ;
@@ -596,9 +596,9 @@ impl Func {
596596 let mut values_vec = vec ! [ 0 ; max( params. len( ) , my_ty. results( ) . len( ) ) ] ;
597597
598598 // Store the argument values into `values_vec`.
599- let param_tys = my_ty. params ( ) . iter ( ) ;
599+ let param_tys = my_ty. params ( ) ;
600600 for ( ( arg, slot) , ty) in params. iter ( ) . cloned ( ) . zip ( & mut values_vec) . zip ( param_tys) {
601- if arg. ty ( ) != * ty {
601+ if arg. ty ( ) != ty {
602602 bail ! (
603603 "argument type mismatch: found {} but expected {}" ,
604604 arg. ty( ) ,
@@ -628,7 +628,7 @@ impl Func {
628628
629629 // Load the return values out of `values_vec`.
630630 let mut results = Vec :: with_capacity ( my_ty. results ( ) . len ( ) ) ;
631- for ( index, ty) in my_ty. results ( ) . iter ( ) . enumerate ( ) {
631+ for ( index, ty) in my_ty. results ( ) . enumerate ( ) {
632632 unsafe {
633633 let ptr = values_vec. as_ptr ( ) . add ( index) ;
634634 results. push ( Val :: read_value_from ( & self . instance . store , ptr, ty) ) ;
@@ -876,7 +876,7 @@ pub unsafe trait WasmTy {
876876
877877 // Add this type to the given vec of expected valtypes.
878878 #[ doc( hidden) ]
879- fn push ( dst : & mut Vec < ValType > ) ;
879+ fn valtype ( ) -> Option < ValType > ;
880880
881881 // Does the next valtype(s) match this type?
882882 #[ doc( hidden) ]
@@ -923,7 +923,7 @@ pub unsafe trait WasmRet {
923923
924924 // Same as `WasmTy::push`.
925925 #[ doc( hidden) ]
926- fn push ( dst : & mut Vec < ValType > ) ;
926+ fn valtype ( ) -> Option < ValType > ;
927927
928928 // Same as `WasmTy::matches`.
929929 #[ doc( hidden) ]
@@ -952,7 +952,9 @@ unsafe impl WasmTy for () {
952952 #[ inline]
953953 unsafe fn from_abi < ' a > ( _abi : Self :: Abi , _store : WeakStore < ' a > ) -> Self { }
954954
955- fn push ( _dst : & mut Vec < ValType > ) { }
955+ fn valtype ( ) -> Option < ValType > {
956+ None
957+ }
956958
957959 fn matches ( _tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
958960 Ok ( ( ) )
@@ -983,8 +985,8 @@ unsafe impl WasmTy for i32 {
983985 abi
984986 }
985987
986- fn push ( dst : & mut Vec < ValType > ) {
987- dst . push ( ValType :: I32 ) ;
988+ fn valtype ( ) -> Option < ValType > {
989+ Some ( ValType :: I32 )
988990 }
989991
990992 fn matches ( mut tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
@@ -1028,8 +1030,8 @@ unsafe impl WasmTy for u32 {
10281030 abi as Self
10291031 }
10301032
1031- fn push ( dst : & mut Vec < ValType > ) {
1032- <i32 as WasmTy >:: push ( dst )
1033+ fn valtype ( ) -> Option < ValType > {
1034+ <i32 as WasmTy >:: valtype ( )
10331035 }
10341036
10351037 fn matches ( tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
@@ -1065,8 +1067,8 @@ unsafe impl WasmTy for i64 {
10651067 abi
10661068 }
10671069
1068- fn push ( dst : & mut Vec < ValType > ) {
1069- dst . push ( ValType :: I64 ) ;
1070+ fn valtype ( ) -> Option < ValType > {
1071+ Some ( ValType :: I64 )
10701072 }
10711073
10721074 fn matches ( mut tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
@@ -1110,8 +1112,8 @@ unsafe impl WasmTy for u64 {
11101112 abi as Self
11111113 }
11121114
1113- fn push ( dst : & mut Vec < ValType > ) {
1114- <i64 as WasmTy >:: push ( dst )
1115+ fn valtype ( ) -> Option < ValType > {
1116+ <i64 as WasmTy >:: valtype ( )
11151117 }
11161118
11171119 fn matches ( tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
@@ -1147,8 +1149,8 @@ unsafe impl WasmTy for f32 {
11471149 abi
11481150 }
11491151
1150- fn push ( dst : & mut Vec < ValType > ) {
1151- dst . push ( ValType :: F32 ) ;
1152+ fn valtype ( ) -> Option < ValType > {
1153+ Some ( ValType :: F32 )
11521154 }
11531155
11541156 fn matches ( mut tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
@@ -1192,8 +1194,8 @@ unsafe impl WasmTy for f64 {
11921194 abi
11931195 }
11941196
1195- fn push ( dst : & mut Vec < ValType > ) {
1196- dst . push ( ValType :: F64 ) ;
1197+ fn valtype ( ) -> Option < ValType > {
1198+ Some ( ValType :: F64 )
11971199 }
11981200
11991201 fn matches ( mut tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
@@ -1254,8 +1256,8 @@ unsafe impl WasmTy for Option<ExternRef> {
12541256 }
12551257 }
12561258
1257- fn push ( dst : & mut Vec < ValType > ) {
1258- dst . push ( ValType :: ExternRef ) ;
1259+ fn valtype ( ) -> Option < ValType > {
1260+ Some ( ValType :: ExternRef )
12591261 }
12601262
12611263 fn matches ( mut tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
@@ -1307,8 +1309,8 @@ unsafe impl WasmTy for Option<Func> {
13071309 Func :: from_caller_checked_anyfunc ( & store, abi)
13081310 }
13091311
1310- fn push ( dst : & mut Vec < ValType > ) {
1311- dst . push ( ValType :: FuncRef ) ;
1312+ fn valtype ( ) -> Option < ValType > {
1313+ Some ( ValType :: FuncRef )
13121314 }
13131315
13141316 fn matches ( mut tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
@@ -1353,9 +1355,8 @@ where
13531355 <Self as WasmTy >:: from_abi ( abi, store)
13541356 }
13551357
1356- #[ inline]
1357- fn push ( dst : & mut Vec < ValType > ) {
1358- <Self as WasmTy >:: push ( dst)
1358+ fn valtype ( ) -> Option < ValType > {
1359+ <Self as WasmTy >:: valtype ( )
13591360 }
13601361
13611362 #[ inline]
@@ -1405,8 +1406,8 @@ where
14051406 Ok ( <T as WasmTy >:: from_abi ( abi, store) )
14061407 }
14071408
1408- fn push ( dst : & mut Vec < ValType > ) {
1409- <T as WasmTy >:: push ( dst )
1409+ fn valtype ( ) -> Option < ValType > {
1410+ <T as WasmTy >:: valtype ( )
14101411 }
14111412
14121413 fn matches ( tys : impl Iterator < Item = ValType > ) -> anyhow:: Result < ( ) > {
@@ -1657,11 +1658,12 @@ macro_rules! impl_into_func {
16571658 R :: store_to_args( ret, args) ;
16581659 }
16591660
1660- let mut _args = Vec :: new( ) ;
1661- $( $args:: push( & mut _args) ; ) *
1662- let mut ret = Vec :: new( ) ;
1663- R :: push( & mut ret) ;
1664- let ty = FuncType :: new( _args. into( ) , ret. into( ) ) ;
1661+ let ty = FuncType :: new(
1662+ None :: <ValType >. into_iter( )
1663+ $( . chain( $args:: valtype( ) ) ) *
1664+ ,
1665+ R :: valtype( ) ,
1666+ ) ;
16651667
16661668 let store_weak = store. weak( ) ;
16671669 let trampoline = host_trampoline:: <$( $args, ) * R >;
0 commit comments