Skip to content

Commit

Permalink
Replace some panics to compiler magic
Browse files Browse the repository at this point in the history
  • Loading branch information
minseongg committed Oct 29, 2024
1 parent 1470ffd commit 5c048b8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion hazardflow-designs/src/std/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use hazardflow_macro::magic;

use super::*;
use crate::prelude::*;

/// Interface trait.
#[must_use]
Expand Down Expand Up @@ -61,7 +62,7 @@ pub trait Interface: Sized {
_init_state: S,
_f: impl Fn(Self::Fwd, E::Bwd, S) -> (E::Fwd, Self::Bwd, S),
) -> E {
panic!("compiler magic")
compiler_magic!()
}

/// Combines the module to the given interface and returns the egress interface.
Expand Down
7 changes: 4 additions & 3 deletions hazardflow-designs/src/std/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
use hazardflow_macro::magic;

use super::*;
use crate::prelude::*;

/// Splits a module into two modules.
// TODO: Can we make return type `FnOnce(I1) -> O1`?
#[magic(module::split)]
pub fn module_split<I1: Interface, I2: Interface, O1: Interface, O2: Interface>(
_m: impl FnOnce(I1, I2) -> (O1, O2),
) -> (fn(I1) -> O1, fn(I2) -> O2) {
panic!("compiler magic")
compiler_magic!()
}

/// Splits a module into three modules.
Expand All @@ -35,7 +36,7 @@ pub fn module_split3<I1: Interface, I2: Interface, I3: Interface, O1: Interface,
#[magic(module::from_fn)]
pub fn from_fn<I: Interface, O: Interface, J: Interface, T, const N: usize>(f: T) -> [fn(I, J) -> (O, J); N]
where T: FnOnce(I, J) -> (O, J) {
panic!("compiler magic")
compiler_magic!()
}

/// Generates a 1D systolic array from an array of modules.
Expand All @@ -52,7 +53,7 @@ pub fn seq<I: Interface, O: Interface, J: Interface, const N: usize>(
ms: [fn(I, J) -> (O, J); N],
) -> impl FnOnce([I; N], J) -> ([O; N], J) {
// This should be primitive?
|is, j| panic!("compiler magic")
|is, j| compiler_magic!()
}

/// Applies `f` to the given interfaces.
Expand Down
6 changes: 4 additions & 2 deletions hazardflow-designs/src/std/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use hazardflow_macro::magic;

use crate::prelude::*;

/// Returns ceiling log2.
pub const fn clog2(value: usize) -> usize {
if value == 0 {
Expand Down Expand Up @@ -34,7 +36,7 @@ pub const fn max(lhs: usize, rhs: usize) -> usize {
/// Display function
#[magic(system::display)]
pub fn display<V: Copy>(_fstring: &str, _args: V) {
panic!("compiler magic")
compiler_magic!()
}

/// Display macro
Expand All @@ -53,7 +55,7 @@ macro_rules! display {
/// Assertion function
#[magic(system::assert)]
pub fn assert<V: Copy>(_cond: bool, _fstring: &str, _args: V) {
panic!("compiler magic")
compiler_magic!()
}

/// Assert macro
Expand Down
4 changes: 3 additions & 1 deletion hazardflow-designs/src/std/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use hazardflow_macro::magic;

use crate::prelude::*;

mod array;
mod bounded;
mod integer;
Expand All @@ -19,5 +21,5 @@ pub use option::*;
/// TODO: Write safety condition
#[magic(x)]
pub unsafe fn x<T: Copy>() -> T {
panic!("compiler magic")
compiler_magic!()
}
4 changes: 2 additions & 2 deletions hazardflow-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ pub fn heq(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
impl #impl_generics ::core::cmp::PartialEq for #name #ty_generics #where_clause {
#[magic(adt::enum_eq)]
fn eq(&self, other: &Self) -> bool {
::core::todo!("compiler magic")
crate::prelude::compiler_magic!()
}
#[allow(clippy::partialeq_ne_impl)]
#[magic(adt::enum_ne)]
fn ne(&self, other: &Self) -> bool {
::core::todo!("compiler magic")
crate::prelude::compiler_magic!()
}
}
impl #impl_generics ::core::cmp::Eq for #name #ty_generics #where_clause {
Expand Down

0 comments on commit 5c048b8

Please sign in to comment.