From 5c52ef947c8a74187959adc02ffa67fd5f94c7b0 Mon Sep 17 00:00:00 2001 From: callym Date: Thu, 1 Aug 2024 22:31:04 +0100 Subject: [PATCH] Remove string length check in preprocessing --- src/compose/error.rs | 2 +- src/compose/mod.rs | 4 ++-- src/compose/preprocess.rs | 42 +++++++-------------------------------- 3 files changed, 10 insertions(+), 38 deletions(-) diff --git a/src/compose/error.rs b/src/compose/error.rs index 5b747e4..479dfd4 100644 --- a/src/compose/error.rs +++ b/src/compose/error.rs @@ -42,7 +42,7 @@ impl ErrSource { .. }) = composer .preprocessor - .preprocess(raw_source, defs, composer.validate) + .preprocess(raw_source, defs) else { return Default::default(); }; diff --git a/src/compose/mod.rs b/src/compose/mod.rs index 2d330d6..43c24b7 100644 --- a/src/compose/mod.rs +++ b/src/compose/mod.rs @@ -1323,7 +1323,7 @@ impl Composer { imports, } = self .preprocessor - .preprocess(&module_set.sanitized_source, shader_defs, self.validate) + .preprocess(&module_set.sanitized_source, shader_defs) .map_err(|inner| ComposerError { inner, source: ErrSource::Module { @@ -1673,7 +1673,7 @@ impl Composer { imports, } = self .preprocessor - .preprocess(&sanitized_source, &shader_defs, self.validate) + .preprocess(&sanitized_source, &shader_defs) .map_err(|inner| ComposerError { inner, source: ErrSource::Constructing { diff --git a/src/compose/preprocess.rs b/src/compose/preprocess.rs index d1f3190..e5785ab 100644 --- a/src/compose/preprocess.rs +++ b/src/compose/preprocess.rs @@ -233,7 +233,6 @@ impl Preprocessor { &self, shader_str: &str, shader_defs: &HashMap, - validate_len: bool, ) -> Result { let mut declared_imports = IndexMap::new(); let mut used_imports = IndexMap::new(); @@ -241,9 +240,6 @@ impl Preprocessor { let mut final_string = String::new(); let mut offset = 0; - #[cfg(debug_assertions)] - let len = shader_str.len(); - // this code broadly stolen from bevy_render::ShaderProcessor let mut lines = shader_str.lines(); let mut lines = lines.replace_comments().zip(shader_str.lines()).peekable(); @@ -371,14 +367,6 @@ impl Preprocessor { scope.finish(offset)?; - #[cfg(debug_assertions)] - if validate_len { - let revised_len = final_string.len(); - debug_assert_eq!(len, revised_len); - } - #[cfg(not(debug_assertions))] - let _ = validate_len; - Ok(PreprocessOutput { preprocessed_source: final_string, imports: used_imports.into_values().collect(), @@ -576,7 +564,6 @@ fn vertex( let result_missing = processor.preprocess( WGSL, &[("TEXTURE".to_owned(), ShaderDefValue::Bool(true))].into(), - true, ); let expected: Result = @@ -677,7 +664,6 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Int(3))].into(), - true, ) .unwrap(); assert_eq!(result_eq.preprocessed_source, EXPECTED_EQ); @@ -686,12 +672,11 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Int(7))].into(), - true, ) .unwrap(); assert_eq!(result_neq.preprocessed_source, EXPECTED_NEQ); - let result_missing = processor.preprocess(WGSL, &Default::default(), true); + let result_missing = processor.preprocess(WGSL, &Default::default()); let expected_err: Result< (Option, String, Vec), @@ -705,7 +690,6 @@ fn vertex( let result_wrong_type = processor.preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ); let expected_err: Result< @@ -814,7 +798,6 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!(result_eq.preprocessed_source, EXPECTED_EQ); @@ -823,7 +806,6 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(false))].into(), - true, ) .unwrap(); assert_eq!(result_neq.preprocessed_source, EXPECTED_NEQ); @@ -919,7 +901,6 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!(result_eq.preprocessed_source, EXPECTED_EQ); @@ -928,12 +909,11 @@ fn vertex( .preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Bool(false))].into(), - true, ) .unwrap(); assert_eq!(result_neq.preprocessed_source, EXPECTED_NEQ); - let result_missing = processor.preprocess(WGSL, &[].into(), true); + let result_missing = processor.preprocess(WGSL, &[].into()); let expected_err: Result< (Option, String, Vec), ComposerErrorInner, @@ -946,7 +926,6 @@ fn vertex( let result_wrong_type = processor.preprocess( WGSL, &[("TEXTURE".to_string(), ShaderDefValue::Int(7))].into(), - true, ); let expected_err: Result< @@ -1031,7 +1010,6 @@ fn vertex( ("SECOND_VALUE".to_string(), ShaderDefValue::Int(3)), ] .into(), - true, ) .unwrap(); assert_eq!(result.preprocessed_source, EXPECTED_REPLACED); @@ -1060,7 +1038,7 @@ defined .. } = processor.get_preprocessor_metadata(&WGSL, true).unwrap(); println!("defines: {:?}", shader_defs); - let result = processor.preprocess(&WGSL, &shader_defs, true).unwrap(); + let result = processor.preprocess(&WGSL, &shader_defs).unwrap(); assert_eq!(result.preprocessed_source, EXPECTED); } @@ -1103,7 +1081,7 @@ bool: false .. } = processor.get_preprocessor_metadata(&WGSL, true).unwrap(); println!("defines: {:?}", shader_defs); - let result = processor.preprocess(&WGSL, &shader_defs, true).unwrap(); + let result = processor.preprocess(&WGSL, &shader_defs).unwrap(); assert_eq!(result.preprocessed_source, EXPECTED); } @@ -1136,7 +1114,7 @@ fn vertex( "; let processor = Preprocessor::default(); let result = processor - .preprocess(&WGSL_ELSE_IFDEF, &[].into(), true) + .preprocess(&WGSL_ELSE_IFDEF, &[].into()) .unwrap(); assert_eq!( result @@ -1214,7 +1192,7 @@ fn vertex( "; let processor = Preprocessor::default(); let result = processor - .preprocess(&WGSL_ELSE_IFDEF_NO_ELSE_FALLBACK, &[].into(), true) + .preprocess(&WGSL_ELSE_IFDEF_NO_ELSE_FALLBACK, &[].into()) .unwrap(); assert_eq!( result @@ -1265,7 +1243,6 @@ fn vertex( .preprocess( &WGSL_ELSE_IFDEF, &[("TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!( @@ -1314,7 +1291,6 @@ fn vertex( .preprocess( &WGSL_ELSE_IFDEF, &[("SECOND_TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!( @@ -1363,7 +1339,6 @@ fn vertex( .preprocess( &WGSL_ELSE_IFDEF, &[("THIRD_TEXTURE".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!( @@ -1416,7 +1391,6 @@ fn vertex( ("THIRD_TEXTURE".to_string(), ShaderDefValue::Bool(true)), ] .into(), - true, ) .unwrap(); assert_eq!( @@ -1471,7 +1445,6 @@ fn vertex( .preprocess( &WGSL_COMPLICATED_ELSE_IFDEF, &[("IS_DEFINED".to_string(), ShaderDefValue::Bool(true))].into(), - true, ) .unwrap(); assert_eq!( @@ -1504,7 +1477,7 @@ fail 3 const EXPECTED: &str = r"ok"; let processor = Preprocessor::default(); - let result = processor.preprocess(&INPUT, &[].into(), true).unwrap(); + let result = processor.preprocess(&INPUT, &[].into()).unwrap(); assert_eq!( result .preprocessed_source @@ -1539,7 +1512,6 @@ fail 3 .preprocess( &INPUT, &[("x".to_owned(), ShaderDefValue::Int(2))].into(), - true, ) .unwrap(); assert_eq!(