Skip to content

Commit 9946bcf

Browse files
committed
fix: tests
1 parent 83dc4cb commit 9946bcf

File tree

4 files changed

+54
-66
lines changed

4 files changed

+54
-66
lines changed

libs/@local/hashql/mir/src/body/terminator/switch_int.rs

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,17 @@ pub enum SwitchIntValue {
7474
/// let targets = SwitchTargets::new(
7575
/// &heap,
7676
/// [
77-
/// (0, Target::block(bb0, &interner)),
78-
/// (1, Target::block(bb1, &interner)),
79-
/// (2, Target::block(bb2, &interner)),
77+
/// (0, Target::block(bb0)),
78+
/// (1, Target::block(bb1)),
79+
/// (2, Target::block(bb2)),
8080
/// ],
81-
/// Some(Target::block(otherwise, &interner)),
81+
/// Some(Target::block(otherwise)),
8282
/// );
8383
///
8484
/// // Values are automatically sorted
8585
/// assert_eq!(targets.values(), &[0, 1, 2]);
86-
/// assert_eq!(targets.target(1), Some(Target::block(bb1, &interner)));
87-
/// assert_eq!(
88-
/// targets.target(99),
89-
/// Some(Target::block(otherwise, &interner))
90-
/// );
86+
/// assert_eq!(targets.target(1), Some(Target::block(bb1)));
87+
/// assert_eq!(targets.target(99), Some(Target::block(otherwise)));
9188
/// ```
9289
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9390
pub struct SwitchTargets<'heap> {
@@ -131,11 +128,11 @@ impl<'heap> SwitchTargets<'heap> {
131128
/// let targets = SwitchTargets::new(
132129
/// &heap,
133130
/// [
134-
/// (10, Target::block(BasicBlockId::new(0), &interner)),
135-
/// (20, Target::block(BasicBlockId::new(1), &interner)),
136-
/// (30, Target::block(BasicBlockId::new(2), &interner)),
131+
/// (10, Target::block(BasicBlockId::new(0))),
132+
/// (20, Target::block(BasicBlockId::new(1))),
133+
/// (30, Target::block(BasicBlockId::new(2))),
137134
/// ],
138-
/// Some(Target::block(BasicBlockId::new(3), &interner)),
135+
/// Some(Target::block(BasicBlockId::new(3))),
139136
/// );
140137
///
141138
/// assert_eq!(targets.values(), &[10, 20, 30]);
@@ -158,11 +155,7 @@ impl<'heap> SwitchTargets<'heap> {
158155
/// let heap = Heap::new();
159156
/// let interner = Interner::new(&heap);
160157
///
161-
/// let targets = SwitchTargets::new(
162-
/// &heap,
163-
/// [(0, Target::block(BasicBlockId::new(0), &interner))],
164-
/// None,
165-
/// );
158+
/// let targets = SwitchTargets::new(&heap, [(0, Target::block(BasicBlockId::new(0)))], None);
166159
///
167160
/// assert_eq!(targets.otherwise(), None);
168161
/// assert_eq!(targets.target(99), None); // No otherwise, so None for unmatched values
@@ -214,8 +207,8 @@ impl<'heap> SwitchTargets<'heap> {
214207
/// let heap = Heap::new();
215208
/// let interner = Interner::new(&heap);
216209
///
217-
/// let then_block = Target::block(BasicBlockId::new(1), &interner);
218-
/// let else_block = Target::block(BasicBlockId::new(2), &interner);
210+
/// let then_block = Target::block(BasicBlockId::new(1));
211+
/// let else_block = Target::block(BasicBlockId::new(2));
219212
///
220213
/// let targets = SwitchTargets::new_if(&heap, then_block, else_block);
221214
///
@@ -261,8 +254,8 @@ impl<'heap> SwitchTargets<'heap> {
261254
/// let heap = Heap::new();
262255
/// let interner = Interner::new(&heap);
263256
///
264-
/// let then_block = Target::block(BasicBlockId::new(1), &interner);
265-
/// let else_block = Target::block(BasicBlockId::new(2), &interner);
257+
/// let then_block = Target::block(BasicBlockId::new(1));
258+
/// let else_block = Target::block(BasicBlockId::new(2));
266259
///
267260
/// // Binary switch can be converted
268261
/// let binary = SwitchTargets::new_if(&heap, then_block, else_block);
@@ -316,11 +309,11 @@ impl<'heap> SwitchTargets<'heap> {
316309
/// let heap = Heap::new();
317310
/// let interner = Interner::new(&heap);
318311
///
319-
/// let default = Target::block(BasicBlockId::new(99), &interner);
312+
/// let default = Target::block(BasicBlockId::new(99));
320313
///
321314
/// let with_otherwise = SwitchTargets::new(
322315
/// &heap,
323-
/// [(1, Target::block(BasicBlockId::new(0), &interner))],
316+
/// [(1, Target::block(BasicBlockId::new(0)))],
324317
/// Some(default),
325318
/// );
326319
/// assert_eq!(with_otherwise.otherwise(), Some(default));
@@ -353,9 +346,9 @@ impl<'heap> SwitchTargets<'heap> {
353346
/// let heap = Heap::new();
354347
/// let interner = Interner::new(&heap);
355348
///
356-
/// let bb0 = Target::block(BasicBlockId::new(0), &interner);
357-
/// let bb1 = Target::block(BasicBlockId::new(1), &interner);
358-
/// let otherwise = Target::block(BasicBlockId::new(99), &interner);
349+
/// let bb0 = Target::block(BasicBlockId::new(0));
350+
/// let bb1 = Target::block(BasicBlockId::new(1));
351+
/// let otherwise = Target::block(BasicBlockId::new(99));
359352
///
360353
/// let targets = SwitchTargets::new(&heap, [(10, bb0), (20, bb1)], Some(otherwise));
361354
///
@@ -417,8 +410,8 @@ impl<'heap> SwitchTargets<'heap> {
417410
/// let mut targets = SwitchTargets::new(
418411
/// &heap,
419412
/// [
420-
/// (1, Target::block(BasicBlockId::new(0), &interner)),
421-
/// (2, Target::block(BasicBlockId::new(1), &interner)),
413+
/// (1, Target::block(BasicBlockId::new(0))),
414+
/// (2, Target::block(BasicBlockId::new(1))),
422415
/// ],
423416
/// None,
424417
/// );
@@ -459,10 +452,10 @@ impl<'heap> SwitchTargets<'heap> {
459452
/// let targets = SwitchTargets::new(
460453
/// &heap,
461454
/// [
462-
/// (10, Target::block(BasicBlockId::new(0), &interner)),
463-
/// (20, Target::block(BasicBlockId::new(1), &interner)),
455+
/// (10, Target::block(BasicBlockId::new(0))),
456+
/// (20, Target::block(BasicBlockId::new(1))),
464457
/// ],
465-
/// Some(Target::block(BasicBlockId::new(99), &interner)),
458+
/// Some(Target::block(BasicBlockId::new(99))),
466459
/// );
467460
///
468461
/// let pairs: Vec<_> = targets.iter().collect();
@@ -501,8 +494,8 @@ impl<'heap> SwitchTargets<'heap> {
501494
/// let mut targets = SwitchTargets::new(
502495
/// &heap,
503496
/// [
504-
/// (10, Target::block(BasicBlockId::new(0), &interner)),
505-
/// (20, Target::block(BasicBlockId::new(1), &interner)),
497+
/// (10, Target::block(BasicBlockId::new(0))),
498+
/// (20, Target::block(BasicBlockId::new(1))),
506499
/// ],
507500
/// None,
508501
/// );
@@ -545,8 +538,8 @@ impl<'heap> SwitchTargets<'heap> {
545538
///
546539
/// let mut targets = SwitchTargets::new(&heap, [], None);
547540
///
548-
/// targets.add_target(10, Target::block(BasicBlockId::new(0), &interner));
549-
/// targets.add_target(5, Target::block(BasicBlockId::new(1), &interner));
541+
/// targets.add_target(10, Target::block(BasicBlockId::new(0)));
542+
/// targets.add_target(5, Target::block(BasicBlockId::new(1)));
550543
///
551544
/// // Values are kept sorted
552545
/// assert_eq!(targets.values(), &[5, 10]);
@@ -587,16 +580,12 @@ impl<'heap> SwitchTargets<'heap> {
587580
/// let heap = Heap::new();
588581
/// let interner = Interner::new(&heap);
589582
///
590-
/// let mut first = SwitchTargets::new(
591-
/// &heap,
592-
/// [(10, Target::block(BasicBlockId::new(0), &interner))],
593-
/// None,
594-
/// );
583+
/// let mut first = SwitchTargets::new(&heap, [(10, Target::block(BasicBlockId::new(0)))], None);
595584
///
596585
/// let mut second = SwitchTargets::new(
597586
/// &heap,
598-
/// [(20, Target::block(BasicBlockId::new(1), &interner))],
599-
/// Some(Target::block(BasicBlockId::new(99), &interner)),
587+
/// [(20, Target::block(BasicBlockId::new(1)))],
588+
/// Some(Target::block(BasicBlockId::new(99))),
600589
/// );
601590
///
602591
/// first.append(&mut second);
@@ -702,11 +691,11 @@ impl<'heap> SwitchTargets<'heap> {
702691
/// let targets = SwitchTargets::new(
703692
/// &heap,
704693
/// [
705-
/// (0, Target::block(BasicBlockId::new(0), &interner)),
706-
/// (1, Target::block(BasicBlockId::new(1), &interner)),
707-
/// (2, Target::block(BasicBlockId::new(2), &interner)),
694+
/// (0, Target::block(BasicBlockId::new(0))),
695+
/// (1, Target::block(BasicBlockId::new(1))),
696+
/// (2, Target::block(BasicBlockId::new(2))),
708697
/// ],
709-
/// Some(Target::block(BasicBlockId::new(3), &interner)), // otherwise
698+
/// Some(Target::block(BasicBlockId::new(3))), // otherwise
710699
/// );
711700
///
712701
/// // Create the switch with an integer discriminant
@@ -734,12 +723,12 @@ impl<'heap> SwitchTargets<'heap> {
734723
/// let heap = Heap::new();
735724
/// let interner = Interner::new(&heap);
736725
///
737-
/// let then_target = Target::block(BasicBlockId::new(1), &interner);
738-
/// let else_target = Target::block(BasicBlockId::new(2), &interner);
726+
/// let then_target = Target::block(BasicBlockId::new(1));
727+
/// let else_target = Target::block(BasicBlockId::new(2));
739728
///
740729
/// // Create a binary switch for if-else
741730
/// let switch = SwitchInt {
742-
/// discriminant: Operand::Place(Place::local(Local::new(0), &interner)),
731+
/// discriminant: Operand::Place(Place::local(Local::new(0))),
743732
/// targets: SwitchTargets::new_if(&heap, then_target, else_target),
744733
/// };
745734
///

libs/@local/hashql/mir/src/body/terminator/target.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
66
use hashql_core::intern::Interned;
77

8-
use crate::{
9-
body::{basic_block::BasicBlockId, operand::Operand},
10-
intern::Interner,
11-
};
8+
use crate::body::{basic_block::BasicBlockId, operand::Operand};
129

1310
/// A control flow target in the HashQL MIR.
1411
///
@@ -39,11 +36,12 @@ pub struct Target<'heap> {
3936
pub args: Interned<'heap, [Operand<'heap>]>,
4037
}
4138

42-
impl<'heap> Target<'heap> {
43-
pub fn block(block: impl Into<BasicBlockId>, interner: &Interner<'heap>) -> Self {
39+
impl Target<'_> {
40+
#[must_use]
41+
pub const fn block(block: BasicBlockId) -> Self {
4442
Self {
45-
block: block.into(),
46-
args: interner.operands.intern_slice(&[]),
43+
block,
44+
args: Interned::empty(),
4745
}
4846
}
4947
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use core::mem;
22

33
use hashql_core::{
44
heap::{self, Heap},
5+
intern::Interned,
56
span::SpanId,
67
};
78

@@ -75,11 +76,11 @@ pub(crate) struct CurrentBlock<'mir, 'heap> {
7576
}
7677

7778
impl<'mir, 'heap> CurrentBlock<'mir, 'heap> {
78-
pub(crate) fn new(heap: &'heap Heap, interner: &'mir Interner<'heap>) -> Self {
79+
pub(crate) const fn new(heap: &'heap Heap, interner: &'mir Interner<'heap>) -> Self {
7980
Self {
8081
heap,
8182
interner,
82-
block: Self::empty_block(heap, interner),
83+
block: Self::empty_block(heap),
8384
slot: None,
8485
entry: None,
8586
forward_ref: Vec::new(),
@@ -95,9 +96,9 @@ impl<'mir, 'heap> CurrentBlock<'mir, 'heap> {
9596
self.block.statements.push(statement);
9697
}
9798

98-
fn empty_block(heap: &'heap Heap, interner: &Interner<'heap>) -> BasicBlock<'heap> {
99+
const fn empty_block(heap: &'heap Heap) -> BasicBlock<'heap> {
99100
BasicBlock {
100-
params: interner.locals.intern_slice(&[]),
101+
params: Interned::empty(),
101102
statements: heap::Vec::new_in(heap),
102103
// This terminator is temporary and is going to get replaced once finished
103104
terminator: Terminator {
@@ -165,7 +166,7 @@ impl<'mir, 'heap> CurrentBlock<'mir, 'heap> {
165166
}
166167

167168
pub(crate) fn reserve(&mut self, blocks: &mut BasicBlockVec<BasicBlock<'heap>, &'heap Heap>) {
168-
self.slot = Some(blocks.push(Self::empty_block(self.heap, self.interner)));
169+
self.slot = Some(blocks.push(Self::empty_block(self.heap)));
169170
}
170171

171172
pub(crate) fn terminate<const N: usize>(
@@ -175,7 +176,7 @@ impl<'mir, 'heap> CurrentBlock<'mir, 'heap> {
175176
blocks: &mut BasicBlockVec<BasicBlock<'heap>, &'heap Heap>,
176177
) -> ExitBlock {
177178
// Finishes the current block, and starts a new one
178-
let previous = mem::replace(&mut self.block, Self::empty_block(self.heap, self.interner));
179+
let previous = mem::replace(&mut self.block, Self::empty_block(self.heap));
179180
let (_, id) = Self::complete(
180181
previous,
181182
terminator,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ impl<'mir, 'heap> Reifier<'_, 'mir, '_, '_, 'heap> {
159159
discriminant: test,
160160
targets: SwitchTargets::new_if(
161161
self.context.mir.heap,
162-
Target::block(then_entry, self.context.mir.interner),
163-
Target::block(else_entry, self.context.mir.interner),
162+
Target::block(then_entry.into()),
163+
Target::block(else_entry.into()),
164164
),
165165
}),
166166
},

0 commit comments

Comments
 (0)