Skip to content

Commit 8c8deff

Browse files
committed
hash labels in node values
1 parent 46543d7 commit 8c8deff

File tree

5 files changed

+40
-36
lines changed

5 files changed

+40
-36
lines changed

changelog.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ This version is not yet released. If you are reading this on the website, then t
3030
- Add the [`exponential ₑ`](https://uiua.org/docs/exponential) function, which computes the exponential function
3131
- Deprecate [`logarithm ₙ`](https://uiua.org/docs/logarithm) in favor of [`exponential ₑ`](https://uiua.org/docs/exponential)
3232
- Remove experimental `ln` in favor of [`exponential ₑ`](https://uiua.org/docs/exponential)
33-
- Remove the `ⁿ%:1` ("root" pattern) optimization
34-
- It inverted incorrectly when used with [`under ⍜`](https://uiua.org/docs/under)
35-
- Existing uses should be replaced with [`anti ⌝`](https://uiua.org/docs/anti)[`power ⁿ`](https://uiua.org/docs/power)
3633
- Add [`&seek`](https://uiua.org/docs/&seek) function for working with large files
3734
- Remove previously deprecated `signature` and `stringify` modifiers
3835
- Calling [`&tcpa`](https://uiua.org/docs/&tcpa) on a TLS listener created with [`&tlsl`](https://uiua.org/docs/&tlsl) now automatically tries conducting a TSL handshake
@@ -56,6 +53,9 @@ This version is not yet released. If you are reading this on the website, then t
5653
- Improve "Array would be too large" error messages
5754
- Change short form of the `--experimental` flag for `uiua eval` to use `-x` instead of `-e`
5855
- This is consistent with the corresponding flag for `uiua repl`
56+
- Remove the `ⁿ÷:1` ("root" pattern) optimization
57+
- It inverted incorrectly when used with [`under ⍜`](https://uiua.org/docs/under)
58+
- Existing uses should be replaced with [`anti ⌝`](https://uiua.org/docs/anti)[`power ⁿ`](https://uiua.org/docs/power)
5959
### Pad
6060
- Add `primitives.json` to the pre-included files in the pad
6161

src/algorithm/groups.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ fn multi_partition_indices(markers: &Array<i64>) -> Vec<(i64, Vec<usize>)> {
358358
continue;
359359
}
360360
if group.iter().any(|idx| {
361-
idx.iter()
362-
.zip(&curr)
361+
(idx.iter().zip(&curr))
363362
.map(|(a, b)| a.abs_diff(*b))
364363
.sum::<usize>()
365364
== 1
@@ -369,9 +368,7 @@ fn multi_partition_indices(markers: &Array<i64>) -> Vec<(i64, Vec<usize>)> {
369368
}
370369
// Add the current index to the adjacent group, possibly merging groups
371370
match adjacent_groups.len() {
372-
0 => {
373-
groups.push((marker, vec![curr.clone()]));
374-
}
371+
0 => groups.push((marker, vec![curr.clone()])),
375372
1 => groups[adjacent_groups[0]].1.push(curr.clone()),
376373
_ => {
377374
let mut adjacent_groups = adjacent_groups.into_iter();

src/tree.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use serde::*;
1818
use crate::{
1919
check::SigCheckError,
2020
compile::invert::{InversionError, InversionResult},
21-
Assembly, BindingKind, DynamicFunction, Function, ImplPrimitive, Primitive, Purity, Signature,
22-
Value,
21+
Assembly, BindingKind, DynamicFunction, Function, HashLabels, ImplPrimitive, Primitive, Purity,
22+
Signature, Value,
2323
};
2424

2525
node!(
@@ -1155,15 +1155,16 @@ macro_rules! node {
11551155
#[allow(unused_variables)]
11561156
fn hash<H: Hasher>(&self, state: &mut H) {
11571157
macro_rules! hash_field {
1158-
(span) => {};
1159-
($nm:ident) => {Hash::hash($nm, state)};
1158+
(span span) => {};
1159+
(val $val:ident) => {Hash::hash(&HashLabels($val), state)};
1160+
($nm:ident $_nm:ident) => {Hash::hash($nm, state)};
11601161
}
11611162
match self {
11621163
$(
11631164
Self::$name $(($($tup_name),*))? $({$($field_name),*})? => {
11641165
discriminant(self).hash(state);
1165-
$($(hash_field!($field_name);)*)?
1166-
$($(hash_field!($tup_name);)*)?
1166+
$($(hash_field!($field_name $field_name);)*)?
1167+
$($(hash_field!($tup_name $tup_name);)*)?
11671168
}
11681169
)*
11691170
}

src/value.rs

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,43 +2355,51 @@ impl Ord for Value {
23552355
}
23562356

23572357
impl Hash for Value {
2358-
fn hash<H: Hasher>(&self, state: &mut H) {
2359-
val_as_arr!(self, |arr| arr.hash(state))
2358+
fn hash<H: Hasher>(&self, hasher: &mut H) {
2359+
val_as_arr!(self, |arr| arr.hash(hasher))
23602360
}
23612361
}
23622362

2363-
/// A wrapper for values that hashes their labels in addition to the normal hashing
2364-
///
2365-
/// Works with both [`Value`] and `&Value`
2366-
#[derive(Debug, Clone)]
2367-
pub struct HashLabels<T = Value>(pub T);
2363+
#[derive(Clone)]
2364+
pub(crate) struct HashLabels<V = Value>(pub V);
23682365

2369-
impl PartialEq for HashLabels {
2366+
impl PartialEq for HashLabels<Value> {
23702367
fn eq(&self, other: &Self) -> bool {
2371-
HashLabels(&self.0).eq(&HashLabels(&other.0))
2368+
HashLabels(&self.0) == HashLabels(&other.0)
23722369
}
23732370
}
2374-
impl Eq for HashLabels {}
2375-
impl Hash for HashLabels {
2376-
fn hash<H: Hasher>(&self, state: &mut H) {
2377-
HashLabels(&self.0).hash(state);
2371+
impl Eq for HashLabels<Value> {}
2372+
impl Hash for HashLabels<Value> {
2373+
fn hash<H: Hasher>(&self, hasher: &mut H) {
2374+
HashLabels(&self.0).hash(hasher)
23782375
}
23792376
}
23802377

23812378
impl PartialEq for HashLabels<&Value> {
23822379
fn eq(&self, other: &Self) -> bool {
2383-
self.0.eq(other.0) && self.0.meta.label == other.0.meta.label
2380+
self.0 == other.0 && self.0.meta.label == other.0.meta.label
23842381
}
23852382
}
23862383
impl Eq for HashLabels<&Value> {}
23872384
impl Hash for HashLabels<&Value> {
2388-
fn hash<H: Hasher>(&self, state: &mut H) {
2389-
self.0.hash(state);
2390-
self.0.meta.label.hash(state);
2391-
if let HashLabels(Value::Box(arr)) = self {
2392-
for Boxed(val) in &arr.data {
2393-
HashLabels(val).hash(state);
2385+
fn hash<H: Hasher>(&self, hasher: &mut H) {
2386+
self.0.meta.label.hash(hasher);
2387+
match self.0 {
2388+
Value::Box(arr) => {
2389+
if let Some(keys) = &arr.meta.map_keys {
2390+
keys.hash(hasher);
2391+
}
2392+
Boxed::TYPE_ID.hash(hasher);
2393+
if let Some(scalar) = arr.as_scalar() {
2394+
if let Some(value) = scalar.nested_value() {
2395+
value.hash(hasher);
2396+
return;
2397+
}
2398+
}
2399+
arr.shape.hash(hasher);
2400+
arr.data.iter().for_each(|x| HashLabels(&x.0).hash(hasher));
23942401
}
2402+
val => val_as_arr!(val, |arr| arr.hash(hasher)),
23952403
}
23962404
}
23972405
}

todo.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Uiua Todo
22

33
# 0.17
4-
- Improve PR validation
5-
- Check for clippy lints
64
- LSP optimizations
75
- Fix rename
86
- Fix goto references

0 commit comments

Comments
 (0)