Skip to content

Commit c3de81f

Browse files
committed
feat: add synthetic file
1 parent 8efe84c commit c3de81f

6 files changed

Lines changed: 479 additions & 6 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ impl<'heap> Symbol<'heap> {
258258
}
259259
}
260260

261+
impl From<ConstantSymbol> for Symbol<'_> {
262+
#[inline]
263+
#[expect(unsafe_code)]
264+
fn from(value: ConstantSymbol) -> Self {
265+
// SAFETY: The constant symbol is already interned, so the repr is valid.
266+
unsafe { Symbol::from_repr(Repr::constant(value.repr)) }
267+
}
268+
}
269+
261270
impl AsRef<Self> for Symbol<'_> {
262271
#[inline]
263272
fn as_ref(&self) -> &Self {

libs/@local/hashql/core/src/symbol/sym.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ hashql_macros::define_symbols! {
206206
json,
207207
JsonPath,
208208
JsonPathSegment,
209+
lhs,
210+
rhs,
209211
// [tidy] sort alphabetically end
210212

211213
internal: {

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

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

33
use hashql_core::{id::Id as _, r#type::kind::TypeKind, value::Primitive};
4-
use hashql_hir::node::{
5-
Node,
6-
access::{Access, FieldAccess, IndexAccess},
7-
data::Data,
8-
kind::NodeKind,
9-
variable::Variable,
4+
use hashql_hir::{
5+
node::{
6+
Node,
7+
access::{Access, FieldAccess, IndexAccess},
8+
data::Data,
9+
kind::NodeKind,
10+
variable::Variable,
11+
},
12+
path::QualifiedPath,
1013
};
1114

1215
use super::{
@@ -154,6 +157,10 @@ impl<'heap, A: Allocator, S: Allocator> Reifier<'_, '_, '_, '_, 'heap, A, S> {
154157
}
155158
}
156159

160+
pub(super) fn qualified_variable(&mut self, path: QualifiedPath<'heap>, requires_thunk: bool) {
161+
todo!()
162+
}
163+
157164
pub(super) fn operand(&mut self, node: Node<'heap>) -> Operand<'heap> {
158165
match node.kind {
159166
NodeKind::Variable(Variable::Qualified(_)) => {

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,76 @@ pub(crate) fn fat_call_on_constant(span: SpanId) -> ReifyDiagnostic {
247247

248248
diagnostic
249249
}
250+
251+
// Synthetic body diagnostics
252+
253+
/// ICE: monomorphized closure type has wrong parameter count for a synthetic binary
254+
/// operation body.
255+
#[coverage(off)]
256+
pub(crate) fn synthetic_binary_arity_mismatch(
257+
span: SpanId,
258+
name: Symbol<'_>,
259+
actual_params: usize,
260+
) -> ReifyDiagnostic<Critical> {
261+
let mut diagnostic = Diagnostic::new(ReifyDiagnosticCategory::TypeInvariant, Critical::BUG)
262+
.primary(Label::new(
263+
span,
264+
format!("monomorphized type of `{name}` has {actual_params} parameters, expected 2"),
265+
));
266+
267+
diagnostic.add_message(Message::note(
268+
"binary operations require exactly 2 parameters after monomorphization",
269+
));
270+
271+
diagnostic.add_message(Message::help(
272+
"type checking should have ensured the correct arity before reification",
273+
));
274+
275+
diagnostic
276+
}
277+
278+
/// ICE: monomorphized closure type has wrong parameter count for a synthetic unary
279+
/// operation body.
280+
#[coverage(off)]
281+
pub(crate) fn synthetic_unary_arity_mismatch(
282+
span: SpanId,
283+
name: Symbol<'_>,
284+
actual_params: usize,
285+
) -> ReifyDiagnostic<Critical> {
286+
let mut diagnostic = Diagnostic::new(ReifyDiagnosticCategory::TypeInvariant, Critical::BUG)
287+
.primary(Label::new(
288+
span,
289+
format!("monomorphized type of `{name}` has {actual_params} parameters, expected 1"),
290+
));
291+
292+
diagnostic.add_message(Message::note(
293+
"unary operations require exactly 1 parameter after monomorphization",
294+
));
295+
296+
diagnostic.add_message(Message::help(
297+
"type checking should have ensured the correct arity before reification",
298+
));
299+
300+
diagnostic
301+
}
302+
303+
/// Intrinsic cannot be used as a first-class value.
304+
pub(crate) fn intrinsic_not_first_class(
305+
span: SpanId,
306+
name: Symbol<'_>,
307+
) -> ReifyDiagnostic<Critical> {
308+
let mut diagnostic =
309+
Diagnostic::new(ReifyDiagnosticCategory::UnsupportedFeature, Critical::ERROR).primary(
310+
Label::new(span, format!("`{name}` cannot be used as a value")),
311+
);
312+
313+
diagnostic.add_message(Message::note(format!(
314+
"`{name}` is a syntactic form that is only valid at a call site"
315+
)));
316+
317+
diagnostic.add_message(Message::help(
318+
"call this intrinsic directly instead of passing it as an argument",
319+
));
320+
321+
diagnostic
322+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod atom;
22
mod current;
33
mod error;
44
mod rvalue;
5+
mod synthetic;
56
mod terminator;
67
mod transform;
78
mod types;

0 commit comments

Comments
 (0)