@@ -42,6 +42,7 @@ const DEFAULT_WASM_MULTI_VALUE: bool = true;
42
42
const DEFAULT_WASM_MULTI_MEMORY : bool = true ;
43
43
const DEFAULT_WASM_BULK_MEMORY : bool = false ;
44
44
const DEFAULT_WASM_SIMD : bool = true ;
45
+ const DEFAULT_WASM_REFERENCE_TYPES : bool = false ;
45
46
46
47
/// The type of data that is stored in the `wasmtime::Store` during
47
48
/// initialization.
@@ -249,6 +250,16 @@ pub struct Wizer {
249
250
/// Enabled by default.
250
251
#[ cfg_attr( feature = "structopt" , structopt( long, value_name = "true|false" ) ) ]
251
252
wasm_simd : Option < bool > ,
253
+
254
+ /// Enable or disable the Wasm reference-types proposal.
255
+ ///
256
+ /// Currently does not implement snapshotting or the use of references,
257
+ /// but enables initializing Wasm modules that use encodings introduced
258
+ /// in the reference-types proposal.
259
+ ///
260
+ /// Disabled by default.
261
+ #[ cfg_attr( feature = "structopt" , structopt( long, value_name = "true|false" ) ) ]
262
+ wasm_reference_types : Option < bool > ,
252
263
}
253
264
254
265
impl std:: fmt:: Debug for Wizer {
@@ -269,6 +280,7 @@ impl std::fmt::Debug for Wizer {
269
280
wasm_multi_value,
270
281
wasm_bulk_memory,
271
282
wasm_simd,
283
+ wasm_reference_types,
272
284
} = self ;
273
285
f. debug_struct ( "Wizer" )
274
286
. field ( "init_func" , & init_func)
@@ -286,6 +298,7 @@ impl std::fmt::Debug for Wizer {
286
298
. field ( "wasm_multi_value" , & wasm_multi_value)
287
299
. field ( "wasm_bulk_memory" , & wasm_bulk_memory)
288
300
. field ( "wasm_simd" , & wasm_simd)
301
+ . field ( "wasm_reference_types" , & wasm_reference_types)
289
302
. finish ( )
290
303
}
291
304
}
@@ -350,6 +363,7 @@ impl Wizer {
350
363
wasm_multi_value : None ,
351
364
wasm_bulk_memory : None ,
352
365
wasm_simd : None ,
366
+ wasm_reference_types : None ,
353
367
}
354
368
}
355
369
@@ -556,6 +570,18 @@ impl Wizer {
556
570
self
557
571
}
558
572
573
+ /// Enable or disable the Wasm reference-types proposal.
574
+ ///
575
+ /// Currently does not implement snapshotting or the use of references,
576
+ /// but enables initializing Wasm modules that use encodings introduced
577
+ /// in the reference-types proposal.
578
+ ///
579
+ /// Defaults to `false`.
580
+ pub fn wasm_reference_types ( & mut self , enable : bool ) -> & mut Self {
581
+ self . wasm_reference_types = Some ( enable) ;
582
+ self
583
+ }
584
+
559
585
/// Initialize the given Wasm, snapshot it, and return the serialized
560
586
/// snapshot as a new, pre-initialized Wasm module.
561
587
pub fn run ( & self , wasm : & [ u8 ] ) -> anyhow:: Result < Vec < u8 > > {
@@ -632,8 +658,14 @@ impl Wizer {
632
658
633
659
config. wasm_simd ( self . wasm_simd . unwrap_or ( DEFAULT_WASM_SIMD ) ) ;
634
660
661
+ // Note that reference_types are not actually supported,
662
+ // but many compilers now enable them by default
663
+ config. wasm_reference_types (
664
+ self . wasm_reference_types
665
+ . unwrap_or ( DEFAULT_WASM_REFERENCE_TYPES ) ,
666
+ ) ;
667
+
635
668
// Proposals that we should add support for.
636
- config. wasm_reference_types ( false ) ;
637
669
config. wasm_threads ( false ) ;
638
670
639
671
Ok ( config)
@@ -654,7 +686,9 @@ impl Wizer {
654
686
multi_value : self . wasm_multi_value . unwrap_or ( DEFAULT_WASM_MULTI_VALUE ) ,
655
687
656
688
// Proposals that we should add support for.
657
- reference_types : false ,
689
+ reference_types : self
690
+ . wasm_reference_types
691
+ . unwrap_or ( DEFAULT_WASM_REFERENCE_TYPES ) ,
658
692
simd : self . wasm_simd . unwrap_or ( DEFAULT_WASM_SIMD ) ,
659
693
threads : false ,
660
694
tail_call : false ,
@@ -730,7 +764,31 @@ impl Wizer {
730
764
anyhow:: bail!( "unsupported `data.drop` instruction" )
731
765
}
732
766
wasmparser:: Operator :: TableSet { .. } => {
733
- unreachable ! ( "part of reference types" )
767
+ anyhow:: bail!( "unsupported `table.set` instruction" )
768
+ }
769
+ wasmparser:: Operator :: TableGet { .. } => {
770
+ anyhow:: bail!( "unsupported `table.get` instruction" )
771
+ }
772
+ wasmparser:: Operator :: RefNull { .. } => {
773
+ anyhow:: bail!( "unsupported `ref.null` instruction" )
774
+ }
775
+ wasmparser:: Operator :: RefIsNull => {
776
+ anyhow:: bail!( "unsupported `ref.is_null` instruction" )
777
+ }
778
+ wasmparser:: Operator :: TypedSelect { .. } => {
779
+ anyhow:: bail!( "unsupported typed `select` instruction" )
780
+ }
781
+ wasmparser:: Operator :: RefFunc { .. } => {
782
+ anyhow:: bail!( "unsupported `ref.func` instruction" )
783
+ }
784
+ wasmparser:: Operator :: TableSize { .. } => {
785
+ anyhow:: bail!( "unsupported `table.size` instruction" )
786
+ }
787
+ wasmparser:: Operator :: TableGrow { .. } => {
788
+ anyhow:: bail!( "unsupported `table.grow` instruction" )
789
+ }
790
+ wasmparser:: Operator :: TableFill { .. } => {
791
+ anyhow:: bail!( "unsupported `table.fill` instruction" )
734
792
}
735
793
_ => continue ,
736
794
}
0 commit comments