diff --git a/cts_runner/test.lst b/cts_runner/test.lst index 831821d1c..5c079fbf6 100644 --- a/cts_runner/test.lst +++ b/cts_runner/test.lst @@ -374,6 +374,7 @@ webgpu:shader,validation,extension,dual_source_blending:blend_src_stage_input_ou webgpu:shader,validation,extension,dual_source_blending:blend_src_syntax_validation:* webgpu:shader,validation,extension,dual_source_blending:use_blend_src_requires_extension_enabled:* webgpu:shader,validation,extension,pointer_composite_access:* +webgpu:shader,validation,functions,restrictions:param_type_can_be_alias:* webgpu:shader,validation,parse,blankspace:blankspace:* webgpu:shader,validation,parse,blankspace:bom:* webgpu:shader,validation,parse,blankspace:null_characters:contains_null=false;* @@ -383,6 +384,7 @@ webgpu:shader,validation,parse,enable:* webgpu:shader,validation,parse,identifiers:* webgpu:shader,validation,parse,requires:* webgpu:shader,validation,parse,semicolon:* +webgpu:shader,validation,parse,shadow_builtins:function_param:* webgpu:shader,validation,parse,source:* webgpu:shader,validation,shader_io,entry_point:* webgpu:shader,validation,shader_io,invariant:* diff --git a/naga/src/front/mod.rs b/naga/src/front/mod.rs index 826100e87..e32243911 100644 --- a/naga/src/front/mod.rs +++ b/naga/src/front/mod.rs @@ -223,6 +223,7 @@ pub struct SymbolTable { /// /// [`scopes`]: Self::scopes cursor: usize, + lookup_cursor_is_one_behind: bool, } impl SymbolTable { @@ -232,8 +233,13 @@ impl SymbolTable { /// until another scope is pushed or [`pop_scope`] is called, causing this /// scope to be removed along with all variables added to it. /// + /// # PANICS + /// - If the current lookup scope doesn't match the current scope + /// /// [`pop_scope`]: Self::pop_scope pub fn push_scope(&mut self) { + self.check_lookup_scope_matches_current_scope(); + // If the cursor is equal to the scope's stack length then we need to // push another empty scope. Otherwise we can reuse the already existing // scope. @@ -250,6 +256,7 @@ impl SymbolTable { /// /// # PANICS /// - If the current lexical scope is the root scope + /// - If the current lookup scope doesn't match the current scope pub fn pop_scope(&mut self) { // Despite the method title, the variables are only deleted when the // scope is reused. This is because while a clear is inevitable if the @@ -257,9 +264,38 @@ impl SymbolTable { // popped and not reused, i.e. if another scope with the same nesting // level is never pushed again. assert!(self.cursor != 1, "Tried to pop the root scope"); + self.check_lookup_scope_matches_current_scope(); self.cursor -= 1; } + + /// Reduces the lookup scope by one level. + /// + /// # PANICS + /// - If the current lookup scope doesn't match the current scope + pub fn reduce_lookup_scope(&mut self) { + self.check_lookup_scope_matches_current_scope(); + self.lookup_cursor_is_one_behind = true; + } + + /// Resets the lookup scope to the current scope. + /// + /// # PANICS + /// - If the current lookup scope already matches the current scope + pub fn reset_lookup_scope(&mut self) { + assert!( + self.lookup_cursor_is_one_behind, + "current lookup scope already matches the current scope" + ); + self.lookup_cursor_is_one_behind = false; + } + + fn check_lookup_scope_matches_current_scope(&self) { + assert!( + !self.lookup_cursor_is_one_behind, + "current lookup scope doesn't match the current scope" + ); + } } impl SymbolTable @@ -277,8 +313,11 @@ where Name: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { + let cursor = self + .cursor + .saturating_sub(self.lookup_cursor_is_one_behind.into()); // Iterate backwards through the scopes and try to find the variable - for scope in self.scopes[..self.cursor].iter().rev() { + for scope in self.scopes[..cursor].iter().rev() { if let Some(var) = scope.get(name) { return Some(var); } @@ -316,6 +355,7 @@ impl Default for SymbolTable { Self { scopes: vec![FastHashMap::default()], cursor: 1, + lookup_cursor_is_one_behind: false, } } } diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs index 27ff77f84..fa69e3a3c 100644 --- a/naga/src/front/wgsl/parse/mod.rs +++ b/naga/src/front/wgsl/parse/mod.rs @@ -1712,6 +1712,9 @@ impl Parser { // start a scope that contains arguments as well as the function body ctx.local_table.push_scope(); + // Reduce lookup scope to parse the parameter list and return type + // avoiding identifier lookup to match newly declared param names. + ctx.local_table.reduce_lookup_scope(); // read parameter list let mut arguments = Vec::new(); @@ -1759,6 +1762,8 @@ impl Parser { None }; + ctx.local_table.reset_lookup_scope(); + // do not use `self.block` here, since we must not push a new scope lexer.expect(Token::Paren('{'))?; let brace_nesting_level = 1;