mirror of
https://github.com/EmbarkStudios/rust-gpu.git
synced 2024-11-21 22:34:34 +00:00
A whole host of minor tweaks and clippy fixes (#824)
This commit is contained in:
parent
7a60181679
commit
9673f39967
@ -797,8 +797,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
|
||||
val
|
||||
}
|
||||
|
||||
// silly clippy, we can't rename this!
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
fn to_immediate_scalar(&mut self, val: Self::Value, _scalar: Scalar) -> Self::Value {
|
||||
val
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
use super::Builder;
|
||||
use crate::builder_spirv::{SpirvValue, SpirvValueExt};
|
||||
use crate::spirv_type::SpirvType;
|
||||
use core::array::IntoIter;
|
||||
use rspirv::spirv::Word;
|
||||
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
|
||||
use rustc_span::DUMMY_SP;
|
||||
@ -39,12 +38,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let u32_ptr = self.type_ptr_to(u32_ty);
|
||||
let ptr = self
|
||||
.emit()
|
||||
.in_bounds_access_chain(
|
||||
u32_ptr,
|
||||
None,
|
||||
array.def(self),
|
||||
IntoIter::new([actual_index.def(self)]),
|
||||
)
|
||||
.in_bounds_access_chain(u32_ptr, None, array.def(self), [actual_index.def(self)])
|
||||
.unwrap()
|
||||
.with_type(u32_ptr);
|
||||
self.load(u32_ty, ptr, Align::ONE)
|
||||
@ -218,12 +212,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
let u32_ptr = self.type_ptr_to(u32_ty);
|
||||
let ptr = self
|
||||
.emit()
|
||||
.in_bounds_access_chain(
|
||||
u32_ptr,
|
||||
None,
|
||||
array.def(self),
|
||||
IntoIter::new([actual_index.def(self)]),
|
||||
)
|
||||
.in_bounds_access_chain(u32_ptr, None, array.def(self), [actual_index.def(self)])
|
||||
.unwrap()
|
||||
.with_type(u32_ptr);
|
||||
self.store(value, ptr, Align::ONE);
|
||||
|
@ -518,7 +518,7 @@ impl BuilderSpirv {
|
||||
|
||||
SpirvConst::Composite(ref v) => v.iter().fold(Ok(()), |composite_legal, field| {
|
||||
let field_entry = &self.id_to_const.borrow()[field];
|
||||
let field_legal_in_composite = field_entry.legal.and_then(|()| {
|
||||
let field_legal_in_composite = field_entry.legal.and(
|
||||
// `field` is itself some legal `SpirvConst`, but can we have
|
||||
// it as part of an `OpConstantComposite`?
|
||||
match field_entry.val {
|
||||
@ -526,8 +526,8 @@ impl BuilderSpirv {
|
||||
LeafIllegalConst::CompositeContainsPtrTo,
|
||||
)),
|
||||
_ => Ok(()),
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
match (composite_legal, field_legal_in_composite) {
|
||||
(Ok(()), Ok(())) => Ok(()),
|
||||
|
@ -113,8 +113,7 @@ impl<'tcx> CodegenCx<'tcx> {
|
||||
let entry_name = entry
|
||||
.name
|
||||
.as_ref()
|
||||
.map(ToString::to_string)
|
||||
.unwrap_or_else(|| instance.to_string());
|
||||
.map_or_else(|| instance.to_string(), ToString::to_string);
|
||||
self.entry_stub(&instance, fn_abi, declared, entry_name, entry);
|
||||
}
|
||||
if attrs.unroll_loops.is_some() {
|
||||
|
@ -120,10 +120,9 @@ pub const a: &str = "x::a";
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use std::array::IntoIter;
|
||||
|
||||
fn test<const N: usize>(arr: [&str; N], expected: &str) {
|
||||
let trie = Trie::create_from(IntoIter::new(arr));
|
||||
let trie = Trie::create_from(IntoIterator::into_iter(arr));
|
||||
let mut builder = String::new();
|
||||
trie.emit(&mut builder, String::new(), 0);
|
||||
assert_eq!(builder, expected);
|
||||
|
@ -89,13 +89,11 @@
|
||||
// END - Embark standard lints v0.4
|
||||
// crate-specific exceptions:
|
||||
#![allow(
|
||||
unsafe_code, // still quite a bit of unsafe
|
||||
clippy::map_unwrap_or, // TODO: test enabling
|
||||
clippy::match_on_vec_items, // TODO: test enabling
|
||||
clippy::enum_glob_use,
|
||||
unsafe_code, // rustc_codegen_ssa requires unsafe functions in traits to be impl'd
|
||||
clippy::match_on_vec_items, // rustc_codegen_spirv has less strict panic requirements than other embark projects
|
||||
clippy::enum_glob_use, // pretty useful pattern with some codegen'd enums (e.g. rspirv::spirv::Op)
|
||||
clippy::todo, // still lots to implement :)
|
||||
)]
|
||||
#![deny(clippy::unimplemented, clippy::ok_expect)]
|
||||
|
||||
// Unfortunately, this will not fail fast when compiling, but rather will wait for
|
||||
// rustc_codegen_spirv to be compiled. Putting this in build.rs will solve that problem, however,
|
||||
|
@ -548,7 +548,6 @@ fn do_link(
|
||||
|
||||
/// As of right now, this is essentially a no-op, just plumbing through all the files.
|
||||
// TODO: WorkProduct impl
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
pub(crate) fn run_thin(
|
||||
cgcx: &CodegenContext<SpirvCodegenBackend>,
|
||||
modules: Vec<(String, SpirvThinBuffer)>,
|
||||
|
@ -31,8 +31,7 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
|
||||
.types_global_values
|
||||
.iter()
|
||||
.find(|inst| inst.class.opcode == Op::TypeVoid)
|
||||
.map(|inst| inst.result_id.unwrap())
|
||||
.unwrap_or(0);
|
||||
.map_or(0, |inst| inst.result_id.unwrap());
|
||||
// Drop all the functions we'll be inlining. (This also means we won't waste time processing
|
||||
// inlines in functions that will get inlined)
|
||||
let mut dropped_ids = FxHashSet::default();
|
||||
|
@ -95,10 +95,10 @@ fn get_names(module: &Module) -> FxHashMap<Word, &str> {
|
||||
}
|
||||
|
||||
fn get_name<'a>(names: &FxHashMap<Word, &'a str>, id: Word) -> Cow<'a, str> {
|
||||
names
|
||||
.get(&id)
|
||||
.map(|&s| Cow::Borrowed(s))
|
||||
.unwrap_or_else(|| Cow::Owned(format!("Unnamed function ID %{}", id)))
|
||||
names.get(&id).map_or_else(
|
||||
|| Cow::Owned(format!("Unnamed function ID %{}", id)),
|
||||
|&s| Cow::Borrowed(s),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn link(sess: &Session, mut inputs: Vec<Module>, opts: &Options) -> Result<LinkResult> {
|
||||
|
@ -289,7 +289,7 @@ fn match_operands(
|
||||
let parameters = (2..results[0].operands.len())
|
||||
.map(|i| match_vector_or_scalars_operand(types, defs, results, i, vector_width));
|
||||
// Do some trickery to reduce allocations.
|
||||
let operands = std::array::IntoIter::new([
|
||||
let operands = IntoIterator::into_iter([
|
||||
Some(IdentifiedOperand::NonValue(set)),
|
||||
Some(IdentifiedOperand::NonValue(instruction)),
|
||||
])
|
||||
|
@ -1094,28 +1094,22 @@ impl<'a> Match<'a> {
|
||||
let other_found = other
|
||||
.storage_class_var_found
|
||||
.get(i)
|
||||
.map(|xs| &xs[..])
|
||||
.unwrap_or(&[]);
|
||||
.map_or(&[][..], |xs| &xs[..]);
|
||||
self_found.retain(|x| other_found.contains(x));
|
||||
}
|
||||
for (i, self_found) in ty_var_found {
|
||||
let other_found = other.ty_var_found.get(i).map(|xs| &xs[..]).unwrap_or(&[]);
|
||||
let other_found = other.ty_var_found.get(i).map_or(&[][..], |xs| &xs[..]);
|
||||
self_found.retain(|x| other_found.contains(x));
|
||||
}
|
||||
for (i, self_found) in index_composite_ty_var_found {
|
||||
let other_found = other
|
||||
.index_composite_ty_var_found
|
||||
.get(i)
|
||||
.map(|xs| &xs[..])
|
||||
.unwrap_or(&[]);
|
||||
.map_or(&[][..], |xs| &xs[..]);
|
||||
self_found.retain(|x| other_found.contains(x));
|
||||
}
|
||||
for (i, self_found) in ty_list_var_found {
|
||||
let other_found = other
|
||||
.ty_list_var_found
|
||||
.get(i)
|
||||
.map(|xs| &xs[..])
|
||||
.unwrap_or(&[]);
|
||||
let other_found = other.ty_list_var_found.get(i).map_or(&[][..], |xs| &xs[..]);
|
||||
self_found.retain(|x| other_found.contains(x));
|
||||
}
|
||||
self
|
||||
|
@ -446,19 +446,17 @@ pub(crate) fn parse_attrs_for_checking<'a>(
|
||||
));
|
||||
}
|
||||
};
|
||||
sym.attributes
|
||||
.get(&name.name)
|
||||
.map(|a| {
|
||||
sym.attributes.get(&name.name).map_or_else(
|
||||
|| Err((name.span, "unknown argument to spirv attribute".to_string())),
|
||||
|a| {
|
||||
Ok(match a {
|
||||
SpirvAttribute::Entry(entry) => SpirvAttribute::Entry(
|
||||
parse_entry_attrs(sym, arg, &name, entry.execution_model)?,
|
||||
),
|
||||
_ => a.clone(),
|
||||
})
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
Err((name.span, "unknown argument to spirv attribute".to_string()))
|
||||
})?
|
||||
},
|
||||
)?
|
||||
};
|
||||
Ok((span, parsed_attr))
|
||||
}))
|
||||
|
@ -75,9 +75,9 @@ impl Parse for ImageType {
|
||||
let int = input.parse::<syn::LitInt>().unwrap();
|
||||
set_unique!(
|
||||
dimensionality = match (int.base10_digits(), int.suffix()) {
|
||||
("1", "D") | ("1", "d") => Dimensionality::OneD,
|
||||
("2", "D") | ("2", "d") => Dimensionality::TwoD,
|
||||
("3", "D") | ("3", "d") => Dimensionality::ThreeD,
|
||||
("1", "D" | "d") => Dimensionality::OneD,
|
||||
("2", "D" | "d") => Dimensionality::TwoD,
|
||||
("3", "D" | "d") => Dimensionality::ThreeD,
|
||||
_ => return Err(syn::Error::new(int.span(), "Unexpected integer")),
|
||||
}
|
||||
);
|
||||
|
@ -68,8 +68,7 @@
|
||||
)]
|
||||
// END - Embark standard lints v0.4
|
||||
// crate-specific exceptions:
|
||||
// `or_patterns` is not stable yet.
|
||||
#![allow(clippy::unnested_or_patterns)]
|
||||
// #![allow()]
|
||||
|
||||
mod image;
|
||||
|
||||
|
@ -39,7 +39,6 @@ pub unsafe fn report_intersection(hit: f32, hit_kind: u32) -> bool {
|
||||
#[spirv_std_macros::gpu_only]
|
||||
#[doc(alias = "OpIgnoreIntersectionKHR")]
|
||||
#[inline]
|
||||
#[allow(clippy::empty_loop)]
|
||||
pub unsafe fn ignore_intersection() -> ! {
|
||||
asm!("OpIgnoreIntersectionKHR", options(noreturn));
|
||||
}
|
||||
@ -51,7 +50,6 @@ pub unsafe fn ignore_intersection() -> ! {
|
||||
#[spirv_std_macros::gpu_only]
|
||||
#[doc(alias = "OpTerminateRayKHR")]
|
||||
#[inline]
|
||||
#[allow(clippy::empty_loop)]
|
||||
pub unsafe fn terminate_ray() -> ! {
|
||||
asm!("OpTerminateRayKHR", options(noreturn));
|
||||
}
|
||||
|
@ -89,8 +89,6 @@
|
||||
// We deblierately provide an unimplemented version of our API on CPU
|
||||
// platforms so that code completion still works.
|
||||
clippy::unimplemented,
|
||||
// The part of `adt_const_params` we're using (C-like enums) is not incomplete.
|
||||
incomplete_features,
|
||||
)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
|
@ -15,7 +15,6 @@ impl AccelerationStructure {
|
||||
/// The 64-bit integer must point to a valid acceleration structure.
|
||||
#[spirv_std_macros::gpu_only]
|
||||
#[doc(alias = "OpConvertUToAccelerationStructureKHR")]
|
||||
#[allow(clippy::empty_loop)]
|
||||
#[inline]
|
||||
pub unsafe fn from_u64(id: u64) -> AccelerationStructure {
|
||||
// Since we can't represent an uninitalized opaque type in Rust at the
|
||||
@ -35,7 +34,6 @@ impl AccelerationStructure {
|
||||
/// The combination must point to a valid acceleration structure.
|
||||
#[spirv_std_macros::gpu_only]
|
||||
#[doc(alias = "OpConvertUToAccelerationStructureKHR")]
|
||||
#[allow(clippy::empty_loop)]
|
||||
#[inline]
|
||||
pub unsafe fn from_vec(id: impl Vector<u32, 2>) -> AccelerationStructure {
|
||||
// Since we can't represent an uninitalized opaque type in Rust at the
|
||||
|
@ -22,7 +22,6 @@ impl<T> RuntimeArray<T> {
|
||||
/// Bounds checking is not performed, and indexing outside the bounds of the array can happen,
|
||||
/// and lead to UB.
|
||||
#[spirv_std_macros::gpu_only]
|
||||
#[allow(clippy::empty_loop)]
|
||||
pub unsafe fn index(&self, index: usize) -> &T {
|
||||
asm! {
|
||||
"%result = OpAccessChain _ {arr} {index}",
|
||||
@ -41,7 +40,6 @@ impl<T> RuntimeArray<T> {
|
||||
/// Bounds checking is not performed, and indexing outside the bounds of the array can happen,
|
||||
/// and lead to UB.
|
||||
#[spirv_std_macros::gpu_only]
|
||||
#[allow(clippy::empty_loop)]
|
||||
pub unsafe fn index_mut(&mut self, index: usize) -> &mut T {
|
||||
asm! {
|
||||
"%result = OpAccessChain _ {arr} {index}",
|
||||
|
@ -59,9 +59,7 @@ pub async fn start_internal(
|
||||
|
||||
let src = src_range
|
||||
.clone()
|
||||
// Not sure which endianness is correct to use here
|
||||
.map(u32::to_ne_bytes)
|
||||
.flat_map(core::array::IntoIter::new)
|
||||
.flat_map(u32::to_ne_bytes)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
|
@ -96,9 +96,9 @@ error[E0277]: the trait bound `{float}: Vector<f32, 2_usize>` is not satisfied
|
||||
<DVec2 as Vector<f64, 2_usize>>
|
||||
and 13 others
|
||||
note: required by a bound in `debug_printf_assert_is_vector`
|
||||
--> $SPIRV_STD_SRC/lib.rs:148:8
|
||||
--> $SPIRV_STD_SRC/lib.rs:146:8
|
||||
|
|
||||
148 | V: crate::vector::Vector<TY, SIZE>,
|
||||
146 | V: crate::vector::Vector<TY, SIZE>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `debug_printf_assert_is_vector`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
|
Loading…
Reference in New Issue
Block a user