From fe3d8fe1827a556ba01fe3781a9eebb31206ee49 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Fri, 20 Nov 2026 12:38:58 -0800 Subject: [PATCH] :bug: Name rt's refusals as structure alone in lines and NSErrors The first line of each of rt's refusal kinds wrote rt's error as it displays, and the NSError a refused creator answers carried the same text. For the translator's refusals that text names the guest's functions, symbols and entry points ("at function ...", "(air....)", EntryNotFound's request), so the host's log and the decoder's refusal lines carried the guest's names. said() now gives rt's error as a Display of structure alone: the translator's refusal as the feature it refused, what it needs and its attachment, any other translator error as a refusal alone, and rt's other errors as they display. rt_refused's first line and rt_refused_error's NSError both use it, as the per-name detail line already did. A kernel made unspecialized that declares constants is refused without its name too. Log lines and NSError descriptions are free under the contract (the guest sees an NSError's domain and code only), so nothing changes for the guest. A test feeds refusals naming secret_fn through each path in a child and checks its stderr holds no such name. --- .../src/rt_platform/pipeline.rs | 47 ++++- .../src/rt_platform/unbuilt.rs | 180 ++++++++++++++---- 2 files changed, 184 insertions(+), 43 deletions(-) diff --git a/crates/reims-vgpu-vulkan/src/rt_platform/pipeline.rs b/crates/reims-vgpu-vulkan/src/rt_platform/pipeline.rs index 697b516c4..5aeb14cad 100644 --- a/crates/reims-vgpu-vulkan/src/rt_platform/pipeline.rs +++ b/crates/reims-vgpu-vulkan/src/rt_platform/pipeline.rs @@ -275,7 +275,8 @@ pub fn of_descriptor( /// Whether Metal makes a state of `stage` by the creator `sel`: none of a function made /// unspecialized that declares function constants (`FunctionDescriptor::needs_specialization`), /// whose creation ends the process on Metal. `Err` is the creator's `NSError`, counted: Metal's -/// refusal, or the translator's of the function's constants. +/// refusal, or the translator's of the function's constants. Neither names the function, whose +/// name is the guest's. pub(super) fn specialized( sel: &'static str, stage: &rt::FunctionDescriptor, @@ -283,10 +284,7 @@ pub(super) fn specialized( match stage.needs_specialization(&Budget::standard(), &StageEntries::default()) { Ok(false) => Ok(()), Ok(true) => { - let why = format!( - "function {} declares function constants and was made unspecialized", - stage.function.info().name - ); + let why = "a function that declares function constants was made unspecialized"; Err(refused_error_as(sel, RtRefusal::Refused, &why)) } Err(error) => Err(rt_refused_error(sel, &rt::Error::Translation(error))), @@ -636,6 +634,45 @@ mod tests { .map_or(0, |(_, n)| n) } + /// A kernel made unspecialized that declares function constants is refused, and neither the + /// refusal's line nor its `NSError` names the function, whose name is the guest's (in a child, + /// whose stderr is its own) + #[test] + fn an_unspecialized_function_s_refusal_names_no_function() { + use crate::core::testkit::death::{Expect, Options, Outcome, run}; + const NAME: &str = "optional_constant"; + run( + Expect::Any, + Options::default(), + module_path!(), + "an_unspecialized_function_s_refusal_names_no_function", + |_| { + let library = rt::Library::from_metallib(OPTIONAL).expect("a library"); + let kernel = library.function(NAME).expect("the kernel"); + let stage = rt::FunctionDescriptor::new(kernel); + let refused = specialized(WITH_FUNCTION, &stage).expect_err("a refusal"); + super::super::unbuilt::say(&format!("test: NSError: {}\n", refused.description)); + }, + |r| { + assert_eq!(r.outcome(), &Outcome::Returned, "{}", r.stderr()); + let out = r.stderr(); + let said = "a function that declares function constants was made unspecialized"; + let line = format!( + "reims-vgpu: {WITH_FUNCTION}: metal2vulkan-runtime refused it ({said}); \ + refused (rt-refused-metal), the first of its kind" + ); + let answered = format!( + "test: NSError: metal2vulkan-runtime refused it: {said} \ + (rt-refused-metal)" + ); + let lines: Vec<&str> = out.lines().collect(); + assert!(lines.contains(&line.as_str()), "{out}"); + assert!(lines.contains(&answered.as_str()), "{out}"); + assert!(!out.contains(NAME), "{out}"); + }, + ); + } + /// Each value of a stage-input descriptor is the translator's, a dynamic stride none; a value /// it has none of is named. #[test] diff --git a/crates/reims-vgpu-vulkan/src/rt_platform/unbuilt.rs b/crates/reims-vgpu-vulkan/src/rt_platform/unbuilt.rs index 4b3060a43..ccbba981f 100644 --- a/crates/reims-vgpu-vulkan/src/rt_platform/unbuilt.rs +++ b/crates/reims-vgpu-vulkan/src/rt_platform/unbuilt.rs @@ -11,16 +11,17 @@ //! //! A call of a built piece that rt refuses (its `Error`: a limit, a refusal of Metal's, a known //! gap, a failed Vulkan call) answers the same way, counted under the error's kind, -//! `rt-refused-` ([`RtRefusal::code`]), its first line naming the call and rt's error. The -//! first of each of rt's kinds by its name in the boot diagnostics (`Draw-AttachmentRead`, -//! `TextureCopy`, `RenderPass`, `Limit-TextureSamples`, `Translation-Lowering`), whichever count -//! it goes to, writes a line of its own too: rt's error as it displays and as it debugs, which -//! carries the gap's fields (the translator's refusal as the feature it refused, what it needs and -//! its attachment alone), and what the call asked of rt where its site names it, as structure -//! alone: a texture's descriptor, a view's and the texture it views, a copy's kind, textures, -//! places, buffer layout and what its two textures share, a pass's attachments and store actions, -//! a draw's primitive type and its pipeline state's rasterization fields ([`refusal_detail`]). No -//! name of the guest's (a function's, a symbol's, a label) is in it. A texture rt makes none of +//! `rt-refused-` ([`RtRefusal::code`]), its first line naming the call and rt's error as +//! structure alone ([`said`]), as the `NSError` a creator answers names it. The first of each of +//! rt's kinds by its name in the boot diagnostics (`Draw-AttachmentRead`, `TextureCopy`, +//! `RenderPass`, `Limit-TextureSamples`, `Translation-Lowering`), whichever count it goes to, +//! writes a line of its own too: rt's error as [`said`] gives it and, but for the translator's +//! refusal, as it debugs, which carries the gap's fields, and what the call asked of rt where its +//! site names it, as structure alone: a texture's descriptor, a view's and the texture it views, a +//! copy's kind, textures, places, buffer layout and what its two textures share, a pass's +//! attachments and store actions, a draw's primitive type and its pipeline state's rasterization +//! fields ([`refusal_detail`]). No name of the guest's (a function's, a symbol's, a library's, a +//! label) is in a line or an `NSError` of this module's. A texture rt makes none of //! for its pixel format (`Gap::TextureFormat`) is counted under its format's own code instead, //! `rt-refused-texture-format-` ([`rt_refused_texture`]), so a boot's counts line gives each //! format number with its count. A pipeline state's imageblock length rt refuses @@ -333,12 +334,12 @@ static SAID_RT: [AtomicBool; RtRefusal::ALL.len()] = [const { AtomicBool::new(false) }; RtRefusal::ALL.len()]; /// Counts rt's refusal `error` of the call `sel` under its kind's code, and the process's first of -/// the kind writes its line on stderr, naming the call and the error. The caller answers as -/// Metal's call answers where it fails. Returns the kind. +/// the kind writes its line on stderr, naming the call and the error as [`said`] gives it. The +/// caller answers as Metal's call answers where it fails. Returns the kind. pub fn rt_refused(sel: &'static str, error: &rt::Error) -> RtRefusal { let kind = RtRefusal::of(error); super::diag::refusal(error); - refused_as(sel, kind, error); + refused_as(sel, kind, &said(error)); refusal_detail(sel, error, None); kind } @@ -380,8 +381,9 @@ fn first_named(name: String) -> bool { } /// The line [`refusal_detail`] writes of rt's `error` of the call `sel`, of the kind `name`, and -/// what the call asked of rt, `what`, where it names it: rt's error as [`said`] gives it, the -/// name, and the code of [`counted_code`]. +/// what the call asked of rt, `what`, where it names it: rt's error as [`said`] gives it and, but +/// for the translator's refusal, whose fields can name the guest's functions and symbols, as it +/// debugs (its variant's fields), the name, and the code of [`counted_code`]. fn detail_line( sel: &str, error: &rt::Error, @@ -389,36 +391,54 @@ fn detail_line( what: Option<&dyn std::fmt::Display>, ) -> String { let (code, said) = (counted_code(error), said(error)); + let fields = match error { + rt::Error::Translation(_) => String::new(), + _ => format!("; {error:?}"), + }; match what { Some(what) => format!( - "reims-vgpu: {sel}: metal2vulkan-runtime refused it ({said}); the first of {name} \ - ({code}): {what}\n" + "reims-vgpu: {sel}: metal2vulkan-runtime refused it ({said}{fields}); the first of \ + {name} ({code}): {what}\n" ), None => format!( - "reims-vgpu: {sel}: metal2vulkan-runtime refused it ({said}); the first of {name} \ - ({code})\n" + "reims-vgpu: {sel}: metal2vulkan-runtime refused it ({said}{fields}); the first of \ + {name} ({code})\n" ), } } -/// rt's `error` in [`detail_line`]: as it displays and as it debugs (its variant's fields), but -/// the translator's refusal, whose display and fields can name the guest's functions and symbols, -/// as structure alone: the feature it refused and what it needs (their variants' fields) and the -/// attachment it is tied to, else its error's variant -/// ([`refusal_name`](super::diag::refusal_name)). -fn said(error: &rt::Error) -> String { - use metal2vulkan::error::Error as Translator; - match error { - rt::Error::Translation(Translator::Unsupported(u)) => { - let at = (u.location.as_ref()).and_then(|l| l.attachment()); - let at = at.map_or(String::new(), |a| format!(", at the {a}")); - format!( - "the translator refused the feature {:?}, needing {:?}{at}", - u.feature, u.needs - ) +/// rt's `error` as structure alone ([`Said`]), for a line or an `NSError` that names it, which +/// may name an error of any kind. +pub fn said(error: &rt::Error) -> Said<'_> { + Said(error) +} + +/// rt's error as [`said`] gives it: as it displays, but the translator's refusal, whose display +/// and fields can name the guest's functions, symbols and libraries, as the feature it refused and +/// what it needs (their variants' fields, the translator's enums and numbers) and the attachment +/// it is tied to, else as a refusal of the translator's alone. rt's other errors name nothing of +/// the guest's: their fields are rt's own enums and numbers, a Vulkan call and its result, and the +/// host's own I/O and loader errors. +pub struct Said<'a>(&'a rt::Error); + +impl std::fmt::Display for Said<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + use metal2vulkan::error::Error as Translator; + match self.0 { + rt::Error::Translation(Translator::Unsupported(u)) => { + write!( + f, + "the translator refused the feature {:?}, needing {:?}", + u.feature, u.needs + )?; + match (u.location.as_ref()).and_then(|l| l.attachment()) { + Some(at) => write!(f, ", at the {at}"), + None => Ok(()), + } + } + rt::Error::Translation(_) => f.write_str("the translator refused it"), + error => write!(f, "{error}"), } - rt::Error::Translation(_) => "the translator refused it".to_owned(), - _ => format!("{error}; {error:?}"), } } @@ -572,10 +592,10 @@ fn metal_places(error: &rt::Error) -> bool { } /// [`rt_refused_create`] of a creator with an `error:` out-parameter: the `NSError` it answers, in -/// [`RT_DOMAIN`], code 0, naming rt's error and its kind's code. +/// [`RT_DOMAIN`], code 0, naming rt's error as [`said`] gives it and its kind's code. pub fn rt_refused_error(sel: &'static str, error: &rt::Error) -> NsErrorText { let kind = rt_refused_create(sel, error); - rt_error(kind, error) + rt_error(kind, &said(error)) } /// [`refused_as`] of a creator with an `error:` out-parameter, noted for core as a gap of the @@ -908,6 +928,90 @@ mod tests { ); } + /// No line the library writes of the translator's refusals, nor the `NSError` a creator + /// answers of one, names what the guest named: refusals whose display names a function, a + /// symbol and an entry point (`secret_fn`, a name of our own) write the first line of their + /// kind, the first line of each name and an `NSError` each, which give the refusal as + /// structure alone (in a child, whose stderr is its own) + #[test] + fn no_line_of_a_translator_refusal_names_the_guest_s_function() { + use crate::core::testkit::death::{Expect, Options, Outcome, run}; + use metal2vulkan::error::{DescriptorError, DiagName, Error as Translator, Feature}; + use metal2vulkan::error::{Location, LowerFamily, RuntimeInput, Unsupported}; + const SECRET: &str = "secret_fn"; + let refusals = || { + let at = Location::function(DiagName::new(SECRET), Some(3), Some(9)); + let lowering = Unsupported::not_implemented(Feature::Lowering(LowerFamily::Texture)) + .at(at) + .naming(DiagName::new(SECRET)); + [ + Translator::Unsupported(lowering), + Translator::InvalidDescriptor(DescriptorError::EntryNotFound { + requested: DiagName::new(SECRET), + available: 2, + }), + Translator::NeedsInput(RuntimeInput::LinkedFunction { + symbol: DiagName::new(SECRET), + }), + ] + .map(rt::Error::Translation) + }; + for error in refusals() { + assert!(error.to_string().contains(SECRET), "{error}"); + } + run( + Expect::Any, + Options::default(), + module_path!(), + "no_line_of_a_translator_refusal_names_the_guest_s_function", + |_| { + for error in refusals() { + rt_refused("newRenderPipelineStateWithDescriptor:error:", &error); + let sel = "newComputePipelineStateWithFunction:error:"; + let answered = rt_refused_error(sel, &error); + say(&format!("test: NSError: {}\n", answered.description)); + } + }, + |r| { + assert_eq!(r.outcome(), &Outcome::Returned, "{}", r.stderr()); + let out = r.stderr(); + let lines: Vec<&str> = out.lines().collect(); + assert!( + lines.contains( + &"reims-vgpu: newRenderPipelineStateWithDescriptor:error:: \ + metal2vulkan-runtime refused it (the translator refused the feature \ + Lowering(Texture), needing NotImplemented); refused \ + (rt-refused-translation), the first of its kind" + ), + "{out}" + ); + for name in ["Lowering", "InvalidDescriptor", "NeedsInput"] { + let first = format!("the first of Translation-{name} (rt-refused-translation)"); + assert!(lines.iter().any(|l| l.ends_with(&first)), "{first}: {out}"); + } + let answered = |said: &str| { + format!( + "test: NSError: metal2vulkan-runtime refused it: {said} \ + (rt-refused-translation)" + ) + }; + let lowering = "the translator refused the feature Lowering(Texture), needing \ + NotImplemented"; + let answers = [ + lowering, + "the translator refused it", + "the translator refused it", + ] + .map(answered); + let said: Vec<&str> = (lines.iter().copied()) + .filter(|l| l.starts_with("test: NSError: ")) + .collect(); + assert_eq!(said, answers, "{out}"); + assert!(!out.contains(SECRET), "{out}"); + }, + ); + } + /// The refusals counted under a code of their own (a pixel format's, an imageblock length's, a /// heap texture's place Metal places) write their name's line too, as every refusal the boot /// diagnostics count by name does.