From 933de407f6d794b652d9120d618425f6a7b73514 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 7 May 2026 15:41:35 -0400 Subject: [PATCH] nak: Don't use the proc macro to implement auto-boxing of ops We can do this with a generic trait implementation as long as we have something on it to keep it from recursing on Box. Part-of: --- src/nouveau/compiler/nak/ir.rs | 10 ++++++++ src/nouveau/compiler/nak/ir_proc.rs | 38 ----------------------------- 2 files changed, 10 insertions(+), 38 deletions(-) diff --git a/src/nouveau/compiler/nak/ir.rs b/src/nouveau/compiler/nak/ir.rs index cb056f3332a..29c9a5cb93a 100644 --- a/src/nouveau/compiler/nak/ir.rs +++ b/src/nouveau/compiler/nak/ir.rs @@ -8256,6 +8256,16 @@ const _: () = { debug_assert!(size_of::() == 16); }; +// The DisplayOp constraint exists to keep the type system from recursing +impl From for Op +where + Box: Into, +{ + fn from(op: T) -> Self { + Box::new(op).into() + } +} + impl Op { pub fn is_branch(&self) -> bool { matches!( diff --git a/src/nouveau/compiler/nak/ir_proc.rs b/src/nouveau/compiler/nak/ir_proc.rs index 371aafd8bd7..34ca9253bc5 100644 --- a/src/nouveau/compiler/nak/ir_proc.rs +++ b/src/nouveau/compiler/nak/ir_proc.rs @@ -145,32 +145,6 @@ pub fn enum_derive_display_op(input: TokenStream) -> TokenStream { } } -fn into_box_inner_type<'a>(from_type: &'a syn::Type) -> Option<&'a syn::Type> { - let last = match from_type { - Type::Path(TypePath { path, .. }) => path.segments.last()?, - _ => return None, - }; - - if last.ident != "Box" { - return None; - } - - let PathArguments::AngleBracketed(AngleBracketedGenericArguments { - args, - .. - }) = &last.arguments - else { - panic!("Expected Box (with angle brackets)"); - }; - - for arg in args { - if let GenericArgument::Type(inner_type) = arg { - return Some(inner_type); - } - } - panic!("Expected Box to use a type argument"); -} - #[proc_macro_derive(FromVariants)] pub fn derive_from_variants(input: TokenStream) -> TokenStream { let DeriveInput { ident, data, .. } = parse_macro_input!(input); @@ -198,18 +172,6 @@ pub fn derive_from_variants(input: TokenStream) -> TokenStream { }; impls.extend(quote); - - if let Some(inner_type) = into_box_inner_type(from_type) { - let quote = quote! { - impl From<#inner_type> for #enum_type { - fn from(value: #inner_type) -> Self { - From::from(Box::new(value)) - } - } - }; - - impls.extend(quote); - } } }