Skip to content

Commit 01100c1

Browse files
committed
feat: checkpoint
fix: checkpoint feat: checkpoint feat: checkpoint feat: checkpoint feat: checkpoint fix: checkpoint fix: checkpoint fix: checkpoint feat: checkpoint feat: checkpoint chore: better unreachable messages feat: add lookup methods fix: add tests directory feat: bb checkpoint feat: bb checkpoint test: checkpoint feat: first test fix: lints feat: test cases
1 parent a04422f commit 01100c1

24 files changed

+2257
-36
lines changed

Cargo.lock

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ pub fn fast_hash_set<T>() -> FastHashSet<T> {
8080

8181
pub type TinyVec<T> = smallvec::SmallVec<T, 4>;
8282
pub type SmallVec<T> = smallvec::SmallVec<T, 16>;
83+
pub type InlineVec<T, const N: usize> = smallvec::SmallVec<T, N>;

libs/@local/hashql/core/src/graph/algorithms/dominators/iterated_frontier.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ where
110110
self.inner.is_empty()
111111
}
112112

113+
/// Returns `true` if the iterated dominance frontier contains the given node.
114+
#[must_use]
115+
pub fn contains(&self, node: N) -> bool {
116+
self.inner.contains(node)
117+
}
118+
113119
/// Returns the number of nodes in the iterated dominance frontier.
114120
#[must_use]
115121
pub fn count(&self) -> usize {

libs/@local/hashql/core/src/id/slice.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,90 @@ where
190190
}
191191
}
192192

193+
impl<I, T> IdSlice<I, Option<T>>
194+
where
195+
I: Id,
196+
{
197+
/// Removes and returns the value at the given ID index.
198+
///
199+
/// Returns `None` if the index is out of bounds or if the value was already `None`.
200+
/// The vector is not shrunk after removal.
201+
///
202+
/// # Examples
203+
///
204+
/// ```
205+
/// # use hashql_core::{id::{IdVec, Id as _}, newtype};
206+
/// # newtype!(struct MyId(u32 is 0..=0xFFFF_FF00));
207+
/// let mut vec = IdVec::<MyId, Option<String>>::new();
208+
/// vec.insert(MyId::from_usize(0), "hello".to_string());
209+
/// let removed = vec.remove(MyId::from_usize(0));
210+
/// assert_eq!(removed, Some("hello".to_string()));
211+
/// assert!(vec[MyId::from_usize(0)].is_none());
212+
/// ```
213+
pub fn remove(&mut self, index: I) -> Option<T> {
214+
self.get_mut(index)?.take()
215+
}
216+
217+
/// Returns `true` if the vector contains a value (not `None`) at the given ID index.
218+
///
219+
/// # Examples
220+
///
221+
/// ```
222+
/// # use hashql_core::{id::{IdVec, Id as _}, newtype};
223+
/// # newtype!(struct MyId(u32 is 0..=0xFFFF_FF00));
224+
/// let mut vec = IdVec::<MyId, Option<String>>::new();
225+
/// vec.insert(MyId::from_usize(0), "hello".to_string());
226+
/// assert!(vec.contains(MyId::from_usize(0)));
227+
/// assert!(!vec.contains(MyId::from_usize(1)));
228+
/// ```
229+
pub fn contains(&self, index: I) -> bool {
230+
self.get(index).and_then(Option::as_ref).is_some()
231+
}
232+
233+
/// Gets a reference to the inner value at `index`, if present.
234+
///
235+
/// Returns [`None`] if the index is out of bounds or if the value at that index is [`None`].
236+
///
237+
/// # Examples
238+
///
239+
/// ```
240+
/// # use hashql_core::{id::{IdVec, Id as _}, newtype};
241+
/// # newtype!(struct MyId(u32 is 0..=0xFFFF_FF00));
242+
/// let mut vec = IdVec::<MyId, Option<String>>::new();
243+
/// vec.insert(MyId::from_usize(0), "hello".to_string());
244+
///
245+
/// assert_eq!(vec.lookup(MyId::from_usize(0)), Some(&"hello".to_string()));
246+
/// assert_eq!(vec.lookup(MyId::from_usize(1)), None); // out of bounds
247+
/// ```
248+
pub fn lookup(&self, index: I) -> Option<&T> {
249+
self.get(index).and_then(Option::as_ref)
250+
}
251+
252+
/// Gets a mutable reference to the inner value at `index`, if present.
253+
///
254+
/// Returns [`None`] if the index is out of bounds or if the value at that index is [`None`].
255+
///
256+
/// # Examples
257+
///
258+
/// ```
259+
/// # use hashql_core::{id::{IdVec, Id as _}, newtype};
260+
/// # newtype!(struct MyId(u32 is 0..=0xFFFF_FF00));
261+
/// let mut vec = IdVec::<MyId, Option<String>>::new();
262+
/// vec.insert(MyId::from_usize(0), "hello".to_string());
263+
///
264+
/// if let Some(value) = vec.lookup_mut(MyId::from_usize(0)) {
265+
/// value.push_str(" world");
266+
/// }
267+
/// assert_eq!(
268+
/// vec.lookup(MyId::from_usize(0)),
269+
/// Some(&"hello world".to_string())
270+
/// );
271+
/// ```
272+
pub fn lookup_mut(&mut self, index: I) -> Option<&mut T> {
273+
self.get_mut(index).and_then(Option::as_mut)
274+
}
275+
}
276+
193277
impl<I, T> Debug for IdSlice<I, T>
194278
where
195279
I: Id,

