core: change `debug_assert_prim_is_allowed` to take &allowlist
This commit is contained in:
parent
9ae4fad92e
commit
8b1668c3e6
|
@ -551,7 +551,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
fn build_simple_primitive_class(&self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
[
|
||||
&[
|
||||
PrimDef::Int32,
|
||||
PrimDef::Int64,
|
||||
PrimDef::UInt32,
|
||||
|
@ -570,7 +570,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
/// Build the class `Exception` and its associated methods.
|
||||
fn build_exception_class_related(&self, prim: PrimDef) -> TopLevelDef {
|
||||
// NOTE: currently only contains the class `Exception`
|
||||
debug_assert_prim_is_allowed(prim, [PrimDef::Exception]);
|
||||
debug_assert_prim_is_allowed(prim, &[PrimDef::Exception]);
|
||||
|
||||
let PrimitiveStore { int32, int64, str, .. } = *self.primitives;
|
||||
|
||||
|
@ -608,7 +608,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
fn build_option_class_related(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
[
|
||||
&[
|
||||
PrimDef::Option,
|
||||
PrimDef::OptionIsSome,
|
||||
PrimDef::OptionIsNone,
|
||||
|
@ -727,7 +727,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
fn build_ndarray_class_related(&self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
[PrimDef::NDArray, PrimDef::NDArrayCopy, PrimDef::NDArrayFill],
|
||||
&[PrimDef::NDArray, PrimDef::NDArrayCopy, PrimDef::NDArrayFill],
|
||||
);
|
||||
|
||||
match prim {
|
||||
|
@ -788,7 +788,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
fn build_cast_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
[
|
||||
&[
|
||||
PrimDef::FunInt32,
|
||||
PrimDef::FunInt64,
|
||||
PrimDef::FunUInt32,
|
||||
|
@ -837,7 +837,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
|
||||
/// Build the functions `round()` and `round64()`.
|
||||
fn build_round_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(prim, [PrimDef::FunRound, PrimDef::FunRound64]);
|
||||
debug_assert_prim_is_allowed(prim, &[PrimDef::FunRound, PrimDef::FunRound64]);
|
||||
|
||||
let float = self.primitives.float;
|
||||
|
||||
|
@ -891,7 +891,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
fn build_ceil_floor_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
[PrimDef::FunFloor, PrimDef::FunFloor64, PrimDef::FunCeil, PrimDef::FunCeil64],
|
||||
&[PrimDef::FunFloor, PrimDef::FunFloor64, PrimDef::FunCeil, PrimDef::FunCeil64],
|
||||
);
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
@ -961,7 +961,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
fn build_ndarray_from_shape_factory_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
[PrimDef::FunNpNDArray, PrimDef::FunNpEmpty, PrimDef::FunNpZeros, PrimDef::FunNpOnes],
|
||||
&[PrimDef::FunNpNDArray, PrimDef::FunNpEmpty, PrimDef::FunNpZeros, PrimDef::FunNpOnes],
|
||||
);
|
||||
|
||||
create_fn_by_codegen(
|
||||
|
@ -990,7 +990,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
fn build_ndarray_other_factory_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
[PrimDef::FunNpArray, PrimDef::FunNpFull, PrimDef::FunNpEye, PrimDef::FunNpIdentity],
|
||||
&[PrimDef::FunNpArray, PrimDef::FunNpFull, PrimDef::FunNpEye, PrimDef::FunNpIdentity],
|
||||
);
|
||||
|
||||
let PrimitiveStore { int32, bool, ndarray, .. } = *self.primitives;
|
||||
|
@ -1254,7 +1254,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
|
||||
/// Build functions `np_ceil()` and `np_floor()`.
|
||||
fn build_np_ceil_floor_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(prim, [PrimDef::FunNpCeil, PrimDef::FunNpFloor]);
|
||||
debug_assert_prim_is_allowed(prim, &[PrimDef::FunNpCeil, PrimDef::FunNpFloor]);
|
||||
|
||||
create_fn_by_codegen(
|
||||
&mut self.unifier,
|
||||
|
@ -1412,7 +1412,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
|
||||
/// Build the functions `min()` and `max()`.
|
||||
fn build_min_max_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(prim, [PrimDef::FunMin, PrimDef::FunMax]);
|
||||
debug_assert_prim_is_allowed(prim, &[PrimDef::FunMin, PrimDef::FunMax]);
|
||||
|
||||
TopLevelDef::Function {
|
||||
name: prim.name().into(),
|
||||
|
@ -1450,7 +1450,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
|
||||
/// Build the functions `np_min()` and `np_max()`.
|
||||
fn build_np_min_max_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(prim, [PrimDef::FunNpMin, PrimDef::FunNpMax]);
|
||||
debug_assert_prim_is_allowed(prim, &[PrimDef::FunNpMin, PrimDef::FunNpMax]);
|
||||
|
||||
let ret_ty = self.unifier.get_fresh_var(Some("R".into()), None);
|
||||
let var_map = self
|
||||
|
@ -1483,7 +1483,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
|
||||
/// Build the functions `np_minimum()` and `np_maximum()`.
|
||||
fn build_np_minimum_maximum_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(prim, [PrimDef::FunNpMinimum, PrimDef::FunNpMaximum]);
|
||||
debug_assert_prim_is_allowed(prim, &[PrimDef::FunNpMinimum, PrimDef::FunNpMaximum]);
|
||||
|
||||
let x1_ty = self.new_type_or_ndarray_ty(self.num_ty.0);
|
||||
let x2_ty = self.new_type_or_ndarray_ty(self.num_ty.0);
|
||||
|
@ -1561,7 +1561,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
|
||||
/// Build numpy functions that take in a float and return a boolean.
|
||||
fn build_np_float_to_bool_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(prim, [PrimDef::FunNpIsInf, PrimDef::FunNpIsNan]);
|
||||
debug_assert_prim_is_allowed(prim, &[PrimDef::FunNpIsInf, PrimDef::FunNpIsNan]);
|
||||
|
||||
let PrimitiveStore { bool, float, .. } = *self.primitives;
|
||||
|
||||
|
@ -1590,7 +1590,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
fn build_np_sp_float_or_ndarray_1ary_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
[
|
||||
&[
|
||||
PrimDef::FunNpSin,
|
||||
PrimDef::FunNpCos,
|
||||
PrimDef::FunNpTan,
|
||||
|
@ -1690,7 +1690,7 @@ impl<'a> BuiltinBuilder<'a> {
|
|||
fn build_np_2ary_function(&mut self, prim: PrimDef) -> TopLevelDef {
|
||||
debug_assert_prim_is_allowed(
|
||||
prim,
|
||||
[
|
||||
&[
|
||||
PrimDef::FunNpArctan2,
|
||||
PrimDef::FunNpCopysign,
|
||||
PrimDef::FunNpFmax,
|
||||
|
|
|
@ -249,7 +249,7 @@ impl PrimDef {
|
|||
///
|
||||
/// Like `debug_assert!`, this statements of this function are only
|
||||
/// enabled if `cfg!(debug_assertions)` is true.
|
||||
pub fn debug_assert_prim_is_allowed<const N: usize>(prim: PrimDef, allowlist: [PrimDef; N]) {
|
||||
pub fn debug_assert_prim_is_allowed(prim: PrimDef, allowlist: &[PrimDef]) {
|
||||
if cfg!(debug_assertions) {
|
||||
let allowed = allowlist.iter().any(|p| *p == prim);
|
||||
if !allowed {
|
||||
|
|
Loading…
Reference in New Issue