Validation test: the oracle-fuel fixture round trip skips what the toolchain is too old for and puts its status at the oracle's slot

oracle_fuel::tests::public_fixtures_with_loops_round_trip_instrumented failed on macOS CI (run
47003321413, macos-26, MetalToolchain 17.6), the first macOS run to reach it, in three ways:

- Ten .metal fixtures that name metal4.1, newer than that toolchain's metal4.0: "invalid value
  'metal4.1' in '-std=metal4.1'".
- tns_mm_fp8, tns_mm_left and tns_mm_v2 .air.ll: metal-opt "unrecognized architecture
  'air64_v29' provided." for the fixtures' own target triple.
- parked_heap_handles (.metal and .air.ll, four entries each): "buffer argument m2v_oracle_status
  has invalid location (<29,1>)". The fixture binds buffers 28 and 29, and the test put every
  status buffer at a fixed slot 29. The oracle itself puts it at the highest slot the entry's
  interface leaves free (NativeBufferSlots::from_interface(..).allocate(), via producer_slots);
  that is slot 30 here. This one is a test defect on any SDK.

The air writer's round trips already skip, list and count an input above the toolchain's AIR
version or Metal standard (Tally::refused). That rule moves into
air_writer::tests::above_the_toolchain and gains a third case, arch_ceiling: metal-opt's
refusal of an `air64_v<N>` architecture that the input's own target triple names. Each is the
toolchain's own refusal of something the input states; any other error stays a failure.

The oracle-fuel round trip now applies above_the_toolchain to a failure of a step on the fixture's
own AIR (compiling or assembling it, and finding the strictest level metal-opt passes). It prints
each skip and their count, "SKIP N of M inputs above the toolchain's newest version", as the air
writer's round trips do. A failure of the instrumented module's own round trip is never skipped.
Each entry is instrumented with its status buffer at the slot the oracle gives it, from the
entry's interface (status_slot).

Verified: red job m3-max-81148 (msi CPU) failed
an_input_of_an_architecture_the_toolchain_does_not_know_is_skipped_and_counted, and
every_other_toolchain_error_fails passed, at bec8a8dea1. The green and the macOS runs are named
in the hand-over.
This commit is contained in:
Anees Iqbal committed 2026-12-02 18:09:53 -08:00
1 parent 4bd7516305
commit 9186e2fe46
2 files changed
+96 -22

No files matched your search

@@ -570,18 +570,12 @@ struct Tally {
}
impl Tally {
/// 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.
/// A step on the input at `path` failed with `error`: skipped where the toolchain refused a
/// version the input states that is newer than it takes ([`above_the_toolchain`]); else a
/// failure.
fn refused(&mut self, path: &Path, error: &str) {
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()
)),
match above_the_toolchain(path, error) {
Some(why) => self.above.push(format!("{}: {why}", path.display())),
None => self.failures.push(format!("{}: {error}", path.display())),
}
}
@@ -607,6 +601,37 @@ impl Tally {
}
}
/// Why the toolchain refused the input at `path` with `error`, where `error` is its own refusal of
/// a version the input states that is newer than the toolchain takes: the input's AIR version
/// ([`air_ceiling`]), its Metal standard ([`std_ceiling`]) or its target architecture
/// ([`arch_ceiling`]). `None` for any other error, which is a failure.
pub(crate) fn above_the_toolchain(path: &Path, error: &str) -> Option<String> {
let text = std::fs::read_to_string(path).unwrap_or_default();
let ceiling = (air_version_of(&text).and_then(|input| air_ceiling(error, input)))
.or_else(|| metal_std_of(&text).and_then(|std| std_ceiling(error, std)))
.map(|(input, newest)| format!("the input's {input}, the toolchain's newest {newest}"));
ceiling.or_else(|| target_arch_of(&text).and_then(|arch| arch_ceiling(error, arch)))
}
/// The architecture of the `target triple` typed AIR text states: the triple's first part.
fn target_arch_of(text: &str) -> Option<&str> {
let triple = (text.lines())
.find_map(|l| l.strip_prefix("target triple = \""))?
.strip_suffix('"')?;
triple.split('-').next()
}
/// `metal-opt`'s refusal of the input's own AIR architecture `arch` in `error`: "unrecognized
/// architecture 'A' provided", A an AIR architecture of a version (`air64_v29`), which an older
/// toolchain does not know. The reason as text; `None` for any other error.
fn arch_ceiling(error: &str, arch: &str) -> Option<String> {
let versioned = (arch.strip_prefix("air64_v"))
.is_some_and(|v| !v.is_empty() && v.bytes().all(|b| b.is_ascii_digit()));
let refused = error.contains(&format!("unrecognized architecture '{arch}' provided"));
(versioned && refused)
.then(|| format!("the input's architecture {arch}, which the toolchain does not know"))
}
/// 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];
@@ -10,6 +10,7 @@
//! `metal-opt -passes=verify` and `metallib`, the oracle's next steps: synthetic typed MSL and
//! every public fixture whose entry reaches a loop.
use std::collections::BTreeMap;
use std::ffi::OsString;
use std::path::PathBuf;
@@ -26,8 +27,11 @@ use metal2vulkan_air::ir::{
use super::plan::barrier_budget;
use super::status::{check_status, initial_status, STATUS_BYTES};
use super::*;
use crate::air_writer::tests::compile_msl;
use crate::air_writer::tests::{above_the_toolchain, compile_msl};
use crate::air_writer::{decode_as_written, metal_as, write};
use crate::check::interface::AirInterface;
use crate::check::loop_free::DecodedModule;
use crate::executor_contract::buffer_slots::NativeBufferSlots;
use crate::gpu::compile::xcrun;
use crate::ScratchDir;
@@ -1528,12 +1532,25 @@ fn has_loop(m: &Module) -> bool {
})
}
/// The status slot the oracle gives `entry` of `bitcode`: the highest buffer slot the entry's
/// interface leaves free, as the oracle allocates it (`NativeBufferSlots::allocate`).
fn status_slot(bitcode: &[u8], entry: &str) -> Result<u32, String> {
let decoded = DecodedModule::from_bitcode(entry, bitcode).map_err(|e| format!("{e:?}"))?;
let abi = decoded.abi().map_err(str::to_string)?;
let interface = AirInterface::new(decoded.module(), abi, entry, &BTreeMap::new())?;
NativeBufferSlots::from_interface(&interface)?.allocate()
}
/// Every public fixture with a loop, as typed AIR (`.air.ll` through `metal-as`, `.metal`
/// through `metal -c`): each entry that reaches a loop is instrumented and round-trips. Typed
/// refusals are listed visibly; any other error fails.
/// through `metal -c`): each entry that reaches a loop is instrumented with its status buffer at
/// the slot the oracle gives it ([`status_slot`]) and round-trips. Typed refusals are listed
/// visibly; a fixture whose own version the toolchain refuses as newer than it takes is skipped,
/// listed and counted, as the air writer's round trips skip it (`above_the_toolchain`); any other
/// error fails.
#[test]
fn public_fixtures_with_loops_round_trip_instrumented() {
if !have_xcrun("public_fixtures_with_loops_round_trip_instrumented") {
const TEST: &str = "public_fixtures_with_loops_round_trip_instrumented";
if !have_xcrun(TEST) {
return;
}
let scratch = ScratchDir::new("oracle-fuel-fixtures").unwrap();
@@ -1549,6 +1566,17 @@ fn public_fixtures_with_loops_round_trip_instrumented() {
}
inputs.sort();
let (mut instrumented, mut refused, mut failures) = (0, Vec::new(), Vec::new());
let mut above = Vec::new();
// A step on the fixture's own AIR failed: skipped where the toolchain refused a version the
// fixture states as newer than it takes, else a failure.
let fixture_failed =
|[above, failures]: [&mut Vec<String>; 2], path: &PathBuf, error: String| {
let name = path.display();
match above_the_toolchain(path, &error) {
Some(why) => above.push(format!("{name}: {why}")),
None => failures.push(format!("{name}: {error}")),
}
};
for path in &inputs {
let name = path.to_string_lossy().into_owned();
let bytes = if name.ends_with(".air.ll") {
@@ -1558,9 +1586,12 @@ fn public_fixtures_with_loops_round_trip_instrumented() {
} else {
compile_msl(path, &scratch)
};
let Ok(bytes) = bytes else {
failures.push(format!("{name}: {}", bytes.unwrap_err()));
continue;
let bytes = match bytes {
Ok(bytes) => bytes,
Err(e) => {
fixture_failed([&mut above, &mut failures], path, e);
continue;
}
};
let Ok(d) = decode_as_written(&bytes, &mut Meter::new(&Budget::default())) else {
continue; // outside the writer's input
@@ -1574,14 +1605,22 @@ fn public_fixtures_with_loops_round_trip_instrumented() {
let level = match strictest_level(&bytes, &scratch) {
Ok(level) => level,
Err(e) => {
failures.push(format!("{name}: {e}"));
fixture_failed([&mut above, &mut failures], path, e);
continue;
}
};
for entry in stage_entries(&d.module) {
let slot = match status_slot(&bytes, &entry) {
Ok(slot) => slot,
Err(e) => {
failures.push(format!("{name} @{entry}: {e}"));
continue;
}
};
let d = decode_bytes(&bytes);
let pointees = Pointees::from_table(&d.pointees, &d.module);
match instrument(d.module, pointees, d.enum_attrs, &entry, &config()) {
let config = FuelConfig::oracle(slot);
match instrument(d.module, pointees, d.enum_attrs, &entry, &config) {
Ok(out) if out.report.loops + out.report.barrier_loops == 0 => {}
Ok(out) => match round_trip_at(&out, &scratch, level) {
Ok(()) => instrumented += 1,
@@ -1593,12 +1632,22 @@ fn public_fixtures_with_loops_round_trip_instrumented() {
}
}
for r in &refused {
eprintln!("public_fixtures_with_loops_round_trip_instrumented: REFUSED {r}");
eprintln!("{TEST}: REFUSED {r}");
}
for a in &above {
eprintln!("{TEST}: SKIP (above the toolchain's newest version): {a}");
}
if !above.is_empty() {
eprintln!(
"{TEST}: SKIP {} of {} inputs above the toolchain's newest version",
above.len(),
inputs.len()
);
}
assert!(failures.is_empty(), "{}", failures.join("\n\n"));
assert!(instrumented > 0, "no fixture entry reached a loop");
eprintln!(
"public_fixtures_with_loops_round_trip_instrumented: {instrumented} entries instrumented, {} refused",
"{TEST}: {instrumented} entries instrumented, {} refused",
refused.len()
);
}