1use crate::prelude::*;
4use crate::*;
5use core::ops::Range;
6use cranelift_entity::{EntityRef, packed_option::ReservedValue};
7use serde_derive::{Deserialize, Serialize};
8
9#[derive(Clone, Debug)]
11pub struct MemoryInitializer<'a> {
12 pub memory_index: MemoryIndex,
14 pub offset: ConstExpr,
16 pub data: &'a [u8],
21}
22
23#[derive(Debug, Serialize, Deserialize)]
25pub enum MemoryInitialization {
26 Segmented,
39
40 Static {
60 map: TryPrimaryMap<MemoryIndex, Option<(u64, RuntimeDataIndex)>>,
73 },
74}
75
76impl Default for MemoryInitialization {
77 fn default() -> Self {
78 Self::Segmented
79 }
80}
81
82impl MemoryInitialization {
83 pub fn is_segmented(&self) -> bool {
86 match self {
87 MemoryInitialization::Segmented => true,
88 _ => false,
89 }
90 }
91}
92
93#[derive(Debug, Default, Serialize, Deserialize)]
95pub struct TableInitialization {
96 pub initial_values: TryPrimaryMap<DefinedTableIndex, TableInitialValue>,
106
107 pub segments: TryVec<TableSegment>,
113}
114
115#[derive(Debug, Serialize, Deserialize)]
117pub enum TableInitialValue {
118 Null,
121 Expr(ConstExpr),
123}
124
125#[derive(Clone, Debug, Serialize, Deserialize)]
127pub struct TableSegment {
128 pub table_index: TableIndex,
130 pub offset: ConstExpr,
132 pub init: TableSegmentInit,
134}
135
136#[derive(Clone, Debug, Serialize, Deserialize)]
138pub enum TableSegmentInit {
139 Direct(TableSegmentElements),
145 Staged {
154 index: PassiveElemIndex,
156 len: u64,
158 },
159}
160
161impl TableSegmentInit {
162 pub fn len(&self) -> u64 {
164 match self {
165 Self::Direct(elements) => elements.len(),
166 Self::Staged { len, .. } => *len,
167 }
168 }
169}
170
171#[derive(Clone, Debug, Serialize, Deserialize)]
174pub enum TableSegmentElements {
175 Functions(
178 #[serde(deserialize_with = "crate::types::deserialize_boxed_slice")] Box<[FuncIndex]>,
179 ),
180 Expressions {
182 ty: WasmRefType,
184 #[serde(deserialize_with = "crate::types::deserialize_boxed_slice")]
186 exprs: Box<[ConstExpr]>,
187 },
188}
189
190impl TableSegmentElements {
191 pub fn ty(&self) -> WasmRefType {
193 match self {
194 Self::Functions(_) => WasmRefType::FUNCREF,
195 Self::Expressions { ty, .. } => *ty,
196 }
197 }
198
199 pub fn len(&self) -> u64 {
201 match self {
202 Self::Functions(s) => u64::try_from(s.len()).unwrap(),
203 Self::Expressions { exprs, .. } => u64::try_from(exprs.len()).unwrap(),
204 }
205 }
206}
207
208#[derive(Debug, Serialize, Deserialize)]
211pub struct Module {
212 pub module_index: StaticModuleIndex,
214
215 pub strings: StringPool,
217
218 pub name: Option<Atom>,
220
221 pub initializers: TryVec<Initializer>,
223
224 pub exports: ModuleExports,
226
227 pub startup: ModuleStartup,
229
230 pub table_initialization: TryPrimaryMap<DefinedTableIndex, TryVec<FuncIndex>>,
238
239 pub memory_initialization: MemoryInitialization,
245
246 pub passive_elements: TryPrimaryMap<PassiveElemIndex, (WasmRefType, u64)>,
252
253 pub runtime_data: TryPrimaryMap<RuntimeDataIndex, Range<u32>>,
259
260 pub types: TryPrimaryMap<TypeIndex, EngineOrModuleTypeIndex>,
262
263 pub num_imported_funcs: usize,
265
266 pub num_imported_tables: usize,
268
269 pub num_imported_memories: usize,
271
272 pub num_imported_globals: usize,
274
275 pub num_imported_tags: usize,
277
278 pub needs_gc_heap: bool,
280
281 pub has_shadow_memories: bool,
285
286 pub num_escaped_funcs: usize,
292
293 pub functions: TryPrimaryMap<FuncIndex, FunctionType>,
295
296 pub tables: TryPrimaryMap<TableIndex, Table>,
298
299 pub memories: TryPrimaryMap<MemoryIndex, Memory>,
301
302 pub globals: TryPrimaryMap<GlobalIndex, Global>,
304
305 pub global_initializers: TryVec<(DefinedGlobalIndex, GlobalConstValue)>,
317
318 pub tags: TryPrimaryMap<TagIndex, Tag>,
320}
321
322#[derive(Debug, Serialize, Deserialize)]
325pub enum Initializer {
326 Import {
328 name: Atom,
330 field: Atom,
332 index: EntityIndex,
335 },
336}
337
338#[derive(Debug, Default)]
341pub struct ImportPositions {
342 functions: Vec<u32>,
343 tables: Vec<u32>,
344 memories: Vec<u32>,
345 globals: Vec<u32>,
346 tags: Vec<u32>,
347}
348
349impl ImportPositions {
350 pub fn get(&self, entity: EntityIndex) -> Option<usize> {
355 let (positions, i) = match entity {
356 EntityIndex::Function(i) => (&self.functions, i.index()),
357 EntityIndex::Table(i) => (&self.tables, i.index()),
358 EntityIndex::Memory(i) => (&self.memories, i.index()),
359 EntityIndex::Global(i) => (&self.globals, i.index()),
360 EntityIndex::Tag(i) => (&self.tags, i.index()),
361 };
362 let position = *positions.get(i)?;
363 Some(usize::try_from(position).unwrap())
364 }
365}
366
367impl Module {
368 pub fn new(module_index: StaticModuleIndex) -> Self {
370 Self {
371 module_index,
372 strings: Default::default(),
373 name: Default::default(),
374 initializers: Default::default(),
375 exports: Default::default(),
376 startup: ModuleStartup::None,
377 table_initialization: Default::default(),
378 memory_initialization: Default::default(),
379 passive_elements: Default::default(),
380 runtime_data: Default::default(),
381 types: Default::default(),
382 num_imported_funcs: Default::default(),
383 num_imported_tables: Default::default(),
384 num_imported_memories: Default::default(),
385 num_imported_globals: Default::default(),
386 num_imported_tags: Default::default(),
387 needs_gc_heap: Default::default(),
388 has_shadow_memories: Default::default(),
389 num_escaped_funcs: Default::default(),
390 functions: Default::default(),
391 tables: Default::default(),
392 memories: Default::default(),
393 globals: Default::default(),
394 global_initializers: Default::default(),
395 tags: Default::default(),
396 }
397 }
398
399 #[inline]
401 pub fn func_index(&self, defined_func: DefinedFuncIndex) -> FuncIndex {
402 FuncIndex::new(self.num_imported_funcs + defined_func.index())
403 }
404
405 #[inline]
408 pub fn defined_func_index(&self, func: FuncIndex) -> Option<DefinedFuncIndex> {
409 if func.index() < self.num_imported_funcs {
410 None
411 } else {
412 Some(DefinedFuncIndex::new(
413 func.index() - self.num_imported_funcs,
414 ))
415 }
416 }
417
418 #[inline]
420 pub fn is_imported_function(&self, index: FuncIndex) -> bool {
421 index.index() < self.num_imported_funcs
422 }
423
424 #[inline]
426 pub fn table_index(&self, defined_table: DefinedTableIndex) -> TableIndex {
427 TableIndex::new(self.num_imported_tables + defined_table.index())
428 }
429
430 #[inline]
433 pub fn defined_table_index(&self, table: TableIndex) -> Option<DefinedTableIndex> {
434 if table.index() < self.num_imported_tables {
435 None
436 } else {
437 Some(DefinedTableIndex::new(
438 table.index() - self.num_imported_tables,
439 ))
440 }
441 }
442
443 #[inline]
445 pub fn is_exported_table(&self, index: TableIndex) -> bool {
446 self.exports.tables.contains(index)
447 }
448
449 #[inline]
451 pub fn is_imported_table(&self, index: TableIndex) -> bool {
452 index.index() < self.num_imported_tables
453 }
454
455 #[inline]
457 pub fn memory_index(&self, defined_memory: DefinedMemoryIndex) -> MemoryIndex {
458 MemoryIndex::new(self.num_imported_memories + defined_memory.index())
459 }
460
461 #[inline]
464 pub fn defined_memory_index(&self, memory: MemoryIndex) -> Option<DefinedMemoryIndex> {
465 if memory.index() < self.num_imported_memories {
466 None
467 } else {
468 Some(DefinedMemoryIndex::new(
469 memory.index() - self.num_imported_memories,
470 ))
471 }
472 }
473
474 #[inline]
477 pub fn owned_memory_index(&self, memory: DefinedMemoryIndex) -> OwnedMemoryIndex {
478 assert!(
479 memory.index() < self.memories.len(),
480 "non-shared memory must have an owned index"
481 );
482
483 let owned_memory_index = self
487 .memories
488 .iter()
489 .skip(self.num_imported_memories)
490 .take(memory.index())
491 .filter(|(_, mp)| !mp.shared)
492 .count();
493 OwnedMemoryIndex::new(owned_memory_index)
494 }
495
496 #[inline]
498 pub fn is_exported_memory(&self, index: MemoryIndex) -> bool {
499 self.exports.memories.contains(index)
500 }
501
502 #[inline]
504 pub fn is_imported_memory(&self, index: MemoryIndex) -> bool {
505 index.index() < self.num_imported_memories
506 }
507
508 #[inline]
510 pub fn global_index(&self, defined_global: DefinedGlobalIndex) -> GlobalIndex {
511 GlobalIndex::new(self.num_imported_globals + defined_global.index())
512 }
513
514 #[inline]
517 pub fn defined_global_index(&self, global: GlobalIndex) -> Option<DefinedGlobalIndex> {
518 if global.index() < self.num_imported_globals {
519 None
520 } else {
521 Some(DefinedGlobalIndex::new(
522 global.index() - self.num_imported_globals,
523 ))
524 }
525 }
526
527 #[inline]
529 pub fn is_exported_global(&self, index: GlobalIndex) -> bool {
530 self.exports.globals.contains(index)
531 }
532
533 #[inline]
535 pub fn is_imported_global(&self, index: GlobalIndex) -> bool {
536 index.index() < self.num_imported_globals
537 }
538
539 #[inline]
541 pub fn is_imported_tag(&self, index: TagIndex) -> bool {
542 index.index() < self.num_imported_tags
543 }
544
545 #[inline]
547 pub fn tag_index(&self, defined_tag: DefinedTagIndex) -> TagIndex {
548 TagIndex::new(self.num_imported_tags + defined_tag.index())
549 }
550
551 #[inline]
554 pub fn defined_tag_index(&self, tag: TagIndex) -> Option<DefinedTagIndex> {
555 if tag.index() < self.num_imported_tags {
556 None
557 } else {
558 Some(DefinedTagIndex::new(tag.index() - self.num_imported_tags))
559 }
560 }
561
562 pub fn imports(&self) -> impl ExactSizeIterator<Item = (&str, &str, EntityType)> {
565 let pool = &self.strings;
566 self.initializers.iter().map(move |i| match i {
567 Initializer::Import { name, field, index } => {
568 (&pool[name], &pool[field], self.type_of(*index))
569 }
570 })
571 }
572
573 pub fn import(&self, i: usize) -> Option<(&str, &str, EntityType)> {
575 match self.initializers.get(i)? {
576 Initializer::Import { name, field, index } => Some((
577 &self.strings[name],
578 &self.strings[field],
579 self.type_of(*index),
580 )),
581 }
582 }
583
584 pub fn import_index(&self, i: usize) -> Option<EntityIndex> {
586 match self.initializers.get(i)? {
587 Initializer::Import { index, .. } => Some(*index),
588 }
589 }
590
591 pub fn is_imported(&self, entity: EntityIndex) -> bool {
594 match entity {
595 EntityIndex::Function(i) => self.is_imported_function(i),
596 EntityIndex::Table(i) => self.is_imported_table(i),
597 EntityIndex::Memory(i) => self.is_imported_memory(i),
598 EntityIndex::Global(i) => self.is_imported_global(i),
599 EntityIndex::Tag(i) => self.is_imported_tag(i),
600 }
601 }
602
603 pub fn import_positions(&self) -> ImportPositions {
606 let mut positions = ImportPositions::default();
607 for (position, initializer) in self.initializers.iter().enumerate() {
608 let Initializer::Import { index, .. } = initializer;
609 let position = u32::try_from(position).unwrap();
610 let (vec, i) = match *index {
611 EntityIndex::Function(i) => (&mut positions.functions, i.index()),
612 EntityIndex::Table(i) => (&mut positions.tables, i.index()),
613 EntityIndex::Memory(i) => (&mut positions.memories, i.index()),
614 EntityIndex::Global(i) => (&mut positions.globals, i.index()),
615 EntityIndex::Tag(i) => (&mut positions.tags, i.index()),
616 };
617 debug_assert_eq!(vec.len(), i);
618 vec.push(position);
619 }
620 positions
621 }
622
623 pub fn type_of(&self, index: EntityIndex) -> EntityType {
625 match index {
626 EntityIndex::Global(i) => EntityType::Global(self.globals[i]),
627 EntityIndex::Table(i) => EntityType::Table(self.tables[i]),
628 EntityIndex::Memory(i) => EntityType::Memory(self.memories[i]),
629 EntityIndex::Function(i) => EntityType::Function(self.functions[i].signature),
630 EntityIndex::Tag(i) => EntityType::Tag(self.tags[i]),
631 }
632 }
633
634 pub fn push_tag(
636 &mut self,
637 signature: impl Into<EngineOrModuleTypeIndex>,
638 exception: impl Into<EngineOrModuleTypeIndex>,
639 ) -> TagIndex {
640 let signature = signature.into();
641 let exception = exception.into();
642 self.tags
643 .push(Tag {
644 signature,
645 exception,
646 })
647 .panic_on_oom()
648 }
649
650 pub fn push_function(&mut self, signature: impl Into<EngineOrModuleTypeIndex>) -> FuncIndex {
654 let signature = signature.into();
655 self.functions
656 .push(FunctionType {
657 signature,
658 func_ref: FuncRefIndex::reserved_value(),
659 })
660 .panic_on_oom()
661 }
662
663 pub fn defined_func_indices(&self) -> impl ExactSizeIterator<Item = DefinedFuncIndex> + use<> {
666 (0..self.functions.len() - self.num_imported_funcs).map(|i| DefinedFuncIndex::new(i))
667 }
668
669 pub fn num_defined_funcs(&self) -> usize {
672 self.functions.len() - self.num_imported_funcs
673 }
674
675 pub fn num_defined_tables(&self) -> usize {
678 self.tables.len() - self.num_imported_tables
679 }
680
681 pub fn num_defined_memories(&self) -> usize {
684 self.memories.len() - self.num_imported_memories
685 }
686
687 pub fn num_defined_globals(&self) -> usize {
690 self.globals.len() - self.num_imported_globals
691 }
692
693 pub fn num_defined_tags(&self) -> usize {
696 self.tags.len() - self.num_imported_tags
697 }
698
699 pub fn is_valid(&self, index: EntityIndex) -> bool {
701 match index {
702 EntityIndex::Function(i) => self.functions.is_valid(i),
703 EntityIndex::Table(i) => self.tables.is_valid(i),
704 EntityIndex::Memory(i) => self.memories.is_valid(i),
705 EntityIndex::Global(i) => self.globals.is_valid(i),
706 EntityIndex::Tag(i) => self.tags.is_valid(i),
707 }
708 }
709}
710
711impl TypeTrace for Module {
712 fn trace<F, E>(&self, func: &mut F) -> Result<(), E>
713 where
714 F: FnMut(EngineOrModuleTypeIndex) -> Result<(), E>,
715 {
716 let Self {
719 module_index: _,
720 strings: _,
721 name: _,
722 initializers: _,
723 exports: _,
724 startup,
725 table_initialization: _,
726 memory_initialization: _,
727 passive_elements: _,
728 runtime_data: _,
729 types,
730 num_imported_funcs: _,
731 num_imported_tables: _,
732 num_imported_memories: _,
733 num_imported_globals: _,
734 num_imported_tags: _,
735 num_escaped_funcs: _,
736 needs_gc_heap: _,
737 has_shadow_memories: _,
738 functions,
739 tables,
740 memories: _,
741 globals,
742 global_initializers: _,
743 tags,
744 } = self;
745
746 for t in types.values().copied() {
747 func(t)?;
748 }
749 for f in functions.values() {
750 f.trace(func)?;
751 }
752 for t in tables.values() {
753 t.trace(func)?;
754 }
755 for g in globals.values() {
756 g.trace(func)?;
757 }
758 for t in tags.values() {
759 t.trace(func)?;
760 }
761 startup.trace(func)?;
762 Ok(())
763 }
764
765 fn trace_mut<F, E>(&mut self, func: &mut F) -> Result<(), E>
766 where
767 F: FnMut(&mut EngineOrModuleTypeIndex) -> Result<(), E>,
768 {
769 let Self {
772 module_index: _,
773 strings: _,
774 name: _,
775 initializers: _,
776 exports: _,
777 startup,
778 table_initialization: _,
779 memory_initialization: _,
780 passive_elements: _,
781 runtime_data: _,
782 types,
783 num_imported_funcs: _,
784 num_imported_tables: _,
785 num_imported_memories: _,
786 num_imported_globals: _,
787 num_imported_tags: _,
788 num_escaped_funcs: _,
789 needs_gc_heap: _,
790 has_shadow_memories: _,
791 functions,
792 tables,
793 memories: _,
794 globals,
795 global_initializers: _,
796 tags,
797 } = self;
798
799 for t in types.values_mut() {
800 func(t)?;
801 }
802 for f in functions.values_mut() {
803 f.trace_mut(func)?;
804 }
805 for t in tables.values_mut() {
806 t.trace_mut(func)?;
807 }
808 for g in globals.values_mut() {
809 g.trace_mut(func)?;
810 }
811 for t in tags.values_mut() {
812 t.trace_mut(func)?;
813 }
814 startup.trace_mut(func)?;
815 Ok(())
816 }
817}
818
819impl TypeTrace for ModuleStartup {
820 fn trace<F, E>(&self, func: &mut F) -> Result<(), E>
821 where
822 F: FnMut(EngineOrModuleTypeIndex) -> Result<(), E>,
823 {
824 match self {
825 ModuleStartup::None => Ok(()),
826 ModuleStartup::Always(t) | ModuleStartup::IfMemoriesNeedInit(t) => func(*t),
827 }
828 }
829
830 fn trace_mut<F, E>(&mut self, func: &mut F) -> Result<(), E>
831 where
832 F: FnMut(&mut EngineOrModuleTypeIndex) -> Result<(), E>,
833 {
834 match self {
835 ModuleStartup::None => Ok(()),
836 ModuleStartup::Always(t) | ModuleStartup::IfMemoriesNeedInit(t) => func(t),
837 }
838 }
839}
840
841#[derive(Debug, Serialize, Deserialize)]
843pub struct FunctionType {
844 pub signature: EngineOrModuleTypeIndex,
847 pub func_ref: FuncRefIndex,
850}
851
852impl TypeTrace for FunctionType {
853 fn trace<F, E>(&self, func: &mut F) -> Result<(), E>
854 where
855 F: FnMut(EngineOrModuleTypeIndex) -> Result<(), E>,
856 {
857 func(self.signature)
858 }
859
860 fn trace_mut<F, E>(&mut self, func: &mut F) -> Result<(), E>
861 where
862 F: FnMut(&mut EngineOrModuleTypeIndex) -> Result<(), E>,
863 {
864 func(&mut self.signature)
865 }
866}
867
868impl FunctionType {
869 pub fn is_escaping(&self) -> bool {
873 !self.func_ref.is_reserved_value()
874 }
875}
876
877#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug, Serialize, Deserialize)]
879pub struct FuncRefIndex(u32);
880cranelift_entity::entity_impl!(FuncRefIndex);
881
882#[derive(Debug, Serialize, Deserialize)]
884pub enum ModuleStartup {
885 None,
887
888 Always(EngineOrModuleTypeIndex),
893
894 IfMemoriesNeedInit(EngineOrModuleTypeIndex),
904}
905
906impl ModuleStartup {
907 pub fn is_none(&self) -> bool {
909 matches!(self, Self::None)
910 }
911}
912
913#[derive(Debug, Default)]
923pub struct ModuleExports {
924 map: TryIndexMap<Atom, EntityIndex>,
925 globals: TryEntitySet<GlobalIndex>,
926 memories: TryEntitySet<MemoryIndex>,
927 tables: TryEntitySet<TableIndex>,
928}
929
930impl ModuleExports {
931 pub fn reserve(&mut self, additional: usize) -> Result<(), OutOfMemory> {
933 self.map.reserve(additional)
934 }
935
936 pub fn insert(&mut self, name: Atom, entity: EntityIndex) -> Result<(), OutOfMemory> {
941 self.map.reserve(1)?;
942 Self::index(
943 &mut self.globals,
944 &mut self.memories,
945 &mut self.tables,
946 entity,
947 )?;
948 let prev = self.map.insert(name, entity)?;
949 debug_assert!(prev.is_none(), "duplicate export name");
950 Ok(())
951 }
952
953 pub fn get(&self, name: &Atom) -> Option<&EntityIndex> {
955 self.map.get(name)
956 }
957
958 pub fn iter(&self) -> impl ExactSizeIterator<Item = (&Atom, &EntityIndex)> + '_ {
960 self.map.iter()
961 }
962
963 fn index(
965 globals: &mut TryEntitySet<GlobalIndex>,
966 memories: &mut TryEntitySet<MemoryIndex>,
967 tables: &mut TryEntitySet<TableIndex>,
968 entity: EntityIndex,
969 ) -> Result<(), OutOfMemory> {
970 match entity {
971 EntityIndex::Global(i) => {
972 globals.insert(i)?;
973 }
974 EntityIndex::Memory(i) => {
975 memories.insert(i)?;
976 }
977 EntityIndex::Table(i) => {
978 tables.insert(i)?;
979 }
980 EntityIndex::Function(_) | EntityIndex::Tag(_) => {}
982 }
983 Ok(())
984 }
985}
986
987impl core::ops::Index<&Atom> for ModuleExports {
988 type Output = EntityIndex;
989
990 fn index(&self, name: &Atom) -> &EntityIndex {
991 &self.map[name]
992 }
993}
994
995impl serde::ser::Serialize for ModuleExports {
996 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
997 where
998 S: serde::Serializer,
999 {
1000 self.map.serialize(serializer)
1002 }
1003}
1004
1005impl<'de> serde::de::Deserialize<'de> for ModuleExports {
1006 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1007 where
1008 D: serde::Deserializer<'de>,
1009 {
1010 use serde::de::Error as _;
1011
1012 let map = TryIndexMap::<Atom, EntityIndex>::deserialize(deserializer)?;
1013
1014 let mut globals = TryEntitySet::new();
1015 let mut memories = TryEntitySet::new();
1016 let mut tables = TryEntitySet::new();
1017 for entity in map.values() {
1018 Self::index(&mut globals, &mut memories, &mut tables, *entity)
1019 .map_err(D::Error::custom)?;
1020 }
1021
1022 Ok(ModuleExports {
1023 map,
1024 globals,
1025 memories,
1026 tables,
1027 })
1028 }
1029}
1030
1031#[cfg(test)]
1032mod tests {
1033 use super::*;
1034
1035 #[test]
1036 fn exports_reverse_index_survives_serde() -> Result<()> {
1037 let mut module = Module::new(StaticModuleIndex::from_u32(0));
1038 let entities = [
1039 ("f", EntityIndex::Function(FuncIndex::from_u32(4))),
1040 ("g", EntityIndex::Global(GlobalIndex::from_u32(3))),
1041 ("m", EntityIndex::Memory(MemoryIndex::from_u32(0))),
1042 ("t", EntityIndex::Table(TableIndex::from_u32(70))),
1043 ("g2", EntityIndex::Global(GlobalIndex::from_u32(3))),
1044 ];
1045 for (name, entity) in entities {
1046 let name = module.strings.insert(name)?;
1047 module.exports.insert(name, entity)?;
1048 }
1049
1050 let bytes = postcard::to_allocvec(&module)?;
1051 let decoded: Module = postcard::from_bytes(&bytes)?;
1052
1053 for module in [&module, &decoded] {
1054 assert_eq!(module.exports.iter().count(), entities.len());
1055 for (i, expected) in [(0, false), (3, true), (4, false), (70, false), (71, false)] {
1056 assert_eq!(
1057 module.is_exported_global(GlobalIndex::from_u32(i)),
1058 expected
1059 );
1060 }
1061 assert!(module.is_exported_memory(MemoryIndex::from_u32(0)));
1062 assert!(!module.is_exported_memory(MemoryIndex::from_u32(1)));
1063 assert!(module.is_exported_table(TableIndex::from_u32(70)));
1064 assert!(!module.is_exported_table(TableIndex::from_u32(3)));
1065 }
1066 Ok(())
1067 }
1068}