Skip to content

Commit

Permalink
chore(wgsl-in): remove unimplemented directive kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Oct 31, 2024
1 parent 8c13d8f commit 82f9ca6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 72 deletions.
23 changes: 0 additions & 23 deletions naga/src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::front::wgsl::parse::directive::enable_extension::{
use crate::front::wgsl::parse::directive::language_extension::{
LanguageExtension, UnimplementedLanguageExtension,
};
use crate::front::wgsl::parse::directive::{DirectiveKind, UnimplementedDirectiveKind};
use crate::front::wgsl::parse::lexer::Token;
use crate::front::wgsl::Scalar;
use crate::proc::{Alignment, ConstantEvaluatorError, ResolveError};
Expand Down Expand Up @@ -278,10 +277,6 @@ pub(crate) enum Error<'a> {
PipelineConstantIDValue(Span),
NotBool(Span),
ConstAssertFailed(Span),
DirectiveNotYetImplemented {
kind: UnimplementedDirectiveKind,
span: Span,
},
DirectiveAfterFirstGlobalDecl {
directive_span: Span,
},
Expand Down Expand Up @@ -932,24 +927,6 @@ impl<'a> Error<'a> {
labels: vec![(span, "evaluates to false".into())],
notes: vec![],
},
Error::DirectiveNotYetImplemented { kind, span } => ParseError {
message: format!(
"the `{}` directive is not yet implemented",
DirectiveKind::Unimplemented(kind).to_ident()
),
labels: vec![(
span,
"this global directive is standard, but not yet implemented".into(),
)],
notes: vec![format!(
concat!(
"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()
)],
},
Error::DirectiveAfterFirstGlobalDecl { directive_span } => ParseError {
message: "expected global declaration, but found a global directive".into(),
labels: vec![(
Expand Down
47 changes: 2 additions & 45 deletions naga/src/front/wgsl/parse/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ pub(crate) mod language_extension;

/// A parsed sentinel word indicating the type of directive to be parsed next.
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(test, derive(strum::EnumIter))]
pub(crate) enum DirectiveKind {
/// A [`crate::diagnostic_filter`].
Diagnostic,
/// An [`enable_extension`].
Enable,
/// A [`language_extension`].
Requires,
Unimplemented(UnimplementedDirectiveKind),
}

impl DirectiveKind {
Expand All @@ -31,36 +31,6 @@ impl DirectiveKind {
_ => return None,
})
}

/// Maps this [`DirectiveKind`] into the sentinel word associated with it in WGSL.
pub const fn to_ident(self) -> &'static str {
match self {
Self::Diagnostic => Self::DIAGNOSTIC,
Self::Enable => Self::ENABLE,
Self::Requires => Self::REQUIRES,
Self::Unimplemented(kind) => match kind {},
}
}

#[cfg(test)]
fn iter() -> impl Iterator<Item = Self> {
use strum::IntoEnumIterator;

[Self::Diagnostic, Self::Enable, Self::Requires]
.into_iter()
.chain(UnimplementedDirectiveKind::iter().map(Self::Unimplemented))
}
}

/// A [`DirectiveKind`] that is not yet implemented. See [`DirectiveKind::Unimplemented`].
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
#[cfg_attr(test, derive(strum::EnumIter))]
pub(crate) enum UnimplementedDirectiveKind {}

impl UnimplementedDirectiveKind {
pub const fn tracking_issue_num(self) -> u16 {
match self {}
}
}

impl crate::diagnostic_filter::Severity {
Expand All @@ -83,19 +53,7 @@ mod test {

use crate::front::wgsl::assert_parse_err;

use super::{DirectiveKind, UnimplementedDirectiveKind};

#[test]
#[allow(clippy::never_loop, unreachable_code, unused_variables)]
fn unimplemented_directives() {
for unsupported_shader in UnimplementedDirectiveKind::iter() {
let shader;
let expected_msg;
match unsupported_shader {};

assert_parse_err(shader, expected_msg);
}
}
use super::DirectiveKind;

#[test]
fn directive_after_global_decl() {
Expand Down Expand Up @@ -142,7 +100,6 @@ error: expected global declaration, but found a global directive
";
}
DirectiveKind::Unimplemented(kind) => match kind {},
}

let shader = format!(
Expand Down
5 changes: 1 addition & 4 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2525,7 +2525,7 @@ impl Parser {
let mut enable_extensions = EnableExtensions::empty();

// Parse directives.
while let Ok((ident, span)) = lexer.peek_ident_with_span() {
while let Ok((ident, _directive_ident_span)) = lexer.peek_ident_with_span() {
if let Some(kind) = DirectiveKind::from_ident(ident) {
self.push_rule_span(Rule::Directive, &mut lexer);
let _ = lexer.next_ident_with_span().unwrap();
Expand Down Expand Up @@ -2574,9 +2574,6 @@ impl Parser {
}
})?;
}
DirectiveKind::Unimplemented(kind) => {
return Err(Error::DirectiveNotYetImplemented { kind, span })
}
}
self.pop_rule_span(&lexer);
} else {
Expand Down

0 comments on commit 82f9ca6

Please sign in to comment.