@@ -157,7 +157,7 @@ struct HostFn {
157157 module : String ,
158158 name : String ,
159159 returns : HostFnReturn ,
160- is_unstable : bool ,
160+ is_stable : bool ,
161161}
162162
163163enum HostFnReturn {
@@ -199,7 +199,7 @@ impl HostFn {
199199 attrs. retain ( |a| !( a. path . is_ident ( "doc" ) || a. path . is_ident ( "prefixed_alias" ) ) ) ;
200200 let name = item. sig . ident . to_string ( ) ;
201201 let mut maybe_module = None ;
202- let mut is_unstable = false ;
202+ let mut is_stable = true ;
203203 while let Some ( attr) = attrs. pop ( ) {
204204 let ident = attr. path . get_ident ( ) . ok_or ( err ( span, msg) ) ?. to_string ( ) ;
205205 match ident. as_str ( ) {
@@ -212,10 +212,10 @@ impl HostFn {
212212 maybe_module = Some ( format ! ( "seal{}" , ver) ) ;
213213 } ,
214214 "unstable" => {
215- if is_unstable {
215+ if !is_stable {
216216 return Err ( err ( span, "#[unstable] can only be specified once" ) )
217217 }
218- is_unstable = true ;
218+ is_stable = false ;
219219 } ,
220220 _ => return Err ( err ( span, msg) ) ,
221221 }
@@ -312,7 +312,7 @@ impl HostFn {
312312 module : maybe_module. unwrap_or_else ( || "seal0" . to_string ( ) ) ,
313313 name,
314314 returns,
315- is_unstable ,
315+ is_stable ,
316316 } )
317317 } ,
318318 _ => Err ( err ( span, & msg) ) ,
@@ -406,15 +406,15 @@ fn expand_impls(def: &mut EnvDef) -> TokenStream2 {
406406 <E :: T as :: frame_system:: Config >:: AccountId :
407407 :: sp_core:: crypto:: UncheckedFrom <<E :: T as :: frame_system:: Config >:: Hash > + :: core:: convert:: AsRef <[ :: core:: primitive:: u8 ] >,
408408 {
409- fn define( store: & mut :: wasmi:: Store <crate :: wasm:: Runtime <E >>, linker: & mut :: wasmi:: Linker <crate :: wasm:: Runtime <E >>) -> Result <( ) , :: wasmi:: errors:: LinkerError > {
409+ fn define( store: & mut :: wasmi:: Store <crate :: wasm:: Runtime <E >>, linker: & mut :: wasmi:: Linker <crate :: wasm:: Runtime <E >>, allow_unstable : bool ) -> Result <( ) , :: wasmi:: errors:: LinkerError > {
410410 #impls
411411 Ok ( ( ) )
412412 }
413413 }
414414
415415 impl crate :: wasm:: Environment <( ) > for Env
416416 {
417- fn define( store: & mut :: wasmi:: Store <( ) >, linker: & mut :: wasmi:: Linker <( ) >) -> Result <( ) , :: wasmi:: errors:: LinkerError > {
417+ fn define( store: & mut :: wasmi:: Store <( ) >, linker: & mut :: wasmi:: Linker <( ) >, allow_unstable : bool ) -> Result <( ) , :: wasmi:: errors:: LinkerError > {
418418 #dummy_impls
419419 Ok ( ( ) )
420420 }
@@ -437,10 +437,7 @@ fn expand_functions(
437437 f. returns . to_wasm_sig ( ) ,
438438 & f. item . sig . output
439439 ) ;
440- let unstable_feat = match f. is_unstable {
441- true => quote ! { #[ cfg( feature = "unstable-interface" ) ] } ,
442- false => quote ! { } ,
443- } ;
440+ let is_stable = f. is_stable ;
444441
445442 // If we don't expand blocks (implementing for `()`) we change a few things:
446443 // - We replace any code by unreachable!
@@ -480,16 +477,18 @@ fn expand_functions(
480477 quote ! { #[ allow( unused_variables) ] }
481478 } ;
482479
483-
484480 quote ! {
485- #unstable_feat
486- #allow_unused
487- linker. define( #module, #name, :: wasmi:: Func :: wrap( & mut * store, |mut __caller__: :: wasmi:: Caller <#host_state>, #( #params, ) * | -> #wasm_output {
488- let mut func = #inner;
489- func( )
490- . map_err( #map_err)
491- . map( :: core:: convert:: Into :: into)
492- } ) ) ?;
481+ // We need to allow unstable functions when runtime benchmarks are performed because
482+ // we generate the weights even when those interfaces are not enabled.
483+ if :: core:: cfg!( feature = "runtime-benchmarks" ) || #is_stable || allow_unstable {
484+ #allow_unused
485+ linker. define( #module, #name, :: wasmi:: Func :: wrap( & mut * store, |mut __caller__: :: wasmi:: Caller <#host_state>, #( #params, ) * | -> #wasm_output {
486+ let mut func = #inner;
487+ func( )
488+ . map_err( #map_err)
489+ . map( :: core:: convert:: Into :: into)
490+ } ) ) ?;
491+ }
493492 }
494493 } ) ;
495494 quote ! {
0 commit comments