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
3 changes: 2 additions & 1 deletion libs/@local/hashql/mir/src/reify/atom.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::alloc::Allocator;

use hashql_core::{id::Id as _, r#type::kind::TypeKind};
use hashql_core::{id::Id as _, r#type::kind::TypeKind, value::Primitive};
use hashql_hir::node::{
Node,
access::{Access, FieldAccess, IndexAccess},
Expand Down Expand Up @@ -165,6 +165,7 @@ impl<'heap, A: Allocator, S: Allocator> Reifier<'_, '_, '_, '_, 'heap, A, S> {
// In the future this would be a simple FnPtr
Operand::Constant(Constant::Unit)
}
NodeKind::Data(Data::Primitive(Primitive::Null)) => Operand::Constant(Constant::Unit),
NodeKind::Data(Data::Primitive(primitive)) => {
// First try if we can promote the primitive to a non-opaque constant:
let constant = match Int::try_from(primitive) {
Expand Down
5 changes: 5 additions & 0 deletions libs/@local/hashql/mir/src/reify/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use hashql_core::{
id::{Id as _, IdVec},
symbol::sym,
r#type::{TypeBuilder, Typed, builder},
value::Primitive,
};
use hashql_hir::node::{
HirPtr, Node,
Expand Down Expand Up @@ -37,6 +38,7 @@ use crate::{
impl<'mir, 'heap, A: Allocator, S: Allocator> Reifier<'_, 'mir, '_, '_, 'heap, A, S> {
fn rvalue_data(&mut self, data: Data<'heap>) -> RValue<'heap> {
match data {
Data::Primitive(Primitive::Null) => RValue::Load(Operand::Constant(Constant::Unit)),
Data::Primitive(primitive) => {
// First try if we can promote the primitive to a non-opaque constant:
let constant = match Int::try_from(primitive) {
Expand Down Expand Up @@ -76,6 +78,9 @@ impl<'mir, 'heap, A: Allocator, S: Allocator> Reifier<'_, 'mir, '_, '_, 'heap, A
operands,
})
}
Data::Tuple(Tuple { fields }) if fields.is_empty() => {
RValue::Load(Operand::Constant(Constant::Unit))
}
Data::Tuple(Tuple { fields }) => {
let mut operands = IdVec::with_capacity_in(fields.len(), self.context.mir.heap);
for &field in fields {
Expand Down

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

3 changes: 3 additions & 0 deletions libs/@local/hashql/mir/tests/ui/reify/empty-tuple.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//@ run: pass
//@ description: empty tuple should be reified as a unit constant
{ "#tuple": [] }
9 changes: 9 additions & 0 deletions libs/@local/hashql/mir/tests/ui/reify/empty-tuple.stdout

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

12 changes: 12 additions & 0 deletions libs/@local/hashql/mir/tests/ui/reify/null-value-in-binary.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ run: pass
//@ description: null should be promoted to a unit constant
[
"if",
{ "#literal": true },
[
"let",
"foo",
{ "#literal": null },
["let", "bar", { "#literal": null }, ["==", "foo", "bar"]]
]
]
55 changes: 55 additions & 0 deletions libs/@local/hashql/mir/tests/ui/reify/null-value-in-binary.stdout

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

3 changes: 3 additions & 0 deletions libs/@local/hashql/mir/tests/ui/reify/null-value.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//@ run: pass
//@ description: null should be promoted to a unit constant
["let", "foo", { "#literal": null }, "foo"]
5 changes: 5 additions & 0 deletions libs/@local/hashql/mir/tests/ui/reify/null-value.stdout

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

Loading