mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 06:50:59 +01:00
[wgsl-in] Avoid looking up newly introduced parameter names while parsing function parameters and its return type. (#8980)
This commit is contained in:
1 parent
c0f04c801c
commit
a54dec07eb
3 files changed
+48
-1
No files matched your search
@@ -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:*
|
||||
|
||||
+41
-1
@@ -223,6 +223,7 @@ pub struct SymbolTable<Name, Var> {
|
||||
///
|
||||
/// [`scopes`]: Self::scopes
|
||||
cursor: usize,
|
||||
lookup_cursor_is_one_behind: bool,
|
||||
}
|
||||
|
||||
impl<Name, Var> SymbolTable<Name, Var> {
|
||||
@@ -232,8 +233,13 @@ impl<Name, Var> SymbolTable<Name, Var> {
|
||||
/// 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<Name, Var> SymbolTable<Name, Var> {
|
||||
///
|
||||
/// # 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<Name, Var> SymbolTable<Name, Var> {
|
||||
// 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<Name, Var> SymbolTable<Name, Var>
|
||||
@@ -277,8 +313,11 @@ where
|
||||
Name: core::borrow::Borrow<Q>,
|
||||
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<Name, Var> Default for SymbolTable<Name, Var> {
|
||||
Self {
|
||||
scopes: vec![FastHashMap::default()],
|
||||
cursor: 1,
|
||||
lookup_cursor_is_one_behind: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user