From 6cc135aa8e74f139d787d95651d6f18db7eb7ef9 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 18 Apr 2024 11:54:25 -0400 Subject: [PATCH] WIP TODO: figure out design, make things compile --- Cargo.lock | 10 +++ moz-webgpu-cts/Cargo.toml | 1 + moz-webgpu-cts/src/main.rs | 8 +-- moz-webgpu-cts/src/wpt/metadata.rs | 72 +++++++++---------- moz-webgpu-cts/src/wpt/metadata/properties.rs | 25 +++++++ 5 files changed, 73 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 363fe85..005eaaf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,6 +92,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "arcstr" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f907281554a3d0312bb7aab855a8e0ef6cbf1614d06de54105039ca8b34460e" +dependencies = [ + "serde", +] + [[package]] name = "backtrace" version = "0.3.71" @@ -587,6 +596,7 @@ dependencies = [ name = "moz-webgpu-cts" version = "1.0.0" dependencies = [ + "arcstr", "camino", "clap", "enum-map", diff --git a/moz-webgpu-cts/Cargo.toml b/moz-webgpu-cts/Cargo.toml index f76b496..874b1c7 100644 --- a/moz-webgpu-cts/Cargo.toml +++ b/moz-webgpu-cts/Cargo.toml @@ -11,6 +11,7 @@ publish = false dist = true [dependencies] +arcstr = { version = "1.1.5", features = ["serde"] } camino = { version = "1.1.6", features = ["serde1"] } clap = { version = "4.4.2", features = ["derive"] } env_logger = "0.10.0" diff --git a/moz-webgpu-cts/src/main.rs b/moz-webgpu-cts/src/main.rs index 6715533..3051b4a 100644 --- a/moz-webgpu-cts/src/main.rs +++ b/moz-webgpu-cts/src/main.rs @@ -1046,14 +1046,14 @@ fn run(cli: Cli) -> ExitCode { } = test; let TestProps { - is_disabled, + disabled, expected, implementation_status: _, } = properties; let test_name = Arc::new(test_name); - if is_disabled { + if disabled.is_some() { analysis.for_each_platform_mut(|analysis| { analysis .tests_with_disabled_or_skip @@ -1161,12 +1161,12 @@ fn run(cli: Cli) -> ExitCode { let Subtest { properties } = subtest; let TestProps { - is_disabled, + disabled, expected, implementation_status: _, } = properties; - if is_disabled { + if disabled.is_some() { analysis .windows .tests_with_disabled_or_skip diff --git a/moz-webgpu-cts/src/wpt/metadata.rs b/moz-webgpu-cts/src/wpt/metadata.rs index a710b96..8ead15b 100644 --- a/moz-webgpu-cts/src/wpt/metadata.rs +++ b/moz-webgpu-cts/src/wpt/metadata.rs @@ -4,6 +4,7 @@ use std::{ hash::Hash, }; +use arcstr::ArcStr; use clap::ValueEnum; use enum_map::Enum; use enumset::EnumSetType; @@ -31,7 +32,9 @@ use whippit::{ }, }; -use crate::wpt::metadata::properties::{ExpandedPropertyValue, Expected, NormalizedPropertyValue}; +use crate::wpt::metadata::properties::{ + DisabledString, ExpandedPropertyValue, Expected, NormalizedPropertyValue, +}; #[cfg(test)] use insta::assert_debug_snapshot; @@ -63,7 +66,7 @@ impl<'a> metadata::File<'a> for File { #[derive(Clone, Debug, Default, Serialize)] pub struct FileProps { - pub is_disabled: Option>, String>>, + pub disabled: Option>, DisabledString>>, #[allow(clippy::type_complexity)] pub prefs: Option>, Vec<(String, String)>>>, pub tags: Option>, Vec>>, @@ -139,11 +142,11 @@ impl<'a> Properties<'a> for FileProps { any() .and_is(newline().or(end()).not()) .repeated() - .at_least(1) .to_slice() - .map(|s: &str| s.to_owned()), + .map(ArcStr::from) + .map(DisabledString::new), ) - .map(|((), is_disabled)| FileProp::Disabled(is_disabled)); + .map(|((), val)| FileProp::Disabled(val)); let implementation_status = helper .parser( @@ -164,7 +167,7 @@ impl<'a> Properties<'a> for FileProps { let (span, prop) = prop; let Self { implementation_status, - is_disabled, + disabled, prefs, tags, } = self; @@ -190,7 +193,7 @@ impl<'a> Properties<'a> for FileProps { FileProp::Prefs(new_prefs) => check_dupe_then_insert!(new_prefs, prefs, "prefs"), FileProp::Tags(new_tags) => check_dupe_then_insert!(new_tags, tags, "tags"), FileProp::Disabled(new_is_disabled) => { - check_dupe_then_insert!(new_is_disabled, is_disabled, DISABLED_IDENT) + check_dupe_then_insert!(new_is_disabled, disabled, DISABLED_IDENT) } } } @@ -453,7 +456,7 @@ const DISABLED_IDENT: &str = "disabled"; pub enum FileProp { Prefs(PropertyValue>, Vec<(String, String)>>), Tags(PropertyValue>, Vec>), - Disabled(PropertyValue>, String>), + Disabled(PropertyValue>, DisabledString>), ImplementationStatus(PropertyValue>, ImplementationStatus>), } @@ -521,7 +524,7 @@ fn format_file_properties(props: &FileProps) -> impl Display + '_ { lazy_format!(|f| { let FileProps { implementation_status, - is_disabled, + disabled, prefs, tags, } = props; @@ -559,8 +562,8 @@ fn format_file_properties(props: &FileProps) -> impl Display + '_ { )?; } - if let Some(is_disabled) = is_disabled { - write_prop_val(DISABLED_IDENT, is_disabled, Display::fmt, f)?; + if let Some(disabled) = disabled { + write_prop_val(DISABLED_IDENT, disabled, Display::fmt, f)?; } Ok(()) @@ -749,15 +752,11 @@ where .join_with(" ") )); let TestProps { - is_disabled, + disabled, expected, implementation_status, } = property; - if *is_disabled { - writeln!(f, "{indent}disabled: true")?; - } - fn write_normalized( f: &mut Formatter<'_>, indent: &dyn Display, @@ -841,6 +840,10 @@ where )?; } + if let Some(disabled) = disabled { + write_normalized(f, &indent, "disabled", disabled)?; + } + if let Some(exps) = expected { write_normalized(f, &indent, EXPECTED_IDENT, exps)?; } @@ -867,7 +870,7 @@ pub struct TestProps where Out: EnumSetType, { - pub is_disabled: bool, + pub disabled: Option>, pub expected: Option>>, pub implementation_status: Option>, } @@ -878,7 +881,7 @@ where { fn insert(&mut self, prop: TestProp, emitter: &mut Emitter>) { let Self { - is_disabled, + disabled, expected, implementation_status, } = self; @@ -946,11 +949,8 @@ where TestPropKind::Expected(val) => { conditional(emitter, span, EXPECTED_IDENT, expected, val) } - TestPropKind::Disabled => { - if *is_disabled { - emitter.emit(Rich::custom(span, "duplicate `disabled` key detected")) - } - *is_disabled = true; + TestPropKind::Disabled(val) => { + conditional(emitter, span, DISABLED_IDENT, disabled, val) } TestPropKind::ImplementationStatus(val) => conditional( emitter, @@ -984,7 +984,7 @@ where Out: EnumSetType, { Expected(PropertyValue>), - Disabled, + Disabled(PropertyValue), ImplementationStatus(PropertyValue), } @@ -1143,22 +1143,16 @@ where .parser( just(DISABLED_IDENT).to(()), conditional_term.clone(), - just("true").to(()), + any() + .and_is(newline().not()) + .repeated() + .to_slice() + .map(ArcStr::from) + .map(DisabledString::new), ) - .validate(|((), val), e, emitter| { - match val { - PropertyValue::Unconditional(()) => (), - PropertyValue::Conditional { .. } => { - emitter.emit(Rich::custom( - e.span(), - "conditional rules for `disabled` aren't supported yet", - )); - } - } - TestProp { - span: e.span(), - kind: TestPropKind::Disabled, - } + .map_with(|((), val), e| TestProp { + span: e.span(), + kind: TestPropKind::Disabled(val), }), helper .parser( diff --git a/moz-webgpu-cts/src/wpt/metadata/properties.rs b/moz-webgpu-cts/src/wpt/metadata/properties.rs index 8e3eaeb..7404c41 100644 --- a/moz-webgpu-cts/src/wpt/metadata/properties.rs +++ b/moz-webgpu-cts/src/wpt/metadata/properties.rs @@ -5,6 +5,7 @@ use std::{ ops::{BitOr, BitOrAssign, Index, IndexMut}, }; +use arcstr::ArcStr; use enum_map::EnumMap; use enumset::{EnumSet, EnumSetType}; use itertools::Itertools; @@ -206,6 +207,30 @@ where impl Eq for Expected where Out: EnumSetType + Eq {} +#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)] +pub struct DisabledString(ArcStr); + +impl DisabledString { + const FALSE: ArcStr = arcstr::literal!("@False"); + + pub fn new(inner: ArcStr) -> Self { + Self(if inner == Self::FALSE { + Self::FALSE + } else { + inner + }) + } + + pub fn value(&self) -> &str { + self.0.as_ref() + } +} + +impl Display for DisabledString { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Display::fmt(self.value(), f) + } +} /// A completely flat representation of [`NormalizedPropertyValue`] suitable for byte /// representation in memory. #[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Serialize)]