Skip to content

Commit

Permalink
Start working on a HashMap implementation using hashbrown::raw
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Aug 23, 2023
1 parent 7034356 commit cc81a5e
Show file tree
Hide file tree
Showing 18 changed files with 495 additions and 179 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ default-members = [
[profile.bench]
lto = false
debug = true

[patch.crates-io]
hashbrown = { git = "https://github.com/udoprog/hashbrown", branch = "raw-infallible-context" }
8 changes: 8 additions & 0 deletions crates/rune-core/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,12 @@ define! {
repr: Some("value?"),
doc: ["Allows the `?` operator to apply to values of this type."],
};

/// Protocol used when calculating a hash.
pub const [HASH, HASH_HASH]: Protocol = Protocol {
name: "hash",
hash: 0xf6cf2d9f416cef08u64,
repr: Some("let output = hash($value)"),
doc: ["Hash the given value."],
};
}
7 changes: 4 additions & 3 deletions crates/rune-macros/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ where
value,
vm_result,
install_with,
non_null,
..
} = &tokens;

Expand Down Expand Up @@ -602,7 +603,7 @@ where
#vm_result::Err(err) => return #vm_result::Err(err),
};

#vm_result::Ok((&*value, guard))
#vm_result::Ok((#non_null::as_ref(&value), guard))
}
}

Expand All @@ -611,12 +612,12 @@ where
type Guard = #raw_into_mut;

unsafe fn unsafe_to_mut<'a>(value: #value) -> #vm_result<(&'a mut Self, Self::Guard)> {
let (value, guard) = match value.into_any_mut() {
let (mut value, guard) = match value.into_any_mut() {
#vm_result::Ok(value) => value,
#vm_result::Err(err) => return #vm_result::Err(err),
};

#vm_result::Ok((&mut *value, guard))
#vm_result::Ok((#non_null::as_mut(&mut value), guard))
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/rune-macros/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ impl Context {
iterator: path(&core, ["iter", "Iterator"]),
double_ended_iterator: path(&core, ["iter", "DoubleEndedIterator"]),
option: path(&core, ["option", "Option"]),
non_null: path(&core, ["ptr", "NonNull"]),
}
}
}
Expand Down Expand Up @@ -693,6 +694,7 @@ pub(crate) struct Tokens {
pub(crate) iterator: syn::Path,
pub(crate) double_ended_iterator: syn::Path,
pub(crate) option: syn::Path,
pub(crate) non_null: syn::Path,
}

impl Tokens {
Expand Down
2 changes: 1 addition & 1 deletion crates/rune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ serde = { version = "1.0.163", default-features = false, features = ["derive", "
serde_bytes = { version = "0.11.9", default-features = false, features = ["alloc"] }
smallvec = { version = "1.10.0", default-features = false, features = ["serde", "const_new"] }
tracing = { version = "0.1.37", default-features = false, features = ["attributes"] }
hashbrown = { version = "0.13.2", features = ["serde"] }
hashbrown = { version = "0.14.0", features = ["raw", "serde"] }
musli = { version = "0.0.42", default-features = false, features = ["alloc"] }
slab = { version = "0.4.8", default-features = false }

Expand Down
6 changes: 3 additions & 3 deletions crates/rune/src/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ macro_rules! from_value {
let value = vm_try!(value.$into());
let value = vm_try!(value.into_ref());
let (value, guard) = $crate::runtime::Ref::into_raw(value);
$crate::runtime::VmResult::Ok((&*value, guard))
$crate::runtime::VmResult::Ok((value.as_ref(), guard))
}
}

Expand All @@ -131,8 +131,8 @@ macro_rules! from_value {
) -> $crate::runtime::VmResult<(&'a mut Self, Self::Guard)> {
let value = vm_try!(value.$into());
let value = vm_try!(value.into_mut());
let (value, guard) = $crate::runtime::Mut::into_raw(value);
$crate::runtime::VmResult::Ok((&mut *value, guard))
let (mut value, guard) = $crate::runtime::Mut::into_raw(value);
$crate::runtime::VmResult::Ok((value.as_mut(), guard))
}
}

Expand Down
Loading

0 comments on commit cc81a5e

Please sign in to comment.