Skip to content

Commit

Permalink
fix array concat lint
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Jan 21, 2025
1 parent 686f130 commit b5fc787
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontends/rioterm/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ impl Screen<'_> {
return;
}

let build_key_sequence = Self::should_build_sequence(&key, text, mode, mods);
let build_key_sequence = Self::should_build_sequence(key, text, mode, mods);

let bytes = if build_key_sequence {
crate::bindings::kitty_keyboard::build_key_sequence(key, mods, mode)
Expand Down
6 changes: 1 addition & 5 deletions rio-backend/src/config/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ pub fn default_opacity() -> f32 {

#[inline]
pub fn default_option_as_alt() -> String {
if cfg!(target_os = "macos") {
return String::from("both");
} else {
return String::from("none");
}
String::from("none")
}

#[inline]
Expand Down
1 change: 0 additions & 1 deletion sugarloaf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ librashader-reflect = { version = "0.6.2", features = ["stable", "wgsl"], defaul
librashader-runtime = "0.6.2"
librashader-cache = "0.6.2"
thiserror = "2.0.1"
array-concat = "0.5.2"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
crossbeam-channel = "0.5.13"
Expand Down
2 changes: 1 addition & 1 deletion sugarloaf/src/components/filters/runtime/draw_quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SnowflakePowered/librashader is licensed under MPL-2.0
// https://github.com/SnowflakePowered/librashader/blob/master/LICENSE.md

use array_concat::concat_arrays;
use crate::concat_arrays;
use librashader_runtime::quad::{QuadType, VertexInput};
use wgpu::util::{BufferInitDescriptor, DeviceExt};
use wgpu::{Buffer, Device, RenderPass};
Expand Down
55 changes: 55 additions & 0 deletions sugarloaf/src/components/filters/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,61 @@ pub use framebuffer::WgpuOutputView;
pub mod error;
pub mod options;

/// Concatenates provided arrays.
#[macro_export]
macro_rules! concat_arrays {
($( $array:expr ),*) => ({
#[repr(C)]
struct ArrayConcatDecomposed<T, A, B>(core::mem::ManuallyDrop<[T; 0]>, core::mem::ManuallyDrop<A>, core::mem::ManuallyDrop<B>);

impl<T> ArrayConcatDecomposed<T, [T; 0], [T; 0]> {
#[inline(always)]
const fn default() -> Self {
Self::new(core::mem::ManuallyDrop::new([]), [])
}
}
impl<T, A, B> ArrayConcatDecomposed<T, A, B> {
#[inline(always)]
const fn new(a: core::mem::ManuallyDrop<A>, b: B) -> Self {
Self(core::mem::ManuallyDrop::new([]), a, core::mem::ManuallyDrop::new(b))
}
#[inline(always)]
const fn concat<const N: usize>(self, v: [T; N]) -> ArrayConcatDecomposed<T, A, ArrayConcatDecomposed<T, B, [T; N]>> {
ArrayConcatDecomposed::new(self.1, ArrayConcatDecomposed::new(self.2, v))
}
}

#[repr(C)]
union ArrayConcatComposed<T, A, B, const N: usize> {
full: core::mem::ManuallyDrop<[T; N]>,
decomposed: core::mem::ManuallyDrop<ArrayConcatDecomposed<T, A, B>>,
}

impl<T, A, B, const N: usize> ArrayConcatComposed<T, A, B, N> {
const HAVE_SAME_SIZE: bool = core::mem::size_of::<[T; N]>() == core::mem::size_of::<Self>();

const PANIC: bool = !["Size mismatch"][!Self::HAVE_SAME_SIZE as usize].is_empty();

#[inline(always)]
const fn have_same_size(&self) -> bool {
Self::PANIC
}
}

let composed = ArrayConcatComposed {
decomposed: core::mem::ManuallyDrop::new(
ArrayConcatDecomposed::default()$(.concat($array))*,
)
};

// Sanity check that composed's two fields are the same size
composed.have_same_size();

// SAFETY: Sizes of both fields in composed are the same so this assignment should be sound
core::mem::ManuallyDrop::into_inner(unsafe { composed.full })
});
}

use librashader_runtime::impl_filter_chain_parameters;
impl_filter_chain_parameters!(FilterChain);

Expand Down

0 comments on commit b5fc787

Please sign in to comment.