From da37e9e5df4288b547bed8c3d4480fbfe137214b Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 2 Dec 2026 13:54:10 -0800 Subject: [PATCH] validation test: skip an input whose version the toolchain refuses as above its newest Tally::refused now reads the input's own version and keys the skip on the toolchain's own refusal of it, compared with the version the toolchain says it takes: - typed AIR: the input's `!air.version` node, and `xcrun metallib`'s "air version set to X (...), but expecting Y". Skipped only where X is the input's version and Y is below it. - MSL: the source's `// metal-std:` standard S, and `xcrun metal`'s "invalid value 'S' in '-std=S'". Skipped only where every `metalX.Y` the compiler's notes offer is below S. Anything else stays a failure. finish lists each skipped input with both versions, then prints "SKIP of inputs above the toolchain's newest version". Over the public fixtures, 31 of 582 typed inputs state AIR 2.9.0 (545 state 2.8.0, the rest older) and 10 of 747 MSL sources name metal4.1. Those are the counts of the two refusals in CI run 46959260218 on macos-26 (31 and 10). On that runner, the two round trips should print "SKIP 31 of 582" and "SKIP 10 of 747" and pass. ci.yml is unchanged. The macos-26 arm64 image 20261123.0526.1 carries Xcode 26.0.1 to 26.6 (default 26.6) and SDKs up to macOS 26.5, so no Xcode on it takes AIR 2.9. --- .../src/air_writer/tests.rs | 78 ++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/crates/metal2vulkan-validation/src/air_writer/tests.rs b/crates/metal2vulkan-validation/src/air_writer/tests.rs index dd28ab703..55218700e 100644 --- a/crates/metal2vulkan-validation/src/air_writer/tests.rs +++ b/crates/metal2vulkan-validation/src/air_writer/tests.rs @@ -570,9 +570,20 @@ struct Tally { } impl Tally { - /// A step on the input at `path` failed with `error`: a failure. + /// A step on the input at `path` failed with `error`: skipped where it is the toolchain's own + /// refusal of the version the input states, above the newest version the toolchain says it + /// takes ([`air_ceiling`], [`std_ceiling`]); else a failure. fn refused(&mut self, path: &Path, error: &str) { - self.failures.push(format!("{}: {error}", path.display())); + let text = std::fs::read_to_string(path).unwrap_or_default(); + let above = (air_version_of(&text).and_then(|input| air_ceiling(error, input))) + .or_else(|| metal_std_of(&text).and_then(|std| std_ceiling(error, std))); + match above { + Some((input, newest)) => self.above.push(format!( + "{}: the input's {input}, the toolchain's newest {newest}", + path.display() + )), + None => self.failures.push(format!("{}: {error}", path.display())), + } } /// Lists each skipped input, and the total of those above the toolchain's newest version; then @@ -596,6 +607,69 @@ impl Tally { } } +/// The dotted numbers of `version` (`2.9.0`, `2.8`), as major, minor and patch, a missing one 0. +fn version_numbers(version: &str) -> Option<[u32; 3]> { + let mut numbers = [0; 3]; + for (at, part) in version.split('.').enumerate() { + *numbers.get_mut(at)? = part.parse().ok()?; + } + Some(numbers) +} + +/// The AIR version typed AIR text states: the operands of the node its `!air.version` names. +fn air_version_of(text: &str) -> Option<[u32; 3]> { + let node = (text.lines()) + .find_map(|l| l.strip_prefix("!air.version = !{!"))? + .strip_suffix('}')?; + let prefix = format!("!{node} = !{{"); + let operands = (text.lines()) + .find_map(|l| l.strip_prefix(prefix.as_str()))? + .strip_suffix('}')?; + let numbers: Vec = (operands.split(',')) + .map(|o| o.trim().strip_prefix("i32 ")?.parse().ok()) + .collect::>()?; + numbers.try_into().ok() +} + +/// The Metal standard an MSL source names: its `// metal-std:` line. +fn metal_std_of(text: &str) -> Option<&str> { + (text.lines()) + .find_map(|l| l.trim().strip_prefix("// metal-std:")) + .map(str::trim) +} + +/// `xcrun metallib`'s refusal of an input of AIR version `input` in `error`: "air version set to +/// X (...), but expecting Y", where X is the input's own version and Y, the version the toolchain +/// says it expects, is below it. The two versions as text; `None` for any other error. +fn air_ceiling(error: &str, input: [u32; 3]) -> Option<(String, String)> { + let (set, rest) = error.split_once("air version set to ")?.1.split_once(' ')?; + let expecting = rest + .split_once("but expecting ")? + .1 + .split_whitespace() + .next()?; + let ok = version_numbers(set)? == input && version_numbers(expecting)? < input; + ok.then(|| (format!("AIR {set}"), format!("AIR {expecting}"))) +} + +/// `xcrun metal`'s refusal of the Metal standard `std` a source names, in `error`: "invalid value +/// 'S' in '-std=S'" with S the source's own, where every `metalX.Y` standard the compiler's notes +/// offer is below it. The source's standard and the newest offered; `None` for any other error. +fn std_ceiling(error: &str, std: &str) -> Option<(String, String)> { + if !error.contains(&format!("invalid value '{std}' in '-std={std}'")) { + return None; + } + let input = version_numbers(std.strip_prefix("metal")?)?; + let newest = (error.lines()) + .filter_map(|l| l.split_once("note: use 'metal")?.1.split_once('\'')) + .filter_map(|(offered, _)| version_numbers(offered)) + .max()?; + (newest < input).then(|| { + let newest = format!("metal{}.{}", newest[0], newest[1]); + (std.to_string(), newest) + }) +} + /// Round trip every input, each outcome in a [`Tally`]: an input the decoder itself refuses is /// listed visibly, not failed. fn round_trip_all(