Skip to content

Commit 8ec5d3b

Browse files
authored
BE-208: HashQL: Introduce graph data structures (#8060)
1 parent 341766b commit 8ec5d3b

File tree

19 files changed

+2692
-29
lines changed

19 files changed

+2692
-29
lines changed

libs/@local/graph/api/src/rest/entity_query_request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use hash_graph_store::{
3939
};
4040
use hashql_ast::error::AstDiagnosticCategory;
4141
use hashql_core::{
42-
collections::fast_hash_map,
42+
collections::fast_hash_map_with_capacity,
4343
heap::Heap,
4444
module::ModuleRegistry,
4545
span::{SpanId, SpanTable},
@@ -399,7 +399,7 @@ impl<'q> EntityQuery<'q> {
399399

400400
// Evaluate the HIR
401401
// TODO: https://linear.app/hash/issue/BE-41/hashql-expose-input-in-graph-api
402-
let inputs = fast_hash_map(0);
402+
let inputs = fast_hash_map_with_capacity(0);
403403
let mut compiler = hashql_eval::graph::read::GraphReadCompiler::new(heap, &inputs);
404404

405405
compiler.visit_node(hir);

libs/@local/hashql/ast/src/lowering/special_form_expander/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::{
66
};
77

88
use hashql_core::{
9-
collections::{FastHashMap, fast_hash_map},
9+
collections::{FastHashMap, fast_hash_map_with_capacity},
1010
heap::{self, Heap},
1111
span::SpanId,
1212
symbol::{Ident, IdentKind},
@@ -520,7 +520,7 @@ impl<'heap> SpecialFormExpander<'heap> {
520520
) -> Option<heap::Vec<'heap, GenericConstraint<'heap>>> {
521521
let mut constraints = self.heap.vec(Some(arguments.len()));
522522

523-
let mut seen = fast_hash_map(arguments.len());
523+
let mut seen = fast_hash_map_with_capacity(arguments.len());
524524

525525
for argument in arguments {
526526
match argument {

libs/@local/hashql/ast/src/lowering/type_extractor/contractive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use hashql_core::{
2-
collections::{FastHashSet, fast_hash_set},
2+
collections::{FastHashSet, fast_hash_set_with_capacity},
33
intern::Interned,
44
span::SpanId,
55
r#type::{
@@ -112,7 +112,7 @@ pub(crate) fn is_contractive<'heap>(
112112
root: Interned<'heap, TypeKind<'heap>>,
113113
) -> Result<(), SpanId> {
114114
// if this ever becomes a bottleneck, consider using the temporary heap
115-
let mut visited = fast_hash_set(4);
115+
let mut visited = fast_hash_set_with_capacity(4);
116116

117117
is_contractive_kind(env, root, root, &mut visited)
118118
}

libs/@local/hashql/ast/src/lowering/type_extractor/definition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alloc::borrow::Cow;
22
use core::mem;
33

44
use hashql_core::{
5-
collections::{FastHashMap, TinyVec, fast_hash_map},
5+
collections::{FastHashMap, TinyVec, fast_hash_map_with_capacity},
66
module::{
77
ModuleRegistry,
88
locals::{Local, Locals, TypeLocals},
@@ -154,7 +154,7 @@ impl<'env, 'heap> TypeDefinitionExtractor<'env, 'heap> {
154154
}
155155
}
156156

157-
let mut constraints = fast_hash_map(allocated_generic_constraints);
157+
let mut constraints = fast_hash_map_with_capacity(allocated_generic_constraints);
158158

159159
let mut unit = TranslationUnit {
160160
env: self.environment,

libs/@local/hashql/ast/src/lowering/type_extractor/translate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use alloc::borrow::Cow;
99

1010
use hashql_core::{
11-
collections::{FastHashMap, FastHashSet, SmallVec, TinyVec, fast_hash_set},
11+
collections::{FastHashMap, FastHashSet, SmallVec, TinyVec, fast_hash_set_with_capacity},
1212
intern::Provisioned,
1313
module::{
1414
ModuleRegistry, Universe,
@@ -56,7 +56,7 @@ impl<'env, 'heap> GenericArgumentVisitor<'env, 'heap> {
5656
fn new(scope: &'env [GenericArgumentReference<'heap>]) -> Self {
5757
Self {
5858
scope,
59-
used: fast_hash_set(scope.len()),
59+
used: fast_hash_set_with_capacity(scope.len()),
6060
}
6161
}
6262
}

libs/@local/hashql/core/src/collections/mod.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@ pub type FastHashSetEntry<'map, T, A = Global> =
2121

2222
#[inline]
2323
#[must_use]
24-
pub fn fast_hash_map<K, V>(capacity: usize) -> FastHashMap<K, V> {
25-
FastHashMap::with_capacity_and_hasher(capacity, foldhash::fast::RandomState::default())
24+
pub fn fast_hash_map_in<K, V, A: Allocator>(allocator: A) -> FastHashMap<K, V, A> {
25+
FastHashMap::with_hasher_in(foldhash::fast::RandomState::default(), allocator)
2626
}
2727

2828
#[inline]
2929
#[must_use]
30-
pub fn fast_hash_map_in<K, V, A: Allocator>(capacity: usize, allocator: A) -> FastHashMap<K, V, A> {
30+
pub fn fast_hash_map<K, V>() -> FastHashMap<K, V> {
31+
fast_hash_map_in(Global)
32+
}
33+
34+
#[inline]
35+
#[must_use]
36+
pub fn fast_hash_map_with_capacity_in<K, V, A: Allocator>(
37+
capacity: usize,
38+
allocator: A,
39+
) -> FastHashMap<K, V, A> {
3140
FastHashMap::with_capacity_and_hasher_in(
3241
capacity,
3342
foldhash::fast::RandomState::default(),
@@ -37,19 +46,40 @@ pub fn fast_hash_map_in<K, V, A: Allocator>(capacity: usize, allocator: A) -> Fa
3746

3847
#[inline]
3948
#[must_use]
40-
pub fn fast_hash_set<T>(capacity: usize) -> FastHashSet<T> {
41-
FastHashSet::with_capacity_and_hasher(capacity, foldhash::fast::RandomState::default())
49+
pub fn fast_hash_map_with_capacity<K, V>(capacity: usize) -> FastHashMap<K, V> {
50+
fast_hash_map_with_capacity_in(capacity, Global)
4251
}
4352

4453
#[inline]
4554
#[must_use]
46-
pub fn fast_hash_set_in<T, A: Allocator>(capacity: usize, allocator: A) -> FastHashSet<T, A> {
55+
pub fn fast_hash_set_with_capacity_in<T, A: Allocator>(
56+
capacity: usize,
57+
allocator: A,
58+
) -> FastHashSet<T, A> {
4759
FastHashSet::with_capacity_and_hasher_in(
4860
capacity,
4961
foldhash::fast::RandomState::default(),
5062
allocator,
5163
)
5264
}
5365

66+
#[inline]
67+
#[must_use]
68+
pub fn fast_hash_set_in<T, A: Allocator>(allocator: A) -> FastHashSet<T, A> {
69+
FastHashSet::with_hasher_in(foldhash::fast::RandomState::default(), allocator)
70+
}
71+
72+
#[inline]
73+
#[must_use]
74+
pub fn fast_hash_set_with_capacity<T>(capacity: usize) -> FastHashSet<T> {
75+
fast_hash_set_with_capacity_in(capacity, Global)
76+
}
77+
78+
#[inline]
79+
#[must_use]
80+
pub fn fast_hash_set<T>() -> FastHashSet<T> {
81+
fast_hash_set_in(Global)
82+
}
83+
5484
pub type TinyVec<T> = smallvec::SmallVec<T, 4>;
5585
pub type SmallVec<T> = smallvec::SmallVec<T, 16>;

0 commit comments

Comments
 (0)