diff --git a/src/front/wgsl/lexer.rs b/src/front/wgsl/lexer.rs index 70b50a9958..d3a00e0117 100644 --- a/src/front/wgsl/lexer.rs +++ b/src/front/wgsl/lexer.rs @@ -286,7 +286,6 @@ fn consume_number(input: &str) -> (Token, &str) { } else { NumberType::Sint }, - width: None, }, rest, ) @@ -664,7 +663,6 @@ fn test_tokens() { Token::Number { value: "92", ty: NumberType::Sint, - width: None, }, Token::Word("No"), ], @@ -675,12 +673,10 @@ fn test_tokens() { Token::Number { value: "2", ty: NumberType::Uint, - width: None, }, Token::Number { value: "3", ty: NumberType::Sint, - width: None, }, Token::Word("o"), ], @@ -691,7 +687,6 @@ fn test_tokens() { Token::Number { value: "2.4", ty: NumberType::Float, - width: None, }, Token::Word("f44po"), ], @@ -725,7 +720,6 @@ fn test_variable_decl() { Token::Number { value: "0", ty: NumberType::Sint, - width: None, }, Token::Paren(')'), Token::Word("var"), diff --git a/src/front/wgsl/mod.rs b/src/front/wgsl/mod.rs index 164d5aa708..2271a915d2 100644 --- a/src/front/wgsl/mod.rs +++ b/src/front/wgsl/mod.rs @@ -60,11 +60,7 @@ pub enum Token<'a> { DoubleColon, Paren(char), Attribute, - Number { - value: &'a str, - ty: NumberType, - width: Option, - }, + Number { value: &'a str, ty: NumberType }, String(&'a str), Word(&'a str), Operation(char), @@ -1266,18 +1262,10 @@ impl Parser { fn get_constant_inner<'a>( word: &'a str, ty: NumberType, - width: Option, token_span: TokenSpan<'a>, ) -> Result> { let span = token_span.1; - if let Some(width) = width { - if width != 4 { - // Only 32-bit literals supported by the spec and naga for now! - return Err(Error::BadScalarWidth(span, width)); - } - } - let value = match ty { NumberType::Sint => { get_i32_literal(word, span).map(|val| crate::ScalarValue::Sint(val as i64))? @@ -1290,25 +1278,13 @@ impl Parser { } }; - Ok(crate::ConstantInner::Scalar { - value, - width: width.unwrap_or(4), - }) + Ok(crate::ConstantInner::Scalar { value, width: 4 }) } fn parse_switch_value<'a>(lexer: &mut Lexer<'a>, uint: bool) -> Result> { let token_span = lexer.next(); let word = match token_span.0 { - Token::Number { value, width, .. } => { - if let Some(width) = width { - if width != 4 { - // Only 32-bit literals supported by the spec and naga for now! - return Err(Error::BadScalarWidth(token_span.1, width)); - } - } - - value - } + Token::Number { value, .. } => value, _ => return Err(Error::Unexpected(token_span, ExpectedToken::Integer)), }; @@ -1856,7 +1832,6 @@ impl Parser { Token::Number { value, ty: NumberType::Sint, - width: None, }, span, ) = lexer.peek() @@ -2223,8 +2198,8 @@ impl Parser { let inner = match first_token_span { (Token::Word("true"), _) => crate::ConstantInner::boolean(true), (Token::Word("false"), _) => crate::ConstantInner::boolean(false), - (Token::Number { value, ty, width }, _) => { - Self::get_constant_inner(value, ty, width, first_token_span)? + (Token::Number { value, ty }, _) => { + Self::get_constant_inner(value, ty, first_token_span)? } (Token::Word(name), name_span) => { // look for an existing constant first diff --git a/src/front/wgsl/number_literals.rs b/src/front/wgsl/number_literals.rs index 9279989e94..6691ab2d05 100644 --- a/src/front/wgsl/number_literals.rs +++ b/src/front/wgsl/number_literals.rs @@ -85,10 +85,9 @@ pub(super) fn _parse_uint_literal<'a>( Token::Number { value, ty: NumberType::Uint, - width: token_width, }, span, - ) if token_width.unwrap_or(4) == width => get_u32_literal(value, span), + ) => get_u32_literal(value, span), other => Err(Error::Unexpected( other, ExpectedToken::Number { @@ -117,10 +116,9 @@ pub(super) fn parse_non_negative_sint_literal<'a>( Token::Number { value, ty: NumberType::Sint, - width: token_width, }, span, - ) if token_width.unwrap_or(4) == width => { + ) => { let i32_val = get_i32_literal(value, span.clone())?; u32::try_from(i32_val).map_err(|_| Error::NegativeInt(span)) } @@ -153,10 +151,9 @@ pub(super) fn parse_generic_non_negative_int_literal<'a>( Token::Number { value, ty: NumberType::Sint, - width: token_width, }, span, - ) if token_width.unwrap_or(4) == width => { + ) => { let i32_val = get_i32_literal(value, span.clone())?; u32::try_from(i32_val).map_err(|_| Error::NegativeInt(span)) } @@ -164,10 +161,9 @@ pub(super) fn parse_generic_non_negative_int_literal<'a>( Token::Number { value, ty: NumberType::Uint, - width: token_width, }, span, - ) if token_width.unwrap_or(4) == width => get_u32_literal(value, span), + ) => get_u32_literal(value, span), other => Err(Error::Unexpected( other, ExpectedToken::Number { @@ -194,10 +190,9 @@ pub(super) fn _parse_float_literal<'a>( Token::Number { value, ty: NumberType::Float, - width: token_width, }, span, - ) if token_width.unwrap_or(4) == width => get_f32_literal(value, span), + ) => get_f32_literal(value, span), other => Err(Error::Unexpected( other, ExpectedToken::Number {