Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
42338ff
add `optionally_typed_ident` fn
teoxoy Aug 21, 2025
4adede5
[wgsl] rename `type_decl` to `type_specifier`
teoxoy Aug 21, 2025
54fe3ca
rename `assignment_statement` to `variable_updating_statement`
teoxoy Aug 21, 2025
e99eb01
rename `general_expression` to `expression`
teoxoy Aug 21, 2025
ed6a032
remove `next_scalar_generic`
teoxoy Aug 27, 2025
75fbca1
remove `peek_ident_with_span`
teoxoy Aug 27, 2025
47108f6
update `lhs_expression` to be in line with the spec
teoxoy Aug 27, 2025
fe63d07
rename `postfix` to `component_or_swizzle_specifier`
teoxoy Aug 27, 2025
086c0e4
remove `lexer.clone()`
teoxoy Aug 27, 2025
16c2777
rename `function_statement` to `func_call_statement`
teoxoy Aug 27, 2025
527cf31
rename `function_call_or_assignment_statement` to `func_call_or_varia…
teoxoy Aug 27, 2025
68ca96d
use `lexer.next()` instead of `peek()` for most statements
teoxoy Aug 27, 2025
97c58d0
flatten match
teoxoy Aug 27, 2025
35799e6
add function that parses variable, value, func call and variable upda…
teoxoy Aug 27, 2025
1149d02
use `lexer.skip()` in one more place
teoxoy Aug 27, 2025
f33897d
rename `Lexer` `skip` to `next_if`
teoxoy Aug 27, 2025
bf6be2e
use `lexer.next()` in `primary_expression`
teoxoy Aug 27, 2025
afcdc3c
rename `function_call` to `call_expression`
teoxoy Aug 27, 2025
f827139
use `lexer.next()` in `unary_expression`
teoxoy Aug 27, 2025
0e65fa3
avoid recursing into `unary_expression`
teoxoy Aug 27, 2025
6ae7230
remove `Clone` derive from the `Lexer`
teoxoy Oct 3, 2025
0c6ff52
add `Lexer::span_with_start`
teoxoy Oct 7, 2025
c12bf68
add `TemplateArgsStart` & `TemplateArgsEnd` tokens
teoxoy Oct 7, 2025
393213b
handle `var` decl template list in the lowerer
teoxoy Oct 7, 2025
f52a0ad
handle `bitcast` and construction expressions in the lowerer
teoxoy Oct 20, 2025
081dbe1
handle all type resolution in the lowerer
teoxoy Oct 20, 2025
5262323
add `shadowing_predeclared_types` test
teoxoy Oct 20, 2025
4c87309
add `test_template_list` test
teoxoy Oct 20, 2025
7fe5aa3
document `consume_tokens`
teoxoy Oct 20, 2025
4ebbc67
implement template list discovery
teoxoy Oct 7, 2025
96a378e
[wgsl] update reserved list to latest CR
teoxoy Aug 21, 2025
92e95ff
adjust GLSL snapshots
teoxoy Oct 21, 2025
13a9c1b
[wgsl-out] avoid shadowing built-ins
teoxoy Oct 22, 2025
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 naga/src/back/glsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ impl<'a, W: Write> Writer<'a, W> {
namer.reset(
module,
&keywords::RESERVED_KEYWORD_SET,
proc::KeywordSet::empty(),
proc::CaseInsensitiveKeywordSet::empty(),
&[
"gl_", // all GL built-in variables
Expand Down
1 change: 1 addition & 0 deletions naga/src/back/hlsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
self.namer.reset(
module,
&super::keywords::RESERVED_SET,
proc::KeywordSet::empty(),
&super::keywords::RESERVED_CASE_INSENSITIVE_SET,
super::keywords::RESERVED_PREFIXES,
&mut self.names,
Expand Down
1 change: 1 addition & 0 deletions naga/src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4279,6 +4279,7 @@ impl<W: Write> Writer<W> {
self.namer.reset(
module,
&super::keywords::RESERVED_SET,
proc::KeywordSet::empty(),
proc::CaseInsensitiveKeywordSet::empty(),
&[CLAMPED_LOD_LOAD_PREFIX],
&mut self.names,
Expand Down
1 change: 1 addition & 0 deletions naga/src/back/wgsl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl<W: Write> Writer<W> {
self.namer.reset(
module,
&crate::keywords::wgsl::RESERVED_SET,
&crate::keywords::wgsl::BUILTIN_IDENTIFIER_SET,
// an identifier must not start with two underscore
proc::CaseInsensitiveKeywordSet::empty(),
&["__", "_naga"],
Expand Down
82 changes: 64 additions & 18 deletions naga/src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pub enum ExpectedToken<'a> {
Identifier,
AfterIdentListComma,
AfterIdentListArg,
LhsExpression,
/// Expected: constant, parenthesized expression, identifier
PrimaryExpression,
/// Expected: assignment, increment/decrement expression
Expand All @@ -145,8 +146,6 @@ pub enum ExpectedToken<'a> {
WorkgroupSizeSeparator,
/// Expected: 'struct', 'let', 'var', 'type', ';', 'fn', eof
GlobalItem,
/// Expected a type.
Type,
/// Access of `var`, `let`, `const`.
Variable,
/// Access of a function
Expand Down Expand Up @@ -191,21 +190,20 @@ pub(crate) enum Error<'a> {
},
BadIncrDecrReferenceType(Span),
InvalidResolve(ResolveError),
InvalidForInitializer(Span),
/// A break if appeared outside of a continuing block
InvalidBreakIf(Span),
InvalidGatherComponent(Span),
InvalidConstructorComponentType(Span, i32),
InvalidIdentifierUnderscore(Span),
ReservedIdentifierPrefix(Span),
UnknownAddressSpace(Span),
UnknownRayFlag(Span),
RepeatedAttribute(Span),
UnknownAttribute(Span),
UnknownBuiltin(Span),
UnknownAccess(Span),
UnknownIdent(Span, &'a str),
UnknownScalarType(Span),
UnknownType(Span),
UnknownStorageFormat(Span),
UnknownConservativeDepth(Span),
UnknownEnableExtension(Span, &'a str),
Expand Down Expand Up @@ -275,6 +273,7 @@ pub(crate) enum Error<'a> {
span: Span,
},
CalledEntryPoint(Span),
CalledLocalDecl(Span),
WrongArgumentCount {
span: Span,
expected: Range<u32>,
Expand Down Expand Up @@ -412,6 +411,15 @@ pub(crate) enum Error<'a> {
TypeTooLarge {
span: Span,
},
UnexpectedIdentForEnumerant(Span),
UnexpectedExprForEnumerant(Span),
UnusedArgsForTemplate(Vec<Span>),
UnexpectedTemplate(Span),
MissingTemplateArg {
span: Span,
arg: &'static str,
},
UnexpectedExprForTypeExpression(Span),
}

impl From<ConflictingDiagnosticRuleError> for Error<'_> {
Expand Down Expand Up @@ -480,13 +488,16 @@ impl<'a> Error<'a> {
Token::IncrementOperation => "increment operation".to_string(),
Token::DecrementOperation => "decrement operation".to_string(),
Token::Arrow => "->".to_string(),
Token::TemplateArgsStart => "template args start".to_string(),
Token::TemplateArgsEnd => "template args end".to_string(),
Token::Unknown(c) => format!("unknown (`{c}`)"),
Token::Trivia => "trivia".to_string(),
Token::DocComment(s) => format!("doc comment ('{s}')"),
Token::ModuleDocComment(s) => format!("module doc comment ('{s}')"),
Token::End => "end".to_string(),
},
ExpectedToken::Identifier => "identifier".to_string(),
ExpectedToken::LhsExpression => "lhs_expression".to_string(),
Copy link
Member

@jimblandy jimblandy Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think lhs_expression is spec jargon. Isn't there something we could say here that would be more readily recognized by WGSL programmers? "expression to be assigned to"? "destination for assignment"?

(Spec jargon is fine when we need to be precise and there's nothing better.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"destination for assignment"/"assignment destination" sound good.
It's also used by increment/decrement statements but it's probably ok?

ExpectedToken::PrimaryExpression => "expression".to_string(),
ExpectedToken::Assignment => "assignment or increment/decrement".to_string(),
ExpectedToken::SwitchItem => concat!(
Expand All @@ -503,7 +514,6 @@ impl<'a> Error<'a> {
"or the end of the file"
)
.to_string(),
ExpectedToken::Type => "type".to_string(),
ExpectedToken::Variable => "variable access".to_string(),
ExpectedToken::Function => "function name".to_string(),
ExpectedToken::AfterIdentListArg => {
Expand Down Expand Up @@ -610,14 +620,6 @@ impl<'a> Error<'a> {
labels: vec![],
notes: vec![],
},
Error::InvalidForInitializer(bad_span) => ParseError {
message: format!(
"for(;;) initializer is not an assignment or a function call: `{}`",
&source[bad_span]
),
labels: vec![(bad_span, "not an assignment or function call".into())],
notes: vec![],
},
Error::InvalidBreakIf(bad_span) => ParseError {
message: "A break if is only allowed in a continuing block".to_string(),
labels: vec![(bad_span, "not in a continuing block".into())],
Expand Down Expand Up @@ -657,6 +659,11 @@ impl<'a> Error<'a> {
labels: vec![(bad_span, "unknown address space".into())],
notes: vec![],
},
Error::UnknownRayFlag(bad_span) => ParseError {
message: format!("unknown ray flag: `{}`", &source[bad_span]),
labels: vec![(bad_span, "unknown ray flag".into())],
notes: vec![],
},
Error::RepeatedAttribute(bad_span) => ParseError {
message: format!("repeated attribute: `{}`", &source[bad_span]),
labels: vec![(bad_span, "repeated attribute".into())],
Expand Down Expand Up @@ -687,11 +694,6 @@ impl<'a> Error<'a> {
labels: vec![(bad_span, "unknown conservative depth".into())],
notes: vec![],
},
Error::UnknownType(bad_span) => ParseError {
message: format!("unknown type: `{}`", &source[bad_span]),
labels: vec![(bad_span, "unknown type".into())],
notes: vec![],
},
Error::UnknownEnableExtension(span, word) => ParseError {
message: format!("unknown enable-extension `{word}`"),
labels: vec![(span, "".into())],
Expand Down Expand Up @@ -916,6 +918,11 @@ impl<'a> Error<'a> {
labels: vec![(span, "entry point cannot be called".into())],
notes: vec![],
},
Error::CalledLocalDecl(span) => ParseError {
message: "local declaration cannot be called".to_string(),
labels: vec![(span, "local declaration cannot be called".into())],
notes: vec![],
},
Error::WrongArgumentCount {
span,
ref expected,
Expand Down Expand Up @@ -1386,6 +1393,45 @@ impl<'a> Error<'a> {
crate::valid::MAX_TYPE_SIZE
)],
},
Error::UnexpectedIdentForEnumerant(ident_span) => ParseError {
message: format!(
"identifier `{}` resolves to a declaration",
&source[ident_span]
),
labels: vec![(ident_span, "needs to resolve to a predeclared enumerant".into())],
notes: vec![],
},
Error::UnexpectedExprForEnumerant(expr_span) => ParseError {
message: "unexpected expression".to_string(),
labels: vec![(expr_span, "needs to be an identifier resolving to a predeclared enumerant".into())],
notes: vec![],
},
Error::UnusedArgsForTemplate(ref expr_spans) => ParseError {
message: "unused expressions for template".to_string(),
labels: expr_spans.iter().cloned().map(|span| -> (_, _){ (span, "unused".into()) }).collect(),
notes: vec![],
},
Error::UnexpectedTemplate(span) => ParseError {
message: "unexpected template".to_string(),
labels: vec![(span, "expected identifier".into())],
notes: vec![],
},
Error::MissingTemplateArg {
span,
arg,
} => ParseError {
message: format!(
"`{}` needs a template argument specified: {arg}",
&source[span]
),
labels: vec![(span, "is missing a template argument".into())],
notes: vec![],
},
Error::UnexpectedExprForTypeExpression(expr_span) => ParseError {
message: "unexpected expression".to_string(),
labels: vec![(expr_span, "needs to be an identifier resolving to a type declaration (alias or struct) or predeclared type(-generator)".into())],
notes: vec![],
}
}
}
}
Loading