Skip to content

Commit 751639a

Browse files
committed
feat: implement Null -> Unit conversion
1 parent cc66617 commit 751639a

9 files changed

Lines changed: 97 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use core::alloc::Allocator;
22

3-
use hashql_core::{id::Id as _, r#type::kind::TypeKind};
3+
use hashql_core::{id::Id as _, r#type::kind::TypeKind, value::Primitive};
44
use hashql_hir::node::{
55
Node,
66
access::{Access, FieldAccess, IndexAccess},
@@ -165,6 +165,7 @@ impl<'heap, A: Allocator, S: Allocator> Reifier<'_, '_, '_, '_, 'heap, A, S> {
165165
// In the future this would be a simple FnPtr
166166
Operand::Constant(Constant::Unit)
167167
}
168+
NodeKind::Data(Data::Primitive(Primitive::Null)) => Operand::Constant(Constant::Unit),
168169
NodeKind::Data(Data::Primitive(primitive)) => {
169170
// First try if we can promote the primitive to a non-opaque constant:
170171
let constant = match Int::try_from(primitive) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use hashql_core::{
44
id::{Id as _, IdVec},
55
symbol::sym,
66
r#type::{TypeBuilder, Typed, builder},
7+
value::Primitive,
78
};
89
use hashql_hir::node::{
910
HirPtr, Node,
@@ -37,6 +38,7 @@ use crate::{
3738
impl<'mir, 'heap, A: Allocator, S: Allocator> Reifier<'_, 'mir, '_, '_, 'heap, A, S> {
3839
fn rvalue_data(&mut self, data: Data<'heap>) -> RValue<'heap> {
3940
match data {
41+
Data::Primitive(Primitive::Null) => RValue::Load(Operand::Constant(Constant::Unit)),
4042
Data::Primitive(primitive) => {
4143
// First try if we can promote the primitive to a non-opaque constant:
4244
let constant = match Int::try_from(primitive) {
@@ -76,6 +78,9 @@ impl<'mir, 'heap, A: Allocator, S: Allocator> Reifier<'_, 'mir, '_, '_, 'heap, A
7678
operands,
7779
})
7880
}
81+
Data::Tuple(Tuple { fields }) if fields.is_empty() => {
82+
RValue::Load(Operand::Constant(Constant::Unit))
83+
}
7984
Data::Tuple(Tuple { fields }) => {
8085
let mut operands = IdVec::with_capacity_in(fields.len(), self.context.mir.heap);
8186
for &field in fields {

libs/@local/hashql/mir/tests/ui/pass/inline/filter-aggressive.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.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ run: pass
2+
//@ description: empty tuple should be reified as a unit constant
3+
{ "#tuple": [] }

libs/@local/hashql/mir/tests/ui/reify/empty-tuple.stdout

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ run: pass
2+
//@ description: null should be promoted to a unit constant
3+
[
4+
"if",
5+
{ "#literal": true },
6+
[
7+
"let",
8+
"foo",
9+
{ "#literal": null },
10+
["let", "bar", { "#literal": null }, ["==", "foo", "bar"]]
11+
]
12+
]

libs/@local/hashql/mir/tests/ui/reify/null-value-in-binary.stdout

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ run: pass
2+
//@ description: null should be promoted to a unit constant
3+
["let", "foo", { "#literal": null }, "foo"]

libs/@local/hashql/mir/tests/ui/reify/null-value.stdout

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

0 commit comments

Comments
 (0)