diff --git a/src/compiler/rust/as_slice.rs b/src/compiler/rust/as_slice.rs index 8e6657cc36a..c4e7e6cc04e 100644 --- a/src/compiler/rust/as_slice.rs +++ b/src/compiler/rust/as_slice.rs @@ -3,30 +3,13 @@ use std::ops::Deref; use std::ops::DerefMut; -use std::ops::Index; - -pub enum AttrList { - Array(&'static [T]), - Uniform(T), -} - -impl Index for AttrList { - type Output = T; - - fn index(&self, idx: usize) -> &T { - match self { - AttrList::Array(arr) => &arr[idx], - AttrList::Uniform(typ) => typ, - } - } -} pub trait AsSlice { type Attr; fn as_slice(&self) -> &[T]; fn as_mut_slice(&mut self) -> &mut [T]; - fn attrs(&self) -> AttrList; + fn attrs(&self) -> &'static [Self::Attr]; } impl AsSlice for Box @@ -41,7 +24,7 @@ where fn as_mut_slice(&mut self) -> &mut [T] { self.deref_mut().as_mut_slice() } - fn attrs(&self) -> AttrList { + fn attrs(&self) -> &'static [Self::Attr] { self.deref().attrs() } } diff --git a/src/compiler/rust/proc/as_slice.rs b/src/compiler/rust/proc/as_slice.rs index 6ea28506abf..725b88d4f67 100644 --- a/src/compiler/rust/proc/as_slice.rs +++ b/src/compiler/rust/proc/as_slice.rs @@ -142,9 +142,9 @@ pub fn derive_as_slice( } } - fn attrs(&self) -> AttrList { + fn attrs(&self) -> &'static [Self::Attr] { static ATTRS: [#attr_type; #count] = [#attrs]; - AttrList::Array(&ATTRS) + &ATTRS } } } @@ -161,8 +161,8 @@ pub fn derive_as_slice( &mut [] } - fn attrs(&self) -> AttrList { - AttrList::Uniform(#attr_type::DEFAULT) + fn attrs(&self) -> &'static [Self::Attr] { + &[] } } } @@ -203,7 +203,7 @@ pub fn derive_as_slice( } } - fn attrs(&self) -> AttrList { + fn attrs(&self) -> &'static [Self::Attr] { match self { #types_cases } diff --git a/src/nouveau/compiler/nak/ir.rs b/src/nouveau/compiler/nak/ir.rs index 8b02ca58efa..cb056f3332a 100644 --- a/src/nouveau/compiler/nak/ir.rs +++ b/src/nouveau/compiler/nak/ir.rs @@ -1345,6 +1345,22 @@ impl SrcType { } } +pub enum AttrList { + Array(&'static [T]), + Uniform(T), +} + +impl Index for AttrList { + type Output = T; + + fn index(&self, idx: usize) -> &T { + match self { + AttrList::Array(arr) => &arr[idx], + AttrList::Uniform(typ) => typ, + } + } +} + pub type SrcTypeList = AttrList; pub trait SrcsAsSlice { @@ -1371,7 +1387,7 @@ impl> SrcsAsSlice for T { } fn src_types(&self) -> SrcTypeList { - self.attrs() + AttrList::Array(self.attrs()) } } @@ -1436,7 +1452,7 @@ impl> DstsAsSlice for T { } fn dst_types(&self) -> DstTypeList { - self.attrs() + AttrList::Array(self.attrs()) } }