Skip to content

Commit

Permalink
feat(hax-lib): drop explicit dependency to num_bigint in interface
Browse files Browse the repository at this point in the history
  • Loading branch information
W95Psp committed May 16, 2024
1 parent f7fa833 commit f7193f6
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions hax-lib/src/int/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,38 @@ pub trait Concretization<T> {
fn concretize(self) -> T;
}

impl<T: Into<num_bigint::BigInt>> Abstraction for T {
type AbstractType = Int;
fn lift(self) -> Self::AbstractType {
Int::new(self.into())
}
/// Instead of defining one overloaded instance, which relies
/// explicitely on `num_bigint`:
///
/// ```ignore
/// impl<T: Into<num_bigint::BigInt>> Abstraction for T {
/// type AbstractType = Int;
/// fn lift(self) -> Self::AbstractType {
/// Int::new(self.into())
/// }
/// }
/// ```
///
/// We define an instance per machine type: we don't want the
/// interface of this module to rely specifically on
/// `num_bigint`. This module should be a very thin layer.
macro_rules! implement_abstraction {
($ty:ident) => {
impl Abstraction for $ty {
type AbstractType = Int;
fn lift(self) -> Self::AbstractType {
Int::new(num_bigint::BigInt::from(self))
}
}
};
($($ty:ident)*) => {
$(implement_abstraction!($ty);)*
};
}

implement_abstraction!(u8 u16 u32 u64 u128 usize);
implement_abstraction!(i8 i16 i32 i64 i128 isize);

macro_rules! implement_concretize {
($ty:ident $method:ident) => {
impl Concretization<$ty> for Int {
Expand Down

0 comments on commit f7193f6

Please sign in to comment.