Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[naga] allow trailing commas in template lists #7142

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ By @brodycj in [#6924](https://github.com/gfx-rs/wgpu/pull/6924).
- Fix some instances of functions which have a return type but don't return a value being incorrectly validated. By @jamienicol in [#7013](https://github.com/gfx-rs/wgpu/pull/7013).
- Allow abstract expressions to be used in WGSL function return statements. By @jamienicol in [#7035](https://github.com/gfx-rs/wgpu/pull/7035).
- Error if structs have two fields with the same name. By @SparkyPotato in [#7088](https://github.com/gfx-rs/wgpu/pull/7088).
- Allow template lists to have a trailing comma. By @KentSlaney in [#7142](https://github.com/gfx-rs/wgpu/pull/7142).

#### General

Expand Down
4 changes: 4 additions & 0 deletions naga/src/front/wgsl/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ impl<'a> Lexer<'a> {
}
}

pub(in crate::front::wgsl) fn optional_generic_term(&mut self) -> bool {
self.skip(Token::Separator(',')) && self.peek().0 != Token::Paren('>')
}

/// If the next token matches it is skipped and true is returned
pub(in crate::front::wgsl) fn skip(&mut self, what: Token<'_>) -> bool {
let (peeked_token, rest) = self.peek_token_and_rest();
Expand Down
16 changes: 11 additions & 5 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,9 @@ impl Parser {
(Token::Paren('<'), ast::ConstructorType::PartialArray) => {
lexer.expect_generic_paren('<')?;
let base = self.type_decl(lexer, ctx)?;
let size = if lexer.skip(Token::Separator(',')) {
let size = if lexer.optional_generic_term() {
let expr = self.const_generic_expression(lexer, ctx)?;
lexer.skip(Token::Separator(','));
ast::ArraySize::Constant(expr)
} else {
ast::ArraySize::Dynamic
Expand Down Expand Up @@ -1244,6 +1245,7 @@ impl Parser {
let start = lexer.start_byte_offset();
let ty = self.type_decl(lexer, ctx)?;
let span = lexer.span_from(start);
lexer.skip(Token::Separator(','));
lexer.expect_generic_paren('>')?;
Ok((ty, span))
}
Expand Down Expand Up @@ -1436,8 +1438,10 @@ impl Parser {
lexer.expect(Token::Separator(','))?;
let base = self.type_decl(lexer, ctx)?;
if let crate::AddressSpace::Storage { ref mut access } = space {
*access = if lexer.skip(Token::Separator(',')) {
lexer.next_storage_access()?
*access = if lexer.optional_generic_term() {
let result = lexer.next_storage_access()?;
lexer.skip(Token::Separator(','));
result
} else {
crate::StorageAccess::LOAD
};
Expand All @@ -1448,8 +1452,9 @@ impl Parser {
"array" => {
lexer.expect_generic_paren('<')?;
let base = self.type_decl(lexer, ctx)?;
let size = if lexer.skip(Token::Separator(',')) {
let size = if lexer.optional_generic_term() {
let size = self.const_generic_expression(lexer, ctx)?;
lexer.skip(Token::Separator(','));
ast::ArraySize::Constant(size)
} else {
ast::ArraySize::Dynamic
Expand All @@ -1461,8 +1466,9 @@ impl Parser {
"binding_array" => {
lexer.expect_generic_paren('<')?;
let base = self.type_decl(lexer, ctx)?;
let size = if lexer.skip(Token::Separator(',')) {
let size = if lexer.optional_generic_term() {
let size = self.unary_expression(lexer, ctx)?;
lexer.skip(Token::Separator(','));
ast::ArraySize::Constant(size)
} else {
ast::ArraySize::Dynamic
Expand Down
4 changes: 2 additions & 2 deletions tests/tests/shader/array_size_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use wgpu_test::{fail_if, gpu_test, GpuTestConfiguration, TestParameters, Testing
const SHADER: &str = r#"
override n = 8;

var<workgroup> arr: array<u32, n - 2>;
var<workgroup> arr: array<u32, n - 2,>;

@group(0) @binding(0)
var<storage, read_write> output: array<u32>;
var<storage, read_write> output: array<u32,>;

@compute @workgroup_size(1) fn main() {
// 1d spiral
Expand Down