feat(wgsl-in): use more general enable-not-set diag. w/ unimpl. hint

This commit is contained in:
Erich Gubler 2024-10-17 15:22:05 -04:00
parent bf4cd9cd31
commit d539466997
2 changed files with 43 additions and 2 deletions

View File

@ -283,6 +283,10 @@ pub(crate) enum Error<'a> {
kind: UnimplementedEnableExtension,
span: Span,
},
EnableExtensionNotEnabled {
kind: EnableExtension,
span: Span,
},
}
#[derive(Clone, Debug)]
@ -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![]
},
},
}
}
}

View File

@ -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;
@ -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"), _) => {