libs/@local/hashql/core/src/id/vec.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -367,42 +367,6 @@ where
367367
self.fill_until(index, || None).replace(value)
368368
}
369369

370-
/// Removes and returns the value at the given ID index.
371-
///
372-
/// Returns `None` if the index is out of bounds or if the value was already `None`.
373-
/// The vector is not shrunk after removal.
374-
///
375-
/// # Examples
376-
///
377-
/// ```
378-
/// # use hashql_core::{id::{IdVec, Id as _}, newtype};
379-
/// # newtype!(struct MyId(u32 is 0..=0xFFFF_FF00));
380-
/// let mut vec = IdVec::<MyId, Option<String>>::new();
381-
/// vec.insert(MyId::from_usize(0), "hello".to_string());
382-
/// let removed = vec.remove(MyId::from_usize(0));
383-
/// assert_eq!(removed, Some("hello".to_string()));
384-
/// assert!(vec[MyId::from_usize(0)].is_none());
385-
/// ```
386-
pub fn remove(&mut self, index: I) -> Option<T> {
387-
self.get_mut(index)?.take()
388-
}
389-
390-
/// Returns `true` if the vector contains a value (not `None`) at the given ID index.
391-
///
392-
/// # Examples
393-
///
394-
/// ```
395-
/// # use hashql_core::{id::{IdVec, Id as _}, newtype};
396-
/// # newtype!(struct MyId(u32 is 0..=0xFFFF_FF00));
397-
/// let mut vec = IdVec::<MyId, Option<String>>::new();
398-
/// vec.insert(MyId::from_usize(0), "hello".to_string());
399-
/// assert!(vec.contains(MyId::from_usize(0)));
400-
/// assert!(!vec.contains(MyId::from_usize(1)));
401-
/// ```
402-
pub fn contains(&self, index: I) -> bool {
403-
self.get(index).and_then(Option::as_ref).is_some()
404-
}
405-
406370
/// Gets the value at `index`, or inserts one by calling `value` if it doesn't exist.
407371
///
408372
/// This method works on `IdVec<I, Option<T>>` to provide map-like semantics.

libs/@local/hashql/mir/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ simple-mermaid = { workspace = true }
2323

2424
[dev-dependencies]
2525
hashql-compiletest = { workspace = true }
26+
insta.workspace = true
2627

2728
[lints]
2829
workspace = true

libs/@local/hashql/mir/src/body/operand.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,15 @@ pub enum Operand<'heap> {
3434
/// value.
3535
Constant(Constant<'heap>),
3636
}
37+
38+
impl<'heap> From<Place<'heap>> for Operand<'heap> {
39+
fn from(place: Place<'heap>) -> Self {
40+
Operand::Place(place)
41+
}
42+
}
43+
44+
impl<'heap> From<Constant<'heap>> for Operand<'heap> {
45+
fn from(constant: Constant<'heap>) -> Self {
46+
Operand::Constant(constant)
47+
}
48+
}

libs/@local/hashql/mir/src/intern.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use crate::body::{local::Local, operand::Operand, place::Projection};
44

55
#[derive(Debug)]
66
pub struct Interner<'heap> {
7+
pub heap: &'heap Heap,
8+
79
pub locals: InternSet<'heap, [Local]>,
810
pub symbols: InternSet<'heap, [Symbol<'heap>]>,
911
pub operands: InternSet<'heap, [Operand<'heap>]>,
@@ -13,6 +15,8 @@ pub struct Interner<'heap> {
1315
impl<'heap> Interner<'heap> {
1416
pub fn new(heap: &'heap Heap) -> Self {
1517
Self {
18+
heap,
19+
1620
locals: InternSet::new(heap),
1721
symbols: InternSet::new(heap),
1822
operands: InternSet::new(heap),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pub mod error;
2+
pub mod ssa_repair;

0 commit comments

Comments
 (0)