Skip to content

Commit

Permalink
feat(wgsl-in): use more general enable-not-set diag. w/ unimpl. hint
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Oct 22, 2024
1 parent aa67f45 commit bcee0c7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
31 changes: 31 additions & 0 deletions naga/src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ pub(crate) enum Error<'a> {
kind: UnimplementedEnableExtension,
span: Span,
},
EnableExtensionNotEnabled {
kind: EnableExtension,
span: Span,
},
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -945,6 +949,33 @@ impl<'a> Error<'a> {
kind.tracking_issue_num()
)],
},
Error::EnableExtensionNotEnabled { kind, span } => ParseError {
message: format!("`{}` enable extension is not enabled", kind.to_ident()),
labels: vec![(
span,
format!(
concat!(
"the `{}` enable extension is needed for this functionality, ",
"but it is not currently enabled"
),
kind.to_ident()
)
.into(),
)],
notes: if let EnableExtension::Unimplemented(kind) = kind {
vec![format!(
concat!(
"This extension is not yet implemented. ",
"Let Naga maintainers know that you ran into this at ",
"<https://github.com/gfx-rs/wgpu/issues/{}>, ",
"so they can prioritize it!"
),
kind.tracking_issue_num()
)]
} else {
vec![]
},
},
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::front::wgsl::error::{Error, ExpectedToken};
use crate::front::wgsl::parse::directive::enable_extension::{EnableExtension, EnableExtensions};
use crate::front::wgsl::parse::directive::enable_extension::{
EnableExtension, EnableExtensions, UnimplementedEnableExtension,
};
use crate::front::wgsl::parse::directive::DirectiveKind;
use crate::front::wgsl::parse::lexer::{Lexer, Token};
use crate::front::wgsl::parse::number::Number;
Expand Down Expand Up @@ -667,7 +669,15 @@ impl Parser {
}
(Token::Number(res), span) => {
let _ = lexer.next();
let num = res.map_err(|err| Error::BadNumber(span, err))?;
let num = res.map_err(|err| match err {
super::error::NumberError::UnimplementedF16 => {
Error::EnableExtensionNotEnabled {
kind: EnableExtension::Unimplemented(UnimplementedEnableExtension::F16),
span,
}
}
err => Error::BadNumber(span, err),
})?;
ast::Expression::Literal(ast::Literal::Number(num))
}
(Token::Word("RAY_FLAG_NONE"), _) => {
Expand Down

0 comments on commit bcee0c7

Please sign in to comment.