Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions libs/@local/hashql/core/src/collections/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
//! assert_eq!(vec2.len(), 0);
//! ```

use alloc::alloc::Global;
use core::alloc::Allocator;

use crate::id::{Id, bit_vec::MixedBitSet};

/// Trait for defining how objects are recycled, created, and prepared in a pool.
Expand Down Expand Up @@ -234,13 +237,13 @@ pub trait Recycler<T> {
/// // Pool now contains 2 recycled vectors ready for reuse
/// ```
#[derive(Debug)]
pub struct Pool<T, R> {
free: Vec<T>,
pub struct Pool<T, R, A: Allocator = Global> {
free: Vec<T, A>,
recycler: R,
capacity: usize,
}

impl<T, R> Pool<T, R> {
impl<T, R> Pool<T, R, Global> {
/// Creates a new pool with the specified capacity and a default recycler.
///
/// The `capacity` parameter sets the maximum number of objects that will be
Expand Down Expand Up @@ -278,16 +281,30 @@ impl<T, R> Pool<T, R> {
/// let mut pool = MixedBitSetPool::<VarId>::with_recycler(5, recycler);
/// ```
pub fn with_recycler(capacity: usize, recycler: R) -> Self {
Self::with_recycler_in(capacity, recycler, Global)
}
}

impl<T, R, A: Allocator> Pool<T, R, A> {
pub fn new_in(capacity: usize, alloc: A) -> Self
where
R: Default,
{
Self::with_recycler_in(capacity, R::default(), alloc)
}

pub fn with_recycler_in(capacity: usize, recycler: R, alloc: A) -> Self {
Self {
free: Vec::with_capacity(capacity),
free: Vec::with_capacity_in(capacity, alloc),
recycler,
capacity,
}
}
}

impl<T, R> Pool<T, R>
impl<T, R, A> Pool<T, R, A>
where
A: Allocator,
R: Recycler<T>,
{
/// Changes the pool's capacity, adjusting internal storage as needed.
Expand Down Expand Up @@ -673,4 +690,4 @@ where
/// // Return to pool for reuse
/// pool.release(bitset);
/// ```
pub type MixedBitSetPool<I> = Pool<MixedBitSet<I>, MixedBitSetRecycler>;
pub type MixedBitSetPool<I, A = Global> = Pool<MixedBitSet<I>, MixedBitSetRecycler, A>;
38 changes: 34 additions & 4 deletions libs/@local/hashql/core/src/module/std_lib/core/json.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,39 @@
use core::alloc::Allocator;

use self::types::JsonPathDependencies;
use crate::{
module::std_lib::{
CacheId, ItemDef, ModuleCache, ModuleDef, StandardLibraryContext, StandardLibraryModule,
},
symbol::{Symbol, sym},
};

pub mod types {
use crate::r#type::{TypeBuilder, TypeId};

// type JsonPathSegment = String | Integer;
#[must_use]
pub fn json_path_segment(ty: &TypeBuilder<'_, '_>) -> TypeId {
ty.union([ty.string(), ty.integer()])
}

pub struct JsonPathDependencies {
pub json_path_segment: TypeId,
}

// type JsonPath = JsonPathSegment[];
#[must_use]
pub fn json_path(
ty: &TypeBuilder<'_, '_>,
dependencies: Option<JsonPathDependencies>,
) -> TypeId {
ty.list(dependencies.map_or_else(
|| json_path_segment(ty),
|dependencies| dependencies.json_path_segment,
))
}
}

pub(in crate::module::std_lib) struct Json {
_dependencies: (),
}
Expand All @@ -28,16 +55,19 @@ impl<'heap> StandardLibraryModule<'heap> for Json {

// type JsonPathSegment = String | Integer;
// Note: The type should be Natural instead, but this requires refinement types
let json_path_segment_ty = context
.ty
.union([context.ty.string(), context.ty.integer()]);
let json_path_segment_ty = self::types::json_path_segment(&context.ty);
def.push(
sym::JsonPathSegment,
ItemDef::r#type(context.ty.env, json_path_segment_ty, &[]),
);

// type JsonPath = JsonPathSegment[];
let json_path_ty = context.ty.list(json_path_segment_ty);
let json_path_ty = self::types::json_path(
&context.ty,
Some(JsonPathDependencies {
json_path_segment: json_path_segment_ty,
}),
);
def.push(
sym::JsonPath,
ItemDef::r#type(context.ty.env, json_path_ty, &[]),
Expand Down
2 changes: 1 addition & 1 deletion libs/@local/hashql/core/src/module/std_lib/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
pub(in crate::module::std_lib) mod bits;
pub(in crate::module::std_lib) mod bool;
pub(in crate::module::std_lib) mod cmp;
pub(in crate::module::std_lib) mod json;
pub mod json;
pub(in crate::module::std_lib) mod math;
pub mod option;
pub(in crate::module::std_lib) mod result;
Expand Down
9 changes: 5 additions & 4 deletions libs/@local/hashql/core/src/module/std_lib/graph/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use crate::{
locals::TypeDef,
std_lib::{
self, CacheId, ModuleCache, ModuleDef, StandardLibraryContext, StandardLibraryModule,
core::{func, option::types::option},
decl,
core::func, decl,
},
},
symbol::{Symbol, sym},
Expand Down Expand Up @@ -64,11 +63,13 @@ impl<'heap> StandardLibraryModule<'heap> for Entity {
decl,
);

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

func(
Expand Down
1 change: 1 addition & 0 deletions libs/@local/hashql/core/src/symbol/sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ hashql_macros::define_symbols! {
encodings,
end,
entity,
pointer,
Entity,
EntityType,
EntityTypeMetadata,
Expand Down
3 changes: 2 additions & 1 deletion libs/@local/hashql/eval/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ impl<'ctx, 'heap, A: Allocator> CodeGenerationContext<'ctx, 'heap, A> {
Source::Ctor(_)
| Source::Closure(_, _)
| Source::Thunk(_, _)
| Source::Intrinsic(_) => continue,
| Source::Intrinsic(_)
| Source::Synthetic(_) => continue,
Source::GraphReadFilter(_) => {}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions libs/@local/hashql/eval/tests/ui/postgres/dict-construction.aux.mir

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading