core: reformat builtin.rs and helper.rs
This commit is contained in:
parent
1cedbbcd42
commit
2e3b00214c
|
@ -890,13 +890,16 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
/// Build the functions `ceil()` and `floor()` and their 64 bit variants.
|
||||
fn build_ceil_floor_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
#[derive(Clone, Copy)]
|
||||
enum Kind { Floor, Ceil }
|
||||
enum Kind {
|
||||
Floor,
|
||||
Ceil,
|
||||
}
|
||||
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
&[PrimDef::FunFloor, PrimDef::FunFloor64, PrimDef::FunCeil, PrimDef::FunCeil64],
|
||||
);
|
||||
|
||||
|
||||
let (size_variant, kind) = {
|
||||
match prim {
|
||||
PrimDef::FunFloor => (SizeVariant::Bits32, Kind::Floor),
|
||||
|
|
|
@ -104,13 +104,8 @@ pub enum PrimDef {
|
|||
|
||||
/// Associated details of a [`PrimDef`]
|
||||
enum PrimDefDetails {
|
||||
PrimFunction {
|
||||
name: &'static str,
|
||||
simple_name: &'static str
|
||||
},
|
||||
PrimClass {
|
||||
name: &'static str,
|
||||
},
|
||||
PrimFunction { name: &'static str, simple_name: &'static str },
|
||||
PrimClass { name: &'static str },
|
||||
}
|
||||
|
||||
impl PrimDef {
|
||||
|
@ -138,7 +133,9 @@ impl PrimDef {
|
|||
pub fn simple_name(&self) -> &'static str {
|
||||
match self.details() {
|
||||
PrimDefDetails::PrimFunction { simple_name, .. } => simple_name,
|
||||
PrimDefDetails::PrimClass {..} => panic!("PrimDef {self:?} has no simple_name as it is not a function."),
|
||||
PrimDefDetails::PrimClass { .. } => {
|
||||
panic!("PrimDef {self:?} has no simple_name as it is not a function.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,8 +147,7 @@ impl PrimDef {
|
|||
#[must_use]
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self.details() {
|
||||
PrimDefDetails::PrimFunction { name, .. }
|
||||
| PrimDefDetails::PrimClass { name } => name,
|
||||
PrimDefDetails::PrimFunction { name, .. } | PrimDefDetails::PrimClass { name } => name,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,12 +174,12 @@ impl PrimDef {
|
|||
PrimDef::UInt32 => class("uint32"),
|
||||
PrimDef::UInt64 => class("uint64"),
|
||||
PrimDef::Option => class("Option"),
|
||||
PrimDef::OptionIsSome => fun( "Option.is_some", Some("is_some")),
|
||||
PrimDef::OptionIsNone => fun( "Option.is_none", Some("is_none")),
|
||||
PrimDef::OptionUnwrap => fun( "Option.unwrap", Some("unwrap")),
|
||||
PrimDef::OptionIsSome => fun("Option.is_some", Some("is_some")),
|
||||
PrimDef::OptionIsNone => fun("Option.is_none", Some("is_none")),
|
||||
PrimDef::OptionUnwrap => fun("Option.unwrap", Some("unwrap")),
|
||||
PrimDef::NDArray => class("ndarray"),
|
||||
PrimDef::NDArrayCopy => fun( "ndarray.copy", Some("copy")),
|
||||
PrimDef::NDArrayFill => fun( "ndarray.fill", Some("fill")),
|
||||
PrimDef::NDArrayCopy => fun("ndarray.copy", Some("copy")),
|
||||
PrimDef::NDArrayFill => fun("ndarray.fill", Some("fill")),
|
||||
PrimDef::FunInt32 => fun("int32", None),
|
||||
PrimDef::FunInt64 => fun("int64", None),
|
||||
PrimDef::FunUInt32 => fun("uint32", None),
|
||||
|
@ -266,7 +262,8 @@ impl PrimDef {
|
|||
pub fn debug_assert_prim_is_allowed(prim: PrimDef, allowlist: &[PrimDef]) {
|
||||
if cfg!(debug_assertions) {
|
||||
let allowed = allowlist.iter().any(|p| *p == prim);
|
||||
assert!(allowed,
|
||||
assert!(
|
||||
allowed,
|
||||
"Disallowed primitive definition. Got {prim:?}, but expects it to be in {allowlist:?}"
|
||||
);
|
||||
}
|
||||
|
@ -887,11 +884,12 @@ pub fn parse_parameter_default_value(
|
|||
/// Obtains the element type of an array-like type.
|
||||
pub fn arraylike_flatten_element_type(unifier: &mut Unifier, ty: Type) -> Type {
|
||||
match &*unifier.get_ty(ty) {
|
||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() =>
|
||||
unpack_ndarray_var_tys(unifier, ty).0,
|
||||
TypeEnum::TObj { obj_id, .. } if *obj_id == PrimDef::NDArray.id() => {
|
||||
unpack_ndarray_var_tys(unifier, ty).0
|
||||
}
|
||||
|
||||
TypeEnum::TList { ty } => arraylike_flatten_element_type(unifier, *ty),
|
||||
_ => ty
|
||||
_ => ty,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -912,6 +910,6 @@ pub fn arraylike_get_ndims(unifier: &mut Unifier, ty: Type) -> u64 {
|
|||
}
|
||||
|
||||
TypeEnum::TList { ty } => arraylike_get_ndims(unifier, *ty) + 1,
|
||||
_ => 0
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue