1616use crate :: prelude:: * ;
1717use crate :: {
1818 limits:: * , AbstractHeapType , BinaryReaderError , Encoding , FromReader , FunctionBody , HeapType ,
19- Order , Parser , Payload , RefType , Result , SectionLimited , ValType , WasmFeatures ,
20- WASM_MODULE_VERSION ,
19+ Parser , Payload , RefType , Result , SectionLimited , ValType , WasmFeatures , WASM_MODULE_VERSION ,
2120} ;
2221use :: core:: mem;
2322use :: core:: ops:: Range ;
@@ -581,10 +580,10 @@ impl Validator {
581580 ElementSection ( s) => self . element_section ( s) ?,
582581 DataCountSection { count, range } => self . data_count_section ( * count, range) ?,
583582 CodeSectionStart {
584- count,
583+ count : _ ,
585584 range,
586585 size : _,
587- } => self . code_section_start ( * count , range) ?,
586+ } => self . code_section_start ( range) ?,
588587 CodeSectionEntry ( body) => {
589588 let func_validator = self . code_section_entry ( body) ?;
590589 return Ok ( ValidPayload :: Func ( func_validator, body. clone ( ) ) ) ;
@@ -706,7 +705,6 @@ impl Validator {
706705 /// Validates [`Payload::TypeSection`](crate::Payload).
707706 pub fn type_section ( & mut self , section : & crate :: TypeSectionReader < ' _ > ) -> Result < ( ) > {
708707 self . process_module_section (
709- Order :: Type ,
710708 section,
711709 "type" ,
712710 |state, _types, count, offset| {
@@ -735,7 +733,6 @@ impl Validator {
735733 /// This method should only be called when parsing a module.
736734 pub fn import_section ( & mut self , section : & crate :: ImportSectionReader < ' _ > ) -> Result < ( ) > {
737735 self . process_module_section (
738- Order :: Import ,
739736 section,
740737 "import" ,
741738 |state, _, count, offset| {
@@ -760,7 +757,6 @@ impl Validator {
760757 /// This method should only be called when parsing a module.
761758 pub fn function_section ( & mut self , section : & crate :: FunctionSectionReader < ' _ > ) -> Result < ( ) > {
762759 self . process_module_section (
763- Order :: Function ,
764760 section,
765761 "function" ,
766762 |state, _, count, offset| {
@@ -772,8 +768,6 @@ impl Validator {
772768 offset,
773769 ) ?;
774770 state. module . assert_mut ( ) . functions . reserve ( count as usize ) ;
775- debug_assert ! ( state. expected_code_bodies. is_none( ) ) ;
776- state. expected_code_bodies = Some ( count) ;
777771 Ok ( ( ) )
778772 } ,
779773 |state, types, ty, offset| state. module . assert_mut ( ) . add_function ( ty, types, offset) ,
@@ -785,7 +779,6 @@ impl Validator {
785779 /// This method should only be called when parsing a module.
786780 pub fn table_section ( & mut self , section : & crate :: TableSectionReader < ' _ > ) -> Result < ( ) > {
787781 self . process_module_section (
788- Order :: Table ,
789782 section,
790783 "table" ,
791784 |state, _, count, offset| {
@@ -808,7 +801,6 @@ impl Validator {
808801 /// This method should only be called when parsing a module.
809802 pub fn memory_section ( & mut self , section : & crate :: MemorySectionReader < ' _ > ) -> Result < ( ) > {
810803 self . process_module_section (
811- Order :: Memory ,
812804 section,
813805 "memory" ,
814806 |state, _, count, offset| {
@@ -830,15 +822,7 @@ impl Validator {
830822 ///
831823 /// This method should only be called when parsing a module.
832824 pub fn tag_section ( & mut self , section : & crate :: TagSectionReader < ' _ > ) -> Result < ( ) > {
833- if !self . features . exceptions ( ) {
834- return Err ( BinaryReaderError :: new (
835- "exceptions proposal not enabled" ,
836- section. range ( ) . start ,
837- ) ) ;
838- }
839-
840825 self . process_module_section (
841- Order :: Tag ,
842826 section,
843827 "tag" ,
844828 |state, _, count, offset| {
@@ -861,7 +845,6 @@ impl Validator {
861845 /// This method should only be called when parsing a module.
862846 pub fn global_section ( & mut self , section : & crate :: GlobalSectionReader < ' _ > ) -> Result < ( ) > {
863847 self . process_module_section (
864- Order :: Global ,
865848 section,
866849 "global" ,
867850 |state, _, count, offset| {
@@ -884,7 +867,6 @@ impl Validator {
884867 /// This method should only be called when parsing a module.
885868 pub fn export_section ( & mut self , section : & crate :: ExportSectionReader < ' _ > ) -> Result < ( ) > {
886869 self . process_module_section (
887- Order :: Export ,
888870 section,
889871 "export" ,
890872 |state, _, count, offset| {
@@ -913,7 +895,6 @@ impl Validator {
913895 let offset = range. start ;
914896 self . state . ensure_module ( "start" , offset) ?;
915897 let state = self . module . as_mut ( ) . unwrap ( ) ;
916- state. update_order ( Order :: Start , offset) ?;
917898
918899 let ty = state. module . get_func_type ( func, & self . types , offset) ?;
919900 if !ty. params ( ) . is_empty ( ) || !ty. results ( ) . is_empty ( ) {
@@ -931,7 +912,6 @@ impl Validator {
931912 /// This method should only be called when parsing a module.
932913 pub fn element_section ( & mut self , section : & crate :: ElementSectionReader < ' _ > ) -> Result < ( ) > {
933914 self . process_module_section (
934- Order :: Element ,
935915 section,
936916 "element" ,
937917 |state, _, count, offset| {
@@ -961,7 +941,6 @@ impl Validator {
961941 self . state . ensure_module ( "data count" , offset) ?;
962942
963943 let state = self . module . as_mut ( ) . unwrap ( ) ;
964- state. update_order ( Order :: DataCount , offset) ?;
965944
966945 if count > MAX_WASM_DATA_SEGMENTS as u32 {
967946 return Err ( BinaryReaderError :: new (
@@ -977,31 +956,11 @@ impl Validator {
977956 /// Validates [`Payload::CodeSectionStart`](crate::Payload).
978957 ///
979958 /// This method should only be called when parsing a module.
980- pub fn code_section_start ( & mut self , count : u32 , range : & Range < usize > ) -> Result < ( ) > {
959+ pub fn code_section_start ( & mut self , range : & Range < usize > ) -> Result < ( ) > {
981960 let offset = range. start ;
982961 self . state . ensure_module ( "code" , offset) ?;
983962
984963 let state = self . module . as_mut ( ) . unwrap ( ) ;
985- state. update_order ( Order :: Code , offset) ?;
986-
987- match state. expected_code_bodies . take ( ) {
988- Some ( n) if n == count => { }
989- Some ( _) => {
990- return Err ( BinaryReaderError :: new (
991- "function and code section have inconsistent lengths" ,
992- offset,
993- ) ) ;
994- }
995- // empty code sections are allowed even if the function section is
996- // missing
997- None if count == 0 => { }
998- None => {
999- return Err ( BinaryReaderError :: new (
1000- "code section without function section" ,
1001- offset,
1002- ) )
1003- }
1004- }
1005964
1006965 // Take a snapshot of the types when we start the code section.
1007966 state. module . assert_mut ( ) . snapshot = Some ( Arc :: new ( self . types . commit ( ) ) ) ;
@@ -1031,7 +990,7 @@ impl Validator {
1031990
1032991 let state = self . module . as_mut ( ) . unwrap ( ) ;
1033992
1034- let ( index, ty) = state. next_code_index_and_type ( offset ) ? ;
993+ let ( index, ty) = state. next_code_index_and_type ( ) ;
1035994 Ok ( FuncToValidate {
1036995 index,
1037996 ty,
@@ -1045,11 +1004,9 @@ impl Validator {
10451004 /// This method should only be called when parsing a module.
10461005 pub fn data_section ( & mut self , section : & crate :: DataSectionReader < ' _ > ) -> Result < ( ) > {
10471006 self . process_module_section (
1048- Order :: Data ,
10491007 section,
10501008 "data" ,
1051- |state, _, count, offset| {
1052- state. data_segment_count = count;
1009+ |_, _, count, offset| {
10531010 check_max ( 0 , count, MAX_WASM_DATA_SEGMENTS , "data segments" , offset)
10541011 } ,
10551012 |state, types, d, offset| state. add_data_segment ( d, types, offset) ,
@@ -1360,7 +1317,6 @@ impl Validator {
13601317 ) ) ,
13611318 State :: Module => {
13621319 let mut state = self . module . take ( ) . unwrap ( ) ;
1363- state. validate_end ( offset) ?;
13641320
13651321 // If there's a parent component, we'll add a module to the parent state
13661322 // and continue to validate the component
@@ -1408,7 +1364,6 @@ impl Validator {
14081364
14091365 fn process_module_section < ' a , T > (
14101366 & mut self ,
1411- order : Order ,
14121367 section : & SectionLimited < ' a , T > ,
14131368 name : & str ,
14141369 validate_section : impl FnOnce ( & mut ModuleState , & mut TypeAlloc , u32 , usize ) -> Result < ( ) > ,
@@ -1421,7 +1376,6 @@ impl Validator {
14211376 self . state . ensure_module ( name, offset) ?;
14221377
14231378 let state = self . module . as_mut ( ) . unwrap ( ) ;
1424- state. update_order ( order, offset) ?;
14251379
14261380 validate_section ( state, & mut self . types , section. count ( ) , offset) ?;
14271381
@@ -1457,13 +1411,6 @@ impl Validator {
14571411 {
14581412 let offset = section. range ( ) . start ;
14591413
1460- if !self . features . component_model ( ) {
1461- return Err ( BinaryReaderError :: new (
1462- "component model feature is not enabled" ,
1463- offset,
1464- ) ) ;
1465- }
1466-
14671414 self . state . ensure_component ( name, offset) ?;
14681415 validate_section (
14691416 & mut self . components ,
0 commit comments