Skip to content

Commit c015a34

Browse files
committed
fix: suggestion from code review
1 parent a7ca792 commit c015a34

44 files changed

Lines changed: 208 additions & 202 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libs/@local/hashql/eval/src/postgres/filter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<'ctx, 'heap, A: Allocator, S: Allocator> GraphReadFilterCompiler<'ctx, 'hea
295295
},
296296
rest @ ..,
297297
] => {
298-
let param = db.parameters.env(*field);
298+
let param = db.parameters.env(self.body.id, *field);
299299
(param.into(), rest)
300300
}
301301
[..] => {

libs/@local/hashql/eval/src/postgres/mod.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use hash_graph_postgres_store::store::postgres::query::{
3636
self, Column, Expression, Identifier, SelectExpression, SelectStatement, Transpile as _,
3737
WhereExpression, table::EntityTemporalMetadata,
3838
};
39-
use hashql_core::{heap::BumpAllocator, id::Id as _};
39+
use hashql_core::heap::BumpAllocator;
4040
use hashql_mir::{
4141
body::{
4242
Body,
@@ -110,16 +110,11 @@ impl<A: Allocator> DatabaseContext<'_, A> {
110110
fn add_temporal_conditions(&mut self) {
111111
let temporal_metadata = self.projections.temporal_metadata();
112112

113-
let tx_param = Expression::Parameter(
114-
self.parameters
115-
.temporal_axis(TemporalAxis::Transaction)
116-
.as_usize(),
117-
);
118-
let dt_param = Expression::Parameter(
119-
self.parameters
120-
.temporal_axis(TemporalAxis::Decision)
121-
.as_usize(),
122-
);
113+
let tx_param = self
114+
.parameters
115+
.temporal_axis(TemporalAxis::Transaction)
116+
.into();
117+
let dt_param = self.parameters.temporal_axis(TemporalAxis::Decision).into();
123118

124119
self.where_expression.add_condition(Expression::overlap(
125120
Expression::ColumnReference(query::ColumnReference {

libs/@local/hashql/eval/src/postgres/parameters.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
//! the reverse mapping to bind runtime values in the correct `$N` order.
77
88
use alloc::alloc::Global;
9-
use core::{alloc::Allocator, fmt};
9+
use core::{
10+
alloc::Allocator,
11+
fmt::{self, Display},
12+
};
1013

1114
use hash_graph_postgres_store::store::postgres::query::Expression;
1215
use hashql_core::{
@@ -15,13 +18,20 @@ use hashql_core::{
1518
symbol::Symbol,
1619
value::Primitive,
1720
};
18-
use hashql_mir::{body::place::FieldIndex, interpret::value::Int};
21+
use hashql_mir::{body::place::FieldIndex, def::DefId, interpret::value::Int};
1922

2023
id::newtype!(
2124
/// Index of a SQL parameter in the compiled query, rendered as `$N` by the SQL formatter.
25+
#[id(display = !)]
2226
pub struct ParameterIndex(u32 is 0..=u32::MAX)
2327
);
2428

29+
impl Display for ParameterIndex {
30+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
31+
write!(fmt, "${}", self.as_u32() + 1)
32+
}
33+
}
34+
2535
impl From<ParameterIndex> for Expression {
2636
fn from(value: ParameterIndex) -> Self {
2737
Self::Parameter(value.as_usize() + 1)
@@ -43,7 +53,7 @@ enum Parameter<'heap> {
4353
/// A symbol used as a JSON object key in SQL expressions.
4454
Symbol(Symbol<'heap>),
4555
/// A captured-environment field access.
46-
Env(FieldIndex),
56+
Env(DefId, FieldIndex),
4757
/// Temporal axis range provided by the interpreter at execution time.
4858
///
4959
/// The interpreter binds these based on the user's temporal axes configuration:
@@ -59,7 +69,7 @@ impl fmt::Display for Parameter<'_> {
5969
Self::Int(int) => write!(fmt, "Int({int})"),
6070
Self::Primitive(primitive) => write!(fmt, "Primitive({primitive})"),
6171
Self::Symbol(symbol) => write!(fmt, "Symbol({symbol})"),
62-
Self::Env(field) => write!(fmt, "Env(#{})", field.as_u32()),
72+
Self::Env(def, field) => write!(fmt, "Env({def}, #{})", field.as_u32()),
6373
Self::TemporalAxis(axis) => write!(fmt, "TemporalAxis({axis})"),
6474
}
6575
}
@@ -129,8 +139,8 @@ impl<'heap, A: Allocator> Parameters<'heap, A> {
129139
self.get_or_insert(Parameter::Primitive(primitive))
130140
}
131141

132-
pub(crate) fn env(&mut self, field: FieldIndex) -> ParameterIndex {
133-
self.get_or_insert(Parameter::Env(field))
142+
pub(crate) fn env(&mut self, body: DefId, field: FieldIndex) -> ParameterIndex {
143+
self.get_or_insert(Parameter::Env(body, field))
134144
}
135145

136146
pub(crate) fn temporal_axis(&mut self, axis: TemporalAxis) -> ParameterIndex {
@@ -150,11 +160,11 @@ impl<'heap, A: Allocator> Parameters<'heap, A> {
150160

151161
impl<A: Allocator> fmt::Display for Parameters<'_, A> {
152162
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
153-
for (index, param) in self.reverse.iter().enumerate() {
154-
if index > 0 {
163+
for (index, param) in self.reverse.iter_enumerated() {
164+
if index.as_usize() > 0 {
155165
fmt.write_str("\n")?;
156166
}
157-
write!(fmt, "${index}: {param}")?;
167+
write!(fmt, "{index}: {param}")?;
158168
}
159169

160170
Ok(())
@@ -168,9 +178,10 @@ mod tests {
168178

169179
use hashql_core::{
170180
heap::Heap,
181+
id::Id as _,
171182
value::{Primitive, String},
172183
};
173-
use hashql_mir::{body::place::FieldIndex, interpret::value::Int};
184+
use hashql_mir::{body::place::FieldIndex, def::DefId, interpret::value::Int};
174185

175186
use super::{Parameters, TemporalAxis};
176187

@@ -236,8 +247,8 @@ mod tests {
236247
#[test]
237248
fn env_dedup() {
238249
let mut params = Parameters::new_in(Global);
239-
let a = params.env(FieldIndex::new(0));
240-
let b = params.env(FieldIndex::new(0));
250+
let a = params.env(DefId::MIN, FieldIndex::new(0));
251+
let b = params.env(DefId::MIN, FieldIndex::new(0));
241252

242253
assert_eq!(a, b);
243254
assert_eq!(params.len(), 1);

libs/@local/hashql/eval/tests/ui/postgres/comparison-no-cast.stdout

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/@local/hashql/eval/tests/ui/postgres/constant-true-filter.stdout

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/@local/hashql/eval/tests/ui/postgres/dict-construction.stdout

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/@local/hashql/eval/tests/ui/postgres/entity-archived-check.stdout

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/@local/hashql/eval/tests/ui/postgres/entity-draft-id-equality.stdout

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/@local/hashql/eval/tests/ui/postgres/entity-type-ids-lateral.stdout

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/@local/hashql/eval/tests/ui/postgres/entity-uuid-equality.stdout

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)