From 29662c14dad36c5e68e63512c5a2e033dad39c77 Mon Sep 17 00:00:00 2001 From: RTTV Date: Tue, 17 Dec 2024 18:50:13 -0500 Subject: [PATCH] updated libs --- Cargo.toml | 21 +++++---- README.md | 4 +- src/elements/compound.rs | 93 +++++++++++++++++++--------------------- src/elements/element.rs | 8 ++-- src/main.rs | 8 ++-- src/window.rs | 8 ++-- src/workbench_action.rs | 2 +- 7 files changed, 68 insertions(+), 76 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6be547a..96b4c41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,21 +52,20 @@ winres = "0.1.12" zune-inflate = { version = "0.2.54", features = ["gzip", "zlib"] } flate2 = "1.0.31" winit = "0.30.5" -wgpu = { version = "22.1.0", default-features = false, features = ["webgl", "wgsl", "dx12", "metal"] } +wgpu = { version = "23.0.1", default-features = false, features = ["webgl", "wgsl", "dx12", "metal"] } fxhash = "0.2.1" -hashbrown = { version = "0.14.5", features = ["raw", "inline-more", "nightly"], default-features = false } -getrandom = { version = "0.2.15", features = ["js"] } -notify = "6.1.1" +hashbrown = { version = "0.15.2", features = ["inline-more", "nightly"], default-features = false } +notify = "7.0.0" uuid = { version = "1.10.0", features = ["v4"] } compact_str = "0.8.0" wgsl-inline = { version = "0.2.1", features = ["minify"] } static_assertions = "1.1.0" -anyhow = "1.0.86" +anyhow = "1.0.94" lz4_flex = { version = "0.11.3", default-features = false, features = ["std", "nightly"] } -regex = "1.10.6" +regex = "1.11.1" glob = "0.3.1" zune-png = { version = "0.4.10", features = [] } -polonius-the-crab = "0.4.1" +polonius-the-crab = "0.4.2" enum-map = "3.0.0-beta.2" parking_lot = "0.12.3" @@ -75,11 +74,11 @@ winapi = { version = "0.3.9", features = ["wincon"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] cli-clipboard = "0.4.0" -pollster = "0.3.0" +pollster = "0.4.0" native-dialog = "0.7.0" dirs = "5.0.1" [target.'cfg(target_arch = "wasm32")'.dependencies] -wasm-bindgen = "0.2.91" -wasm-bindgen-futures = "0.4.41" -web-sys = { version = "=0.3.69", features = ["console", "Document", "Window", "Element", "Clipboard", "DateTimeValue", "HtmlElement", "HtmlDocument", "HtmlTextAreaElement", "Blob", "HtmlAreaElement", "Url", "Storage"] } +wasm-bindgen = "0.2.99" +wasm-bindgen-futures = "0.4.49" +web-sys = { version = "0.3.72", features = ["console", "Document", "Window", "Element", "Clipboard", "DateTimeValue", "HtmlElement", "HtmlDocument", "HtmlTextAreaElement", "Blob", "HtmlAreaElement", "Url", "Storage"] } diff --git a/README.md b/README.md index afc5b8a..b775d61 100644 --- a/README.md +++ b/README.md @@ -111,12 +111,12 @@ however, it would not come to be without the lovely projects below inspiring it. # Compiling ### For Windows -* You must have [Rust](https://rustup.rs) 1.80.0+ \[Nightly\] (target: x86_64-pc-windows-msvc) +* You must have [Rust](https://rustup.rs) 1.85.0+ \[Nightly\] (target: x86_64-pc-windows-msvc) * Uncomment the windows-only section of your `Cargo.toml` file and make sure the other sections are commented out. * Run the following command to make a release build in `./target/x86_64-pc-windows-msvc/release`:\ `cargo +nightly build --release --target x86_64-pc-windows-msvc -Zbuild-std=std,panic_abort -Zbuild-std-features=panic_immediate_abort` ### For Wasm -* You must have [Rust](https://rustup.rs) 1.80.0+ \[Nightly\] (target: x86_64-pc-windows-msvc) +* You must have [Rust](https://rustup.rs) 1.85.0+ \[Nightly\] * You must have [wasm-pack](https://crates.io/crates/wasm-pack) installed using cargo * Uncomment the wasm-only section of your `Cargo.toml` file and make sure the other sections are commented out. * Run the following command to compile for web assembly in `./web`:\ diff --git a/src/elements/compound.rs b/src/elements/compound.rs index 5b023a7..eefbd6f 100644 --- a/src/elements/compound.rs +++ b/src/elements/compound.rs @@ -7,7 +7,8 @@ use std::ops::Deref; use std::thread::Scope; use compact_str::{CompactString, format_compact, ToCompactString}; -use hashbrown::raw::RawTable; +use hashbrown::hash_table::Entry::*; +use hashbrown::hash_table::HashTable; use crate::{config, hash, width_ascii, DropFn, NbtElementAndKey, RenderContext, StrExt, VertexBufferBuilder}; use crate::assets::{BASE_Z, COMPOUND_ROOT_UV, COMPOUND_UV, CONNECTION_UV, HEADER_SIZE, JUST_OVERLAPPING_BASE_TEXT_Z, LINE_NUMBER_CONNECTOR_Z, LINE_NUMBER_SEPARATOR_UV, ZOffset}; @@ -752,7 +753,7 @@ impl NbtCompound { // Based on indexmap, but they didn't let me clone with unchecked mem stuff #[allow(clippy::module_name_repetitions)] pub struct CompoundMap { - pub indices: RawTable, + pub indices: HashTable, pub entries: Vec, } @@ -787,13 +788,8 @@ impl Clone for CompoundMap { } unsafe { - let mut table = RawTable::try_with_capacity(self.indices.len()).unwrap_unchecked(); - for (idx, bucket) in self.indices.iter().enumerate() { - let hash = hash!(self.entries.get_unchecked(idx).key); - let _ = table.insert_in_slot(hash, core::mem::transmute(idx), *bucket.as_ref()); - } Self { - indices: table, + indices: HashTable::clone(&self.indices), entries: clone_entries(&self.entries), } } @@ -810,7 +806,7 @@ pub struct Entry { impl Default for CompoundMap { fn default() -> Self { Self { - indices: RawTable::new(), + indices: HashTable::new(), entries: Vec::new(), } } @@ -826,7 +822,7 @@ impl CompoundMap { #[must_use] pub fn idx_of(&self, key: &str) -> Option { self.indices - .get(hash!(key), |&idx| unsafe { self.entries.get_unchecked(idx).key.as_str() == key }) + .find(hash!(key), |&idx| unsafe { self.entries.get_unchecked(idx).key.as_str() == key }) .copied() } @@ -844,9 +840,9 @@ impl CompoundMap { pub fn insert_full(&mut self, key: CompactString, element: NbtElement) -> (usize, Option) { unsafe { let hash = hash!(key); - match self.indices.find_or_find_insert_slot(hash, |&idx| self.entries.get_unchecked(idx).key == key, |&idx| hash!(self.entries.get_unchecked(idx).key), ) { - Ok(bucket) => { - let idx = *bucket.as_ref(); + match self.indices.entry(hash, |&idx| self.entries.get_unchecked(idx).key == key, |&idx| hash!(self.entries.get_unchecked(idx).key)) { + Occupied(entry) => { + let idx = *entry.get(); ( idx, Some(core::mem::replace( @@ -855,7 +851,7 @@ impl CompoundMap { )), ) } - Err(slot) => { + Vacant(slot) => { let len = self.entries.len(); self.entries.try_reserve(1).unwrap_unchecked(); self.entries.as_mut_ptr().add(len).write(Entry { @@ -864,7 +860,7 @@ impl CompoundMap { additional: 0, }); self.entries.set_len(len + 1); - self.indices.insert_in_slot(hash, slot, len); + slot.insert(len); (len, None) } } @@ -874,9 +870,9 @@ impl CompoundMap { pub fn insert_at(&mut self, key: CompactString, element: NbtElement, idx: usize) -> Option<(CompactString, NbtElement)> { unsafe { let hash = hash!(key); - let (prev, end, bucket) = match self.indices.find_or_find_insert_slot(hash, |&idx| self.entries.get_unchecked(idx).key == key, |&idx| hash!(self.entries.get_unchecked(idx).key)) { - Ok(bucket) => { - let before = core::mem::replace(bucket.as_mut(), idx); + let (prev, end, ptr) = match self.indices.entry(hash, |&idx| self.entries.get_unchecked(idx).key == key, |&idx| hash!(self.entries.get_unchecked(idx).key)) { + Occupied(mut entry) => { + let before = core::mem::replace(entry.get_mut(), idx); let Entry { key: k, value: v, .. } = self.entries.remove(before); @@ -888,9 +884,9 @@ impl CompoundMap { additional: 0, }, ); - (Some((k, v)), before, bucket) + (Some((k, v)), before, entry.get_mut() as *mut usize) } - Err(slot) => { + Vacant(slot) => { let len = self.entries.len(); self.entries.try_reserve_exact(1).unwrap_unchecked(); let ptr = self.entries.as_mut_ptr().add(idx); @@ -901,32 +897,32 @@ impl CompoundMap { additional: 0, }); self.entries.set_len(len + 1); - let bucket = self.indices.insert_in_slot(hash, slot, idx); - (None, len, bucket) + let mut entry = slot.insert(len); + (None, len, entry.get_mut() as *mut usize) } }; match idx.cmp(&end) { Ordering::Less => { - for index in self.indices.iter() { - let value = *index.as_ref(); + for index in self.indices.iter_mut() { + let value = *index; if value >= idx && value <= end { - *index.as_mut() += 1; + *index += 1; } } } Ordering::Equal => {} Ordering::Greater => { - for index in self.indices.iter() { - let value = *index.as_ref(); + for index in self.indices.iter_mut() { + let value = *index; if value <= idx && value >= end { - *index.as_mut() -= 1; + *index -= 1; } } } } - *bucket.as_mut() = idx; + *ptr = idx; prev } @@ -940,18 +936,28 @@ impl CompoundMap { pub unsafe fn update_key_idx_unchecked(&mut self, idx: usize, key: CompactString) -> CompactString { let new_hash = hash!(key); let old_key = core::mem::replace(&mut self.entries.get_unchecked_mut(idx).key, key); - self.indices.remove_entry(hash!(old_key), |&target_idx| target_idx == idx).unwrap_unchecked(); - self.indices.insert(new_hash, idx, |&idx| hash!(self.entries.get_unchecked(idx).key)); + if let Ok(entry) = self.indices.find_entry(hash!(old_key), |&target_idx| target_idx == idx) { + entry.remove(); + } else { + // should **never** happen + core::hint::unreachable_unchecked(); + } + self.indices.insert_unique(new_hash, idx, |&idx| hash!(self.entries.get_unchecked(idx).key)); old_key } pub fn shift_remove_idx(&mut self, idx: usize) -> Option<(CompactString, NbtElement)> { if idx > self.entries.len() { return None } unsafe { - self.indices.remove_entry(hash!(self.entries.get_unchecked(idx).key), |&found_idx| found_idx == idx); - for bucket in self.indices.iter() { - if *bucket.as_ref() > idx { - *bucket.as_mut() -= 1; + if let Ok(entry) = self.indices.find_entry(hash!(self.entries.get_unchecked(idx).key), |&found_idx| found_idx == idx) { + entry.remove(); + } else { + // should **never** happen + core::hint::unreachable_unchecked(); + } + for entry in self.indices.iter_mut() { + if *entry > idx { + *entry -= 1; } } } @@ -960,25 +966,14 @@ impl CompoundMap { Some((key, value)) } - pub fn swap_remove_idx(&mut self, idx: usize) -> Option<(CompactString, NbtElement)> { - if idx > self.entries.len() { return None } - let Entry { key, value, .. } = self.entries.swap_remove(idx); - let hash = hash!(key); - unsafe { - let tail = self.indices.remove_entry(hash, |&idx| idx + 1 == self.entries.len()).unwrap_unchecked(); - *self.indices.get_mut(hash, |&idx| self.entries.get_unchecked(idx).key == key).unwrap_unchecked() = tail; - } - Some((key, value)) - } - pub fn swap(&mut self, a: usize, b: usize) { if a >= self.entries.len() || b >= self.entries.len() { return; } unsafe { let a_hash = hash!(self.entries.get_unchecked(a).key); let b_hash = hash!(self.entries.get_unchecked(b).key); self.entries.swap(a, b); - let a = self.indices.get_mut(a_hash, |&idx| idx == a).unwrap_unchecked() as *mut usize; - let b = self.indices.get_mut(b_hash, |&idx| idx == b).unwrap_unchecked() as *mut usize; + let a = self.indices.find_mut(a_hash, |&idx| idx == a).unwrap_unchecked() as *mut usize; + let b = self.indices.find_mut(b_hash, |&idx| idx == b).unwrap_unchecked() as *mut usize; core::ptr::swap(a, b); } } @@ -1018,7 +1013,7 @@ impl CompoundMap { // SAFETY: these indices are valid since the length did not change and since the values written were indexes unsafe { let entry = self.entries.get_unchecked_mut(new_idx); - *self.indices.find(hash!(entry.key), |&target_idx| target_idx == idx).expect("index obviously exists").as_mut() = new_idx; + *self.indices.find_mut(hash!(entry.key), |&target_idx| target_idx == idx).expect("index obviously exists") = new_idx; let true_line_number = *true_line_numbers.get_unchecked(idx); let line_number = *line_numbers.get_unchecked(idx); diff --git a/src/elements/element.rs b/src/elements/element.rs index 2e7420d..91926ca 100644 --- a/src/elements/element.rs +++ b/src/elements/element.rs @@ -9,7 +9,7 @@ use std::slice::{Iter, IterMut}; use std::thread::Scope; use compact_str::{CompactString, format_compact, ToCompactString}; -use hashbrown::raw::RawTable; +use hashbrown::HashTable; use polonius_the_crab::{polonius, polonius_return}; use crate::{array, assets::JUST_OVERLAPPING_BASE_TEXT_Z, DropFn, primitive, RenderContext, since_epoch, StrExt, TextColor, VertexBufferBuilder, NbtElementAndKey, width_ascii}; @@ -1592,7 +1592,7 @@ impl Drop for NbtElement { NbtCompound::ID => { let map = &mut *self.compound.entries; let CompoundMap { indices, entries } = map; - (indices as *mut RawTable).drop_in_place(); + (indices as *mut HashTable).drop_in_place(); for Entry { value, key, .. } in &mut *entries { (value as *mut Self).drop_in_place(); if key.is_heap_allocated() { @@ -1616,7 +1616,7 @@ impl Drop for NbtElement { NbtChunk::ID => { let map = &mut *self.chunk.entries; let CompoundMap { indices, entries } = map; - (indices as *mut RawTable).drop_in_place(); + (indices as *mut HashTable).drop_in_place(); for Entry { value, key, .. } in &mut *entries { (value as *mut Self).drop_in_place(); if key.is_heap_allocated() { @@ -1644,7 +1644,7 @@ impl Drop for NbtElement { let ptr = &mut **chunk.as_chunk_unchecked_mut(); let map = &mut *ptr.entries; let CompoundMap { indices, entries } = map; - (indices as *mut RawTable).drop_in_place(); + (indices as *mut HashTable).drop_in_place(); for Entry { value, key, .. } in &mut *entries { (value as *mut Self).drop_in_place(); if key.is_heap_allocated() { diff --git a/src/main.rs b/src/main.rs index 2b284f4..b3e2e00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,19 +6,17 @@ #![feature( array_chunks, box_patterns, - const_collections_with_hasher, core_intrinsics, iter_array_chunks, iter_next_chunk, - lazy_cell, - let_chains, optimize_attribute, panic_update_hook, stmt_expr_attributes, float_next_up_down, variant_count, sync_unsafe_cell, - duration_millis_float + duration_millis_float, + let_chains )] #![windows_subsystem = "windows"] @@ -656,7 +654,7 @@ impl SortAlgorithm { // SAFETY: these indices are valid since the length did not change and since the values written were indexes unsafe { let entry = map.entries.get_unchecked_mut(new_idx); - *map.indices.find(hash!(entry.key), |&target_idx| target_idx == idx).expect("index obviously exists").as_mut() = new_idx; + *map.indices.find_mut(hash!(entry.key), |&target_idx| target_idx == idx).expect("index obviously exists") = new_idx; } } } diff --git a/src/window.rs b/src/window.rs index c1a1ed2..49939cc 100644 --- a/src/window.rs +++ b/src/window.rs @@ -299,7 +299,7 @@ impl<'window> State<'window> { layout: Some(&render_pipeline_layout), vertex: VertexState { module: &shader, - entry_point: "vertex", + entry_point: Some("vertex"), compilation_options: Default::default(), buffers: &[VertexBufferLayout { array_stride: 20, @@ -309,7 +309,7 @@ impl<'window> State<'window> { }, fragment: Some(FragmentState { module: &shader, - entry_point: "fragment", + entry_point: Some("fragment"), compilation_options: Default::default(), targets: &[Some(ColorTargetState { format: config.format, @@ -405,7 +405,7 @@ impl<'window> State<'window> { layout: Some(&text_render_pipeline_layout), vertex: VertexState { module: &text_shader, - entry_point: "vertex", + entry_point: Some("vertex"), compilation_options: Default::default(), buffers: &[VertexBufferLayout { array_stride: 16, @@ -415,7 +415,7 @@ impl<'window> State<'window> { }, fragment: Some(FragmentState { module: &text_shader, - entry_point: "fragment", + entry_point: Some("fragment"), compilation_options: Default::default(), targets: &[Some(ColorTargetState { format: config.format, diff --git a/src/workbench_action.rs b/src/workbench_action.rs index 762e158..a811719 100644 --- a/src/workbench_action.rs +++ b/src/workbench_action.rs @@ -159,7 +159,7 @@ impl WorkbenchAction { let mut current_true_line_number = true_line_number + 1; for (idx, &new_idx) in reordering_indices.iter().enumerate() { let entry = core::mem::replace(previous_entries.get_unchecked_mut(new_idx), MaybeUninit::uninit()).assume_init(); - *indices.find(hash!(entry.key), |&x| x == new_idx).expect("index obviously exists").as_mut() = idx; + *indices.find_mut(hash!(entry.key), |&x| x == new_idx).expect("index obviously exists") = idx; let line_number = *line_numbers.get_unchecked(new_idx); let true_line_number = *true_line_numbers.get_unchecked(new_idx); let height = entry.value.height();