From 7d0c50f20aebd8bc695cc1f935fcd6ec7385396c Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Wed, 6 May 2026 18:18:49 -0400 Subject: [PATCH] nak: Move Srcs/DstsAsSlice implementations This allows us to remove the dependence on AsSlice. Part-of: --- src/nouveau/compiler/nak/ir.rs | 52 +++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/nouveau/compiler/nak/ir.rs b/src/nouveau/compiler/nak/ir.rs index 8d5feffb9c7..d3a7aa40723 100644 --- a/src/nouveau/compiler/nak/ir.rs +++ b/src/nouveau/compiler/nak/ir.rs @@ -1347,7 +1347,21 @@ impl SrcType { pub type SrcTypeList = AttrList; -pub trait SrcsAsSlice: AsSlice { +pub trait SrcsAsSlice { + fn srcs_as_slice(&self) -> &[Src]; + + fn srcs_as_mut_slice(&mut self) -> &mut [Src]; + + fn src_types(&self) -> SrcTypeList; + + fn src_idx(&self, src: &Src) -> usize { + let r = self.srcs_as_slice().as_ptr_range(); + assert!(r.contains(&(src as *const Src))); + unsafe { (src as *const Src).offset_from(r.start) as usize } + } +} + +impl> SrcsAsSlice for T { fn srcs_as_slice(&self) -> &[Src] { self.as_slice() } @@ -1359,16 +1373,8 @@ pub trait SrcsAsSlice: AsSlice { fn src_types(&self) -> SrcTypeList { self.attrs() } - - fn src_idx(&self, src: &Src) -> usize { - let r = self.srcs_as_slice().as_ptr_range(); - assert!(r.contains(&(src as *const Src))); - unsafe { (src as *const Src).offset_from(r.start) as usize } - } } -impl> SrcsAsSlice for T {} - fn all_dsts_uniform(dsts: &[Dst]) -> bool { let mut uniform = None; for dst in dsts { @@ -1403,20 +1409,14 @@ impl DstType { pub type DstTypeList = AttrList; -pub trait DstsAsSlice: AsSlice { - fn dsts_as_slice(&self) -> &[Dst] { - self.as_slice() - } +pub trait DstsAsSlice { + fn dsts_as_slice(&self) -> &[Dst]; - fn dsts_as_mut_slice(&mut self) -> &mut [Dst] { - self.as_mut_slice() - } + fn dsts_as_mut_slice(&mut self) -> &mut [Dst]; // Currently only used by test code #[allow(dead_code)] - fn dst_types(&self) -> DstTypeList { - self.attrs() - } + fn dst_types(&self) -> DstTypeList; fn dst_idx(&self, dst: &Dst) -> usize { let r = self.dsts_as_slice().as_ptr_range(); @@ -1425,7 +1425,19 @@ pub trait DstsAsSlice: AsSlice { } } -impl> DstsAsSlice for T {} +impl> DstsAsSlice for T { + fn dsts_as_slice(&self) -> &[Dst] { + self.as_slice() + } + + fn dsts_as_mut_slice(&mut self) -> &mut [Dst] { + self.as_mut_slice() + } + + fn dst_types(&self) -> DstTypeList { + self.attrs() + } +} pub trait IsUniform { fn is_uniform(&self) -> bool;