Truly independent web browser
Everywhere: Build Rust slices over C++ arrays without null pointers
Andreas Kling704cb64f1bf8
diff --git a/AK/Rust/src/lib.rs b/AK/Rust/src/lib.rsindex 122fc1a1d90..9c9a4e46ff2 100644--- a/AK/Rust/src/lib.rs+++ b/AK/Rust/src/lib.rs@@ -7,8 +7,10 @@//! Rust views of shared AK data structures.mod scope_guard;+mod slice;pub use scope_guard::ScopeGuard;+pub use slice::{slice_from_raw_parts, slice_from_raw_parts_mut};use core::mem::MaybeUninit;use std::num::NonZeroUsize;@@ -339,7 +341,7 @@ impl Utf16String {// SAFETY: The allocation has space for exactly `length` ASCII bytes, which are zeroed before they are lent out.let storage = unsafe {std::ptr::write_bytes(result.long_storage(), 0, length);- std::slice::from_raw_parts_mut(result.long_storage(), length)+ crate::slice_from_raw_parts_mut(result.long_storage(), length)};fill(storage);assert!(storage.is_ascii(), "an ASCII string holds ASCII bytes");@@ -802,7 +804,7 @@ pub unsafe fn utf16_string_units(raw: &usize) -> Utf16StringUnits<'_> {// SAFETY: The short-string bytes are stored inline in `raw` and `length`// is constrained to the remaining bytes in the word.- return Utf16StringUnits::Ascii(unsafe { std::slice::from_raw_parts(pointer, length) });+ return Utf16StringUnits::Ascii(unsafe { crate::slice_from_raw_parts(pointer, length) });}// SAFETY: The caller guarantees that `raw` points to a live long string allocation.@@ -813,10 +815,10 @@ pub unsafe fn utf16_string_units(raw: &usize) -> Utf16StringUnits<'_> {.wrapping_add(size_of::<Utf16StringDataHeader>());if header.flags.load(Ordering::Acquire) & HAS_UTF16_STORAGE == 0 {// SAFETY: Long ASCII storage starts immediately after the header and contains `length` bytes.- Utf16StringUnits::Ascii(unsafe { std::slice::from_raw_parts(storage, length) })+ Utf16StringUnits::Ascii(unsafe { crate::slice_from_raw_parts(storage, length) })} else {// SAFETY: Long UTF-16 storage starts immediately after the aligned header and contains// `length` u16 code units.- Utf16StringUnits::Utf16(unsafe { std::slice::from_raw_parts(storage.cast::<u16>(), length) })+ Utf16StringUnits::Utf16(unsafe { crate::slice_from_raw_parts(storage.cast::<u16>(), length) })}}diff --git a/AK/Rust/src/slice.rs b/AK/Rust/src/slice.rsnew file mode 100644index 00000000000..e6ba323c014--- /dev/null+++ b/AK/Rust/src/slice.rs@@ -0,0 +1,46 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! Slices over arrays that C++ lends. An empty AK container lends a null pointer, which+//! `std::slice::from_raw_parts` forbids even for an empty slice.++/// The `length` values at `data`, where `data` may be null if `length` is zero.+///+/// # Safety+///+/// Unless `length` is zero, `data` must meet the requirements of `std::slice::from_raw_parts` for+/// the lifetime `'a`.+#[allow(clippy::disallowed_methods)]+#[inline]+pub unsafe fn slice_from_raw_parts<'a, T>(data: *const T, length: usize) -> &'a [T] {+ // NB: Testing the pointer rather than the length lets the compiler drop the test where the+ // pointer comes from a reference, as on the hot interpreter paths.+ if data.is_null() {+ assert!(length == 0, "a non-empty slice from a null pointer");+ return &[];+ }+ // SAFETY: Guaranteed by the caller.+ unsafe { std::slice::from_raw_parts(data, length) }+}++/// The `length` values at `data`, mutably, where `data` may be null if `length` is zero.+///+/// # Safety+///+/// Unless `length` is zero, `data` must meet the requirements of `std::slice::from_raw_parts_mut`+/// for the lifetime `'a`.+#[allow(clippy::disallowed_methods)]+#[inline]+pub unsafe fn slice_from_raw_parts_mut<'a, T>(data: *mut T, length: usize) -> &'a mut [T] {+ // NB: Testing the pointer rather than the length lets the compiler drop the test where the+ // pointer comes from a reference, as on the hot interpreter paths.+ if data.is_null() {+ assert!(length == 0, "a non-empty slice from a null pointer");+ return &mut [];+ }+ // SAFETY: Guaranteed by the caller.+ unsafe { std::slice::from_raw_parts_mut(data, length) }+}diff --git a/Cargo.lock b/Cargo.lockindex 0f5979d9683..f220ed74a89 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -856,6 +856,7 @@ checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78"name = "libcompositing_rust"version = "0.1.0"dependencies = [+ "ak","cbindgen","foldhash 0.2.0","ladybird_allocator",@@ -867,6 +868,7 @@ dependencies = [name = "libgfx_rust"version = "0.1.0"dependencies = [+ "ak","cbindgen","foldhash 0.2.0","ladybird_allocator",@@ -878,6 +880,7 @@ dependencies = [name = "libimagedecoders_rust"version = "0.1.0"dependencies = [+ "ak","cbindgen","jxl","ladybird_allocator",@@ -900,6 +903,7 @@ dependencies = [name = "libjs_jit"version = "0.1.0"dependencies = [+ "ak","fARM64","flapc","iced-x86",@@ -952,6 +956,7 @@ checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"name = "libregex_rust"version = "0.1.0"dependencies = [+ "ak","cbindgen","ladybird_allocator","libunicode_rust",@@ -962,6 +967,7 @@ dependencies = [name = "libtextcodec_rust"version = "0.1.0"dependencies = [+ "ak","cbindgen","encoding_rs","ladybird_allocator",@@ -972,6 +978,7 @@ dependencies = [name = "libunicode_rust"version = "0.1.0"dependencies = [+ "ak","calendrical_calculations","cbindgen","icu_calendar",@@ -983,6 +990,7 @@ dependencies = [name = "liburl_rust"version = "0.1.0"dependencies = [+ "ak","cbindgen","encoding_rs","ladybird_allocator",@@ -995,6 +1003,7 @@ dependencies = [name = "libwasm_cranelift"version = "0.1.0"dependencies = [+ "ak","cbindgen","cranelift-codegen","cranelift-frontend",@@ -1024,6 +1033,7 @@ name = "libweb_content_blocker_rust"version = "0.1.0"dependencies = ["adblock",+ "ak","cbindgen","ladybird_allocator","rustc-demangle",diff --git a/Libraries/LibCompositing/Rust/Cargo.toml b/Libraries/LibCompositing/Rust/Cargo.tomlindex 6ded91c18ad..3cf54006189 100644--- a/Libraries/LibCompositing/Rust/Cargo.toml+++ b/Libraries/LibCompositing/Rust/Cargo.toml@@ -11,6 +11,7 @@ default = []allocator = ["dep:ladybird_allocator"][dependencies]+ak = { path = "../../../AK/Rust" }foldhash = "0.2"ladybird_allocator = { path = "../../RustAllocator", optional = true }libgfx_rust = { path = "../../LibGfx/Rust", default-features = false }diff --git a/Libraries/LibCompositing/Rust/src/display_list/storage.rs b/Libraries/LibCompositing/Rust/src/display_list/storage.rsindex f59b1dc1254..7c0d2d57054 100644--- a/Libraries/LibCompositing/Rust/src/display_list/storage.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/storage.rs@@ -67,7 +67,7 @@ impl AlignedBytes {fn as_slice(&self) -> &[u8] {// SAFETY: The words hold at least `size` initialized bytes.- unsafe { std::slice::from_raw_parts(self.words.as_ptr().cast(), self.size) }+ unsafe { ak::slice_from_raw_parts(self.words.as_ptr().cast(), self.size) }}}@@ -199,8 +199,8 @@ pub unsafe fn tape_of<'a>(storage: *const c_void) -> (&'a [u8], &'a [DisplayListunsafe {let view = *storage.cast::<TapeView>();(- crate::ffi::ffi_slice(view.bytes, view.byte_count),- crate::ffi::ffi_slice(view.command_runs, view.command_run_count),+ ak::slice_from_raw_parts(view.bytes, view.byte_count),+ ak::slice_from_raw_parts(view.command_runs, view.command_run_count),)}}@@ -293,7 +293,7 @@ pub unsafe extern "C" fn display_list_storage_write_packed(storage: *const c_voireturn;}// SAFETY: The caller guarantees `destination` addresses `size` writable bytes.- let destination = unsafe { std::slice::from_raw_parts_mut(destination, size) };+ let destination = unsafe { ak::slice_from_raw_parts_mut(destination, size) };let (tape_destination, runs_destination) = destination.split_at_mut(tape.len());tape_destination.copy_from_slice(tape);let (run_destinations, _) = runs_destination.as_chunks_mut::<{ std::mem::size_of::<DisplayListCommandRun>() }>();diff --git a/Libraries/LibCompositing/Rust/src/easing.rs b/Libraries/LibCompositing/Rust/src/easing.rsindex cd823400ef8..ac0829c44c8 100644--- a/Libraries/LibCompositing/Rust/src/easing.rs+++ b/Libraries/LibCompositing/Rust/src/easing.rs@@ -86,7 +86,7 @@ unsafe fn linear_points(descriptor: &FfiEasingDescriptor) -> &[FfiLinearEasingPoreturn &[];}// SAFETY: The caller guarantees the point range is live for a linear descriptor.- unsafe { std::slice::from_raw_parts(descriptor.linear_points, descriptor.linear_point_count) }+ unsafe { ak::slice_from_raw_parts(descriptor.linear_points, descriptor.linear_point_count) }}impl Easing {diff --git a/Libraries/LibCompositing/Rust/src/ffi.rs b/Libraries/LibCompositing/Rust/src/ffi.rsindex bef0472bba3..7761d1c9be0 100644--- a/Libraries/LibCompositing/Rust/src/ffi.rs+++ b/Libraries/LibCompositing/Rust/src/ffi.rs@@ -12,20 +12,6 @@ use crate::display_list::storage::storage_from_handle;use crate::node_slot_id::NodeSlotId;use std::ffi::c_void;-/// # Safety-///-/// `data` must point at `length` readable values for the duration of the borrow, or be null with-/// a `length` of zero.-pub unsafe fn ffi_slice<'a, T>(data: *const T, length: usize) -> &'a [T] {- assert!(!data.is_null() || length == 0);- if length == 0 {- return &[];- }- // SAFETY: The caller guarantees `data` points at `length` valid values for- // the duration of the borrow.- unsafe { std::slice::from_raw_parts(data, length) }-}-/// # Safety////// `tree` must be a live retained tree handle.@@ -49,7 +35,7 @@ pub unsafe extern "C" fn ladybird_web_force_dark_should_filter_image(return false;}// Color is repr(transparent) over u32, so the buffer needs no copy to be read as colors.- let colors = unsafe { std::slice::from_raw_parts(samples.cast::<libgfx_rust::Color>(), count) };+ let colors = unsafe { ak::slice_from_raw_parts(samples.cast::<libgfx_rust::Color>(), count) };let features = crate::force_dark::features_from_samples(colors, transparency_ratio);crate::force_dark::should_filter(&features)}@@ -78,10 +64,10 @@ pub unsafe extern "C" fn display_list_compute_damage((storage_from_handle(old_storage),tree_from_handle(old_tree),- ffi_slice(old_scroll_offsets, old_scroll_offsets_len),+ ak::slice_from_raw_parts(old_scroll_offsets, old_scroll_offsets_len),storage_from_handle(new_storage),tree_from_handle(new_tree),- ffi_slice(new_scroll_offsets, new_scroll_offsets_len),+ ak::slice_from_raw_parts(new_scroll_offsets, new_scroll_offsets_len),)};let damage = crate::display_list::damage::compute_display_list_damage(@@ -129,7 +115,7 @@ pub unsafe extern "C" fn display_list_animated_content_may_affect_viewport(storage.bytes(),storage.command_runs(),tree_from_handle(tree),- ffi_slice(scroll_offsets, scroll_offsets_len),+ ak::slice_from_raw_parts(scroll_offsets, scroll_offsets_len),viewport_rect,sample_time_ns,)@@ -155,7 +141,7 @@ pub unsafe extern "C" fn display_list_replay((tree_from_handle(tree),storage_from_handle(storage),- ffi_slice(scroll_offsets, scroll_offsets_len),+ ak::slice_from_raw_parts(scroll_offsets, scroll_offsets_len),)};// SAFETY: The caller guarantees `callbacks` is live for the call.@@ -188,8 +174,8 @@ pub unsafe extern "C" fn display_list_replay_records(// SAFETY: The caller guarantees the slices address the stated number of values.let (records, scroll_offsets) = unsafe {(- ffi_slice(records, records_size),- ffi_slice(scroll_offsets, scroll_offsets_len),+ ak::slice_from_raw_parts(records, records_size),+ ak::slice_from_raw_parts(scroll_offsets, scroll_offsets_len),)};// SAFETY: The caller guarantees `callbacks` is live for the call.@@ -249,7 +235,7 @@ pub unsafe extern "C" fn visual_context_tree_serialize(#[unsafe(no_mangle)]pub unsafe extern "C" fn visual_context_tree_deserialize(bytes: *const u8, length: usize) -> *const c_void {// SAFETY: The caller guarantees `bytes` addresses `length` readable bytes.- let bytes = unsafe { ffi_slice(bytes, length) };+ let bytes = unsafe { ak::slice_from_raw_parts(bytes, length) };match crate::visual_context::VisualContextTree::from_bytes(bytes) {Some(tree) => std::sync::Arc::into_raw(std::sync::Arc::new(tree)).cast(),None => std::ptr::null(),@@ -317,7 +303,7 @@ pub unsafe extern "C" fn visual_context_tree_transform_point_for_hit_test() -> bool {let tree = unsafe { tree_from_handle(tree) };// SAFETY: The caller guarantees the offsets address `scroll_offsets_len` points.- let scroll_offsets = unsafe { ffi_slice(scroll_offsets, scroll_offsets_len) };+ let scroll_offsets = unsafe { ak::slice_from_raw_parts(scroll_offsets, scroll_offsets_len) };let clip_behavior = crate::visual_context::ClipBehavior::from_respect_clip(respect_clip);match tree.transform_point_for_hit_test(context, screen_point, scroll_offsets, clip_behavior) {Some(local_point) => {@@ -365,7 +351,7 @@ pub unsafe extern "C" fn visual_context_tree_transform_rect_to_viewport() {let tree = unsafe { tree_from_handle(tree) };// SAFETY: The caller guarantees the offsets address `scroll_offsets_len` points.- let scroll_offsets = unsafe { ffi_slice(scroll_offsets, scroll_offsets_len) };+ let scroll_offsets = unsafe { ak::slice_from_raw_parts(scroll_offsets, scroll_offsets_len) };*out = tree.transform_rect_to_viewport(spatial,rect,@@ -387,7 +373,7 @@ pub unsafe extern "C" fn visual_context_tree_cumulative_scroll_chain_offset() {let tree = unsafe { tree_from_handle(tree) };// SAFETY: The caller guarantees the offsets address `scroll_offsets_len` points.- let scroll_offsets = unsafe { ffi_slice(scroll_offsets, scroll_offsets_len) };+ let scroll_offsets = unsafe { ak::slice_from_raw_parts(scroll_offsets, scroll_offsets_len) };*out = tree.cumulative_scroll_chain_offset(spatial, scroll_offsets);}@@ -404,7 +390,7 @@ pub unsafe extern "C" fn visual_context_tree_accumulated_matrix() -> libgfx_rust::FloatMatrix4x4 {let tree = unsafe { tree_from_handle(tree) };// SAFETY: The caller guarantees the offsets address `scroll_offsets_len` points.- let scroll_offsets = unsafe { ffi_slice(scroll_offsets, scroll_offsets_len) };+ let scroll_offsets = unsafe { ak::slice_from_raw_parts(scroll_offsets, scroll_offsets_len) };tree.accumulated_matrix(spatial,scroll_offsets,@@ -428,7 +414,7 @@ pub unsafe extern "C" fn visual_context_tree_resolve_sticky_offsets(let tree = unsafe { tree_from_handle(tree) };// SAFETY: The caller guarantees the offsets address `scroll_offsets_len` points, and the// borrow ends before the sink may grow the same storage.- let scroll_offsets = unsafe { ffi_slice(scroll_offsets, scroll_offsets_len) };+ let scroll_offsets = unsafe { ak::slice_from_raw_parts(scroll_offsets, scroll_offsets_len) };tree.resolve_sticky_offsets(scroll_offsets)};for (node_index, offset) in resolved_sticky_entries {@@ -582,7 +568,7 @@ pub unsafe extern "C" fn visual_context_tree_mark_spatial_subtrees() {let tree = unsafe { tree_from_handle(tree) };// SAFETY: The caller guarantees the roots address `root_count` indices.- let roots = unsafe { ffi_slice(roots, root_count) };+ let roots = unsafe { ak::slice_from_raw_parts(roots, root_count) };let in_subtree = tree.spatial_nodes_in_subtrees_of(roots);assert_eq!(in_subtree.len(), flag_count);// SAFETY: The caller guarantees `out_flags` addresses `flag_count` writable flags.@@ -801,7 +787,7 @@ pub unsafe extern "C" fn visual_context_tree_test_builder_append_clip_path() -> u32 {let tree = unsafe { test_builder_tree(builder) };// SAFETY: The caller guarantees `path_bytes` addresses `path_bytes_length` readable bytes.- let path_bytes = unsafe { ffi_slice(path_bytes, path_bytes_length) };+ let path_bytes = unsafe { ak::slice_from_raw_parts(path_bytes, path_bytes_length) };let path = libgfx_rust::path::OwnedPath::from_serialized_bytes(path_bytes);tree.append_clip(crate::visual_context::ClipNodeData::Path(crate::visual_context::ClipPathData {diff --git a/Libraries/LibGfx/Rust/Cargo.toml b/Libraries/LibGfx/Rust/Cargo.tomlindex c298e188a2e..182f2d6ecc1 100644--- a/Libraries/LibGfx/Rust/Cargo.toml+++ b/Libraries/LibGfx/Rust/Cargo.toml@@ -11,6 +11,7 @@ default = []allocator = ["dep:ladybird_allocator"][dependencies]+ak = { path = "../../../AK/Rust" }foldhash = "0.2"ladybird_allocator = { path = "../../RustAllocator", optional = true }rustc-demangle = "0.1"diff --git a/Libraries/LibGfx/Rust/src/filter.rs b/Libraries/LibGfx/Rust/src/filter.rsindex 76890cc0494..bd0a3cca29f 100644--- a/Libraries/LibGfx/Rust/src/filter.rs+++ b/Libraries/LibGfx/Rust/src/filter.rs@@ -821,7 +821,7 @@ pub unsafe extern "C" fn ladybird_gfx_filter_for_each_image_frame_id(&[]} else {// SAFETY: The caller guarantees `count` readable bytes.- unsafe { std::slice::from_raw_parts(bytes, count) }+ unsafe { ak::slice_from_raw_parts(bytes, count) }};if let Some(filter) = Filter::deserialize(bytes) {// SAFETY: The caller guarantees `visit` accepts `context`.diff --git a/Libraries/LibGfx/Rust/src/font_catalog.rs b/Libraries/LibGfx/Rust/src/font_catalog.rsindex 2e5f7236167..f6251406c5a 100644--- a/Libraries/LibGfx/Rust/src/font_catalog.rs+++ b/Libraries/LibGfx/Rust/src/font_catalog.rs@@ -273,7 +273,7 @@ impl FontCatalog {return None;}// SAFETY: parse() validated this range and the snapshot outlives the catalog.- Some(unsafe { std::slice::from_raw_parts(self.data.add(face.family_offset), face.family_length) })+ Some(unsafe { ak::slice_from_raw_parts(self.data.add(face.family_offset), face.family_length) })}fn family_face_count(&self, family: &[u8]) -> usize {@@ -342,7 +342,7 @@ pub unsafe extern "C" fn font_catalog_builder_add_face(if input.family.is_null() {return false;}- let family = unsafe { std::slice::from_raw_parts(input.family, input.family_length) };+ let family = unsafe { ak::slice_from_raw_parts(input.family, input.family_length) };if !valid_face(input.face_id,family,@@ -413,7 +413,7 @@ pub unsafe extern "C" fn font_catalog_parse(if data.is_null() {return std::ptr::null_mut();}- let data = unsafe { std::slice::from_raw_parts(data, data_length) };+ let data = unsafe { ak::slice_from_raw_parts(data, data_length) };FontCatalog::parse(data, expected_generation).map(|catalog| Box::into_raw(Box::new(catalog))).unwrap_or(std::ptr::null_mut())@@ -476,7 +476,7 @@ pub unsafe extern "C" fn font_catalog_family_face_count(if family.is_null() {return 0;}- let family = unsafe { std::slice::from_raw_parts(family, family_length) };+ let family = unsafe { ak::slice_from_raw_parts(family, family_length) };catalog.family_face_count(family)}@@ -497,7 +497,7 @@ pub unsafe extern "C" fn font_catalog_family_face_at(if family.is_null() {return false;}- let family = unsafe { std::slice::from_raw_parts(family, family_length) };+ let family = unsafe { ak::slice_from_raw_parts(family, family_length) };let Some(face_index) = catalog.family_face_index_at(family, index) else {return false;};@@ -548,7 +548,7 @@ pub unsafe extern "C" fn font_catalog_match_style(if family.is_null() {return false;}- let family = unsafe { std::slice::from_raw_parts(family, family_length) };+ let family = unsafe { ak::slice_from_raw_parts(family, family_length) };let Some(index) = catalog.match_style_index(family, weight, width, slope) else {return false;};diff --git a/Libraries/LibGfx/Rust/src/path.rs b/Libraries/LibGfx/Rust/src/path.rsindex 7a54b0bb593..d1c95dbc7a5 100644--- a/Libraries/LibGfx/Rust/src/path.rs+++ b/Libraries/LibGfx/Rust/src/path.rs@@ -176,7 +176,7 @@ unsafe extern "C" fn append_to_vec(context: *mut c_void, bytes: *const u8, lengt// SAFETY: `context` is the Vec pointer handed out by serialize_to_bytes; the bytes are live// for this synchronous call.let out = unsafe { &mut *context.cast::<Vec<u8>>() };- out.extend_from_slice(unsafe { std::slice::from_raw_parts(bytes, length) });+ out.extend_from_slice(unsafe { ak::slice_from_raw_parts(bytes, length) });}unsafe extern "C" fn append_to_string(context: *mut c_void, bytes: *const u8, length: usize) {@@ -185,7 +185,7 @@ unsafe extern "C" fn append_to_string(context: *mut c_void, bytes: *const u8, leunsafe {let output = &mut *context.cast::<String>();if length > 0 {- output.push_str(&String::from_utf8_lossy(std::slice::from_raw_parts(bytes, length)));+ output.push_str(&String::from_utf8_lossy(ak::slice_from_raw_parts(bytes, length)));}}}diff --git a/Libraries/LibGfx/Rust/src/text_layout.rs b/Libraries/LibGfx/Rust/src/text_layout.rsindex 02756cb45b5..8489b9d0f97 100644--- a/Libraries/LibGfx/Rust/src/text_layout.rs+++ b/Libraries/LibGfx/Rust/src/text_layout.rs@@ -384,7 +384,7 @@ fn shape_text_uncached(} else {// SAFETY: The C++ side hands a pointer to glyph_count glyphs that// outlive the callback.- Arc::from(unsafe { std::slice::from_raw_parts(glyphs, glyph_count) })+ Arc::from(unsafe { ak::slice_from_raw_parts(glyphs, glyph_count) })};*shape = Some(CachedShape {glyphs,@@ -498,7 +498,7 @@ pub unsafe extern "C" fn ladybird_gfx_shape_text_cached(let text = if length == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(text, length) }+ unsafe { ak::slice_from_raw_parts(text, length) }};let params = ShapeParams {text_type,diff --git a/Libraries/LibGfx/Rust/src/yuv.rs b/Libraries/LibGfx/Rust/src/yuv.rsindex 7a2de40a4eb..bad34c08743 100644--- a/Libraries/LibGfx/Rust/src/yuv.rs+++ b/Libraries/LibGfx/Rust/src/yuv.rs@@ -73,18 +73,18 @@ pub unsafe extern "C" fn yuv_u8_to_rgba(let uv_len = u_stride as usize * uv_height;let planar_image = YuvPlanarImage {- y_plane: unsafe { core::slice::from_raw_parts(y_plane, y_len) },+ y_plane: unsafe { ak::slice_from_raw_parts(y_plane, y_len) },y_stride,- u_plane: unsafe { core::slice::from_raw_parts(u_plane, uv_len) },+ u_plane: unsafe { ak::slice_from_raw_parts(u_plane, uv_len) },u_stride,- v_plane: unsafe { core::slice::from_raw_parts(v_plane, uv_len) },+ v_plane: unsafe { ak::slice_from_raw_parts(v_plane, uv_len) },v_stride,width,height,};let dst_len = dst_stride as usize * height as usize;- let dst_slice = unsafe { core::slice::from_raw_parts_mut(dst, dst_len) };+ let dst_slice = unsafe { ak::slice_from_raw_parts_mut(dst, dst_len) };let result = match (subsampling_x, subsampling_y) {(true, true) => yuv::yuv420_to_rgba(&planar_image, dst_slice, dst_stride, range.into(), matrix.into()),@@ -123,18 +123,18 @@ pub unsafe extern "C" fn yuv_u16_to_rgba(let uv_len = u_stride as usize * uv_height;let planar_image = YuvPlanarImage {- y_plane: unsafe { core::slice::from_raw_parts(y_plane, y_len) },+ y_plane: unsafe { ak::slice_from_raw_parts(y_plane, y_len) },y_stride,- u_plane: unsafe { core::slice::from_raw_parts(u_plane, uv_len) },+ u_plane: unsafe { ak::slice_from_raw_parts(u_plane, uv_len) },u_stride,- v_plane: unsafe { core::slice::from_raw_parts(v_plane, uv_len) },+ v_plane: unsafe { ak::slice_from_raw_parts(v_plane, uv_len) },v_stride,width,height,};let dst_len = dst_stride as usize * height as usize;- let dst_slice = unsafe { core::slice::from_raw_parts_mut(dst, dst_len) };+ let dst_slice = unsafe { ak::slice_from_raw_parts_mut(dst, dst_len) };let result = if bit_depth <= 10 {match (subsampling_x, subsampling_y) {@@ -146,15 +146,15 @@ pub unsafe extern "C" fn yuv_u16_to_rgba(} else {// 12-bit 4:4:4 has no 8-bit RGBA output; shift to 10-bit and use I410.if !subsampling_x && !subsampling_y {- let y_10: Vec<u16> = unsafe { core::slice::from_raw_parts(y_plane, y_len) }+ let y_10: Vec<u16> = unsafe { ak::slice_from_raw_parts(y_plane, y_len) }.iter().map(|&v| v >> 2).collect();- let u_10: Vec<u16> = unsafe { core::slice::from_raw_parts(u_plane, uv_len) }+ let u_10: Vec<u16> = unsafe { ak::slice_from_raw_parts(u_plane, uv_len) }.iter().map(|&v| v >> 2).collect();- let v_10: Vec<u16> = unsafe { core::slice::from_raw_parts(v_plane, uv_len) }+ let v_10: Vec<u16> = unsafe { ak::slice_from_raw_parts(v_plane, uv_len) }.iter().map(|&v| v >> 2).collect();@@ -201,16 +201,16 @@ pub unsafe extern "C" fn yuv_nv12_to_rgba(let uv_len = uv_stride as usize * height.div_ceil(2) as usize;let bi_planar_image = YuvBiPlanarImage {- y_plane: unsafe { core::slice::from_raw_parts(y_plane, y_len) },+ y_plane: unsafe { ak::slice_from_raw_parts(y_plane, y_len) },y_stride,- uv_plane: unsafe { core::slice::from_raw_parts(uv_plane, uv_len) },+ uv_plane: unsafe { ak::slice_from_raw_parts(uv_plane, uv_len) },uv_stride,width,height,};let dst_len = dst_stride as usize * height as usize;- let dst_slice = unsafe { core::slice::from_raw_parts_mut(dst, dst_len) };+ let dst_slice = unsafe { ak::slice_from_raw_parts_mut(dst, dst_len) };yuv::yuv_nv12_to_rgba(&bi_planar_image,@@ -244,16 +244,16 @@ pub unsafe extern "C" fn yuv_p010_to_rgba(let uv_len = uv_stride as usize * height.div_ceil(2) as usize;let bi_planar_image = YuvBiPlanarImage {- y_plane: unsafe { core::slice::from_raw_parts(y_plane, y_len) },+ y_plane: unsafe { ak::slice_from_raw_parts(y_plane, y_len) },y_stride,- uv_plane: unsafe { core::slice::from_raw_parts(uv_plane, uv_len) },+ uv_plane: unsafe { ak::slice_from_raw_parts(uv_plane, uv_len) },uv_stride,width,height,};let dst_len = dst_stride as usize * height as usize;- let dst_slice = unsafe { core::slice::from_raw_parts_mut(dst, dst_len) };+ let dst_slice = unsafe { ak::slice_from_raw_parts_mut(dst, dst_len) };yuv::p010_to_rgba(&bi_planar_image,diff --git a/Libraries/LibImageDecoders/Rust/Cargo.toml b/Libraries/LibImageDecoders/Rust/Cargo.tomlindex 83824ccab58..c4f5a23c0f9 100644--- a/Libraries/LibImageDecoders/Rust/Cargo.toml+++ b/Libraries/LibImageDecoders/Rust/Cargo.toml@@ -11,6 +11,7 @@ default = []allocator = ["dep:ladybird_allocator"][dependencies]+ak = { path = "../../../AK/Rust" }jxl = "0.7.4"ladybird_allocator = { path = "../../RustAllocator", optional = true }rustc-demangle = "0.1"diff --git a/Libraries/LibImageDecoders/Rust/src/jpeg_xl.rs b/Libraries/LibImageDecoders/Rust/src/jpeg_xl.rsindex 3778d02a5db..04ce2d1bf9e 100644--- a/Libraries/LibImageDecoders/Rust/src/jpeg_xl.rs+++ b/Libraries/LibImageDecoders/Rust/src/jpeg_xl.rs@@ -55,7 +55,7 @@ unsafe fn bytes_from_raw<'a>(bytes: *const u8, len: usize) -> Option<&'a [u8]> {}// SAFETY: The caller guarantees that `bytes` is valid for `len` bytes.- Some(unsafe { std::slice::from_raw_parts(bytes, len) })+ Some(unsafe { ak::slice_from_raw_parts(bytes, len) })}fn decode_header(input: &mut &[u8], options: JxlDecoderOptions) -> Option<JxlDecoder<WithImageInfo>> {diff --git a/Libraries/LibJS/JIT/Rust/Cargo.toml b/Libraries/LibJS/JIT/Rust/Cargo.tomlindex 4eb05fa2ded..4a826b1f057 100644--- a/Libraries/LibJS/JIT/Rust/Cargo.toml+++ b/Libraries/LibJS/JIT/Rust/Cargo.toml@@ -19,6 +19,7 @@ iced-x86 = { version = "1.21", default-features = false, features = ["decoder",farm64 = { package = "fARM64", version = "0.0.2", features = ["alloc"] }[dev-dependencies]+ak = { path = "../../../../AK/Rust" }farm64 = { package = "fARM64", version = "0.0.2", features = ["alloc"] }iced-x86 = { version = "1.21", default-features = false, features = ["decoder", "intel", "std"] }libc = "0.2"diff --git a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rsindex 17611fe52bb..962a1a82b54 100644--- a/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs+++ b/Libraries/LibJS/JIT/Rust/src/codegen/tests.rs@@ -3082,7 +3082,7 @@ mod direct_calls {// slot count in the header.unsafe {let slot_count = *frame.cast::<u8>().add(148).cast::<u32>() as usize;- let copy = std::slice::from_raw_parts(frame, FRAME_HEADER_WORDS + slot_count).to_vec();+ let copy = ak::slice_from_raw_parts(frame, FRAME_HEADER_WORDS + slot_count).to_vec();let mut state = test_state(vm).borrow_mut();state.direct.callee_frames.push(copy);let (value, status) = state.direct.callee_result.expect("a callee result");@@ -4004,7 +4004,7 @@ mod direct_calls {unsafe {let frame = *vm as *mut u64;let slot_count = *frame.cast::<u8>().add(148).cast::<u32>() as usize;- let copy = std::slice::from_raw_parts(frame, FRAME_HEADER_WORDS + slot_count).to_vec();+ let copy = ak::slice_from_raw_parts(frame, FRAME_HEADER_WORDS + slot_count).to_vec();let mut sum = int(*frame.add(120 / 8));for index in 0..slot_count {sum = sum.wrapping_add(int(*frame.add(FRAME_HEADER_WORDS + index)));diff --git a/Libraries/LibJS/Rust/generate/ops.rs b/Libraries/LibJS/Rust/generate/ops.rsindex beb9fbb92e0..851698fb813 100644--- a/Libraries/LibJS/Rust/generate/ops.rs+++ b/Libraries/LibJS/Rust/generate/ops.rs@@ -101,7 +101,7 @@ pub fn generate(ops: &[InstructionDefinition], ops_with_values: &BTreeSet<Stringlet ty = rust_type(&array_field.ty);let _ = writeln!(out,- "impl {op_name} {{\n /// The elements the instruction holds after its fixed fields, within the length it records.\n pub fn {name}(&self) -> &[{ty}] {{\n let count = self.{count_field} as usize;\n assert!(core::mem::offset_of!({op_name}, {name}) + count * size_of::<{ty}>() <= self.length() as usize);\n // SAFETY: The instruction is a view of bytecode that holds the length it records, which the elements are\n // within.\n unsafe {{ core::slice::from_raw_parts(self.{name}.as_ptr(), count) }}\n }}\n}}",+ "impl {op_name} {{\n /// The elements the instruction holds after its fixed fields, within the length it records.\n pub fn {name}(&self) -> &[{ty}] {{\n let count = self.{count_field} as usize;\n assert!(core::mem::offset_of!({op_name}, {name}) + count * size_of::<{ty}>() <= self.length() as usize);\n // SAFETY: The instruction is a view of bytecode that holds the length it records, which the elements are\n // within.\n unsafe {{ ak::slice_from_raw_parts(self.{name}.as_ptr(), count) }}\n }}\n}}",op_name = op.name);}diff --git a/Libraries/LibJS/Rust/generate/runtime_functions.rs b/Libraries/LibJS/Rust/generate/runtime_functions.rsindex 4e2b4e478a4..77990b8196a 100644--- a/Libraries/LibJS/Rust/generate/runtime_functions.rs+++ b/Libraries/LibJS/Rust/generate/runtime_functions.rs@@ -63,7 +63,7 @@ impl<'a> Record<'a> {);let _ = writeln!(out,- " let {array} = unsafe {{ core::slice::from_raw_parts_mut((&raw mut (*values).{array}).cast::<Value>(), instruction.{count} as usize) }};"+ " let {array} = unsafe {{ ak::slice_from_raw_parts_mut((&raw mut (*values).{array}).cast::<Value>(), instruction.{count} as usize) }};");}let _ = writeln!(diff --git a/Libraries/LibJS/Rust/src/bytecode/dump.rs b/Libraries/LibJS/Rust/src/bytecode/dump.rsindex 276cb3070b7..6ec4b2e40bc 100644--- a/Libraries/LibJS/Rust/src/bytecode/dump.rs+++ b/Libraries/LibJS/Rust/src/bytecode/dump.rs@@ -58,7 +58,7 @@ unsafe fn native_code_between(start: *const u8, end: *const u8) -> &'static [u8]return &[];}// SAFETY: The caller guarantees the range.- unsafe { std::slice::from_raw_parts(start, end_address - start_address) }+ unsafe { ak::slice_from_raw_parts(start, end_address - start_address) }}struct ColdCodeRange {diff --git a/Libraries/LibJS/Rust/src/bytecode/feedback.rs b/Libraries/LibJS/Rust/src/bytecode/feedback.rsindex 48f9821adc8..fdb41cba4ae 100644--- a/Libraries/LibJS/Rust/src/bytecode/feedback.rs+++ b/Libraries/LibJS/Rust/src/bytecode/feedback.rs@@ -76,7 +76,7 @@ impl ExecutableFeedback {};// SAFETY: new() laid out `count` initialized elements of type T, aligned for T, at `offset` in the storage,// which lives as long as the feedback. Its elements are cells, which allow shared mutation.- unsafe { core::slice::from_raw_parts(storage.data().add(offset).cast::<T>(), count as usize) }+ unsafe { ak::slice_from_raw_parts(storage.data().add(offset).cast::<T>(), count as usize) }}/// Takes over what `other`, the feedback of an executable with the same bytecode, observed.diff --git a/Libraries/LibJS/Rust/src/bytecode_cache.rs b/Libraries/LibJS/Rust/src/bytecode_cache.rsindex 2be2f87ae7a..9ba912d7464 100644--- a/Libraries/LibJS/Rust/src/bytecode_cache.rs+++ b/Libraries/LibJS/Rust/src/bytecode_cache.rs@@ -474,11 +474,11 @@ impl DecodedUtf16String {#[cfg(target_endian = "little")]// SAFETY: The record this string was reached through keeps the blob alive, and the decoder checked that// the code units lie within it and are aligned.- Self::Foreign { data, length } => Cow::Borrowed(unsafe { std::slice::from_raw_parts(*data, *length) }),+ Self::Foreign { data, length } => Cow::Borrowed(unsafe { ak::slice_from_raw_parts(*data, *length) }),#[cfg(not(target_endian = "little"))]// SAFETY: As above.Self::Foreign { data, length } => Cow::Owned(unsafe {- std::slice::from_raw_parts(*data, *length)+ ak::slice_from_raw_parts(*data, *length).iter().map(|code_unit| u16::from_le(*code_unit)).collect()@@ -529,7 +529,7 @@ impl DecodedBytecodeBytes {pub fn as_slice(&self) -> &[u8] {debug_assert!(self.range.end <= self.blob.length);// SAFETY: The decoder checked that the range lies within the blob, which the Rc keeps alive.- unsafe { std::slice::from_raw_parts(self.blob.data.add(self.range.start), self.range.len()) }+ unsafe { ak::slice_from_raw_parts(self.blob.data.add(self.range.start), self.range.len()) }}fn decoder(&self) -> Decoder<'_> {@@ -3123,7 +3123,7 @@ mod tests {std::ptr::copy_nonoverlapping(bytes.as_ptr(), storage.words.as_mut_ptr().cast::<u8>(), bytes.len());}// SAFETY: The owner keeps the words alive until the decoded blob releases it.- let view = unsafe { std::slice::from_raw_parts(storage.words.as_ptr().cast::<u8>(), bytes.len()) };+ let view = unsafe { ak::slice_from_raw_parts(storage.words.as_ptr().cast::<u8>(), bytes.len()) };let owner = BytecodeCacheBlobOwner::Foreign {owner: Box::into_raw(storage).cast(),free_owner: release_test_blob,diff --git a/Libraries/LibJS/Rust/src/embedding/abi_types.rs b/Libraries/LibJS/Rust/src/embedding/abi_types.rsindex 5576dd03393..af2a7aa1d69 100644--- a/Libraries/LibJS/Rust/src/embedding/abi_types.rs+++ b/Libraries/LibJS/Rust/src/embedding/abi_types.rs@@ -311,10 +311,10 @@ impl JSUtf16View {assert!(!self.data.is_null(), "a view of code units has its data");if self.has_ascii_storage {// SAFETY: The caller guarantees that the data is this many ASCII bytes.- Utf16View::Ascii(unsafe { core::slice::from_raw_parts(self.data.cast(), self.length_in_code_units) })+ Utf16View::Ascii(unsafe { ak::slice_from_raw_parts(self.data.cast(), self.length_in_code_units) })} else {// SAFETY: The caller guarantees that the data is this many UTF-16 code units.- Utf16View::Utf16(unsafe { core::slice::from_raw_parts(self.data.cast(), self.length_in_code_units) })+ Utf16View::Utf16(unsafe { ak::slice_from_raw_parts(self.data.cast(), self.length_in_code_units) })}}}diff --git a/Libraries/LibJS/Rust/src/embedding/array_buffer.rs b/Libraries/LibJS/Rust/src/embedding/array_buffer.rsindex faf25267e99..f8b152f20e0 100644--- a/Libraries/LibJS/Rust/src/embedding/array_buffer.rs+++ b/Libraries/LibJS/Rust/src/embedding/array_buffer.rs@@ -225,7 +225,7 @@ pub unsafe extern "C" fn js_array_buffer_create_from_bytes(&[]} else {// SAFETY: The caller passes `length` readable bytes.- unsafe { core::slice::from_raw_parts(bytes, length) }+ unsafe { ak::slice_from_raw_parts(bytes, length) }};object_into_abi(ArrayBuffer::create_from_bytes(vm,diff --git a/Libraries/LibJS/Rust/src/embedding/bigint.rs b/Libraries/LibJS/Rust/src/embedding/bigint.rsindex 0198a9dd507..ac015bc6103 100644--- a/Libraries/LibJS/Rust/src/embedding/bigint.rs+++ b/Libraries/LibJS/Rust/src/embedding/bigint.rs@@ -36,7 +36,7 @@ pub unsafe extern "C" fn js_bigint_create_from_magnitude(&[]} else {// SAFETY: The caller passes `word_count` words.- unsafe { core::slice::from_raw_parts(words, word_count) }+ unsafe { ak::slice_from_raw_parts(words, word_count) }};let sign = if is_negative { Sign::Minus } else { Sign::Plus };cell_into_abi(BigInt::create(vm, SignedBigInteger::from_slice(sign, words)))@@ -85,7 +85,7 @@ pub unsafe extern "C" fn js_bigint_copy_magnitude_words(bigint: *mut JSBigInt, wreturn;}// SAFETY: The caller passes room for `word_count` words.- let words = unsafe { core::slice::from_raw_parts_mut(words, word_count) };+ let words = unsafe { ak::slice_from_raw_parts_mut(words, word_count) };for (word, magnitude_word) in words.iter_mut().zip(magnitude) {*word = magnitude_word;}diff --git a/Libraries/LibJS/Rust/src/embedding/bytecode_cache.rs b/Libraries/LibJS/Rust/src/embedding/bytecode_cache.rsindex 78541eaea31..9e5edb73e60 100644--- a/Libraries/LibJS/Rust/src/embedding/bytecode_cache.rs+++ b/Libraries/LibJS/Rust/src/embedding/bytecode_cache.rs@@ -67,7 +67,7 @@ unsafe fn source_hash_from_abi<'a>(return None;}// SAFETY: The caller passes readable bytes, which are as many as a hash has.- unsafe { core::slice::from_raw_parts(source_hash, source_hash_length) }+ unsafe { ak::slice_from_raw_parts(source_hash, source_hash_length) }.try_into().ok()}@@ -156,7 +156,7 @@ unsafe fn decode(}let program_type = program_type_from_abi(program_type);// SAFETY: The caller passes bytes that stay alive and unchanged until the owner is released.- let bytes = unsafe { core::slice::from_raw_parts(bytes, length) };+ let bytes = unsafe { ak::slice_from_raw_parts(bytes, length) };let (bytes, owner) = if bytes.as_ptr().addr().is_multiple_of(JS_BYTECODE_CACHE_BLOB_ALIGNMENT) {let owner = BytecodeCacheBlobOwner::Foreign {@@ -173,7 +173,7 @@ unsafe fn decode(}release_owner();// SAFETY: The words, which the owner below keeps, stay alive and unchanged.- let bytes = unsafe { core::slice::from_raw_parts(words.as_ptr().cast::<u8>(), length) };+ let bytes = unsafe { ak::slice_from_raw_parts(words.as_ptr().cast::<u8>(), length) };(bytes, BytecodeCacheBlobOwner::Aligned(words))};// SAFETY: The owner keeps the bytes alive and unchanged until it is released.diff --git a/Libraries/LibJS/Rust/src/embedding/function.rs b/Libraries/LibJS/Rust/src/embedding/function.rsindex 5569443e6b1..2917a0be891 100644--- a/Libraries/LibJS/Rust/src/embedding/function.rs+++ b/Libraries/LibJS/Rust/src/embedding/function.rs@@ -112,7 +112,7 @@ unsafe fn prefix_from_abi<'prefix>(prefix: *const c_char, prefix_length: usize)return None;}// SAFETY: The caller passes `prefix_length` bytes at `prefix`.- let bytes = unsafe { core::slice::from_raw_parts(prefix.cast::<u8>(), prefix_length) };+ let bytes = unsafe { ak::slice_from_raw_parts(prefix.cast::<u8>(), prefix_length) };Some(core::str::from_utf8(bytes).expect("the prefix is UTF-8"))}diff --git a/Libraries/LibJS/Rust/src/embedding/host/class_table.rs b/Libraries/LibJS/Rust/src/embedding/host/class_table.rsindex 0067edfda1c..92d3a593a13 100644--- a/Libraries/LibJS/Rust/src/embedding/host/class_table.rs+++ b/Libraries/LibJS/Rust/src/embedding/host/class_table.rs@@ -89,7 +89,7 @@ impl JSHostClass {}assert!(!self.name.is_null(), "a host class with a name points to it");// SAFETY: The name of a table is static data of the given length, like the table itself.- let name = unsafe { core::slice::from_raw_parts(self.name.cast::<u8>(), self.name_length) };+ let name = unsafe { ak::slice_from_raw_parts(self.name.cast::<u8>(), self.name_length) };core::str::from_utf8(name).expect("the name of a host class is UTF-8")}diff --git a/Libraries/LibJS/Rust/src/embedding/host/console_client.rs b/Libraries/LibJS/Rust/src/embedding/host/console_client.rsindex af77f64e766..54d34971602 100644--- a/Libraries/LibJS/Rust/src/embedding/host/console_client.rs+++ b/Libraries/LibJS/Rust/src/embedding/host/console_client.rs@@ -319,7 +319,7 @@ pub unsafe extern "C" fn js_console_client_generically_format_values(let marked_values = MarkedVec::with_capacity(vm, value_count);if value_count > 0 {// SAFETY: The caller guarantees that `values` points to `value_count` values.- for &value in unsafe { core::slice::from_raw_parts(values, value_count) } {+ for &value in unsafe { ak::slice_from_raw_parts(values, value_count) } {marked_values.push(Value(value));}}diff --git a/Libraries/LibJS/Rust/src/embedding/host/host_module.rs b/Libraries/LibJS/Rust/src/embedding/host/host_module.rsindex 8bb5d60172b..c632c5b25c8 100644--- a/Libraries/LibJS/Rust/src/embedding/host/host_module.rs+++ b/Libraries/LibJS/Rust/src/embedding/host/host_module.rs@@ -138,7 +138,7 @@ unsafe fn code_units_of<'a>(code_units: *const u16, length: usize) -> &'a [u16]return &[];}// SAFETY: The caller passes that many code units.- unsafe { core::slice::from_raw_parts(code_units, length) }+ unsafe { ak::slice_from_raw_parts(code_units, length) }}fn resolved_binding_type_from_abi(binding_type: u8) -> ResolvedBindingType {@@ -309,7 +309,7 @@ pub unsafe extern "C" fn js_host_module_create(Vec::new()} else {// SAFETY: The embedder passes that many module requests.- unsafe { core::slice::from_raw_parts(requested_modules, requested_module_count) }+ unsafe { ak::slice_from_raw_parts(requested_modules, requested_module_count) }.iter()// SAFETY: Each is a module request that outlives the call..map(|&request| unsafe { module_request_from_abi(request) }.clone())diff --git a/Libraries/LibJS/Rust/src/embedding/module.rs b/Libraries/LibJS/Rust/src/embedding/module.rsindex 6b52bbb40e5..a62a670dc19 100644--- a/Libraries/LibJS/Rust/src/embedding/module.rs+++ b/Libraries/LibJS/Rust/src/embedding/module.rs@@ -89,7 +89,7 @@ pub unsafe extern "C" fn js_module_request_create(&[]} else {// SAFETY: The embedder passes that many attributes.- unsafe { core::slice::from_raw_parts(attributes, attribute_count) }+ unsafe { ak::slice_from_raw_parts(attributes, attribute_count) }};// SAFETY: See the module documentation.let module_request = unsafe {diff --git a/Libraries/LibJS/Rust/src/embedding/object.rs b/Libraries/LibJS/Rust/src/embedding/object.rsindex 260ff2f57ac..30157d64626 100644--- a/Libraries/LibJS/Rust/src/embedding/object.rs+++ b/Libraries/LibJS/Rust/src/embedding/object.rs@@ -78,7 +78,7 @@ pub(crate) unsafe fn values_from_abi<'values>(values: *const JSValue, count: usireturn &[];}// SAFETY: Value is a transparent JSValue, and the caller passes `count` of them.- unsafe { core::slice::from_raw_parts(values.cast::<Value>(), count) }+ unsafe { ak::slice_from_raw_parts(values.cast::<Value>(), count) }}const ABSENT_PROPERTY_DESCRIPTOR: JSPropertyDescriptor = JSPropertyDescriptor {diff --git a/Libraries/LibJS/Rust/src/embedding/vm.rs b/Libraries/LibJS/Rust/src/embedding/vm.rsindex 6c7b598c50a..247bcd21346 100644--- a/Libraries/LibJS/Rust/src/embedding/vm.rs+++ b/Libraries/LibJS/Rust/src/embedding/vm.rs@@ -374,7 +374,7 @@ pub unsafe extern "C" fn js_vm_default_host_call_job_callback(&[]} else {// SAFETY: The caller passes `argument_count` values, and a Value is a JSValue.- unsafe { core::slice::from_raw_parts(arguments.cast(), argument_count) }+ unsafe { ak::slice_from_raw_parts(arguments.cast(), argument_count) }};completion_into_abi(call_job_callback(vm, job_callback, Value(this_value), arguments))}diff --git a/Libraries/LibJS/Rust/src/gc/interpreter_buffer.rs b/Libraries/LibJS/Rust/src/gc/interpreter_buffer.rsindex 8c26cf9d76b..aea0a0e76d5 100644--- a/Libraries/LibJS/Rust/src/gc/interpreter_buffer.rs+++ b/Libraries/LibJS/Rust/src/gc/interpreter_buffer.rs@@ -176,7 +176,7 @@ unsafe impl<T: Copy + Trace> Trace for InterpreterBuffer<T> {return;}// SAFETY: The first `size` elements are initialized, and nothing writes them while they are visited.- let elements = unsafe { core::slice::from_raw_parts(self.data.get(), self.size()) };+ let elements = unsafe { ak::slice_from_raw_parts(self.data.get(), self.size()) };T::trace_slice(elements, visitor);}}diff --git a/Libraries/LibJS/Rust/src/interpreter/execution_context.rs b/Libraries/LibJS/Rust/src/interpreter/execution_context.rsindex a66820d3321..8f7feedc54d 100644--- a/Libraries/LibJS/Rust/src/interpreter/execution_context.rs+++ b/Libraries/LibJS/Rust/src/interpreter/execution_context.rs@@ -70,7 +70,7 @@ impl ExecutionContext {pub fn slots(&self) -> &[Cell<Value>] {let count = self.registers_and_constants_and_locals_and_arguments_count.get() as usize;// SAFETY: Contexts are only ever allocated with their slots following them.- unsafe { core::slice::from_raw_parts(core::ptr::from_ref(self).add(1).cast::<Cell<Value>>(), count) }+ unsafe { ak::slice_from_raw_parts(core::ptr::from_ref(self).add(1).cast::<Cell<Value>>(), count) }}pub fn register(&self, index: u32) -> &Cell<Value> {@@ -178,7 +178,7 @@ unsafe impl Trace for ExecutionContext {fn trace_slots(slots: &[Cell<Value>], visitor: &mut Visitor) {// SAFETY: Cell<Value> has the same layout as Value, and nothing writes the slots while they are visited.- let values = unsafe { core::slice::from_raw_parts(slots.as_ptr().cast::<Value>(), slots.len()) };+ let values = unsafe { ak::slice_from_raw_parts(slots.as_ptr().cast::<Value>(), slots.len()) };visitor.visit_values(values);}diff --git a/Libraries/LibJS/Rust/src/runtime/array_buffer.rs b/Libraries/LibJS/Rust/src/runtime/array_buffer.rsindex 302a8de0a61..846a9b6c740 100644--- a/Libraries/LibJS/Rust/src/runtime/array_buffer.rs+++ b/Libraries/LibJS/Rust/src/runtime/array_buffer.rs@@ -965,7 +965,7 @@ impl ArrayBuffer {let data = data_block.data_at(0).cast::<MaybeUninit<u8>>();assert!(!data.is_null() && data_block.size() == byte_length);// SAFETY: The new block has `byte_length` bytes, which nothing else references yet.- write(unsafe { core::slice::from_raw_parts_mut(data, byte_length) })+ write(unsafe { ak::slice_from_raw_parts_mut(data, byte_length) })};assert_eq!(written, byte_length,diff --git a/Libraries/LibJS/Rust/src/runtime/object.rs b/Libraries/LibJS/Rust/src/runtime/object.rsindex b6269d972be..651f38c5a86 100644--- a/Libraries/LibJS/Rust/src/runtime/object.rs+++ b/Libraries/LibJS/Rust/src/runtime/object.rs@@ -342,7 +342,7 @@ unsafe impl Trace for Object {debug_assert!(property_count <= self.named_storage_capacity() as usize);// SAFETY: The storage holds at least one slot per property of the shape, and nothing writes it during// a collection.- visitor.visit_values(unsafe { core::slice::from_raw_parts(named_properties, property_count) });+ visitor.visit_values(unsafe { ak::slice_from_raw_parts(named_properties, property_count) });}if !named_properties.is_null()&& !self.named_storage_is_inline()@@ -3799,7 +3799,7 @@ impl Object {return;}// SAFETY: The count is within the elements buffer, and nothing writes it during a collection.- visitor.visit_values(unsafe { core::slice::from_raw_parts(self.indexed_elements.get(), count as usize) });+ visitor.visit_values(unsafe { ak::slice_from_raw_parts(self.indexed_elements.get(), count as usize) });}/// Storage for at least `capacity` elements, all empty.@@ -4419,7 +4419,7 @@ impl Object {return None;}// SAFETY: The count is within the elements buffer, and IsStrictlyEqual runs no code that could write it.- let elements = unsafe { core::slice::from_raw_parts(self.indexed_elements.get(), count as usize) };+ let elements = unsafe { ak::slice_from_raw_parts(self.indexed_elements.get(), count as usize) };elements[start as usize..].iter().position(|element| is_strictly_equal(value, *element))diff --git a/Libraries/LibJS/Rust/src/test_host.rs b/Libraries/LibJS/Rust/src/test_host.rsindex 1aa9a933f09..6952f0d4650 100644--- a/Libraries/LibJS/Rust/src/test_host.rs+++ b/Libraries/LibJS/Rust/src/test_host.rs@@ -97,13 +97,13 @@ fn fly_string_from_utf16(units: &[u16]) -> usize {#[unsafe(no_mangle)]extern "C" fn ladybird_utf16_fly_string_from_utf16(data: *const u16, length: usize) -> usize {// SAFETY: The frontend passes `length` readable code units.- fly_string_from_utf16(unsafe { std::slice::from_raw_parts(data, length) })+ fly_string_from_utf16(unsafe { ak::slice_from_raw_parts(data, length) })}#[unsafe(no_mangle)]extern "C" fn ladybird_utf16_fly_string_from_utf8(data: *const u8, length: usize) -> usize {// SAFETY: The frontend passes `length` readable bytes of UTF-8.- let string = std::str::from_utf8(unsafe { std::slice::from_raw_parts(data, length) }).expect("valid UTF-8");+ let string = std::str::from_utf8(unsafe { ak::slice_from_raw_parts(data, length) }).expect("valid UTF-8");fly_string_from_utf16(&string.encode_utf16().collect::<Vec<_>>())}diff --git a/Libraries/LibJS/Rust/src/unicode/date_time_format.rs b/Libraries/LibJS/Rust/src/unicode/date_time_format.rsindex b8a6db95c02..f264a56550f 100644--- a/Libraries/LibJS/Rust/src/unicode/date_time_format.rs+++ b/Libraries/LibJS/Rust/src/unicode/date_time_format.rs@@ -446,9 +446,9 @@ unsafe extern "C" fn append_date_time_format_part(let (parts, type_, value, source) = unsafe {(&mut *context.cast::<Vec<DateTimeFormatPartition>>(),- core::slice::from_raw_parts(type_, type_length),- core::slice::from_raw_parts(value, value_length),- core::slice::from_raw_parts(source, source_length),+ ak::slice_from_raw_parts(type_, type_length),+ ak::slice_from_raw_parts(value, value_length),+ ak::slice_from_raw_parts(source, source_length),)};parts.push(DateTimeFormatPartition {diff --git a/Libraries/LibJS/Rust/src/unicode/intl.rs b/Libraries/LibJS/Rust/src/unicode/intl.rsindex dc41b6eb094..68f1f1c084b 100644--- a/Libraries/LibJS/Rust/src/unicode/intl.rs+++ b/Libraries/LibJS/Rust/src/unicode/intl.rs@@ -226,7 +226,7 @@ unsafe extern "C" fn append_string(context: *mut c_void, text: *const u16, lengtlet (list, text) = unsafe {(&mut *context.cast::<Vec<Utf16String>>(),- core::slice::from_raw_parts(text, length),+ ak::slice_from_raw_parts(text, length),)};list.push(Utf16String::from_utf16(text));@@ -450,7 +450,7 @@ unsafe extern "C" fn append_locale_id_part(context: *mut c_void, part: u8, text:let (builder, text) = unsafe {(&mut *context.cast::<LocaleIDBuilder>(),- core::slice::from_raw_parts(text, length),+ ak::slice_from_raw_parts(text, length),)};builder.append(LocaleIDPart::from_u8(part), Utf16String::from_utf16(text));@@ -984,8 +984,8 @@ unsafe extern "C" fn append_list_format_part(let (parts, type_, value) = unsafe {(&mut *context.cast::<Vec<ListFormatPartition>>(),- core::slice::from_raw_parts(type_, type_length),- core::slice::from_raw_parts(value, value_length),+ ak::slice_from_raw_parts(type_, type_length),+ ak::slice_from_raw_parts(value, value_length),)};parts.push(ListFormatPartition {diff --git a/Libraries/LibJS/Rust/src/unicode/number_format.rs b/Libraries/LibJS/Rust/src/unicode/number_format.rsindex e231b746eef..35489fe7ff9 100644--- a/Libraries/LibJS/Rust/src/unicode/number_format.rs+++ b/Libraries/LibJS/Rust/src/unicode/number_format.rs@@ -405,9 +405,9 @@ unsafe extern "C" fn append_number_format_part(let (parts, type_, value, source) = unsafe {(&mut *context.cast::<Vec<NumberFormatPartition>>(),- core::slice::from_raw_parts(type_, type_length),- core::slice::from_raw_parts(value, value_length),- core::slice::from_raw_parts(source, source_length),+ ak::slice_from_raw_parts(type_, type_length),+ ak::slice_from_raw_parts(value, value_length),+ ak::slice_from_raw_parts(source, source_length),)};parts.push(NumberFormatPartition {diff --git a/Libraries/LibJS/Rust/src/unicode/relative_time_format.rs b/Libraries/LibJS/Rust/src/unicode/relative_time_format.rsindex 4caf49bebfc..72b85f4c3e5 100644--- a/Libraries/LibJS/Rust/src/unicode/relative_time_format.rs+++ b/Libraries/LibJS/Rust/src/unicode/relative_time_format.rs@@ -123,9 +123,9 @@ unsafe extern "C" fn append_relative_time_format_part(let (parts, type_, value, unit) = unsafe {(&mut *context.cast::<Vec<RelativeTimeFormatPartition>>(),- core::slice::from_raw_parts(type_, type_length),- core::slice::from_raw_parts(value, value_length),- core::slice::from_raw_parts(unit, unit_length),+ ak::slice_from_raw_parts(type_, type_length),+ ak::slice_from_raw_parts(value, value_length),+ ak::slice_from_raw_parts(unit, unit_length),)};parts.push(RelativeTimeFormatPartition {diff --git a/Libraries/LibJS/Rust/src/unicode/time_zone.rs b/Libraries/LibJS/Rust/src/unicode/time_zone.rsindex 3925e3294b3..95dd64f3fc2 100644--- a/Libraries/LibJS/Rust/src/unicode/time_zone.rs+++ b/Libraries/LibJS/Rust/src/unicode/time_zone.rs@@ -165,7 +165,7 @@ unsafe extern "C" fn append_time_zone(context: *mut c_void, time_zone: *const u1// SAFETY: The context is the list available_time_zones() passes, which outlives the call.let time_zones = unsafe { &mut *context.cast::<Vec<Vec<u16>>>() };// SAFETY: LibUnicode passes a time zone of `length` code units that stays alive for the call.- time_zones.push(unsafe { core::slice::from_raw_parts(time_zone, length) }.to_vec());+ time_zones.push(unsafe { ak::slice_from_raw_parts(time_zone, length) }.to_vec());}/// Unicode::available_time_zones: every time zone LibUnicode knows, sorted, which it computes once.diff --git a/Libraries/LibRegex/Rust/Cargo.toml b/Libraries/LibRegex/Rust/Cargo.tomlindex 79a0424cc7b..e7dd1db31e0 100644--- a/Libraries/LibRegex/Rust/Cargo.toml+++ b/Libraries/LibRegex/Rust/Cargo.toml@@ -9,6 +9,7 @@ crate-type = ["staticlib", "rlib"]# After changing dependencies, regenerate the Flatpak sources:# python3 Meta/CMake/flatpak/generate-cargo-sources.py[dependencies]+ak = { path = "../../../AK/Rust" }ladybird_allocator = { path = "../../RustAllocator", optional = true }libunicode_rust = { path = "../../LibUnicode/Rust", default-features = false }rustc-demangle = "0.1"diff --git a/Libraries/LibRegex/Rust/src/ffi.rs b/Libraries/LibRegex/Rust/src/ffi.rsindex 44102b69d62..aed2b58d98e 100644--- a/Libraries/LibRegex/Rust/src/ffi.rs+++ b/Libraries/LibRegex/Rust/src/ffi.rs@@ -10,7 +10,6 @@/// All functions use `extern "C"` linkage and opaque pointer types.use crate::ast::Flags;use crate::regex::Regex;-use std::slice;/// Opaque regex handle.pub struct RustRegex(Regex);@@ -80,7 +79,7 @@ pub unsafe extern "C" fn rust_regex_compile(return std::ptr::null_mut();}- let code_units = unsafe { slice::from_raw_parts(pattern, pattern_len) };+ let code_units = unsafe { ak::slice_from_raw_parts(pattern, pattern_len) };let pattern = char::decode_utf16(code_units.iter().copied()).map(|result| result.unwrap_or(char::REPLACEMENT_CHARACTER)).collect();@@ -107,7 +106,7 @@ pub unsafe extern "C" fn rust_regex_compile_ascii(return std::ptr::null_mut();}- let bytes = unsafe { slice::from_raw_parts(pattern, pattern_len) };+ let bytes = unsafe { ak::slice_from_raw_parts(pattern, pattern_len) };let pattern = bytes.iter().map(|byte| *byte as char).collect();compile_pattern(pattern, flags, error_out, error_len_out)@@ -144,7 +143,7 @@ fn exec_into_internal<I: crate::vm::Input>() -> i32 {use crate::vm::VmResult;- let out = unsafe { slice::from_raw_parts_mut(out_captures, out_capture_slots as usize) };+ let out = unsafe { ak::slice_from_raw_parts_mut(out_captures, out_capture_slots as usize) };match regex.0.exec_into_input(input, start_pos, out) {VmResult::Match => 1,VmResult::NoMatch => 0,@@ -169,7 +168,7 @@ fn find_all_internal<I: crate::vm::Input>(out: *mut i32,out_capacity: u32,) -> i32 {- let out_slice = unsafe { slice::from_raw_parts_mut(out, out_capacity as usize) };+ let out_slice = unsafe { ak::slice_from_raw_parts_mut(out, out_capacity as usize) };regex.0.find_all_into_input(input, start_pos, out_slice)}@@ -197,7 +196,7 @@ pub unsafe extern "C" fn rust_regex_exec_into(let input = if input.is_null() {&[]} else {- unsafe { slice::from_raw_parts(input, input_len) }+ unsafe { ak::slice_from_raw_parts(input, input_len) }};exec_into_internal(regex, input, start_pos, out_captures, out_capture_slots)}@@ -224,7 +223,7 @@ pub unsafe extern "C" fn rust_regex_exec_into_ascii(let input = if input.is_null() {&[]} else {- unsafe { slice::from_raw_parts(input, input_len) }+ unsafe { ak::slice_from_raw_parts(input, input_len) }};exec_into_internal(regex, input, start_pos, out_captures, out_capture_slots)}@@ -248,7 +247,7 @@ pub unsafe extern "C" fn rust_regex_test(let input = if input.is_null() {&[]} else {- unsafe { slice::from_raw_parts(input, input_len) }+ unsafe { ak::slice_from_raw_parts(input, input_len) }};test_internal(regex, input, start_pos)}@@ -271,7 +270,7 @@ pub unsafe extern "C" fn rust_regex_test_ascii(let input = if input.is_null() {&[]} else {- unsafe { slice::from_raw_parts(input, input_len) }+ unsafe { ak::slice_from_raw_parts(input, input_len) }};test_internal(regex, input, start_pos)}@@ -327,7 +326,7 @@ pub unsafe extern "C" fn rust_regex_find_all(let input = if input.is_null() {&[]} else {- unsafe { slice::from_raw_parts(input, input_len) }+ unsafe { ak::slice_from_raw_parts(input, input_len) }};find_all_internal(regex, input, start_pos, out, out_capacity)}@@ -354,7 +353,7 @@ pub unsafe extern "C" fn rust_regex_find_all_ascii(let input = if input.is_null() {&[]} else {- unsafe { slice::from_raw_parts(input, input_len) }+ unsafe { ak::slice_from_raw_parts(input, input_len) }};find_all_internal(regex, input, start_pos, out, out_capacity)}diff --git a/Libraries/LibTextCodec/Rust/Cargo.toml b/Libraries/LibTextCodec/Rust/Cargo.tomlindex 1c4899a320d..3154c3dde5a 100644--- a/Libraries/LibTextCodec/Rust/Cargo.toml+++ b/Libraries/LibTextCodec/Rust/Cargo.toml@@ -10,6 +10,7 @@ crate-type = ["staticlib"]allocator = ["dep:ladybird_allocator"][dependencies]+ak = { path = "../../../AK/Rust" }encoding_rs = "0.8.42"ladybird_allocator = { path = "../../RustAllocator", optional = true }rustc-demangle = "0.1"diff --git a/Libraries/LibTextCodec/Rust/src/lib.rs b/Libraries/LibTextCodec/Rust/src/lib.rsindex a5d88718110..2a6bedba483 100644--- a/Libraries/LibTextCodec/Rust/src/lib.rs+++ b/Libraries/LibTextCodec/Rust/src/lib.rs@@ -37,7 +37,7 @@ unsafe fn bytes_from_raw<'a>(bytes: *const u8, len: usize) -> Option<&'a [u8]> {eprintln!("bytes_from_raw: null pointer with non-zero length {len}");return None;}- Some(std::slice::from_raw_parts(bytes, len))+ Some(ak::slice_from_raw_parts(bytes, len))}}diff --git a/Libraries/LibURL/Rust/Cargo.toml b/Libraries/LibURL/Rust/Cargo.tomlindex de61163655e..ef4d5eb5a56 100644--- a/Libraries/LibURL/Rust/Cargo.toml+++ b/Libraries/LibURL/Rust/Cargo.toml@@ -7,6 +7,7 @@ edition = "2024"crate-type = ["rlib", "staticlib"][dependencies]+ak = { path = "../../../AK/Rust" }encoding_rs = "0.8.42"ladybird_allocator = { path = "../../RustAllocator", optional = true }libregex_rust = { path = "../../LibRegex/Rust" }diff --git a/Libraries/LibURL/Rust/src/ffi/pattern.rs b/Libraries/LibURL/Rust/src/ffi/pattern.rsindex 4faf54d8bb3..157bb4af240 100644--- a/Libraries/LibURL/Rust/src/ffi/pattern.rs+++ b/Libraries/LibURL/Rust/src/ffi/pattern.rs@@ -105,7 +105,7 @@ fn decode_utf8(slice: RustUrlByteSlice) -> String {return String::new();}// SAFETY: slice.data is valid for slice.length bytes (contract with C++ caller).- let bytes = unsafe { std::slice::from_raw_parts(slice.data, slice.length) };+ let bytes = unsafe { ak::slice_from_raw_parts(slice.data, slice.length) };String::from_utf8_lossy(bytes).into_owned()}@@ -344,7 +344,7 @@ pub unsafe extern "C" fn rust_url_pattern_create_from_string(}// SAFETY: caller guarantees input is valid for input_len bytes.- let input_bytes = unsafe { std::slice::from_raw_parts(input, input_len) };+ let input_bytes = unsafe { ak::slice_from_raw_parts(input, input_len) };let Ok(input_str) = std::str::from_utf8(input_bytes) else {return std::ptr::null_mut();};@@ -504,7 +504,7 @@ pub unsafe extern "C" fn rust_url_pattern_exec_string(// SAFETY: caller guarantees pointers are valid.let pattern = unsafe { &*pattern };- let input_bytes = unsafe { std::slice::from_raw_parts(input, input_len) };+ let input_bytes = unsafe { ak::slice_from_raw_parts(input, input_len) };let Ok(input_str) = std::str::from_utf8(input_bytes) else {return false;};@@ -573,7 +573,7 @@ pub unsafe extern "C" fn rust_url_pattern_test_string(// SAFETY: caller guarantees pointers are valid.let pattern = unsafe { &*pattern };- let input_bytes = unsafe { std::slice::from_raw_parts(input, input_len) };+ let input_bytes = unsafe { ak::slice_from_raw_parts(input, input_len) };let Ok(input_str) = std::str::from_utf8(input_bytes) else {return false;};diff --git a/Libraries/LibURL/Rust/src/ffi/url.rs b/Libraries/LibURL/Rust/src/ffi/url.rsindex 43097cafa8d..1a3f6dc06d9 100644--- a/Libraries/LibURL/Rust/src/ffi/url.rs+++ b/Libraries/LibURL/Rust/src/ffi/url.rs@@ -33,9 +33,9 @@ impl RustUrlInput {return UrlInput::Utf8("");}if !self.utf16.is_null() {- UrlInput::Utf16(unsafe { std::slice::from_raw_parts(self.utf16, self.length) })+ UrlInput::Utf16(unsafe { ak::slice_from_raw_parts(self.utf16, self.length) })} else {- UrlInput::Utf8(unsafe { std::str::from_utf8_unchecked(std::slice::from_raw_parts(self.utf8, self.length)) })+ UrlInput::Utf8(unsafe { std::str::from_utf8_unchecked(ak::slice_from_raw_parts(self.utf8, self.length)) })}}}@@ -61,7 +61,7 @@ impl RustUrlByteSlice {if self.data.is_null() {return None;}- let bytes = unsafe { std::slice::from_raw_parts(self.data, self.length) };+ let bytes = unsafe { ak::slice_from_raw_parts(self.data, self.length) };Some(std::str::from_utf8(bytes).expect("URL strings should be valid UTF-8"))}}@@ -329,7 +329,7 @@ pub unsafe extern "C" fn rust_url_set_path(let segments = if segment_count == 0 {&[]} else {- std::slice::from_raw_parts(segments, segment_count)+ ak::slice_from_raw_parts(segments, segment_count)};modify_url(url, ctx, on_complete, |url| {url.set_path(segments.iter().map(|segment| segment.borrow().unwrap_or("")))diff --git a/Libraries/LibUnicode/Rust/Cargo.toml b/Libraries/LibUnicode/Rust/Cargo.tomlindex 6ed9d0104d0..084e9ce8772 100644--- a/Libraries/LibUnicode/Rust/Cargo.toml+++ b/Libraries/LibUnicode/Rust/Cargo.toml@@ -14,6 +14,7 @@ crate-type = ["staticlib", "rlib"]# After changing dependencies, regenerate the Flatpak sources:# python3 Meta/CMake/flatpak/generate-cargo-sources.py[dependencies]+ak = { path = "../../../AK/Rust" }calendrical_calculations = "=0.2.4"icu_calendar = { version = "=2.3.0", features = ["compiled_data"] }ladybird_allocator = { path = "../../RustAllocator", optional = true }diff --git a/Libraries/LibUnicode/Rust/src/calendar.rs b/Libraries/LibUnicode/Rust/src/calendar.rsindex b471687d575..1a3d690956c 100644--- a/Libraries/LibUnicode/Rust/src/calendar.rs+++ b/Libraries/LibUnicode/Rust/src/calendar.rs@@ -68,7 +68,7 @@ const EMPTY_CALENDAR_DATE: FfiCalendarDate = FfiCalendarDate {/// SAFETY: All FFI string inputs are ASCII calendar names (e.g. "chinese") or month codes (e.g. "M01").fn ascii_string_from_ffi<'a>(string: *const u8, length: usize) -> &'a str {- let bytes = unsafe { std::slice::from_raw_parts(string, length) };+ let bytes = unsafe { ak::slice_from_raw_parts(string, length) };debug_assert!(bytes.is_ascii(), "Expected ASCII input from FFI");unsafe { std::str::from_utf8_unchecked(bytes) }}diff --git a/Libraries/LibUnicode/Rust/src/idna.rs b/Libraries/LibUnicode/Rust/src/idna.rsindex 2b57c3fad2d..2912d3b23e5 100644--- a/Libraries/LibUnicode/Rust/src/idna.rs+++ b/Libraries/LibUnicode/Rust/src/idna.rs@@ -42,7 +42,7 @@ unsafe extern "C" fn on_idna_result(ctx: *mut c_void, data: *const u8, len: usiz// SAFETY: `ctx` was set to `addr_of_mut!(result)` in `idna_to_ascii_utf16`.let out = unsafe { &mut *(ctx as *mut Option<String>) };// SAFETY: `data` is valid for `len` bytes; IDNA to_ascii guarantees ASCII output.- let bytes = unsafe { std::slice::from_raw_parts(data, len) };+ let bytes = unsafe { ak::slice_from_raw_parts(data, len) };debug_assert!(bytes.is_ascii(), "unicode_rust_idna_to_ascii must return ASCII");// SAFETY: ASCII is a strict subset of UTF-8.*out = Some(unsafe { String::from_utf8_unchecked(bytes.to_vec()) });diff --git a/Libraries/LibWasm/Rust/Cargo.toml b/Libraries/LibWasm/Rust/Cargo.tomlindex cb14d2d4b99..27fe64f99a8 100644--- a/Libraries/LibWasm/Rust/Cargo.toml+++ b/Libraries/LibWasm/Rust/Cargo.toml@@ -7,6 +7,7 @@ edition = "2024"crate-type = ["rlib"][dependencies]+ak = { path = "../../../AK/Rust" }cranelift-codegen = "0.136"cranelift-frontend = "0.136"cranelift-module = "0.136"diff --git a/Libraries/LibWasm/Rust/src/bin/cranelift-compiler.rs b/Libraries/LibWasm/Rust/src/bin/cranelift-compiler.rsindex 29777865be7..57996d302e9 100644--- a/Libraries/LibWasm/Rust/src/bin/cranelift-compiler.rs+++ b/Libraries/LibWasm/Rust/src/bin/cranelift-compiler.rs@@ -45,11 +45,11 @@ mod unix {}pub fn as_slice(&self) -> &[u8] {- unsafe { std::slice::from_raw_parts(self.ptr, self.len) }+ unsafe { ak::slice_from_raw_parts(self.ptr, self.len) }}pub fn as_slice_mut(&mut self) -> &mut [u8] {- unsafe { std::slice::from_raw_parts_mut(self.ptr, self.len) }+ unsafe { ak::slice_from_raw_parts_mut(self.ptr, self.len) }}}@@ -108,11 +108,11 @@ mod win {}pub fn as_slice(&self) -> &[u8] {- unsafe { std::slice::from_raw_parts(self.ptr, self.len) }+ unsafe { ak::slice_from_raw_parts(self.ptr, self.len) }}pub fn as_slice_mut(&mut self) -> &mut [u8] {- unsafe { std::slice::from_raw_parts_mut(self.ptr, self.len) }+ unsafe { ak::slice_from_raw_parts_mut(self.ptr, self.len) }}}diff --git a/Libraries/LibWasm/Rust/src/serialized.rs b/Libraries/LibWasm/Rust/src/serialized.rsindex 92829294fdd..b644e2cbf71 100644--- a/Libraries/LibWasm/Rust/src/serialized.rs+++ b/Libraries/LibWasm/Rust/src/serialized.rs@@ -65,7 +65,7 @@ fn align_up(value: usize, alignment: usize) -> Result<usize, &'static str> {}fn as_bytes_slice<T>(value: &[T]) -> &[u8] {- unsafe { std::slice::from_raw_parts(value.as_ptr().cast::<u8>(), size_of_val(value)) }+ unsafe { ak::slice_from_raw_parts(value.as_ptr().cast::<u8>(), size_of_val(value)) }}fn read_pod<T: Copy>(base: &[u8], offset: usize) -> Result<T, &'static str> {diff --git a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rsindex 369d765a3e6..0d2426e920c 100644--- a/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/bindings/conversions.rs@@ -497,7 +497,7 @@ unsafe fn borrowed_or_copied_bytes_of_buffer(buffer: &ArrayBuffer, bytes: Range<assert!(!data.is_null());// SAFETY: The buffer is not detached and has the bytes, which nothing writes while they are borrowed, as the// buffer is not shared and the caller keeps script from running.- Some(Cow::Borrowed(unsafe { core::slice::from_raw_parts(data, bytes.len()) }))+ Some(Cow::Borrowed(unsafe { ak::slice_from_raw_parts(data, bytes.len()) }))}impl ArrayBufferView {diff --git a/Libraries/LibWeb/Bindings/Rust/src/encoding/text_encoder.rs b/Libraries/LibWeb/Bindings/Rust/src/encoding/text_encoder.rsindex 84832266e7d..16e25042027 100644--- a/Libraries/LibWeb/Bindings/Rust/src/encoding/text_encoder.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/encoding/text_encoder.rs@@ -125,7 +125,7 @@ impl TextEncoder {// which nothing else accesses while this runs, as the buffer is not shared, and which the// encoding fits.let written = unsafe {- let output = core::slice::from_raw_parts_mut(+ let output = ak::slice_from_raw_parts_mut(destination_bytes.cast::<MaybeUninit<u8>>(),destination_byte_length,);@@ -169,7 +169,7 @@ impl TextEncoder {})} else {// SAFETY: Nothing else accesses the bytes of a buffer that is not shared while this runs.- let output = unsafe { core::slice::from_raw_parts_mut(destination_bytes, destination_byte_length) };+ let output = unsafe { ak::slice_from_raw_parts_mut(destination_bytes, destination_byte_length) };utf8::encode_into(&units, destination_byte_length, |offset, bytes| {output[offset..offset + bytes.len()].copy_from_slice(bytes);})diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rsindex 0a6c4af7beb..0a77f7a93be 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs@@ -36,7 +36,7 @@ unsafe fn extension_names(names: *const ByteSpan, name_count: usize) -> Vec<Vec<return Vec::new();}// SAFETY: The caller passes `name_count` live spans.- let names = unsafe { core::slice::from_raw_parts(names, name_count) };+ let names = unsafe { ak::slice_from_raw_parts(names, name_count) };names.iter().map(|name| {@@ -44,7 +44,7 @@ unsafe fn extension_names(names: *const ByteSpan, name_count: usize) -> Vec<Vec<return Vec::new();}// SAFETY: The caller passes the bytes of a string.- unsafe { core::slice::from_raw_parts(name.data, name.size) }.to_vec()+ unsafe { ak::slice_from_raw_parts(name.data, name.size) }.to_vec()}).collect()}diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/fingerprint.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/fingerprint.rsindex 2a0dcfe4ebc..1fd0d3ff2a1 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/fingerprint.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/fingerprint.rs@@ -59,7 +59,7 @@ pub(crate) fn verify_that_rust_and_cpp_agree_on_layouts_and_constants() {// SAFETY: The function returns a table that lives as long as the process, and stores its length.let replayer_layouts = unsafe {let words = compositing_webgl_wire_struct_layouts(&raw mut word_count);- core::slice::from_raw_parts(words, word_count)+ ak::slice_from_raw_parts(words, word_count)};let first_difference = replayer_layouts.iter()diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/host.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/host.rsindex 59a2bc68fa9..890e8947cb9 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/host.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/host.rs@@ -172,7 +172,7 @@ unsafe extern "C" fn append_reply(reply_sink: *mut c_void, reply: *const u8, rep// SAFETY: sync_call() passes its vector as the sink, and the transport passes the bytes of its reply.unsafe {let reply_sink = &mut *reply_sink.cast::<Vec<u8>>();- reply_sink.extend_from_slice(core::slice::from_raw_parts(reply, reply_size));+ reply_sink.extend_from_slice(ak::slice_from_raw_parts(reply, reply_size));}}diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/custom.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/custom.rsindex 8a4d1dd60ac..9f8b36d1fe4 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/custom.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/custom.rs@@ -347,7 +347,7 @@ impl<T: Transport> Proxy<T> {);// SAFETY: The memory is mapped and at least `length` bytes long, and the replayer, which is the only// other user of it, has answered the call and does not write to it any more.- unsafe { core::slice::from_raw_parts(shared_pixels.as_ptr(), length) }+ unsafe { ak::slice_from_raw_parts(shared_pixels.as_ptr(), length) }}_ => &[],};@@ -389,7 +389,7 @@ impl<T: Transport> Proxy<T> {assert!(size <= shared_data.len());// SAFETY: The memory is mapped and at least `size` bytes long, and the replayer, which is the only other// user of it, has answered the call and does not write to it any more.- use_data(unsafe { core::slice::from_raw_parts(shared_data.as_ptr(), size) });+ use_data(unsafe { ak::slice_from_raw_parts(shared_data.as_ptr(), size) });true}}diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/recorder.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/recorder.rsindex 1681acebc60..2037dcf594e 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/recorder.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/recorder.rs@@ -553,12 +553,12 @@ unsafe impl PlainNumber for i64 {}pub(crate) fn bytes_of<N: PlainNumber>(numbers: &[N]) -> &[u8] {// SAFETY: Per the contract of PlainNumber the numbers are their bytes, all of which are initialized.- unsafe { core::slice::from_raw_parts(numbers.as_ptr().cast::<u8>(), size_of_val(numbers)) }+ unsafe { ak::slice_from_raw_parts(numbers.as_ptr().cast::<u8>(), size_of_val(numbers)) }}pub(super) fn bytes_of_mut<N: PlainNumber>(numbers: &mut [N]) -> &mut [u8] {// SAFETY: Per the contract of PlainNumber the numbers are their bytes, and any bytes written are numbers.- unsafe { core::slice::from_raw_parts_mut(numbers.as_mut_ptr().cast::<u8>(), size_of_val(numbers)) }+ unsafe { ak::slice_from_raw_parts_mut(numbers.as_mut_ptr().cast::<u8>(), size_of_val(numbers)) }}pub(super) fn copy_reply_data(reply: &[u8], span: DataSpan, destination: &mut [u8]) {diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/tests.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/tests.rsindex 15edd074b74..59bb123928d 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/tests.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/tests.rs@@ -37,7 +37,7 @@ impl MockMemory {fn bytes(&self, offset: usize, size: usize) -> Vec<u8> {assert!(offset + size <= self.size);// SAFETY: The range is inside the memory, which nothing else reads or writes while the test runs this.- unsafe { core::slice::from_raw_parts(self.as_ptr().add(offset), size) }.to_vec()+ unsafe { ak::slice_from_raw_parts(self.as_ptr().add(offset), size) }.to_vec()}fn fill(&self, bytes: &[u8]) {diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/wire.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/wire.rsindex 03a17b4c230..05c4cf01d19 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/wire.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/proxy/wire.rs@@ -9,7 +9,7 @@//! format, which reads what this writes.use core::mem::size_of;-use core::{ptr, slice};+use core::ptr;use super::vocabulary::{CommandType, SyncCallType};@@ -59,7 +59,7 @@ pub(crate) unsafe trait WireStruct: Copy + 'static {fn as_bytes(&self) -> &[u8] {// SAFETY: Per the contract of the trait every byte of the struct is initialized.- unsafe { slice::from_raw_parts(ptr::from_ref(self).cast::<u8>(), size_of::<Self>()) }+ unsafe { ak::slice_from_raw_parts(ptr::from_ref(self).cast::<u8>(), size_of::<Self>()) }}}diff --git a/Libraries/LibWeb/ContentBlocker/Rust/Cargo.toml b/Libraries/LibWeb/ContentBlocker/Rust/Cargo.tomlindex 43770df839f..c47ff4295f6 100644--- a/Libraries/LibWeb/ContentBlocker/Rust/Cargo.toml+++ b/Libraries/LibWeb/ContentBlocker/Rust/Cargo.toml@@ -9,6 +9,7 @@ crate-type = ["staticlib"]# After changing dependencies, regenerate the Flatpak sources:# python3 Meta/CMake/flatpak/generate-cargo-sources.py[dependencies]+ak = { path = "../../../../AK/Rust" }adblock = "0.13.3"ladybird_allocator = { path = "../../../RustAllocator", optional = true }rustc-demangle = "0.1"diff --git a/Libraries/LibWeb/ContentBlocker/Rust/src/lib.rs b/Libraries/LibWeb/ContentBlocker/Rust/src/lib.rsindex 69a6b4e5b97..16de68a6043 100644--- a/Libraries/LibWeb/ContentBlocker/Rust/src/lib.rs+++ b/Libraries/LibWeb/ContentBlocker/Rust/src/lib.rs@@ -48,7 +48,7 @@ unsafe fn bytes_from_raw<'a>(bytes: *const u8, len: usize) -> Option<&'a [u8]> {if bytes.is_null() {return None;}- Some(unsafe { std::slice::from_raw_parts(bytes, len) })+ Some(unsafe { ak::slice_from_raw_parts(bytes, len) })}unsafe fn string_from_raw<'a>(bytes: *const u8, len: usize) -> Option<&'a str> {diff --git a/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs b/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rsindex 0653494d586..f285612aefe 100644--- a/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs+++ b/Libraries/LibWeb/HTML/Parser/Rust/src/lib.rs@@ -137,7 +137,7 @@ pub unsafe extern "C" fn rust_html_tokenizer_create_from_utf16(let code_units = if input.is_null() || len == 0 {Vec::new()} else {- unsafe { std::slice::from_raw_parts(input, len) }.to_vec()+ unsafe { ak::slice_from_raw_parts(input, len) }.to_vec()};make_handle(HtmlTokenizer::new(code_units))@@ -155,7 +155,7 @@ pub unsafe extern "C" fn rust_html_tokenizer_create_from_ascii(let code_units = if input.is_null() || len == 0 {Vec::new()} else {- unsafe { std::slice::from_raw_parts(input, len) }+ unsafe { ak::slice_from_raw_parts(input, len) }.iter().map(|byte| u16::from(*byte)).collect()@@ -360,7 +360,7 @@ pub unsafe extern "C" fn rust_html_tokenizer_insert_utf16_input(let code_units = if input.is_null() || len == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(input, len) }+ unsafe { ak::slice_from_raw_parts(input, len) }};handle.tokenizer.insert_input_at_insertion_point(code_units);}@@ -381,7 +381,7 @@ pub unsafe extern "C" fn rust_html_tokenizer_insert_ascii_input(let input = if input.is_null() || len == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(input, len) }+ unsafe { ak::slice_from_raw_parts(input, len) }};handle.tokenizer.insert_ascii_input_at_insertion_point(input);}@@ -402,7 +402,7 @@ pub unsafe extern "C" fn rust_html_tokenizer_append_utf16_input(let code_units = if input.is_null() || len == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(input, len) }+ unsafe { ak::slice_from_raw_parts(input, len) }};handle.tokenizer.append_input(code_units);}@@ -423,7 +423,7 @@ pub unsafe extern "C" fn rust_html_tokenizer_append_ascii_input(let input = if input.is_null() || len == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(input, len) }+ unsafe { ak::slice_from_raw_parts(input, len) }};handle.tokenizer.append_ascii_input(input);}diff --git a/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs b/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rsindex 0ce293a40c0..061285a5702 100644--- a/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs+++ b/Libraries/LibWeb/HTML/Parser/Rust/src/parser.rs@@ -4824,7 +4824,7 @@ unsafe fn utf16_string_from_ffi(ptr: *const u16, len: usize) -> String {return String::new();}- let code_units = unsafe { std::slice::from_raw_parts(ptr, len) };+ let code_units = unsafe { ak::slice_from_raw_parts(ptr, len) };String::from_utf16_lossy(code_units)}@@ -4847,7 +4847,7 @@ unsafe fn owned_context_attributes_from_ffi(return Vec::new();}- let attributes = unsafe { std::slice::from_raw_parts(attributes, attribute_count) };+ let attributes = unsafe { ak::slice_from_raw_parts(attributes, attribute_count) };attributes.iter().map(|attribute| OwnedAttribute {diff --git a/Libraries/LibWeb/HTML/Parser/Rust/src/preload_scanner.rs b/Libraries/LibWeb/HTML/Parser/Rust/src/preload_scanner.rsindex 75e67b87efc..43d6b84470a 100644--- a/Libraries/LibWeb/HTML/Parser/Rust/src/preload_scanner.rs+++ b/Libraries/LibWeb/HTML/Parser/Rust/src/preload_scanner.rs@@ -88,7 +88,7 @@ pub unsafe extern "C" fn rust_html_preload_scanner_scan(let input = if input.is_null() || input_len == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(input, input_len) }+ unsafe { ak::slice_from_raw_parts(input, input_len) }};scan(input, scripting_enabled, |entry| unsafe {@@ -112,7 +112,7 @@ pub unsafe extern "C" fn rust_html_preload_scanner_scan_utf16(let input = if input.is_null() || input_len == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(input, input_len) }+ unsafe { ak::slice_from_raw_parts(input, input_len) }};scan_utf16(input, scripting_enabled, |entry| unsafe {@@ -588,7 +588,7 @@ mod tests {fn collect_with_scripting(input: &str, scripting_enabled: bool) -> Vec<ScannedEntry> {let mut entries = Vec::new();scan(input.as_bytes(), scripting_enabled, |entry| {- let url = unsafe { std::slice::from_raw_parts(entry.url_ptr, entry.url_len) };+ let url = unsafe { ak::slice_from_raw_parts(entry.url_ptr, entry.url_len) };entries.push(ScannedEntry {action: entry.action,url: std::str::from_utf8(url).unwrap().to_string(),@@ -604,7 +604,7 @@ mod tests {let input = input.encode_utf16().collect::<Vec<_>>();let mut entries = Vec::new();scan_utf16(&input, true, |entry| {- let url = unsafe { std::slice::from_raw_parts(entry.url_ptr, entry.url_len) };+ let url = unsafe { ak::slice_from_raw_parts(entry.url_ptr, entry.url_len) };entries.push(ScannedEntry {action: entry.action,url: std::str::from_utf8(url).unwrap().to_string(),@@ -850,7 +850,7 @@ mod tests {true,|entry| {let string = |pointer, length| {- let bytes = unsafe { std::slice::from_raw_parts(pointer, length) };+ let bytes = unsafe { ak::slice_from_raw_parts(pointer, length) };std::str::from_utf8(bytes).unwrap().to_string()};options = Some((diff --git a/Libraries/LibWeb/Rust/src/css/absolutize.rs b/Libraries/LibWeb/Rust/src/css/absolutize.rsindex 75e141406e7..caa9d3578ce 100644--- a/Libraries/LibWeb/Rust/src/css/absolutize.rs+++ b/Libraries/LibWeb/Rust/src/css/absolutize.rs@@ -2077,7 +2077,7 @@ pub unsafe extern "C" fn rust_style_value_absolutize(let document_base_url = if context.document_base_url_length == 0 {&[][..]} else {- unsafe { std::slice::from_raw_parts(context.document_base_url, context.document_base_url_length) }+ unsafe { ak::slice_from_raw_parts(context.document_base_url, context.document_base_url_length) }};match absolutize_with_element_facts(value,diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rsindex 555b3bfff02..c4b84d6182e 100644--- a/Libraries/LibWeb/Rust/src/css/animation.rs+++ b/Libraries/LibWeb/Rust/src/css/animation.rs@@ -135,7 +135,7 @@ pub(crate) unsafe fn style_value_from_easing(descriptor: &FfiEasingDescriptor) -match descriptor.kind {FfiEasingKind::Linear => {assert!(descriptor.linear_point_count > 0);- let points = unsafe { std::slice::from_raw_parts(descriptor.linear_points, descriptor.linear_point_count) };+ let points = unsafe { ak::slice_from_raw_parts(descriptor.linear_points, descriptor.linear_point_count) };stops = points.iter().map(|point| {diff --git a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rsindex eed1f56b5d7..9dc0facd4a8 100644--- a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs@@ -1526,7 +1526,7 @@ pub unsafe extern "C" fn rust_computed_longhand_table_copy_from_values(values: *const *const c_void,count: usize,) {- let values = unsafe { std::slice::from_raw_parts(values, count) };+ let values = unsafe { ak::slice_from_raw_parts(values, count) };table.copy_from_values(values);}@@ -1583,8 +1583,8 @@ pub unsafe extern "C" fn rust_computed_longhand_table_load_flag_bitmaps(inheritance_count: usize,) {table.load_flag_bitmaps(- unsafe { std::slice::from_raw_parts(importance, importance_count) },- unsafe { std::slice::from_raw_parts(inheritance, inheritance_count) },+ unsafe { ak::slice_from_raw_parts(importance, importance_count) },+ unsafe { ak::slice_from_raw_parts(inheritance, inheritance_count) },);}diff --git a/Libraries/LibWeb/Rust/src/css/computed_values.rs b/Libraries/LibWeb/Rust/src/css/computed_values.rsindex f3ca90a3976..0c52e8aef32 100644--- a/Libraries/LibWeb/Rust/src/css/computed_values.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_values.rs@@ -500,7 +500,7 @@ impl RetainedTextDecorationLineList {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}}@@ -570,7 +570,7 @@ macro_rules! impl_retained_computed_list {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}}@@ -923,7 +923,7 @@ impl RetainedComputedResolvedTransformList {}// SAFETY: A non-null pointer/length pair always comes from// from_vec's boxed slice.- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}}@@ -1053,7 +1053,7 @@ macro_rules! impl_retained_grid_list {}// SAFETY: A non-null pointer/length pair always comes from// from_vec's boxed slice.- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}}diff --git a/Libraries/LibWeb/Rust/src/css/counter_representation.rs b/Libraries/LibWeb/Rust/src/css/counter_representation.rsindex cb1a95d7c24..583eee5cb69 100644--- a/Libraries/LibWeb/Rust/src/css/counter_representation.rs+++ b/Libraries/LibWeb/Rust/src/css/counter_representation.rs@@ -1013,7 +1013,7 @@ pub unsafe extern "C" fn rust_list_style_type_depends_on_counter_value(let (list_style_type, scopes) = unsafe {(&*list_style_type.cast::<StyleValueData>(),- std::slice::from_raw_parts(scopes, scope_count),+ ak::slice_from_raw_parts(scopes, scope_count),)};match list_style_type {diff --git a/Libraries/LibWeb/Rust/src/css/counter_style.rs b/Libraries/LibWeb/Rust/src/css/counter_style.rsindex 57162287894..8f77c4b42a2 100644--- a/Libraries/LibWeb/Rust/src/css/counter_style.rs+++ b/Libraries/LibWeb/Rust/src/css/counter_style.rs@@ -487,8 +487,8 @@ pub unsafe extern "C" fn rust_counter_styles_resolve(// SAFETY: Guaranteed by the caller.let (rules, outer_scopes, length_context) = unsafe {(- std::slice::from_raw_parts(rules, rule_count),- std::slice::from_raw_parts(outer_scopes, outer_scope_count),+ ak::slice_from_raw_parts(rules, rule_count),+ ak::slice_from_raw_parts(outer_scopes, outer_scope_count),length_resolution_context.cast::<FfiLengthResolutionContext>().as_ref(),)};diff --git a/Libraries/LibWeb/Rust/src/css/css_string.rs b/Libraries/LibWeb/Rust/src/css/css_string.rsindex 4baa36d36c4..a017747c9b4 100644--- a/Libraries/LibWeb/Rust/src/css/css_string.rs+++ b/Libraries/LibWeb/Rust/src/css/css_string.rs@@ -212,7 +212,7 @@ impl CssStringList {if self.length == 0 {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}}diff --git a/Libraries/LibWeb/Rust/src/css/css_tokenizer.rs b/Libraries/LibWeb/Rust/src/css/css_tokenizer.rsindex 77852297ee4..bb73011139d 100644--- a/Libraries/LibWeb/Rust/src/css/css_tokenizer.rs+++ b/Libraries/LibWeb/Rust/src/css/css_tokenizer.rs@@ -162,8 +162,8 @@ impl TokenizerInput<'_> {return Some(Self::Ascii(&[]));}match (ascii.is_null(), utf16.is_null()) {- (false, true) => Some(Self::Ascii(unsafe { std::slice::from_raw_parts(ascii, length) })),- (true, false) => Some(Self::Utf16(unsafe { std::slice::from_raw_parts(utf16, length) })),+ (false, true) => Some(Self::Ascii(unsafe { ak::slice_from_raw_parts(ascii, length) })),+ (true, false) => Some(Self::Utf16(unsafe { ak::slice_from_raw_parts(utf16, length) })),_ => None,}}diff --git a/Libraries/LibWeb/Rust/src/css/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/custom_properties.rsindex 7f978b8eabf..0b93ca93265 100644--- a/Libraries/LibWeb/Rust/src/css/custom_properties.rs+++ b/Libraries/LibWeb/Rust/src/css/custom_properties.rs@@ -1191,18 +1191,6 @@ fn tokens_for_function_value(data: &StyleValueData) -> (Vec<OwnedToken>, bool) {(tokenize_owned(&source), false)}-/// An array the host lends, empty when it has no entries.-///-/// # Safety-/// A non-empty array must be live for `'a`.-pub(crate) unsafe fn ffi_slice<'a, T>(items: *const T, count: usize) -> &'a [T] {- if count == 0 {- &[]- } else {- unsafe { std::slice::from_raw_parts(items, count) }- }-}-fn custom_function_registry(definitions: &[SubstitutionFunctionDefinition],caller_scope_identity: usize,@@ -3822,7 +3810,7 @@ pub unsafe extern "C" fn rust_custom_property_registry_update(let registrations = if registration_count == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(registrations, registration_count) }+ unsafe { ak::slice_from_raw_parts(registrations, registration_count) }};// SAFETY: Guaranteed by the caller.drop(unsafe { Arc::from_raw(registry.cast::<CustomPropertyRegistry>()) });@@ -3917,7 +3905,7 @@ pub unsafe extern "C" fn rust_custom_property_store_create(let entries = if entry_count == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(entries, entry_count) }+ unsafe { ak::slice_from_raw_parts(entries, entry_count) }};assert!(declared_count <= entries.len());let parent = if parent.is_null() {@@ -3978,7 +3966,7 @@ pub unsafe extern "C" fn rust_custom_property_store_create_animation_overlay(let entries = if entry_count == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(entries, entry_count) }+ unsafe { ak::slice_from_raw_parts(entries, entry_count) }};let base = unsafe { base.cast::<CustomPropertyStore>().as_ref() };let animated = entries.iter().map(|entry| {diff --git a/Libraries/LibWeb/Rust/src/css/dom_selector_matching.rs b/Libraries/LibWeb/Rust/src/css/dom_selector_matching.rsindex 816ad3a2848..67e148d2728 100644--- a/Libraries/LibWeb/Rust/src/css/dom_selector_matching.rs+++ b/Libraries/LibWeb/Rust/src/css/dom_selector_matching.rs@@ -223,7 +223,7 @@ pub unsafe extern "C" fn rust_dom_selector_program_create() -> *mut DomSelectorProgram {let selectors = match count {0 => &[][..],- _ => unsafe { std::slice::from_raw_parts(selectors, count) },+ _ => unsafe { ak::slice_from_raw_parts(selectors, count) },};let mut names = QueryNames::default();let program = {@@ -451,7 +451,7 @@ impl<'q> DomSubject<'q> {let count = self.element.attribute_count;match count <= self.attributes.len() {// SAFETY: The host wrote this many attributes to the buffer when it read the element.- true => unsafe { std::slice::from_raw_parts(self.attributes.as_ptr().cast(), count) },+ true => unsafe { ak::slice_from_raw_parts(self.attributes.as_ptr().cast(), count) },false => &self.spilled_attributes,}}@@ -507,7 +507,7 @@ impl<'q> ElementFeatures for DomFeatures<'_, 'q> {}match self.subject.ids_and_classes_ignore_case {true => unsafe { (self.subject.dom.id_or_class_equals_ignoring_ascii_case)(self.node, true, class) },- false => unsafe { std::slice::from_raw_parts(element.classes, element.class_count) }.contains(&class),+ false => unsafe { ak::slice_from_raw_parts(element.classes, element.class_count) }.contains(&class),}}diff --git a/Libraries/LibWeb/Rust/src/css/font_feature_values.rs b/Libraries/LibWeb/Rust/src/css/font_feature_values.rsindex 5cfc3d0758c..3306a6907ee 100644--- a/Libraries/LibWeb/Rust/src/css/font_feature_values.rs+++ b/Libraries/LibWeb/Rust/src/css/font_feature_values.rs@@ -328,7 +328,7 @@ pub unsafe extern "C" fn rust_font_shape_features(use crate::css::css_enums::keyword::*;use crate::css::style::bridge::{FONT_RESOLUTION_FEATURE_INPUT_COUNT, FontResolutionFeatureInput as Input};// SAFETY: Guaranteed by the caller.- let values = unsafe { std::slice::from_raw_parts(values, FONT_RESOLUTION_FEATURE_INPUT_COUNT) };+ let values = unsafe { ak::slice_from_raw_parts(values, FONT_RESOLUTION_FEATURE_INPUT_COUNT) };let value = |input: Input| unsafe { values[input as usize].cast::<StyleValueData>().as_ref() };let mut shape = ShapeFeatures::default();@@ -449,7 +449,7 @@ pub unsafe extern "C" fn rust_font_shape_features(if feature_values.is_null() || count == 0 {continue;}- let feature_values = unsafe { std::slice::from_raw_parts(feature_values, count) };+ let feature_values = unsafe { ak::slice_from_raw_parts(feature_values, count) };let first = feature_values[0];match kind {// https://drafts.csswg.org/css-fonts/#multi-value-featuresdiff --git a/Libraries/LibWeb/Rust/src/css/font_matching.rs b/Libraries/LibWeb/Rust/src/css/font_matching.rsindex d66a50f6665..8e8163696ef 100644--- a/Libraries/LibWeb/Rust/src/css/font_matching.rs+++ b/Libraries/LibWeb/Rust/src/css/font_matching.rs@@ -113,8 +113,8 @@ pub unsafe extern "C" fn rust_font_matching_order(// SAFETY: Guaranteed by the caller.let (candidates, order) = unsafe {(- std::slice::from_raw_parts(candidates, count),- std::slice::from_raw_parts_mut(order, count),+ ak::slice_from_raw_parts(candidates, count),+ ak::slice_from_raw_parts_mut(order, count),)};font_matching_order(candidates, weight, width, slope, order)diff --git a/Libraries/LibWeb/Rust/src/css/host_shared.rs b/Libraries/LibWeb/Rust/src/css/host_shared.rsindex bb84bbf609a..1185f3db7bc 100644--- a/Libraries/LibWeb/Rust/src/css/host_shared.rs+++ b/Libraries/LibWeb/Rust/src/css/host_shared.rs@@ -134,13 +134,13 @@ impl<T> HostShared<T> {/// layout; this is a reinterpretation, not a copy.pub(crate) fn as_pointer_slice(handles: &[Self]) -> &[*const T] {// SAFETY: `repr(transparent)` makes the element types layout-identical.- unsafe { std::slice::from_raw_parts(handles.as_ptr().cast::<*const T>(), handles.len()) }+ unsafe { ak::slice_from_raw_parts(handles.as_ptr().cast::<*const T>(), handles.len()) }}/// The inverse of [`Self::as_pointer_slice`].pub(crate) fn from_pointer_slice(pointers: &[*const T]) -> &[Self] {// SAFETY: `repr(transparent)` makes the element types layout-identical.- unsafe { std::slice::from_raw_parts(pointers.as_ptr().cast::<Self>(), pointers.len()) }+ unsafe { ak::slice_from_raw_parts(pointers.as_ptr().cast::<Self>(), pointers.len()) }}}diff --git a/Libraries/LibWeb/Rust/src/css/parser/descriptor_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/descriptor_parser.rsindex 558cbf2480f..04e20a80dc1 100644--- a/Libraries/LibWeb/Rust/src/css/parser/descriptor_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/descriptor_parser.rs@@ -478,7 +478,7 @@ pub(crate) fn parse_descriptor(} else if context.value_contexts.is_null() {return None;} else {- unsafe { std::slice::from_raw_parts(context.value_contexts, context.value_context_count) }+ unsafe { ak::slice_from_raw_parts(context.value_contexts, context.value_context_count) }};let mut value_contexts = Vec::with_capacity(inherited_contexts.len() + 1);value_contexts.extend_from_slice(inherited_contexts);diff --git a/Libraries/LibWeb/Rust/src/css/parser/query_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/query_parser.rsindex 89e130e58e0..7c61899f462 100644--- a/Libraries/LibWeb/Rust/src/css/parser/query_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/query_parser.rs@@ -2319,7 +2319,7 @@ unsafe fn ffi_media_environment(if environment.values.is_null() {return None;}- unsafe { std::slice::from_raw_parts(environment.values, environment.value_count) }+ unsafe { ak::slice_from_raw_parts(environment.values, environment.value_count) }};let length_context = unsafe {environmentdiff --git a/Libraries/LibWeb/Rust/src/css/parser/stylesheet_cache.rs b/Libraries/LibWeb/Rust/src/css/parser/stylesheet_cache.rsindex 40a2e13e20d..ee15bcfe274 100644--- a/Libraries/LibWeb/Rust/src/css/parser/stylesheet_cache.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/stylesheet_cache.rs@@ -174,7 +174,7 @@ unsafe fn own_url(pointer: *const u8, length: usize) -> Option<Box<[u16]>> {return Some(Box::default());}// The legacy URL context is UTF-8. Keep the cache's owned strings in native UTF-16.- let bytes = unsafe { std::slice::from_raw_parts(pointer, length) };+ let bytes = unsafe { ak::slice_from_raw_parts(pointer, length) };Some(std::str::from_utf8(bytes).ok()?.encode_utf16().collect())}diff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rsindex 8fb57ec5ff9..95d73d05edd 100644--- a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs@@ -2957,7 +2957,7 @@ impl SyntaxParseBuilder {Vec::new()} else {// SAFETY: C++ keeps the context storage live for the complete syntax parse call.- unsafe { std::slice::from_raw_parts(parse_context.value_contexts, parse_context.value_context_count) }+ unsafe { ak::slice_from_raw_parts(parse_context.value_contexts, parse_context.value_context_count) }.to_vec()};value_contexts.push(FfiValueParsingContext {@@ -3963,7 +3963,7 @@ mod tests {assert_eq!(names, [utf16("未知"), utf16("width")]);let parse = parsed;extern "C" fn diagnostic(values: *const u16, count: usize, diagnostic: &FfiSyntaxDiagnostic) {- let values = unsafe { std::slice::from_raw_parts(values, count) };+ let values = unsafe { ak::slice_from_raw_parts(values, count) };assert_eq!(diagnostic.code, FfiSyntaxDiagnosticCode::UnknownRule);assert_eq!(&values[diagnostic.primary_offset..diagnostic.primary_offset + diagnostic.primary_length],@@ -3971,7 +3971,7 @@ mod tests {);}extern "C" fn declaration(values: *const u16, count: usize, declaration: &FfiSyntaxDeclaration) {- let values = unsafe { std::slice::from_raw_parts(values, count) };+ let values = unsafe { ak::slice_from_raw_parts(values, count) };let value = &values[declaration.value_source_offset..declaration.value_source_offset + declaration.value_source_length];match declaration.rejection {@@ -4010,7 +4010,7 @@ mod tests {declaration: &FfiSyntaxDeclaration,) {let names = unsafe { &mut *context.cast::<Vec<Vec<u16>>>() };- let values = unsafe { std::slice::from_raw_parts(values, count) };+ let values = unsafe { ak::slice_from_raw_parts(values, count) };assert!(declaration.preserve_source_text);names.push(values[declaration.name_offset..declaration.name_offset + declaration.name_length].to_vec());}diff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rsindex 2fe075bda98..b45f8477a4d 100644--- a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rs@@ -212,7 +212,7 @@ fn font_feature_mutation_preserves_live_owners_and_shared_maps() {return None;}let entry = rust_font_feature_values_at(owner, kind, index);- Some(std::slice::from_raw_parts(entry.values, entry.count).to_vec())+ Some(ak::slice_from_raw_parts(entry.values, entry.count).to_vec())}}let kind = FontFeatureValuesRuleKind::Styleset;@@ -221,7 +221,7 @@ fn font_feature_mutation_preserves_live_owners_and_shared_maps() {assert_eq!(rust_font_feature_values_count(values, kind), 3);let entry = rust_font_feature_values_at(values, kind, 1);assert_eq!(entry.name.to_utf16().unwrap(), utf16("色"));- assert_eq!(std::slice::from_raw_parts(entry.values, entry.count), [6, 7]);+ assert_eq!(ak::slice_from_raw_parts(entry.values, entry.count), [6, 7]);assert_eq!(entry.values, rust_font_feature_values_at(&shared, kind, 1).values);rust_font_feature_values_set(values, kind, entry.name, [29].as_ptr(), 1);assert_eq!(get(&shared, kind, "色").unwrap(), [6, 7]);@@ -553,7 +553,7 @@ fn import_preludes_outlive_the_worker_and_shared_sheet() {unsafe extern "C" fn collect_text(context: *mut std::ffi::c_void, text: *const u16, length: usize) {let result = unsafe { &mut *context.cast::<Vec<u16>>() };- result.extend_from_slice(unsafe { std::slice::from_raw_parts(text, length) });+ result.extend_from_slice(unsafe { ak::slice_from_raw_parts(text, length) });}fn page_text(selectors: &PageSelectorList) -> Vec<u16> {diff --git a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rsindex 366b401bf5e..b8e70d1dad4 100644--- a/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/value_parser.rs@@ -1138,7 +1138,7 @@ pub(crate) fn context_allows_tree_counting_functions(context: &ParseContext) ->} else if context.value_contexts.is_null() {return false;} else {- unsafe { std::slice::from_raw_parts(context.value_contexts, context.value_context_count) }+ unsafe { ak::slice_from_raw_parts(context.value_contexts, context.value_context_count) }};!contexts.iter().any(|value_context| {value_context.kind == FfiValueParsingContextKind::Descriptor@@ -1150,7 +1150,7 @@ fn substitution_function_context_names(context: &ParseContext) -> Option<Vec<Vecif context.value_context_count == 0 || context.value_contexts.is_null() {return None;}- let contexts = unsafe { std::slice::from_raw_parts(context.value_contexts, context.value_context_count) };+ let contexts = unsafe { ak::slice_from_raw_parts(context.value_contexts, context.value_context_count) };let names = contexts.iter().filter(|value_context| value_context.kind == FfiValueParsingContextKind::Function)@@ -3674,7 +3674,7 @@ fn context_allows_quirky_color(context: &ParseContext, property: u16) -> bool {} else if context.value_contexts.is_null() {return false;} else {- unsafe { std::slice::from_raw_parts(context.value_contexts, context.value_context_count) }+ unsafe { ak::slice_from_raw_parts(context.value_contexts, context.value_context_count) }};value_contexts.iter().all(|value_context| {value_context.kind == FfiValueParsingContextKind::Property@@ -3688,7 +3688,7 @@ pub(crate) fn context_allows_random_functions(context: &ParseContext) -> bool {} else if context.value_contexts.is_null() {return false;} else {- unsafe { std::slice::from_raw_parts(context.value_contexts, context.value_context_count) }+ unsafe { ak::slice_from_raw_parts(context.value_contexts, context.value_context_count) }};if value_contexts.first().is_some_and(|value_context| {@@ -6128,7 +6128,7 @@ fn parse_css_primitive_values(let property = if context.value_context_count == 0 || context.value_contexts.is_null() {property_id::WIDTH} else {- unsafe { std::slice::from_raw_parts(context.value_contexts, context.value_context_count) }+ unsafe { ak::slice_from_raw_parts(context.value_contexts, context.value_context_count) }.iter().find(|value_context| {value_context.kind == FfiValueParsingContextKind::Property && value_context.value != property_id::CUSTOMdiff --git a/Libraries/LibWeb/Rust/src/css/retained_fly_string.rs b/Libraries/LibWeb/Rust/src/css/retained_fly_string.rsindex 2cbb9b8308d..074b7de3e0b 100644--- a/Libraries/LibWeb/Rust/src/css/retained_fly_string.rs+++ b/Libraries/LibWeb/Rust/src/css/retained_fly_string.rs@@ -149,7 +149,7 @@ impl RetainedUtf16FlyStringList {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}/// The list viewed as raw fly-string words; fly strings are interned, so@@ -159,7 +159,7 @@ impl RetainedUtf16FlyStringList {return &[];}// SAFETY: `RetainedUtf16FlyString` is represented by its single raw word.- unsafe { std::slice::from_raw_parts(self.pointer.cast::<usize>(), self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer.cast::<usize>(), self.length) }}}diff --git a/Libraries/LibWeb/Rust/src/css/rule/compilation.rs b/Libraries/LibWeb/Rust/src/css/rule/compilation.rsindex f29befe6c3e..ee9605860d5 100644--- a/Libraries/LibWeb/Rust/src/css/rule/compilation.rs+++ b/Libraries/LibWeb/Rust/src/css/rule/compilation.rs@@ -1688,7 +1688,7 @@ mod tests {let collection = unsafe { &*data.cast::<Collection>() };if rule_type == NativeRuleType::Style {let layer = context.layer_name.to_utf16().unwrap();- let scopes = unsafe { std::slice::from_raw_parts(context.scopes, context.scope_count) };+ let scopes = unsafe { ak::slice_from_raw_parts(context.scopes, context.scope_count) };collection.rules.borrow_mut().push(CompiledRule {identity,source,diff --git a/Libraries/LibWeb/Rust/src/css/selector_parser.rs b/Libraries/LibWeb/Rust/src/css/selector_parser.rsindex 61a96fd54a1..2b4a730e43a 100644--- a/Libraries/LibWeb/Rust/src/css/selector_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/selector_parser.rs@@ -1297,7 +1297,7 @@ pub(crate) unsafe fn parse_selector_list_from_ffi(&[]} else {assert!(!namespaces.is_null());- std::slice::from_raw_parts(namespaces, namespace_count)+ ak::slice_from_raw_parts(namespaces, namespace_count)};let namespace_storage = namespace_views.iter()@@ -1306,7 +1306,7 @@ pub(crate) unsafe fn parse_selector_list_from_ffi(TokenizerInput::Utf16(&[])} else {assert!(!namespace.data.is_null());- TokenizerInput::Utf16(std::slice::from_raw_parts(namespace.data, namespace.length))+ TokenizerInput::Utf16(ak::slice_from_raw_parts(namespace.data, namespace.length))}}).collect::<Vec<_>>();diff --git a/Libraries/LibWeb/Rust/src/css/selector_serialization.rs b/Libraries/LibWeb/Rust/src/css/selector_serialization.rsindex b9ceb24c266..6675fc2f8fe 100644--- a/Libraries/LibWeb/Rust/src/css/selector_serialization.rs+++ b/Libraries/LibWeb/Rust/src/css/selector_serialization.rs@@ -301,7 +301,7 @@ pub unsafe extern "C" fn rust_selector_serialize(&[]} else {assert!(!prefixes_mapping_to_default.is_null());- std::slice::from_raw_parts(prefixes_mapping_to_default, prefix_count)+ ak::slice_from_raw_parts(prefixes_mapping_to_default, prefix_count)};let prefixes = prefix_views.iter()@@ -310,7 +310,7 @@ pub unsafe extern "C" fn rust_selector_serialize(&[][..]} else {assert!(!prefix.data.is_null());- std::slice::from_raw_parts(prefix.data, prefix.length)+ ak::slice_from_raw_parts(prefix.data, prefix.length)}}).collect::<Vec<_>>();diff --git a/Libraries/LibWeb/Rust/src/css/serialize.rs b/Libraries/LibWeb/Rust/src/css/serialize.rsindex fad1372f9b5..d0da7008521 100644--- a/Libraries/LibWeb/Rust/src/css/serialize.rs+++ b/Libraries/LibWeb/Rust/src/css/serialize.rs@@ -2263,7 +2263,7 @@ fn serialize_calculated(sink: &mut TextSink, value: &StyleValueData, mode: Seria/// Literal pieces are produced from static ASCII strings in calc.rs.fn literal_piece_text(bytes: *const u8, length: usize) -> &'static str {// SAFETY: Literal pieces borrow 'static ASCII strings.- unsafe { std::str::from_utf8_unchecked(std::slice::from_raw_parts(bytes, length)) }+ unsafe { std::str::from_utf8_unchecked(ak::slice_from_raw_parts(bytes, length)) }}/// Port of Web::CSS::serialize_a_positional_value_list: 2 or 4 values with equal-serializationdiff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex 2ce7439d159..0b41a5795f3 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -32,7 +32,7 @@ use std::ffi::c_void;use crate::abort_on_panic;use crate::css::animated_overlay::AnimatedOverlay;use crate::css::computed_longhand_table::ComputedLonghandTable;-use crate::css::custom_properties::{CustomPropertyRegistry, ffi_slice};+use crate::css::custom_properties::CustomPropertyRegistry;use crate::css::host_shared::{HostShared, SharedPayload};use crate::css::selector::CompiledSelector;use crate::css::style_value::RetainedStyleValueData;@@ -1227,9 +1227,9 @@ pub unsafe extern "C" fn style_engine_set_tree_scope_animation_keyframes(// SAFETY: Guaranteed by the caller.let row = unsafe {super::animations::AnimationKeyframes::row(- ffi_slice(name_lengths, count),- ffi_slice(name_units, name_unit_count),- ffi_slice(keyframe_sets, count),+ ak::slice_from_raw_parts(name_lengths, count),+ ak::slice_from_raw_parts(name_units, name_unit_count),+ ak::slice_from_raw_parts(keyframe_sets, count),)};let write = super::engine_calls::EngineWrite::AnimationKeyframes {@@ -1421,12 +1421,12 @@ pub unsafe extern "C" fn style_engine_set_element_animation_effect_descriptions(// SAFETY: Guaranteed by the caller.let effects = unsafe {super::effect_descriptions::PublishedEffectBuffers {- effects: ffi_slice(effects, effect_count),- keyframes: ffi_slice(keyframes, keyframe_count),- declarations: ffi_slice(declarations, declaration_count),- custom_declarations: ffi_slice(custom_declarations, custom_declaration_count),- linear_points: ffi_slice(linear_points, linear_point_count),- base_url_bytes: ffi_slice(base_url_bytes, base_url_byte_count),+ effects: ak::slice_from_raw_parts(effects, effect_count),+ keyframes: ak::slice_from_raw_parts(keyframes, keyframe_count),+ declarations: ak::slice_from_raw_parts(declarations, declaration_count),+ custom_declarations: ak::slice_from_raw_parts(custom_declarations, custom_declaration_count),+ linear_points: ak::slice_from_raw_parts(linear_points, linear_point_count),+ base_url_bytes: ak::slice_from_raw_parts(base_url_bytes, base_url_byte_count),}.effects()};@@ -1456,7 +1456,7 @@ pub unsafe extern "C" fn style_engine_describes_animation_effects(host.engine_memo().described.borrow()- .describe(node, slot, unsafe { ffi_slice(versions, count) })+ .describe(node, slot, unsafe { ak::slice_from_raw_parts(versions, count) })})}@@ -1769,7 +1769,7 @@ pub unsafe extern "C" fn style_engine_set_element_presentational_hint_properties&[]} else {// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(properties.cast::<FfiDeclaredProperty>(), count) }+ unsafe { ak::slice_from_raw_parts(properties.cast::<FfiDeclaredProperty>(), count) }};// A hint may name a shorthand. Expanded as any declaration block is, it declares every longhand it decides, and so// do all declarations the engine is given.@@ -1868,7 +1868,7 @@ pub unsafe fn publish_computed_groups(}let payloads = match count {0 => &[],- _ => SharedPayload::from_pointer_slice(unsafe { std::slice::from_raw_parts(payloads, count) }),+ _ => SharedPayload::from_pointer_slice(unsafe { ak::slice_from_raw_parts(payloads, count) }),};if animation_overlay_payload_count != 0 && animation_overlay_payloads.is_null() {return FfiStyleRecordDelta::default();@@ -1876,7 +1876,7 @@ pub unsafe fn publish_computed_groups(let animation_overlay_payloads = match animation_overlay_payload_count {0 => &[],_ => SharedPayload::from_pointer_slice(unsafe {- std::slice::from_raw_parts(animation_overlay_payloads, animation_overlay_payload_count)+ ak::slice_from_raw_parts(animation_overlay_payloads, animation_overlay_payload_count)}),};let longhand_table = unsafe {@@ -2196,8 +2196,8 @@ pub unsafe extern "C" fn style_engine_publish_sampled_animation_overlays(// SAFETY: Guaranteed by the caller.let (inputs, out) = unsafe {(- std::slice::from_raw_parts(inputs, count),- std::slice::from_raw_parts_mut(out, count),+ ak::slice_from_raw_parts(inputs, count),+ ak::slice_from_raw_parts_mut(out, count),)};with_engine(read, host, |engine| {@@ -2345,8 +2345,8 @@ pub unsafe extern "C" fn style_engine_changed_style_groups(// SAFETY: Guaranteed by the caller: a live record's view holds `payload_count` payloads of each kind.Some(unsafe {[- SharedPayload::from_pointer_slice(std::slice::from_raw_parts(view.base_payloads, view.payload_count)),- SharedPayload::from_pointer_slice(std::slice::from_raw_parts(view.payloads, view.payload_count)),+ SharedPayload::from_pointer_slice(ak::slice_from_raw_parts(view.base_payloads, view.payload_count)),+ SharedPayload::from_pointer_slice(ak::slice_from_raw_parts(view.payloads, view.payload_count)),]})};@@ -2660,7 +2660,7 @@ pub unsafe extern "C" fn style_engine_declared_only_record(let hints = if hint_count == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(hints.cast::<FfiDeclaredProperty>(), hint_count) }+ unsafe { ak::slice_from_raw_parts(hints.cast::<FfiDeclaredProperty>(), hint_count) }};let hints = hints.iter()@@ -3224,7 +3224,7 @@ pub(crate) unsafe fn borrow<'a, T>(pointer: *const T, count: usize) -> &'a [T] {return &[];}assert!(!pointer.is_null(), "a non-empty delta array must not be null");- unsafe { std::slice::from_raw_parts(pointer, count) }+ unsafe { ak::slice_from_raw_parts(pointer, count) }}#[cfg(test)]diff --git a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rsindex 69bc782e871..679fb124d82 100644--- a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs+++ b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs@@ -60,7 +60,7 @@ impl DocumentMediaSnapshot {self.values.clear();if !inputs.media_feature_values.is_none() && inputs.media_feature_value_count != 0 {self.values.extend_from_slice(unsafe {- std::slice::from_raw_parts(+ ak::slice_from_raw_parts(inputs.media_feature_values.as_pointer().cast(),inputs.media_feature_value_count,)@@ -155,7 +155,7 @@ impl DocumentFunctionSnapshot {&[]} else {unsafe {- std::slice::from_raw_parts(+ ak::slice_from_raw_parts(inputs.custom_functions.as_pointer()diff --git a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rsindex 849d795e234..658e72bc364 100644--- a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs+++ b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs@@ -594,8 +594,7 @@ unsafe fn easing_is(easing: &Easing, descriptor: &FfiEasingDescriptor) -> bool {(Easing::Linear(points), FfiEasingKind::Linear) => {points.len() == descriptor.linear_point_count&& (points.is_empty()- || points.as_slice()- == unsafe { std::slice::from_raw_parts(descriptor.linear_points, points.len()) })+ || points.as_slice() == unsafe { ak::slice_from_raw_parts(descriptor.linear_points, points.len()) })}(Easing::CubicBezier { x1, y1, x2, y2 }, FfiEasingKind::CubicBezier) => {[*x1, *y1, *x2, *y2] == [descriptor.x1, descriptor.y1, descriptor.x2, descriptor.y2]diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rsindex fb93bbce9b0..036b32b4873 100644--- a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs+++ b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs@@ -1477,9 +1477,7 @@ pub unsafe extern "C" fn style_engine_decide_transitions() {crate::css::ffi_stats::note_transition_decision();// SAFETY: Guaranteed by the caller.- let existing = unsafe {- crate::css::custom_properties::ffi_slice(input.existing_transitions, input.existing_transition_count)- };+ let existing = unsafe { ak::slice_from_raw_parts(input.existing_transitions, input.existing_transition_count) };// SAFETY: As above.let hand_over = |actions: &[FfiTransitionAction]| unsafe { on_actions(context, actions.as_ptr(), actions.len()) };let decision = TransitionDecision {diff --git a/Libraries/LibWeb/Rust/src/css/style/identities.rs b/Libraries/LibWeb/Rust/src/css/style/identities.rsindex e5421d7e9e4..ba31af36c73 100644--- a/Libraries/LibWeb/Rust/src/css/style/identities.rs+++ b/Libraries/LibWeb/Rust/src/css/style/identities.rs@@ -107,7 +107,7 @@ pub unsafe extern "C" fn style_node_id_allocator_mint(return;}// SAFETY: Guaranteed by the caller.- let (allocator, out) = unsafe { (&mut *allocator, std::slice::from_raw_parts_mut(out, count)) };+ let (allocator, out) = unsafe { (&mut *allocator, ak::slice_from_raw_parts_mut(out, count)) };for slot in out {*slot = if text {allocator.mint_text()diff --git a/Libraries/LibWeb/Rust/src/css/style/prefix.rs b/Libraries/LibWeb/Rust/src/css/style/prefix.rsindex 2d79a28964b..552fcfb89e7 100644--- a/Libraries/LibWeb/Rust/src/css/style/prefix.rs+++ b/Libraries/LibWeb/Rust/src/css/style/prefix.rs@@ -2017,7 +2017,7 @@ impl PrefixStates {// SAFETY: Every referenced state range is initialized. Sparse rebases can leave// unreferenced holes in the arena, but never point a state at one.unsafe {- std::slice::from_raw_parts(+ ak::slice_from_raw_parts(self.delta_steps.as_ptr().add(start).cast::<PrefixStepID>(),state.additions_len as usize,)@@ -2029,7 +2029,7 @@ impl PrefixStates {let start = state.payload_start as usize + state.additions_len as usize;// SAFETY: See `additions_in`; this is the initialized suffix of the same payload.unsafe {- std::slice::from_raw_parts(+ ak::slice_from_raw_parts(self.delta_steps.as_ptr().add(start).cast::<PrefixStepID>(),state.expiring_len as usize,)@@ -3674,7 +3674,7 @@ impl PrefixStates {) {// SAFETY: Callers pass a range from an interned state's initialized payload.let steps = unsafe {- std::slice::from_raw_parts(+ ak::slice_from_raw_parts(self.delta_steps.as_ptr().add(payload_start).cast::<PrefixStepID>(),len as usize,)diff --git a/Libraries/LibWeb/Rust/src/css/style/resource_contexts.rs b/Libraries/LibWeb/Rust/src/css/style/resource_contexts.rsindex 5b5fe0d5273..85595eb917e 100644--- a/Libraries/LibWeb/Rust/src/css/style/resource_contexts.rs+++ b/Libraries/LibWeb/Rust/src/css/style/resource_contexts.rs@@ -39,7 +39,7 @@ impl DocumentResourceContexts {if address.is_null() || length == 0 {&[]} else {- unsafe { std::slice::from_raw_parts(address, length) }+ unsafe { ak::slice_from_raw_parts(address, length) }}}let document_base_url = lent(@@ -51,7 +51,7 @@ impl DocumentResourceContexts {&[][..]} else {unsafe {- std::slice::from_raw_parts(+ ak::slice_from_raw_parts(inputs.style_sheet_resource_contexts.as_pointer()diff --git a/Libraries/LibWeb/Rust/src/css/style/style_job.rs b/Libraries/LibWeb/Rust/src/css/style/style_job.rsindex 2360c4cf8ae..ab97e013a3e 100644--- a/Libraries/LibWeb/Rust/src/css/style/style_job.rs+++ b/Libraries/LibWeb/Rust/src/css/style/style_job.rs@@ -77,7 +77,7 @@ unsafe fn lent_values<'a, T>(values: *const T, count: usize) -> &'a [T] {return &[];}// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(values, count) }+ unsafe { ak::slice_from_raw_parts(values, count) }}impl SealedStyleInputs {diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex ae403fc3328..8e4f67e0a94 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -2796,7 +2796,7 @@ impl FfiEffectiveColorSchemeInput {&[][..]} else {unsafe {- std::slice::from_raw_parts(+ ak::slice_from_raw_parts(self.document_supported_scheme_codes,self.document_supported_scheme_count,)@@ -3346,18 +3346,18 @@ pub(crate) unsafe fn drive_property_computation(let random_base_values = if environment.random_base_value_count == 0 {&[][..]} else {- unsafe { std::slice::from_raw_parts(environment.random_base_values, environment.random_base_value_count) }+ unsafe { ak::slice_from_raw_parts(environment.random_base_values, environment.random_base_value_count) }};let document_base_url = if environment.document_base_url_length == 0 {&[][..]} else {- unsafe { std::slice::from_raw_parts(environment.document_base_url, environment.document_base_url_length) }+ unsafe { ak::slice_from_raw_parts(environment.document_base_url, environment.document_base_url_length) }};let style_sheet_resource_contexts = if environment.style_sheet_resource_context_count == 0 {&[][..]} else {unsafe {- std::slice::from_raw_parts(+ ak::slice_from_raw_parts(environment.style_sheet_resource_contexts,environment.style_sheet_resource_context_count,)@@ -3594,7 +3594,7 @@ pub(crate) unsafe fn drive_property_computation(let base_url = if context.base_url_length == 0 {&[][..]} else {- unsafe { std::slice::from_raw_parts(context.base_url, context.base_url_length) }+ unsafe { ak::slice_from_raw_parts(context.base_url, context.base_url_length) }};crate::css::absolutize::StyleSheetResourceContext {base_url,@@ -5652,10 +5652,7 @@ impl FfiHostAnimationSample {(&*self.longhand_table.cast::<ComputedLonghandTable>(),self.animated_overlay.cast::<AnimatedOverlay>().as_ref(),- HostSampledEffects::new(crate::css::custom_properties::ffi_slice(- self.effects,- self.effect_count,- )),+ HostSampledEffects::new(ak::slice_from_raw_parts(self.effects, self.effect_count)),&*self.environment,)};@@ -5733,7 +5730,7 @@ pub unsafe extern "C" fn rust_sample_animation_effects_each(use crate::css::style::engine_calls::{document_host, with_engine_and_arena};// SAFETY: Guaranteed by the caller.- let inputs = unsafe { crate::css::custom_properties::ffi_slice(inputs, count) };+ let inputs = unsafe { ak::slice_from_raw_parts(inputs, count) };let Some(first) = inputs.first() else {return;};@@ -7300,7 +7297,7 @@ pub(crate) mod ffi_test_stubs {reserved: u32,}const _: () = assert!(size_of::<Header>() == 24);- let units = unsafe { std::slice::from_raw_parts(data, length) };+ let units = unsafe { ak::slice_from_raw_parts(data, length) };static FLY_STRINGS: std::sync::LazyLock<std::sync::Mutex<std::collections::HashMap<Vec<u16>, Box<[u64]>>>> =std::sync::LazyLock::new(|| std::sync::Mutex::new(std::collections::HashMap::new()));{@@ -7389,7 +7386,7 @@ pub(crate) mod ffi_test_stubs {) {// The style tests only need ASCII URL hosts. The production build uses LibUnicode's C++// implementation for the full IDNA algorithm.- let domain = unsafe { std::slice::from_raw_parts(domain, domain_length) };+ let domain = unsafe { ak::slice_from_raw_parts(domain, domain_length) };if domain.is_ascii() {unsafe { on_success(context, domain.as_ptr(), domain.len()) };}diff --git a/Libraries/LibWeb/Rust/src/css/style_sheet.rs b/Libraries/LibWeb/Rust/src/css/style_sheet.rsindex 924ec533179..afc80265b6d 100644--- a/Libraries/LibWeb/Rust/src/css/style_sheet.rs+++ b/Libraries/LibWeb/Rust/src/css/style_sheet.rs@@ -630,7 +630,7 @@ pub unsafe extern "C" fn rust_style_sheet_publish_layer_order(let sheets = if count == 0 {&[][..]} else {- unsafe { std::slice::from_raw_parts(sheets, count) }+ unsafe { ak::slice_from_raw_parts(sheets, count) }};let names = cascade_layer_order(sheets.iter().map(|&sheet| unsafe { &*sheet }));let has_layers = names.len() > 1;diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rsindex 1e2ba4304fd..30ed9fca81c 100644--- a/Libraries/LibWeb/Rust/src/css/style_value.rs+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs@@ -55,7 +55,7 @@ impl RetainedComponentValueList {return &[];}// SAFETY: The allocation is owned by this handle and has `length` initialized elements.- unsafe { std::slice::from_raw_parts(self.pointer.cast(), self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer.cast(), self.length) }}}@@ -421,7 +421,7 @@ impl RetainedStyleValueData {// SAFETY: This repr(C) type has exactly one field, a *const c_void, so its// size, alignment and layout match that pointer. The shared slice// borrows the handles and cannot outlive or modify their storage.- unsafe { std::slice::from_raw_parts(values.as_ptr().cast(), values.len()) }+ unsafe { ak::slice_from_raw_parts(values.as_ptr().cast(), values.len()) }}pub(crate) fn pointer(&self) -> *const StyleValueData {@@ -503,7 +503,7 @@ impl RetainedStyleValueDataList {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}pub(crate) fn from_retained_values(values: Vec<RetainedStyleValueData>) -> Self {@@ -599,7 +599,7 @@ macro_rules! retained_list {length: 0,};}- let elements = unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ let elements = unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }.to_vec().into_boxed_slice();let length = elements.len();@@ -631,7 +631,7 @@ impl RetainedPropertyIdList {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}}@@ -876,7 +876,7 @@ impl RetainedByteList {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}}@@ -1060,7 +1060,7 @@ macro_rules! retained_list_as_slice {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}}};@@ -1155,7 +1155,7 @@ impl RetainedColorStopList {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}}@@ -1305,7 +1305,7 @@ impl RetainedGridTrackEntryList {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer.cast(), self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer.cast(), self.length) }}pub(crate) fn from_retained_entries(entries: Vec<RetainedGridTrackEntry>) -> Self {@@ -1473,7 +1473,7 @@ impl RetainedNumericRangeList {if self.pointer.is_null() {return &[];}- unsafe { std::slice::from_raw_parts(self.pointer, self.length) }+ unsafe { ak::slice_from_raw_parts(self.pointer, self.length) }}pub(crate) fn clone_owned(&self) -> Self {@@ -1501,7 +1501,7 @@ macro_rules! retained_list_partial_eq {if list.pointer.is_null() {&[]} else {- unsafe { std::slice::from_raw_parts(list.pointer.cast::<$element>(), list.length) }+ unsafe { ak::slice_from_raw_parts(list.pointer.cast::<$element>(), list.length) }}};as_slice(self) == as_slice(other)diff --git a/Libraries/LibWeb/Rust/src/encoding_detection.rs b/Libraries/LibWeb/Rust/src/encoding_detection.rsindex 11aa2084693..3cbd6deadad 100644--- a/Libraries/LibWeb/Rust/src/encoding_detection.rs+++ b/Libraries/LibWeb/Rust/src/encoding_detection.rs@@ -45,7 +45,7 @@ pub unsafe extern "C" fn rust_detect_encoding(let tld_slice = if tld.is_null() || tld_len == 0 {None} else {- Some(std::slice::from_raw_parts(tld, tld_len))+ Some(ak::slice_from_raw_parts(tld, tld_len))};// Web browsers must use `Iso2022JpDetection::Deny` and `Utf8Detection::Deny` todiff --git a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs b/Libraries/LibWeb/Rust/src/layout/layout_changes.rsindex 0f63e176704..31684497c18 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_changes.rs@@ -471,7 +471,7 @@ pub unsafe extern "C" fn render_state_detach_remaining_rows_for_removal(return;}// SAFETY: Guaranteed by the caller.- let style_nodes = unsafe { std::slice::from_raw_parts(style_nodes, count) };+ let style_nodes = unsafe { ak::slice_from_raw_parts(style_nodes, count) };host.queue_change(ArenaChange::DetachForRemoval(style_nodes.into()));}@@ -509,7 +509,7 @@ pub unsafe extern "C" fn render_state_style_node_changed(SmallVec::new()} else {// SAFETY: Guaranteed by the caller.- SmallVec::from_slice(unsafe { std::slice::from_raw_parts(generated_for, count) })+ SmallVec::from_slice(unsafe { ak::slice_from_raw_parts(generated_for, count) })};let new = StyleNodeID::from_raw(new);let change = LayoutChange::StyleNodeChanged {@@ -539,7 +539,7 @@ pub unsafe extern "C" fn render_state_set_anchor_name_elements(&[]} else {// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(elements, count) }+ unsafe { ak::slice_from_raw_parts(elements, count) }};let change = LayoutChange::SetAnchorNameElements {scope_host: StyleNodeID::from_raw(scope_host),@@ -605,7 +605,7 @@ pub unsafe extern "C" fn render_state_set_svg_attribute_facts(&[][..]} else {// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(points, count) }+ unsafe { ak::slice_from_raw_parts(points, count) }};let change = LayoutChange::SvgAttributeFacts {element,diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex 12f02bfea8e..3cd7bce2d7e 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -5669,7 +5669,7 @@ fn counter_owner(style_node: u32, generated_for: u8) -> Option<super::counters::pub unsafe extern "C" fn style_resets_forward_list_item_counter(payloads: *const *const c_void, count: usize) -> bool {assert!(!payloads.is_null(), "style group payload array is null");// SAFETY: Guaranteed by the caller.- let groups = unsafe { std::slice::from_raw_parts(payloads, count) };+ let groups = unsafe { ak::slice_from_raw_parts(payloads, count) };super::counters::style_resets_forward_list_item_counter(ComputedValuesView::new(groups))}diff --git a/Libraries/LibWeb/Rust/src/layout/line_box_fragment.rs b/Libraries/LibWeb/Rust/src/layout/line_box_fragment.rsindex 8d37f879b62..ebdb410d40d 100644--- a/Libraries/LibWeb/Rust/src/layout/line_box_fragment.rs+++ b/Libraries/LibWeb/Rust/src/layout/line_box_fragment.rs@@ -149,7 +149,7 @@ impl LineBoxFragmentData {assert!(self.start + self.length_in_code_units <= self.text_length_in_code_units);// SAFETY: The text snapshot owns this buffer for the layout-state// lifetime, and the asserted range comes from its chunk snapshot.- unsafe { std::slice::from_raw_parts(self.text_utf16.add(self.start), self.length_in_code_units) }+ unsafe { ak::slice_from_raw_parts(self.text_utf16.add(self.start), self.length_in_code_units) }}pub(crate) fn ends_in_whitespace(&self) -> bool {diff --git a/Libraries/LibWeb/Rust/src/layout/trace.rs b/Libraries/LibWeb/Rust/src/layout/trace.rsindex 2949b851644..e4e16c3d7fa 100644--- a/Libraries/LibWeb/Rust/src/layout/trace.rs+++ b/Libraries/LibWeb/Rust/src/layout/trace.rs@@ -288,7 +288,7 @@ fn describe_node() -> String {unsafe extern "C" fn append(sink: *mut c_void, bytes: *const u8, length: usize) {// SAFETY: describe receives this live vector and supplies bytes valid for this call.- unsafe { &mut *sink.cast::<Vec<u8>>() }.extend_from_slice(unsafe { std::slice::from_raw_parts(bytes, length) });+ unsafe { &mut *sink.cast::<Vec<u8>>() }.extend_from_slice(unsafe { ak::slice_from_raw_parts(bytes, length) });}let mut bytes = Vec::<u8>::new();// SAFETY: The pass is over, and the rows it ran for are live; describe copies the row's description synchronouslydiff --git a/Libraries/LibWeb/Rust/src/layout/update_layout/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/layout/update_layout/main_thread_entries.rsindex c3d0c19667a..639201be21e 100644--- a/Libraries/LibWeb/Rust/src/layout/update_layout/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/layout/update_layout/main_thread_entries.rs@@ -94,9 +94,9 @@ pub unsafe extern "C" fn render_state_seal_clock_plan(// SAFETY: Guaranteed by the entry point's contract.let main_thread = unsafe { main_thread(host) };// SAFETY: Guaranteed by the caller.- let elements = unsafe { crate::css::custom_properties::ffi_slice(elements, count) };+ let elements = unsafe { ak::slice_from_raw_parts(elements, count) };// SAFETY: Guaranteed by the caller.- let scroll_timelines = unsafe { crate::css::custom_properties::ffi_slice(scroll_timelines, scroll_timeline_count) };+ let scroll_timelines = unsafe { ak::slice_from_raw_parts(scroll_timelines, scroll_timeline_count) };abort_on_panic(|| {let elements: Vec<_> = elements.iter()diff --git a/Libraries/LibWeb/Rust/src/lib.rs b/Libraries/LibWeb/Rust/src/lib.rsindex 7f012f12baa..861e59e7ff1 100644--- a/Libraries/LibWeb/Rust/src/lib.rs+++ b/Libraries/LibWeb/Rust/src/lib.rs@@ -45,6 +45,6 @@ unsafe fn bytes_from_raw<'a>(bytes: *const u8, len: usize) -> Option<&'a [u8]> {eprintln!("bytes_from_raw: null pointer with non-zero length {len}");return None;}- Some(std::slice::from_raw_parts(bytes, len))+ Some(ak::slice_from_raw_parts(bytes, len))}}diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex cd420f2e871..27f8231b3a3 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -22,7 +22,7 @@ use crate::painting::paintable_rows::{PaintableRowsRead, with_inline_pieces};use crate::painting::rect_to_viewport_transform::RectToViewportTransform;use crate::painting::svg_filter::SvgFilterPrimitive;use crate::render_state::{DocumentHost, RenderWait};-use libcompositing_rust::ffi::{ffi_slice, tree_from_handle};+use libcompositing_rust::ffi::tree_from_handle;use libgfx_rust::filter::Filter;use std::ffi::c_void;@@ -588,7 +588,7 @@ pub unsafe extern "C" fn layout_arena_svg_paint_resources_push_pattern(crate::painting::svg_paint_resources::PublishedSvgPattern {description: unsafe { *description },css_transform: unsafe {- ffi_slice(+ ak::slice_from_raw_parts(css_transform_entries.cast::<crate::css::computed_value_types::ComputedResolvedTransform>(),css_transform_count,)@@ -785,7 +785,7 @@ pub(crate) unsafe fn rect_to_viewport_transform_from_ffi(}Some(RectToViewportTransform {visual_context_tree: unsafe { tree_from_handle(transform.visual_context_tree) },- scroll_offsets: unsafe { ffi_slice(transform.scroll_offsets, transform.scroll_offsets_len) },+ scroll_offsets: unsafe { ak::slice_from_raw_parts(transform.scroll_offsets, transform.scroll_offsets_len) },device_pixels_per_css_pixel: transform.device_pixels_per_css_pixel,})}@@ -1387,7 +1387,7 @@ pub unsafe extern "C" fn layout_arena_paint_push_bytes(sink: *mut c_void, bytes:// guarantees the byte range.let vec = unsafe { &mut *sink.cast::<Vec<u8>>() };if length > 0 {- vec.extend_from_slice(unsafe { std::slice::from_raw_parts(bytes, length) });+ vec.extend_from_slice(unsafe { ak::slice_from_raw_parts(bytes, length) });}}@@ -1403,15 +1403,17 @@ unsafe fn svg_filter_primitive_from_ffi(primitive: &FfiSvgFilterPrimitive) -> Svin1: name(primitive.in1),in2: name(primitive.in2),result: name(primitive.result),- merge_inputs: unsafe { ffi_slice(primitive.merge_inputs, primitive.merge_input_count) }+ merge_inputs: unsafe { ak::slice_from_raw_parts(primitive.merge_inputs, primitive.merge_input_count) }.iter().map(|view| name(*view)).collect(),- color_matrix_values: unsafe { ffi_slice(primitive.color_matrix_values, primitive.color_matrix_value_count) }- .to_vec(),+ color_matrix_values: unsafe {+ ak::slice_from_raw_parts(primitive.color_matrix_values, primitive.color_matrix_value_count)+ }+ .to_vec(),component_transfer_tables: primitive.component_transfer_tables.map(|table| {(!table.is_null()).then(|| {- let table = unsafe { ffi_slice(table, 256) };+ let table = unsafe { ak::slice_from_raw_parts(table, 256) };Box::new(<[u8; 256]>::try_from(table).expect("a component transfer table holds 256 entries"))})}),@@ -1460,7 +1462,7 @@ pub unsafe extern "C" fn layout_arena_filter_functions_serialize(append: unsafe extern "C" fn(*mut c_void, *const u8, usize),context: *mut c_void,) -> bool {- let functions = unsafe { ffi_slice(functions, count) };+ let functions = unsafe { ak::slice_from_raw_parts(functions, count) };let Some(graph) = filter_functions_graph(functions.iter().copied().map(Filter::from)) else {return false;};diff --git a/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs b/Libraries/LibWeb/Rust/src/painting/host/hit_test.rsindex 601e27b3006..785fa5a5f84 100644--- a/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs+++ b/Libraries/LibWeb/Rust/src/painting/host/hit_test.rs@@ -60,7 +60,7 @@ impl FfiHitTestQueryCallbacks {return &[];}// SAFETY: QueryContext keeps the document and its resolved scroll snapshot alive for the synchronous query.- unsafe { std::slice::from_raw_parts(self.scroll_offsets, self.scroll_offsets_len) }+ unsafe { ak::slice_from_raw_parts(self.scroll_offsets, self.scroll_offsets_len) }}}@@ -96,7 +96,7 @@ impl FfiCaretPositionQuery {return &[];}// SAFETY: The host keeps the descent alive for the synchronous query.- unsafe { std::slice::from_raw_parts(self.boundary_descent, self.boundary_descent_len) }+ unsafe { ak::slice_from_raw_parts(self.boundary_descent, self.boundary_descent_len) }}pub(crate) fn is_query_node(&self, node: u32) -> bool {diff --git a/Libraries/LibWeb/Rust/src/painting/host/paint.rs b/Libraries/LibWeb/Rust/src/painting/host/paint.rsindex 42100650fdb..221b4518f0d 100644--- a/Libraries/LibWeb/Rust/src/painting/host/paint.rs+++ b/Libraries/LibWeb/Rust/src/painting/host/paint.rs@@ -93,18 +93,17 @@ impl FfiRecordingInputs {CaretPaint, CaretTarget, FocusedAreaOutline, FocusedTextControlSelection, GridOverlays, InspectorHighlight,RecordingInputs, UnframedRecordingInputs,};- use libcompositing_rust::ffi::ffi_slice;// SAFETY: The caller lends these arrays and buffers for this call.let (grid_overlays, flex_overlays, outline_path, text_fragment_indications) = unsafe {(- ffi_slice(self.grid_overlays, self.grid_overlay_count),- ffi_slice(self.flex_overlays, self.flex_overlay_count),- ffi_slice(+ ak::slice_from_raw_parts(self.grid_overlays, self.grid_overlay_count),+ ak::slice_from_raw_parts(self.flex_overlays, self.flex_overlay_count),+ ak::slice_from_raw_parts(self.focused_area_outline.path_bytes,self.focused_area_outline.path_byte_count,),- ffi_slice(self.text_fragment_indications, self.text_fragment_indication_count),+ ak::slice_from_raw_parts(self.text_fragment_indications, self.text_fragment_indication_count),)};let caret = self.caret;@@ -168,7 +167,7 @@ impl FfiRecordingInputs {// SAFETY: The caller lends the label bytes and supplies live fonts for this overlay.let (text, fonts) = unsafe {(- ffi_slice(+ ak::slice_from_raw_parts(self.inspector_highlight_label.text,self.inspector_highlight_label.text_byte_count,),diff --git a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs b/Libraries/LibWeb/Rust/src/painting/paint_changes.rsindex 1e75b86bcc7..f43f4b20019 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_changes.rs@@ -26,7 +26,6 @@ use crate::layout::LayoutNodeArena;use crate::layout::node_data::NodeSlotId;use crate::layout::tree_update_marks::MarkedBox;use crate::render_state::{ArenaChange, DocumentHost};-use libcompositing_rust::ffi::ffi_slice;use std::sync::Arc;/// One write of the host to a document's paint state.@@ -251,7 +250,7 @@ pub unsafe extern "C" fn render_state_apply_selection(Box::default()} else {// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(entries, entry_count) }.into()+ unsafe { ak::slice_from_raw_parts(entries, entry_count) }.into()};let change = PaintChange::ApplySelection {viewport,@@ -284,13 +283,13 @@ pub unsafe extern "C" fn render_state_apply_search_text(Box::default()} else {// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(ranges, range_count) }.into()+ unsafe { ak::slice_from_raw_parts(ranges, range_count) }.into()};let entries = if entry_count == 0 {Box::default()} else {// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(entries, entry_count) }.into()+ unsafe { ak::slice_from_raw_parts(entries, entry_count) }.into()};host.host_tables().shows_search_text.set(range_count != 0);let change = PaintChange::ApplySearchText {@@ -326,7 +325,7 @@ pub unsafe extern "C" fn render_state_apply_spelling_errors(Box::default()} else {// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(errors, error_count) }.into()+ unsafe { ak::slice_from_raw_parts(errors, error_count) }.into()};host.host_tables().shows_spelling_errors.set(error_count != 0);queue(host, PaintChange::ApplySpellingErrors { viewport, errors });@@ -395,7 +394,7 @@ pub unsafe extern "C" fn render_state_set_layer_image_paint_facts(Vec::new()} else {// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(entries, count) }+ unsafe { ak::slice_from_raw_parts(entries, count) }.iter().map(|entry| LayerImagePaintFactsEntry {list: entry.list,@@ -524,7 +523,12 @@ pub unsafe extern "C" fn render_state_publish_image_map_areas(coords_count: usize,) {// SAFETY: Guaranteed by the caller.- let (areas, coords) = unsafe { (ffi_slice(areas, area_count), ffi_slice(coords, coords_count)) };+ let (areas, coords) = unsafe {+ (+ ak::slice_from_raw_parts(areas, area_count),+ ak::slice_from_raw_parts(coords, coords_count),+ )+ };let areas = areas.iter().map(|area| {diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/text_decoration.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/text_decoration.rsindex 2ce6f77bb7e..863cb1d27b4 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/text_decoration.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/text_decoration.rs@@ -43,7 +43,7 @@ fn text_decoration_lines(style: crate::css::computed_value_views::ComputedValuesreturn &[];}// SAFETY: The retained list belongs to the style group payload, which outlives the pass.- unsafe { std::slice::from_raw_parts(list.pointer, list.length) }+ unsafe { ak::slice_from_raw_parts(list.pointer, list.length) }}fn first_available_font(diff --git a/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs b/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rsindex cfa1bd2cbd6..66a31ef5367 100644--- a/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs+++ b/Libraries/LibWeb/Rust/src/painting/visual_animation_builder.rs@@ -38,7 +38,6 @@ use crate::painting::host::{use crate::painting::visual_animation::{VisualAnimation, VisualAnimationKeyframe, VisualAnimationTransformOperation, VisualAnimationValue,};-use libcompositing_rust::ffi::ffi_slice;use libgfx_rust::{Color, ColorFilterType};const TARGET_KIND_COUNT: usize = 4;@@ -142,7 +141,7 @@ impl<'a> Request<'a> {Self {ffi,// SAFETY: The caller guarantees the keyframe range is live.- keyframes: unsafe { ffi_slice(ffi.keyframes, ffi.keyframe_count) },+ keyframes: unsafe { ak::slice_from_raw_parts(ffi.keyframes, ffi.keyframe_count) },}}diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex aa71371800e..d0c564179ca 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -1591,7 +1591,7 @@ pub unsafe extern "C" fn clock_ticks_tick(// SAFETY: Guaranteed by the caller, whose reference this borrows.let ticks = std::mem::ManuallyDrop::new(unsafe { Arc::from_raw(ticks) });// SAFETY: Guaranteed by the caller.- let scroll_offsets = unsafe { crate::css::custom_properties::ffi_slice(scroll_offsets, scroll_offset_count) };+ let scroll_offsets = unsafe { ak::slice_from_raw_parts(scroll_offsets, scroll_offset_count) };ticks.tick(frame_time_nanoseconds, scroll_offsets)}diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rsindex 83209996aac..1de3dac4678 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs@@ -155,7 +155,7 @@ impl HoverPlan {Vec::new()} else {// SAFETY: Guaranteed by the caller.- unsafe { std::slice::from_raw_parts(inputs.scroll_offsets, inputs.scroll_offset_count) }.to_vec()+ unsafe { ak::slice_from_raw_parts(inputs.scroll_offsets, inputs.scroll_offset_count) }.to_vec()};let effect_timings = if inputs.effect_timing_count == 0 {Vec::new()@@ -163,9 +163,9 @@ impl HoverPlan {// SAFETY: Guaranteed by the caller.let (nodes, identities, timings) = unsafe {(- std::slice::from_raw_parts(inputs.effect_timing_nodes, inputs.effect_timing_count),- std::slice::from_raw_parts(inputs.effect_timing_identities, inputs.effect_timing_count),- std::slice::from_raw_parts(+ ak::slice_from_raw_parts(inputs.effect_timing_nodes, inputs.effect_timing_count),+ ak::slice_from_raw_parts(inputs.effect_timing_identities, inputs.effect_timing_count),+ ak::slice_from_raw_parts(inputs.effect_timings.cast::<FfiEffectTiming>(),inputs.effect_timing_count,),diff --git a/Libraries/LibWeb/Rust/src/svg/path_parser.rs b/Libraries/LibWeb/Rust/src/svg/path_parser.rsindex 3a5d9378097..f242f4c86d4 100644--- a/Libraries/LibWeb/Rust/src/svg/path_parser.rs+++ b/Libraries/LibWeb/Rust/src/svg/path_parser.rs@@ -862,10 +862,10 @@ impl FfiSvgInput {}match (self.ascii.is_null(), self.utf16.is_null()) {(false, true) => Some(Input::Ascii(unsafe {- std::slice::from_raw_parts(self.ascii, self.length)+ ak::slice_from_raw_parts(self.ascii, self.length)})),(true, false) => Some(Input::Utf16(unsafe {- std::slice::from_raw_parts(self.utf16, self.length)+ ak::slice_from_raw_parts(self.utf16, self.length)})),_ => None,}diff --git a/Libraries/RustDemangle.rs b/Libraries/RustDemangle.rsindex ec40d9472df..2f98b37281a 100644--- a/Libraries/RustDemangle.rs+++ b/Libraries/RustDemangle.rs@@ -39,7 +39,7 @@ impl Write for Output {extern "C" fn demangle(name: *const c_char, name_length: usize, append: Append, context: *mut c_void) -> bool {// SAFETY: AK passes a name of the given length that outlives this call.- let name = unsafe { std::slice::from_raw_parts(name.cast::<u8>(), name_length) };+ let name = unsafe { ak::slice_from_raw_parts(name.cast::<u8>(), name_length) };let Ok(name) = std::str::from_utf8(name) else {return false;};diff --git a/clippy.toml b/clippy.tomlnew file mode 100644index 00000000000..276ae37f31f--- /dev/null+++ b/clippy.toml@@ -0,0 +1,4 @@+disallowed-methods = [+ { path = "std::slice::from_raw_parts", reason = "a null pointer is undefined behavior even for an empty slice, and an empty AK container lends one: use ak::slice_from_raw_parts" },+ { path = "std::slice::from_raw_parts_mut", reason = "a null pointer is undefined behavior even for an empty slice, and an empty AK container lends one: use ak::slice_from_raw_parts_mut" },+]