<commit_before>use rustc::ty::layout::{Size, HasDataLayout};

use super::{Scalar, ScalarMaybeUndef, EvalResult};
use rustc_mir::interpret::sign_extend;

pub trait ScalarExt {
    fn null(size: Size) -> Self;
    fn from_i32(i: i32) -> Self;
    fn from_uint(i: impl Into<u128>, ptr_size: Size) -> Self;
    fn from_int(i: impl Into<i128>, ptr_size: Size) -> Self;
    fn from_f32(f: f32) -> Self;
    fn from_f64(f: f64) -> Self;
    fn is_null(self) -> bool;
}

pub trait FalibleScalarExt {
    fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'static, u64>;
    fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'static, i64>;
    fn to_i32(self) -> EvalResult<'static, i32>;
    fn to_u8(self) -> EvalResult<'static, u8>;

    /// HACK: this function just extracts all bits if `defined != 0`
    /// Mainly used for args of C-functions and we should totally correctly fetch the size
    /// of their arguments
    fn to_bytes(self) -> EvalResult<'static, u128>;
}

impl ScalarExt for Scalar {
    fn null(size: Size) -> Self {
        Scalar::Bits { bits: 0, size: size.bytes() as u8 }
    }

    fn from_i32(i: i32) -> Self {
        Scalar::Bits { bits: i as u32 as u128, size: 4 }<commit_msg>fix compilation after rustc change<commit_after>use rustc::ty::layout::{Size, HasDataLayout};
use rustc::mir::interpret::sign_extend;

use super::{Scalar, ScalarMaybeUndef, EvalResult};

pub trait ScalarExt {
    fn null(size: Size) -> Self;
    fn from_i32(i: i32) -> Self;
    fn from_uint(i: impl Into<u128>, ptr_size: Size) -> Self;
    fn from_int(i: impl Into<i128>, ptr_size: Size) -> Self;
    fn from_f32(f: f32) -> Self;
    fn from_f64(f: f64) -> Self;
    fn is_null(self) -> bool;
}

pub trait FalibleScalarExt {
    fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'static, u64>;
    fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'static, i64>;
    fn to_i32(self) -> EvalResult<'static, i32>;
    fn to_u8(self) -> EvalResult<'static, u8>;

    /// HACK: this function just extracts all bits if `defined != 0`
    /// Mainly used for args of C-functions and we should totally correctly fetch the size
    /// of their arguments
    fn to_bytes(self) -> EvalResult<'static, u128>;
}

impl ScalarExt for Scalar {
    fn null(size: Size) -> Self {
        Scalar::Bits { bits: 0, size: size.bytes() as u8 }
    }

    fn from_i32(i: i32) -> Self {
        Scalar::Bits { bits: i as u32 as u128, size: 4 }
{'fraction_non_alphanumeric': 0.14238952536824878, 'fraction_numerical': 0.03600654664484452, 'mean_word_length': 3.373881932021467, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6223356', 'n_tokens_mistral': 914, 'n_tokens_neox': 869, 'n_words': 262}