Skip to content

Commit 6cc135a

Browse files
WIP
TODO: figure out design, make things compile
1 parent 0b5de24 commit 6cc135a

5 files changed

Lines changed: 73 additions & 43 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

moz-webgpu-cts/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ publish = false
1111
dist = true
1212

1313
[dependencies]
14+
arcstr = { version = "1.1.5", features = ["serde"] }
1415
camino = { version = "1.1.6", features = ["serde1"] }
1516
clap = { version = "4.4.2", features = ["derive"] }
1617
env_logger = "0.10.0"

moz-webgpu-cts/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,14 +1046,14 @@ fn run(cli: Cli) -> ExitCode {
10461046
} = test;
10471047

10481048
let TestProps {
1049-
is_disabled,
1049+
disabled,
10501050
expected,
10511051
implementation_status: _,
10521052
} = properties;
10531053

10541054
let test_name = Arc::new(test_name);
10551055

1056-
if is_disabled {
1056+
if disabled.is_some() {
10571057
analysis.for_each_platform_mut(|analysis| {
10581058
analysis
10591059
.tests_with_disabled_or_skip
@@ -1161,12 +1161,12 @@ fn run(cli: Cli) -> ExitCode {
11611161

11621162
let Subtest { properties } = subtest;
11631163
let TestProps {
1164-
is_disabled,
1164+
disabled,
11651165
expected,
11661166
implementation_status: _,
11671167
} = properties;
11681168

1169-
if is_disabled {
1169+
if disabled.is_some() {
11701170
analysis
11711171
.windows
11721172
.tests_with_disabled_or_skip

moz-webgpu-cts/src/wpt/metadata.rs

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{
44
hash::Hash,
55
};
66

7+
use arcstr::ArcStr;
78
use clap::ValueEnum;
89
use enum_map::Enum;
910
use enumset::EnumSetType;
@@ -31,7 +32,9 @@ use whippit::{
3132
},
3233
};
3334

34-
use crate::wpt::metadata::properties::{ExpandedPropertyValue, Expected, NormalizedPropertyValue};
35+
use crate::wpt::metadata::properties::{
36+
DisabledString, ExpandedPropertyValue, Expected, NormalizedPropertyValue,
37+
};
3538

3639
#[cfg(test)]
3740
use insta::assert_debug_snapshot;
@@ -63,7 +66,7 @@ impl<'a> metadata::File<'a> for File {
6366

6467
#[derive(Clone, Debug, Default, Serialize)]
6568
pub struct FileProps {
66-
pub is_disabled: Option<PropertyValue<Expr<Value<'static>>, String>>,
69+
pub disabled: Option<PropertyValue<Expr<Value<'static>>, DisabledString>>,
6770
#[allow(clippy::type_complexity)]
6871
pub prefs: Option<PropertyValue<Expr<Value<'static>>, Vec<(String, String)>>>,
6972
pub tags: Option<PropertyValue<Expr<Value<'static>>, Vec<String>>>,
@@ -139,11 +142,11 @@ impl<'a> Properties<'a> for FileProps {
139142
any()
140143
.and_is(newline().or(end()).not())
141144
.repeated()
142-
.at_least(1)
143145
.to_slice()
144-
.map(|s: &str| s.to_owned()),
146+
.map(ArcStr::from)
147+
.map(DisabledString::new),
145148
)
146-
.map(|((), is_disabled)| FileProp::Disabled(is_disabled));
149+
.map(|((), val)| FileProp::Disabled(val));
147150

148151
let implementation_status = helper
149152
.parser(
@@ -164,7 +167,7 @@ impl<'a> Properties<'a> for FileProps {
164167
let (span, prop) = prop;
165168
let Self {
166169
implementation_status,
167-
is_disabled,
170+
disabled,
168171
prefs,
169172
tags,
170173
} = self;
@@ -190,7 +193,7 @@ impl<'a> Properties<'a> for FileProps {
190193
FileProp::Prefs(new_prefs) => check_dupe_then_insert!(new_prefs, prefs, "prefs"),
191194
FileProp::Tags(new_tags) => check_dupe_then_insert!(new_tags, tags, "tags"),
192195
FileProp::Disabled(new_is_disabled) => {
193-
check_dupe_then_insert!(new_is_disabled, is_disabled, DISABLED_IDENT)
196+
check_dupe_then_insert!(new_is_disabled, disabled, DISABLED_IDENT)
194197
}
195198
}
196199
}
@@ -453,7 +456,7 @@ const DISABLED_IDENT: &str = "disabled";
453456
pub enum FileProp {
454457
Prefs(PropertyValue<Expr<Value<'static>>, Vec<(String, String)>>),
455458
Tags(PropertyValue<Expr<Value<'static>>, Vec<String>>),
456-
Disabled(PropertyValue<Expr<Value<'static>>, String>),
459+
Disabled(PropertyValue<Expr<Value<'static>>, DisabledString>),
457460
ImplementationStatus(PropertyValue<Expr<Value<'static>>, ImplementationStatus>),
458461
}
459462

@@ -521,7 +524,7 @@ fn format_file_properties(props: &FileProps) -> impl Display + '_ {
521524
lazy_format!(|f| {
522525
let FileProps {
523526
implementation_status,
524-
is_disabled,
527+
disabled,
525528
prefs,
526529
tags,
527530
} = props;
@@ -559,8 +562,8 @@ fn format_file_properties(props: &FileProps) -> impl Display + '_ {
559562
)?;
560563
}
561564

562-
if let Some(is_disabled) = is_disabled {
563-
write_prop_val(DISABLED_IDENT, is_disabled, Display::fmt, f)?;
565+
if let Some(disabled) = disabled {
566+
write_prop_val(DISABLED_IDENT, disabled, Display::fmt, f)?;
564567
}
565568

566569
Ok(())
@@ -749,15 +752,11 @@ where
749752
.join_with(" ")
750753
));
751754
let TestProps {
752-
is_disabled,
755+
disabled,
753756
expected,
754757
implementation_status,
755758
} = property;
756759

757-
if *is_disabled {
758-
writeln!(f, "{indent}disabled: true")?;
759-
}
760-
761760
fn write_normalized<T>(
762761
f: &mut Formatter<'_>,
763762
indent: &dyn Display,
@@ -841,6 +840,10 @@ where
841840
)?;
842841
}
843842

843+
if let Some(disabled) = disabled {
844+
write_normalized(f, &indent, "disabled", disabled)?;
845+
}
846+
844847
if let Some(exps) = expected {
845848
write_normalized(f, &indent, EXPECTED_IDENT, exps)?;
846849
}
@@ -867,7 +870,7 @@ pub struct TestProps<Out>
867870
where
868871
Out: EnumSetType,
869872
{
870-
pub is_disabled: bool,
873+
pub disabled: Option<ExpandedPropertyValue<DisabledString>>,
871874
pub expected: Option<ExpandedPropertyValue<Expected<Out>>>,
872875
pub implementation_status: Option<ExpandedPropertyValue<ImplementationStatus>>,
873876
}
@@ -878,7 +881,7 @@ where
878881
{
879882
fn insert(&mut self, prop: TestProp<Out>, emitter: &mut Emitter<Rich<'a, char>>) {
880883
let Self {
881-
is_disabled,
884+
disabled,
882885
expected,
883886
implementation_status,
884887
} = self;
@@ -946,11 +949,8 @@ where
946949
TestPropKind::Expected(val) => {
947950
conditional(emitter, span, EXPECTED_IDENT, expected, val)
948951
}
949-
TestPropKind::Disabled => {
950-
if *is_disabled {
951-
emitter.emit(Rich::custom(span, "duplicate `disabled` key detected"))
952-
}
953-
*is_disabled = true;
952+
TestPropKind::Disabled(val) => {
953+
conditional(emitter, span, DISABLED_IDENT, disabled, val)
954954
}
955955
TestPropKind::ImplementationStatus(val) => conditional(
956956
emitter,
@@ -984,7 +984,7 @@ where
984984
Out: EnumSetType,
985985
{
986986
Expected(PropertyValue<Applicability, Expected<Out>>),
987-
Disabled,
987+
Disabled(PropertyValue<Applicability, DisabledString>),
988988
ImplementationStatus(PropertyValue<Applicability, ImplementationStatus>),
989989
}
990990

@@ -1143,22 +1143,16 @@ where
11431143
.parser(
11441144
just(DISABLED_IDENT).to(()),
11451145
conditional_term.clone(),
1146-
just("true").to(()),
1146+
any()
1147+
.and_is(newline().not())
1148+
.repeated()
1149+
.to_slice()
1150+
.map(ArcStr::from)
1151+
.map(DisabledString::new),
11471152
)
1148-
.validate(|((), val), e, emitter| {
1149-
match val {
1150-
PropertyValue::Unconditional(()) => (),
1151-
PropertyValue::Conditional { .. } => {
1152-
emitter.emit(Rich::custom(
1153-
e.span(),
1154-
"conditional rules for `disabled` aren't supported yet",
1155-
));
1156-
}
1157-
}
1158-
TestProp {
1159-
span: e.span(),
1160-
kind: TestPropKind::Disabled,
1161-
}
1153+
.map_with(|((), val), e| TestProp {
1154+
span: e.span(),
1155+
kind: TestPropKind::Disabled(val),
11621156
}),
11631157
helper
11641158
.parser(

moz-webgpu-cts/src/wpt/metadata/properties.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
ops::{BitOr, BitOrAssign, Index, IndexMut},
66
};
77

8+
use arcstr::ArcStr;
89
use enum_map::EnumMap;
910
use enumset::{EnumSet, EnumSetType};
1011
use itertools::Itertools;
@@ -206,6 +207,30 @@ where
206207

207208
impl<Out> Eq for Expected<Out> where Out: EnumSetType + Eq {}
208209

210+
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
211+
pub struct DisabledString(ArcStr);
212+
213+
impl DisabledString {
214+
const FALSE: ArcStr = arcstr::literal!("@False");
215+
216+
pub fn new(inner: ArcStr) -> Self {
217+
Self(if inner == Self::FALSE {
218+
Self::FALSE
219+
} else {
220+
inner
221+
})
222+
}
223+
224+
pub fn value(&self) -> &str {
225+
self.0.as_ref()
226+
}
227+
}
228+
229+
impl Display for DisabledString {
230+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
231+
Display::fmt(self.value(), f)
232+
}
233+
}
209234
/// A completely flat representation of [`NormalizedPropertyValue`] suitable for byte
210235
/// representation in memory.
211236
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Serialize)]

0 commit comments

Comments
 (0)