Skip to content

Commit

Permalink
feat(wgsl-in): add unimpl. diag. for @diagnostic(…)s on fns
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Nov 5, 2024
1 parent 4b4a208 commit c350a63
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
24 changes: 24 additions & 0 deletions naga/src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ pub enum ExpectedToken<'a> {
Variable,
/// Access of a function
Function,
/// The `diagnostic` identifier of the `@diagnostic(…)` attribute.
DiagnosticAttribute,
}

#[derive(Clone, Copy, Debug, Error, PartialEq)]
Expand Down Expand Up @@ -296,6 +298,10 @@ pub(crate) enum Error<'a> {
severity_control_name_span: Span,
},
DiagnosticDuplicateTriggeringRule(ConflictingDiagnosticRuleError),
DiagnosticNotYetImplementedAtParseSite {
site_name_plural: &'static str,
span: Span,
},
}

impl<'a> From<ConflictingDiagnosticRuleError> for Error<'a> {
Expand Down Expand Up @@ -380,6 +386,9 @@ impl<'a> Error<'a> {
ExpectedToken::AfterIdentListComma => {
"next argument or end of list (';')".to_string()
}
ExpectedToken::DiagnosticAttribute => {
"the 'diagnostic' attribute identifier".to_string()
}
};
ParseError {
message: format!(
Expand Down Expand Up @@ -1043,6 +1052,21 @@ impl<'a> Error<'a> {
.into()],
}
}
Error::DiagnosticNotYetImplementedAtParseSite {
site_name_plural,
span,
} => ParseError {
message: "`@diagnostic(…)` attribute(s) not yet implemented".into(),
labels: vec![(
span,
format!("can't use this for {site_name_plural} (yet)").into(),
)],
notes: vec![format!(concat!(
"Let Naga maintainers know that you ran into this at ",
"<https://github.com/gfx-rs/wgpu/issues/5320>, ",
"so they can prioritize it!"
))],
},
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ impl Parser {
let _ = lexer.next();
self.pop_rule_span(lexer);
}
(Token::Paren('{'), _) => {
(Token::Paren('{') | Token::Attribute, _) => {
let (inner, span) = self.block(lexer, ctx, brace_nesting_level)?;
block.stmts.push(ast::Statement {
kind: ast::StatementKind::Block(inner),
Expand Down Expand Up @@ -2328,6 +2328,15 @@ impl Parser {
self.push_rule_span(Rule::Attribute, lexer);
while lexer.skip(Token::Attribute) {
let (name, name_span) = lexer.next_ident_with_span()?;
if let Some(DirectiveKind::Diagnostic) = DirectiveKind::from_ident(name) {
if let Some(_filter) = self.diagnostic_filter(lexer)? {
let span = self.peek_rule_span(lexer);
return Err(Error::DiagnosticNotYetImplementedAtParseSite {
span,
site_name_plural: "functions",
});
}
}
match name {
"binding" => {
lexer.expect(Token::Paren('('))?;
Expand Down

0 comments on commit c350a63

Please sign in to comment.