konst_kernel/
collect_const.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use crate::type_eq::{MakeTypeWitness, TypeEq, TypeWitnessTypeArg};

pub enum CollectorCmd<Ret, T, const CAP: usize> {
    ComputeLength(TypeEq<usize, Ret>),
    BuildArray(TypeEq<[T; CAP], Ret>),
}

impl<Ret, T, const CAP: usize> TypeWitnessTypeArg for CollectorCmd<Ret, T, CAP> {
    type Arg = Ret;
}

impl<T> MakeTypeWitness for CollectorCmd<usize, T, 0> {
    const MAKE: Self = Self::ComputeLength(TypeEq::NEW);
}

impl<T, const CAP: usize> MakeTypeWitness for CollectorCmd<[T; CAP], T, CAP> {
    const MAKE: Self = Self::BuildArray(TypeEq::NEW);
}

#[macro_export]
macro_rules! iter_collect_const {
    (
        $Item:ty =>
        $($rem:tt)*
    ) => {{
        $crate::__collect_const_iter_with!{
            $Item ,
            {let item = $crate::__::MaybeUninit::new(item);},
            |array, length, item| array[length] = item,
            elem_length = 1,
            =>
            $($rem)*
        }

        __ARR81608BFNA5
    }}
}

#[doc(hidden)]
#[macro_export]
macro_rules! __collect_const_iter_with {
    (
        $Item:ty,
        $reassign_item:tt,
        |$array:ident, $length:ident, $item:ident| $elem_initer:expr,
        elem_length = $elem_length:expr,
        =>
        $($rem:tt)*
    ) => {
        const fn __func_zxe7hgbnjs<Ret_KO9Y329U2U, const CAP_KO9Y329U2U: $crate::__::usize>(
            cmd: $crate::__::CollectorCmd<Ret_KO9Y329U2U, $Item, CAP_KO9Y329U2U>
        ) -> Ret_KO9Y329U2U {
            let mut $array = $crate::maybe_uninit::uninit_array::<_, CAP_KO9Y329U2U>();
            let mut $length = 0usize;

            $crate::__process_iter_args!{
                ($crate::__iter_collect_const)
                (cmd, $length, $elem_length, $reassign_item, $elem_initer;)
                (
                    $item,
                    'zxe7hgbnjs,
                    adapter,
                )
                $($rem)*
            }

            match cmd {
                $crate::__::CollectorCmd::ComputeLength(teq) => {
                    $crate::__::forget($array);
                    teq.to_right($length)
                }
                $crate::__::CollectorCmd::BuildArray(teq) => {
                    $crate::__::assert!{
                        $length == CAP_KO9Y329U2U,
                        "initialization was skipped somehow",
                    }

                    // SAFETY: The above assert ensures that
                    // all of the array is initialized
                    let $array = unsafe{ $crate::maybe_uninit::array_assume_init($array) };
                    teq.to_right($array)
                }
            }
        }

        const __COUNT81608BFNA5: $crate::__::usize =
            __func_zxe7hgbnjs($crate::__::MakeTypeWitness::MAKE);

        const __ARR81608BFNA5: [$Item; __COUNT81608BFNA5] =
            __func_zxe7hgbnjs($crate::__::MakeTypeWitness::MAKE);


    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __iter_collect_const {
    (
        @each
        $cmd:ident,
        $length:ident,
        $elem_length:expr,
        {$($reassign_item:tt)*},
        $elem_initer:expr;
        ($item:ident adapter),
        $(,)*
    ) => ({
        $($reassign_item)*
        if let $crate::__::CollectorCmd::BuildArray(teq) = $cmd {
            teq.reachability_hint(());

            $elem_initer
        }

        $length += $elem_length;
    });
    (@end $($tt:tt)*) => {};
}