Skip to content

Commit 72fccc3

Browse files
committed
feat: checkpoint
1 parent cdd0acd commit 72fccc3

7 files changed

Lines changed: 76 additions & 22 deletions

File tree

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
//! assert_eq!(vec2.len(), 0);
4444
//! ```
4545
46+
use std::alloc::{Allocator, Global};
47+
4648
use crate::id::{Id, bit_vec::MixedBitSet};
4749

4850
/// Trait for defining how objects are recycled, created, and prepared in a pool.
@@ -234,13 +236,13 @@ pub trait Recycler<T> {
234236
/// // Pool now contains 2 recycled vectors ready for reuse
235237
/// ```
236238
#[derive(Debug)]
237-
pub struct Pool<T, R> {
238-
free: Vec<T>,
239+
pub struct Pool<T, R, A: Allocator = Global> {
240+
free: Vec<T, A>,
239241
recycler: R,
240242
capacity: usize,
241243
}
242244

243-
impl<T, R> Pool<T, R> {
245+
impl<T, R> Pool<T, R, Global> {
244246
/// Creates a new pool with the specified capacity and a default recycler.
245247
///
246248
/// The `capacity` parameter sets the maximum number of objects that will be
@@ -278,16 +280,30 @@ impl<T, R> Pool<T, R> {
278280
/// let mut pool = MixedBitSetPool::<VarId>::with_recycler(5, recycler);
279281
/// ```
280282
pub fn with_recycler(capacity: usize, recycler: R) -> Self {
283+
Self::with_recycler_in(capacity, recycler, Global)
284+
}
285+
}
286+
287+
impl<T, R, A: Allocator> Pool<T, R, A> {
288+
pub fn new_in(capacity: usize, alloc: A) -> Self
289+
where
290+
R: Default,
291+
{
292+
Self::with_recycler_in(capacity, R::default(), alloc)
293+
}
294+
295+
pub fn with_recycler_in(capacity: usize, recycler: R, alloc: A) -> Self {
281296
Self {
282-
free: Vec::with_capacity(capacity),
297+
free: Vec::with_capacity_in(capacity, alloc),
283298
recycler,
284299
capacity,
285300
}
286301
}
287302
}
288303

289-
impl<T, R> Pool<T, R>
304+
impl<T, R, A> Pool<T, R, A>
290305
where
306+
A: Allocator,
291307
R: Recycler<T>,
292308
{
293309
/// Changes the pool's capacity, adjusting internal storage as needed.
@@ -673,4 +689,4 @@ where
673689
/// // Return to pool for reuse
674690
/// pool.release(bitset);
675691
/// ```
676-
pub type MixedBitSetPool<I> = Pool<MixedBitSet<I>, MixedBitSetRecycler>;
692+
pub type MixedBitSetPool<I, A = Global> = Pool<MixedBitSet<I>, MixedBitSetRecycler, A>;

libs/@local/hashql/core/src/module/std_lib/core/json.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
use core::alloc::Allocator;
22

3+
use self::types::JsonPathDependencies;
34
use crate::{
45
module::std_lib::{
56
CacheId, ItemDef, ModuleCache, ModuleDef, StandardLibraryContext, StandardLibraryModule,
67
},
78
symbol::{Symbol, sym},
89
};
910

11+
pub mod types {
12+
use crate::r#type::{TypeBuilder, TypeId};
13+
14+
// type JsonPathSegment = String | Integer;
15+
#[must_use]
16+
pub fn json_path_segment(ty: &TypeBuilder<'_, '_>) -> TypeId {
17+
ty.union([ty.string(), ty.integer()])
18+
}
19+
20+
pub struct JsonPathDependencies {
21+
pub json_path_segment: TypeId,
22+
}
23+
24+
// type JsonPath = JsonPathSegment[];
25+
#[must_use]
26+
pub fn json_path(
27+
ty: &TypeBuilder<'_, '_>,
28+
dependencies: Option<JsonPathDependencies>,
29+
) -> TypeId {
30+
ty.list(dependencies.map_or_else(
31+
|| json_path_segment(ty),
32+
|dependencies| dependencies.json_path_segment,
33+
))
34+
}
35+
}
36+
1037
pub(in crate::module::std_lib) struct Json {
1138
_dependencies: (),
1239
}
@@ -28,16 +55,19 @@ impl<'heap> StandardLibraryModule<'heap> for Json {
2855

2956
// type JsonPathSegment = String | Integer;
3057
// Note: The type should be Natural instead, but this requires refinement types
31-
let json_path_segment_ty = context
32-
.ty
33-
.union([context.ty.string(), context.ty.integer()]);
58+
let json_path_segment_ty = self::types::json_path_segment(&context.ty);
3459
def.push(
3560
sym::JsonPathSegment,
3661
ItemDef::r#type(context.ty.env, json_path_segment_ty, &[]),
3762
);
3863

3964
// type JsonPath = JsonPathSegment[];
40-
let json_path_ty = context.ty.list(json_path_segment_ty);
65+
let json_path_ty = self::types::json_path(
66+
&context.ty,
67+
Some(JsonPathDependencies {
68+
json_path_segment: json_path_segment_ty,
69+
}),
70+
);
4171
def.push(
4272
sym::JsonPath,
4373
ItemDef::r#type(context.ty.env, json_path_ty, &[]),

libs/@local/hashql/core/src/module/std_lib/core/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
pub(in crate::module::std_lib) mod bits;
1212
pub(in crate::module::std_lib) mod bool;
1313
pub(in crate::module::std_lib) mod cmp;
14-
pub(in crate::module::std_lib) mod json;
14+
pub mod json;
1515
pub(in crate::module::std_lib) mod math;
1616
pub mod option;
1717
pub(in crate::module::std_lib) mod result;

libs/@local/hashql/core/src/module/std_lib/graph/entity.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ impl<'heap> StandardLibraryModule<'heap> for Entity {
6464
decl,
6565
);
6666

67-
// `property<T>(entity: Entity<T>, path: JsonPath) -> Option<?>`
67+
// `property<T>(entity: Entity<T>, path: JsonPath) -> ?`
68+
// TODO(BE-62): return `Option<?>` once pattern matching allows for option destructuring, to
69+
// allow for proper comparison
6870
let decl = decl!(context;
6971
<T>(entity: context.ty.apply([(entity_ty.arguments[0].id, T)], entity_ty.id),
7072
path: json_path_ty.id

libs/@local/hashql/mir/src/intrinsic.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use hashql_core::{
22
id::{Id, IdVec},
33
intern::Interned,
4-
module::std_lib::graph::types::knowledge::entity::types::entity,
4+
module::std_lib::{core::json, graph::types::knowledge::entity::types::entity},
55
span::SpanId,
66
symbol::sym,
77
r#type::{TypeBuilder, environment::Environment},
@@ -37,21 +37,21 @@ pub(crate) fn entity_property_access_body<'heap>(
3737
span: SpanId,
3838
) -> Body<'heap> {
3939
// Intrinsic body for property access, we **cannot** mock this specific intrinsic, because it's
40-
// semantics are - while expressible - compile-time. We cannot index into a struct at run-time
41-
// from a runtime-defined value. We just can't. Meaning that indeed we must mock this specific
42-
// intrinsic on all backends that support it.
40+
// semantics are - while expressible - compile-time only. We cannot index into a struct at
41+
// run-time from a runtime-defined value, without sacrifing correctness guarantees the MIR
42+
// relies on. Meaning that indeed we must mock this specific intrinsic on all backends that
43+
// support it.
4344
let builder = TypeBuilder::spanned(span, env);
4445

45-
let mut local_decls = IdVec::with_capacity_in(1, env.heap);
46+
let mut local_decls = IdVec::with_capacity_in(2, env.heap);
4647
local_decls.push(LocalDecl {
4748
span,
4849
r#type: entity(&builder, builder.unknown(), None),
4950
name: Some(sym::entity),
5051
});
51-
// TODO: we have a json path for exactly this
5252
local_decls.push(LocalDecl {
5353
span,
54-
r#type: builder.list(builder.union([builder.string(), builder.integer()])),
54+
r#type: json::types::json_path(&builder, None),
5555
name: Some(sym::pointer),
5656
});
5757

libs/@local/hashql/mir/src/reify/atom.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use hashql_hir::node::{
66
access::{Access, FieldAccess, IndexAccess},
77
data::Data,
88
kind::NodeKind,
9-
variable::Variable,
9+
variable::{QualifiedVariable, Variable},
1010
};
1111

1212
use super::{
@@ -154,6 +154,11 @@ impl<'heap, A: Allocator, S: Allocator> Reifier<'_, '_, '_, '_, 'heap, A, S> {
154154
}
155155
}
156156

157+
fn qualified_path(&mut self, QualifiedVariable { path, arguments }: QualifiedVariable<'heap>) {
158+
// For the path, we simply match against the tree of values that are supported
159+
todo!()
160+
}
161+
157162
pub(super) fn operand(&mut self, node: Node<'heap>) -> Operand<'heap> {
158163
match node.kind {
159164
NodeKind::Variable(Variable::Qualified(_)) => {

libs/@local/hashql/mir/src/reify/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct CrossCompileState<'heap, S: Allocator> {
112112
/// Cache of already-created type constructors to avoid duplication.
113113
ctor: FastHashMap<Symbol<'heap>, DefId>,
114114

115-
var_pool: MixedBitSetPool<VarId>,
115+
var_pool: MixedBitSetPool<VarId, S>,
116116
}
117117

118118
/// The core reification engine that converts individual HIR nodes to MIR bodies.
@@ -508,11 +508,12 @@ pub fn from_hir<'heap, A: Allocator, S: Allocator + Clone>(
508508
thunks,
509509
ctor: FastHashMap::default(),
510510
diagnostics: ReifyDiagnosticIssues::new(),
511-
var_pool: MixedBitSetPool::with_recycler(
511+
var_pool: MixedBitSetPool::with_recycler_in(
512512
8,
513513
MixedBitSetRecycler {
514514
domain_size: context.hir.counter.var.size(),
515515
},
516+
context.scratch.clone(),
516517
),
517518
};
518519

0 commit comments

Comments
 (0)