Skip to content

Commit

Permalink
refactor(naga)!: diagnostic_filter: s/{from,to}_ident/{from,to}_wgs…
Browse files Browse the repository at this point in the history
…l_ident
  • Loading branch information
ErichDonGubler committed Nov 12, 2024
1 parent 3ee9dca commit a9572d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions naga/src/diagnostic_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Severity {
const OFF: &'static str = "off";

/// Convert from a sentinel word in WGSL into its associated [`Severity`], if possible.
pub fn from_ident(s: &str) -> Option<Self> {
pub fn from_wgsl_ident(s: &str) -> Option<Self> {
Some(match s {
Self::ERROR => Self::Error,
Self::WARNING => Self::Warning,
Expand Down Expand Up @@ -82,15 +82,15 @@ impl FilterableTriggeringRule {
const DERIVATIVE_UNIFORMITY: &'static str = "derivative_uniformity";

/// Convert from a sentinel word in WGSL into its associated [`FilterableTriggeringRule`], if possible.
pub fn from_ident(s: &str) -> Option<Self> {
pub fn from_wgsl_ident(s: &str) -> Option<Self> {
Some(match s {
Self::DERIVATIVE_UNIFORMITY => Self::DerivativeUniformity,
_ => return None,
})
}

/// Maps this [`FilterableTriggeringRule`] into the sentinel word associated with it in WGSL.
pub const fn to_ident(self) -> &'static str {
pub const fn to_wgsl_ident(self) -> &'static str {
match self {
Self::DerivativeUniformity => Self::DERIVATIVE_UNIFORMITY,
}
Expand Down
2 changes: 1 addition & 1 deletion naga/src/front/wgsl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ impl<'a> Error<'a> {
ParseError {
message: format!(
"found conflicting `diagnostic(…)` rule(s) for `{}`",
triggering_rule.to_ident()
triggering_rule.to_wgsl_ident()
),
labels: vec![
(first_span, "first rule".into()),
Expand Down
9 changes: 4 additions & 5 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2631,11 +2631,10 @@ impl Parser {
lexer.expect(Token::Paren('('))?;

let (severity_control_name, severity_control_name_span) = lexer.next_ident_with_span()?;
let new_severity = diagnostic_filter::Severity::from_ident(severity_control_name).ok_or(
Error::DiagnosticInvalidSeverity {
let new_severity = diagnostic_filter::Severity::from_wgsl_ident(severity_control_name)
.ok_or(Error::DiagnosticInvalidSeverity {
severity_control_name_span,
},
)?;
})?;

lexer.expect(Token::Separator(','))?;

Expand All @@ -2652,7 +2651,7 @@ impl Parser {

let filter = diagnostic_rule_name
.and_then(|name| {
FilterableTriggeringRule::from_ident(name)
FilterableTriggeringRule::from_wgsl_ident(name)
.map(Ok)
.or_else(|| {
diagnostic_filter::Severity::Warning
Expand Down

0 comments on commit a9572d7

Please sign in to comment.