jlrs/data/types/
abstract_type.rs

1//! Abstract Julia types
2//!
3//! These types can be used with the `ConstructType` trait.
4
5use std::marker::PhantomData;
6
7use super::construct_type::{ConstructType, TypeVarEnv};
8use crate::{
9    data::managed::{
10        Managed,
11        datatype::DataType,
12        type_var::TypeVar,
13        union_all::UnionAll,
14        value::{Value, ValueData},
15    },
16    inline_static_ref,
17    memory::{scope::LocalScopeExt, target::Target},
18};
19
20/// Marker trait that the constructed type is an abstract type.
21///
22/// Safety: must only be implemented if the constructed type is an abstract type.
23pub unsafe trait AbstractType: ConstructType {}
24
25macro_rules! impl_construct_julia_type_abstract {
26    ($ty:ty, $path:expr_2021) => {
27        unsafe impl ConstructType for $ty {
28            type Static = $ty;
29
30            const CACHEABLE: bool = false;
31
32            #[inline]
33            fn construct_type_uncached<'target, Tgt>(
34                target: Tgt,
35            ) -> ValueData<'target, 'static, Tgt>
36            where
37                Tgt: Target<'target>,
38            {
39                Self::base_type(&target).unwrap().root(target)
40            }
41
42            #[inline]
43            fn construct_type_with_env_uncached<'target, Tgt>(
44                target: Tgt,
45                _: &TypeVarEnv,
46            ) -> ValueData<'target, 'static, Tgt>
47            where
48                Tgt: Target<'target>,
49            {
50                Self::base_type(&target).unwrap().root(target)
51            }
52
53            #[inline]
54            fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
55            where
56                Tgt: Target<'target>,
57            {
58                let value = inline_static_ref!(STATIC, Value, $path, target);
59                Some(value)
60            }
61        }
62    };
63}
64
65macro_rules! impl_construct_julia_type_abstract_using {
66    ($ty:ty, $path:expr_2021) => {
67        unsafe impl ConstructType for $ty {
68            type Static = $ty;
69
70            const CACHEABLE: bool = false;
71
72            #[inline]
73            fn construct_type_uncached<'target, Tgt>(
74                target: Tgt,
75            ) -> ValueData<'target, 'static, Tgt>
76            where
77                Tgt: Target<'target>,
78            {
79                Self::base_type(&target).unwrap().root(target)
80            }
81
82            #[inline]
83            fn construct_type_with_env_uncached<'target, Tgt>(
84                target: Tgt,
85                _: &TypeVarEnv,
86            ) -> ValueData<'target, 'static, Tgt>
87            where
88                Tgt: Target<'target>,
89            {
90                Self::base_type(&target).unwrap().root(target)
91            }
92
93            #[inline]
94            fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
95            where
96                Tgt: Target<'target>,
97            {
98                let value = $path(target).as_value();
99                Some(value)
100            }
101        }
102    };
103}
104
105/// Construct a new `Core.AbstractChar` type object.
106pub struct AbstractChar;
107unsafe impl AbstractType for AbstractChar {}
108impl_construct_julia_type_abstract!(AbstractChar, "Core.AbstractChar");
109
110/// Construct a new `Core.AbstractFloat` type object.
111pub struct AbstractFloat;
112unsafe impl AbstractType for AbstractFloat {}
113impl_construct_julia_type_abstract_using!(AbstractFloat, DataType::floatingpoint_type);
114
115/// Construct a new `Core.AbstractString` type object.
116pub struct AbstractString;
117unsafe impl AbstractType for AbstractString {}
118impl_construct_julia_type_abstract!(AbstractString, "Core.AbstractString");
119
120/// Construct a new `Core.Exception` type object.
121pub struct Exception;
122unsafe impl AbstractType for Exception {}
123impl_construct_julia_type_abstract!(Exception, "Core.Exception");
124
125/// Construct a new `Core.AbstractFloat` type object.
126pub struct Function;
127unsafe impl AbstractType for Function {}
128impl_construct_julia_type_abstract_using!(Function, DataType::function_type);
129
130/// Construct a new `Core.IO` type object.
131pub struct IO;
132unsafe impl AbstractType for IO {}
133impl_construct_julia_type_abstract!(IO, "Core.IO");
134
135/// Construct a new `Core.Integer` type object.
136pub struct Integer;
137unsafe impl AbstractType for Integer {}
138impl_construct_julia_type_abstract!(Integer, "Core.Integer");
139
140/// Construct a new `Core.Real` type object.
141pub struct Real;
142unsafe impl AbstractType for Real {}
143impl_construct_julia_type_abstract!(Real, "Core.Real");
144
145/// Construct a new `Core.Number` type object.
146pub struct Number;
147unsafe impl AbstractType for Number {}
148impl_construct_julia_type_abstract_using!(Number, DataType::number_type);
149
150/// Construct a new `Core.Signed` type object.
151pub struct Signed;
152unsafe impl AbstractType for Signed {}
153impl_construct_julia_type_abstract_using!(Signed, DataType::signed_type);
154
155/// Construct a new `Core.Unsigned` type object.
156pub struct Unsigned;
157unsafe impl AbstractType for Unsigned {}
158impl_construct_julia_type_abstract!(Unsigned, "Core.Unsigned");
159
160/// Construct a new `Base.AbstractDisplay` type object.
161pub struct AbstractDisplay;
162unsafe impl AbstractType for AbstractDisplay {}
163impl_construct_julia_type_abstract!(AbstractDisplay, "Base.AbstractDisplay");
164
165/// Construct a new `Base.AbstractIrrational` type object.
166pub struct AbstractIrrational;
167unsafe impl AbstractType for AbstractIrrational {}
168impl_construct_julia_type_abstract!(AbstractIrrational, "Base.AbstractIrrational");
169
170/// Construct a new `Base.AbstractMatch` type object.
171pub struct AbstractMatch;
172unsafe impl AbstractType for AbstractMatch {}
173impl_construct_julia_type_abstract!(AbstractMatch, "Base.AbstractMatch");
174
175/// Construct a new `Base.AbstractPattern` type object.
176pub struct AbstractPattern;
177unsafe impl AbstractType for AbstractPattern {}
178impl_construct_julia_type_abstract!(AbstractPattern, "Base.AbstractPattern");
179
180/// Construct a new `Base.IndexStyle` type object.
181pub struct IndexStyle;
182unsafe impl AbstractType for IndexStyle {}
183impl_construct_julia_type_abstract!(IndexStyle, "Base.IndexStyle");
184
185/// Construct a new `Core.Signed` type object.
186pub struct AnyType;
187unsafe impl AbstractType for AnyType {}
188impl_construct_julia_type_abstract_using!(AnyType, DataType::any_type);
189
190/// Construct a new `AbstractArray` type object from the provided type parameters.
191pub struct AbstractArray<T: ConstructType, N: ConstructType> {
192    _type: PhantomData<T>,
193    _rank: PhantomData<N>,
194}
195
196unsafe impl<T: ConstructType, N: ConstructType> AbstractType for AbstractArray<T, N> {}
197
198unsafe impl<T: ConstructType, N: ConstructType> ConstructType for AbstractArray<T, N> {
199    type Static = AbstractArray<T::Static, N::Static>;
200
201    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
202    where
203        Tgt: Target<'target>,
204    {
205        target.with_local_scope::<_, 3>(|target, mut frame| {
206            let ty_param = T::construct_type(&mut frame);
207            let rank_param = N::construct_type(&mut frame);
208            let params = [ty_param, rank_param];
209            unsafe {
210                UnionAll::abstractarray_type(&frame)
211                    .as_value()
212                    .apply_type_unchecked(&mut frame, params)
213                    .cast_unchecked::<DataType>()
214                    .rewrap(target)
215            }
216        })
217    }
218
219    #[inline]
220    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
221    where
222        Tgt: Target<'target>,
223    {
224        Some(UnionAll::abstractarray_type(target).as_value())
225    }
226
227    fn construct_type_with_env_uncached<'target, Tgt>(
228        target: Tgt,
229        env: &TypeVarEnv,
230    ) -> ValueData<'target, 'static, Tgt>
231    where
232        Tgt: Target<'target>,
233    {
234        target.with_local_scope::<_, 3>(|target, mut frame| {
235            let ty_param = T::construct_type_with_env(&mut frame, env);
236            let rank_param = N::construct_type_with_env(&mut frame, env);
237            let params = [ty_param, rank_param];
238            unsafe {
239                UnionAll::abstractarray_type(&frame)
240                    .as_value()
241                    .apply_type_unchecked(&mut frame, params)
242                    .cast_unchecked::<DataType>()
243                    .wrap_with_env(target, env)
244            }
245        })
246    }
247}
248
249/// Construct a new `DenseArray` type object from the provided type parameters.
250pub struct DenseArray<T: ConstructType, N: ConstructType> {
251    _type: PhantomData<T>,
252    _rank: PhantomData<N>,
253}
254
255unsafe impl<T: ConstructType, N: ConstructType> AbstractType for DenseArray<T, N> {}
256
257unsafe impl<T: ConstructType, N: ConstructType> ConstructType for DenseArray<T, N> {
258    type Static = DenseArray<T::Static, N::Static>;
259
260    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
261    where
262        Tgt: Target<'target>,
263    {
264        target.with_local_scope::<_, 3>(|target, mut frame| {
265            let ty_param = T::construct_type(&mut frame);
266            let rank_param = N::construct_type(&mut frame);
267            let params = [ty_param, rank_param];
268            unsafe {
269                UnionAll::densearray_type(&frame)
270                    .as_value()
271                    .apply_type_unchecked(&mut frame, params)
272                    .cast_unchecked::<DataType>()
273                    .rewrap(target)
274            }
275        })
276    }
277
278    #[inline]
279    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
280    where
281        Tgt: Target<'target>,
282    {
283        Some(UnionAll::densearray_type(target).as_value())
284    }
285
286    fn construct_type_with_env_uncached<'target, Tgt>(
287        target: Tgt,
288        env: &TypeVarEnv,
289    ) -> ValueData<'target, 'static, Tgt>
290    where
291        Tgt: Target<'target>,
292    {
293        target.with_local_scope::<_, 3>(|target, mut frame| {
294            let ty_param = T::construct_type_with_env(&mut frame, env);
295            let rank_param = N::construct_type_with_env(&mut frame, env);
296            let params = [ty_param, rank_param];
297            unsafe {
298                UnionAll::densearray_type(&frame)
299                    .as_value()
300                    .apply_type_unchecked(&mut frame, params)
301                    .cast_unchecked::<DataType>()
302                    .wrap_with_env(target, env)
303            }
304        })
305    }
306}
307
308/// Construct a new `Ref` type object from the provided type parameters.
309pub struct RefTypeConstructor<T: ConstructType> {
310    _type: PhantomData<T>,
311}
312
313unsafe impl<T: ConstructType> AbstractType for RefTypeConstructor<T> {}
314
315unsafe impl<T: ConstructType> ConstructType for RefTypeConstructor<T> {
316    type Static = RefTypeConstructor<T::Static>;
317
318    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
319    where
320        Tgt: Target<'target>,
321    {
322        target.with_local_scope::<_, 2>(|target, mut frame| {
323            let ty_param = T::construct_type(&mut frame);
324            let params = [ty_param];
325            unsafe {
326                UnionAll::ref_type(&frame)
327                    .as_value()
328                    .apply_type_unchecked(&mut frame, params)
329                    .cast_unchecked::<DataType>()
330                    .rewrap(target)
331            }
332        })
333    }
334
335    #[inline]
336    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
337    where
338        Tgt: Target<'target>,
339    {
340        Some(UnionAll::ref_type(target).as_value())
341    }
342
343    fn construct_type_with_env_uncached<'target, Tgt>(
344        target: Tgt,
345        env: &TypeVarEnv,
346    ) -> ValueData<'target, 'static, Tgt>
347    where
348        Tgt: Target<'target>,
349    {
350        target.with_local_scope::<_, 2>(|target, mut frame| {
351            let ty_param = T::construct_type_with_env(&mut frame, env);
352            let params = [ty_param];
353            unsafe {
354                UnionAll::ref_type(&frame)
355                    .as_value()
356                    .apply_type_unchecked(&mut frame, params)
357                    .cast_unchecked::<DataType>()
358                    .wrap_with_env(target, env)
359            }
360        })
361    }
362}
363
364/// Construct a new `Type` type object from the provided type parameters.
365pub struct TypeTypeConstructor<T: ConstructType> {
366    _type: PhantomData<T>,
367}
368
369unsafe impl<T: ConstructType> AbstractType for TypeTypeConstructor<T> {}
370
371unsafe impl<T: ConstructType> ConstructType for TypeTypeConstructor<T> {
372    type Static = TypeTypeConstructor<T::Static>;
373
374    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
375    where
376        Tgt: Target<'target>,
377    {
378        target.with_local_scope::<_, 2>(|target, mut frame| {
379            let ty_param = T::construct_type(&mut frame);
380            let params = [ty_param];
381            unsafe {
382                UnionAll::type_type(&frame)
383                    .as_value()
384                    .apply_type_unchecked(&mut frame, params)
385                    .cast_unchecked::<DataType>()
386                    .rewrap(target)
387            }
388        })
389    }
390
391    #[inline]
392    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
393    where
394        Tgt: Target<'target>,
395    {
396        Some(UnionAll::type_type(target).as_value())
397    }
398
399    fn construct_type_with_env_uncached<'target, Tgt>(
400        target: Tgt,
401        env: &TypeVarEnv,
402    ) -> ValueData<'target, 'static, Tgt>
403    where
404        Tgt: Target<'target>,
405    {
406        target.with_local_scope::<_, 2>(|target, mut frame| {
407            let ty_param = T::construct_type_with_env(&mut frame, env);
408            let params = [ty_param];
409            unsafe {
410                UnionAll::type_type(&frame)
411                    .as_value()
412                    .apply_type_unchecked(&mut frame, params)
413                    .cast_unchecked::<DataType>()
414                    .wrap_with_env(target, env)
415            }
416        })
417    }
418}
419
420/// Construct a new `AbstractChannel` type object from the provided type parameters.
421pub struct AbstractChannel<T: ConstructType> {
422    _type: PhantomData<T>,
423}
424
425unsafe impl<T: ConstructType> AbstractType for AbstractChannel<T> {}
426
427unsafe impl<T: ConstructType> ConstructType for AbstractChannel<T> {
428    type Static = AbstractChannel<T::Static>;
429
430    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
431    where
432        Tgt: Target<'target>,
433    {
434        target.with_local_scope::<_, 2>(|target, mut frame| {
435            let ty_param = T::construct_type(&mut frame);
436            let params = [ty_param];
437            unsafe {
438                Self::base_type(&frame)
439                    .unwrap()
440                    .apply_type_unchecked(&mut frame, params)
441                    .cast_unchecked::<DataType>()
442                    .rewrap(target)
443            }
444        })
445    }
446
447    #[inline]
448    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
449    where
450        Tgt: Target<'target>,
451    {
452        let value = inline_static_ref!(STATIC, Value, "Base.AbstractChannel", target);
453        Some(value)
454    }
455
456    fn construct_type_with_env_uncached<'target, Tgt>(
457        target: Tgt,
458        env: &TypeVarEnv,
459    ) -> ValueData<'target, 'static, Tgt>
460    where
461        Tgt: Target<'target>,
462    {
463        target.with_local_scope::<_, 2>(|target, mut frame| {
464            let ty_param = T::construct_type_with_env(&mut frame, env);
465            let params = [ty_param];
466            unsafe {
467                Self::base_type(&frame)
468                    .unwrap()
469                    .apply_type_unchecked(&mut frame, params)
470                    .cast_unchecked::<DataType>()
471                    .wrap_with_env(target, env)
472            }
473        })
474    }
475}
476
477/// Construct a new `AbstractDict` type object from the provided type parameters.
478pub struct AbstractDict<K: ConstructType, V: ConstructType> {
479    _key: PhantomData<K>,
480    _value: PhantomData<V>,
481}
482
483unsafe impl<T: ConstructType, K: ConstructType> AbstractType for AbstractDict<T, K> {}
484
485unsafe impl<K: ConstructType, V: ConstructType> ConstructType for AbstractDict<K, V> {
486    type Static = AbstractDict<K::Static, V::Static>;
487
488    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
489    where
490        Tgt: Target<'target>,
491    {
492        target.with_local_scope::<_, 3>(|target, mut frame| {
493            let key_param = K::construct_type(&mut frame);
494            let value_param = V::construct_type(&mut frame);
495            let params = [key_param, value_param];
496            unsafe {
497                Self::base_type(&frame)
498                    .unwrap()
499                    .apply_type_unchecked(&mut frame, params)
500                    .cast_unchecked::<DataType>()
501                    .rewrap(target)
502            }
503        })
504    }
505
506    #[inline]
507    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
508    where
509        Tgt: Target<'target>,
510    {
511        let value = inline_static_ref!(STATIC, Value, "Base.AbstractDict", target);
512        Some(value)
513    }
514
515    fn construct_type_with_env_uncached<'target, Tgt>(
516        target: Tgt,
517        env: &TypeVarEnv,
518    ) -> ValueData<'target, 'static, Tgt>
519    where
520        Tgt: Target<'target>,
521    {
522        target.with_local_scope::<_, 3>(|target, mut frame| {
523            let key_param = K::construct_type_with_env(&mut frame, env);
524            let value_param = V::construct_type_with_env(&mut frame, env);
525            let params = [key_param, value_param];
526            unsafe {
527                Self::base_type(&frame)
528                    .unwrap()
529                    .apply_type_unchecked(&mut frame, params)
530                    .cast_unchecked::<DataType>()
531                    .wrap_with_env(target, env)
532            }
533        })
534    }
535}
536
537/// Construct a new `AbstractMatrix` type object from the provided type parameters.
538pub struct AbstractMatrix<T: ConstructType> {
539    _type: PhantomData<T>,
540}
541
542unsafe impl<T: ConstructType> AbstractType for AbstractMatrix<T> {}
543
544unsafe impl<T: ConstructType> ConstructType for AbstractMatrix<T> {
545    type Static = AbstractMatrix<T::Static>;
546
547    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
548    where
549        Tgt: Target<'target>,
550    {
551        target.with_local_scope::<_, 2>(|target, mut frame| {
552            let ty_param = T::construct_type(&mut frame);
553            let params = [ty_param];
554            unsafe {
555                Self::base_type(&frame)
556                    .unwrap()
557                    .apply_type_unchecked(&mut frame, params)
558                    .cast_unchecked::<DataType>()
559                    .rewrap(target)
560            }
561        })
562    }
563
564    #[inline]
565    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
566    where
567        Tgt: Target<'target>,
568    {
569        let value = inline_static_ref!(STATIC, Value, "Base.AbstractMatrix", target);
570        Some(value)
571    }
572
573    fn construct_type_with_env_uncached<'target, Tgt>(
574        target: Tgt,
575        env: &TypeVarEnv,
576    ) -> ValueData<'target, 'static, Tgt>
577    where
578        Tgt: Target<'target>,
579    {
580        target.with_local_scope::<_, 2>(|target, mut frame| {
581            let ty_param = T::construct_type_with_env(&mut frame, env);
582            let params = [ty_param];
583            unsafe {
584                Self::base_type(&frame)
585                    .unwrap()
586                    .apply_type_unchecked(&mut frame, params)
587                    .cast_unchecked::<DataType>()
588                    .wrap_with_env(target, env)
589            }
590        })
591    }
592}
593
594/// Construct a new `AbstractRange` type object from the provided type parameters.
595pub struct AbstractRange<T: ConstructType> {
596    _type: PhantomData<T>,
597}
598
599unsafe impl<T: ConstructType> AbstractType for AbstractRange<T> {}
600
601unsafe impl<T: ConstructType> ConstructType for AbstractRange<T> {
602    type Static = AbstractRange<T::Static>;
603
604    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
605    where
606        Tgt: Target<'target>,
607    {
608        target.with_local_scope::<_, 2>(|target, mut frame| {
609            let ty_param = T::construct_type(&mut frame);
610            let params = [ty_param];
611            unsafe {
612                Self::base_type(&frame)
613                    .unwrap()
614                    .apply_type_unchecked(&mut frame, params)
615                    .cast_unchecked::<DataType>()
616                    .rewrap(target)
617            }
618        })
619    }
620
621    #[inline]
622    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
623    where
624        Tgt: Target<'target>,
625    {
626        let value = inline_static_ref!(STATIC, Value, "Base.AbstractRange", target);
627        Some(value)
628    }
629
630    fn construct_type_with_env_uncached<'target, Tgt>(
631        target: Tgt,
632        env: &TypeVarEnv,
633    ) -> ValueData<'target, 'static, Tgt>
634    where
635        Tgt: Target<'target>,
636    {
637        target.with_local_scope::<_, 2>(|target, mut frame| {
638            let ty_param = T::construct_type_with_env(&mut frame, env);
639            let params = [ty_param];
640            unsafe {
641                Self::base_type(&frame)
642                    .unwrap()
643                    .apply_type_unchecked(&mut frame, params)
644                    .cast_unchecked::<DataType>()
645                    .wrap_with_env(target, env)
646            }
647        })
648    }
649}
650
651/// Construct a new `AbstractSet` type object from the provided type parameters.
652pub struct AbstractSet<T: ConstructType> {
653    _type: PhantomData<T>,
654}
655
656unsafe impl<T: ConstructType> AbstractType for AbstractSet<T> {}
657
658unsafe impl<T: ConstructType> ConstructType for AbstractSet<T> {
659    type Static = AbstractSet<T::Static>;
660
661    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
662    where
663        Tgt: Target<'target>,
664    {
665        target.with_local_scope::<_, 2>(|target, mut frame| {
666            let ty_param = T::construct_type(&mut frame);
667            let params = [ty_param];
668            unsafe {
669                Self::base_type(&frame)
670                    .unwrap()
671                    .apply_type_unchecked(&mut frame, params)
672                    .cast_unchecked::<DataType>()
673                    .rewrap(target)
674            }
675        })
676    }
677
678    #[inline]
679    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
680    where
681        Tgt: Target<'target>,
682    {
683        let value = inline_static_ref!(STATIC, Value, "Base.AbstractSet", target);
684        Some(value)
685    }
686
687    fn construct_type_with_env_uncached<'target, Tgt>(
688        target: Tgt,
689        env: &TypeVarEnv,
690    ) -> ValueData<'target, 'static, Tgt>
691    where
692        Tgt: Target<'target>,
693    {
694        target.with_local_scope::<_, 2>(|target, mut frame| {
695            let ty_param = T::construct_type_with_env(&mut frame, env);
696            let params = [ty_param];
697            unsafe {
698                Self::base_type(&frame)
699                    .unwrap()
700                    .apply_type_unchecked(&mut frame, params)
701                    .cast_unchecked::<DataType>()
702                    .wrap_with_env(target, env)
703            }
704        })
705    }
706}
707
708/// Construct a new `AbstractSlices` type object from the provided type parameters.
709pub struct AbstractSlices<T: ConstructType, N: ConstructType> {
710    _type: PhantomData<T>,
711    _n: PhantomData<N>,
712}
713
714unsafe impl<T: ConstructType, N: ConstructType> AbstractType for AbstractSlices<T, N> {}
715
716unsafe impl<T: ConstructType, N: ConstructType> ConstructType for AbstractSlices<T, N> {
717    type Static = AbstractSlices<T::Static, N::Static>;
718
719    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
720    where
721        Tgt: Target<'target>,
722    {
723        target.with_local_scope::<_, 3>(|target, mut frame| {
724            let ty_param = T::construct_type(&mut frame);
725            let n_param = N::construct_type(&mut frame);
726            let params = [ty_param, n_param];
727            unsafe {
728                Self::base_type(&frame)
729                    .unwrap()
730                    .apply_type_unchecked(&mut frame, params)
731                    .cast_unchecked::<DataType>()
732                    .rewrap(target)
733            }
734        })
735    }
736
737    fn construct_type_with_env_uncached<'target, Tgt>(
738        target: Tgt,
739        env: &TypeVarEnv,
740    ) -> ValueData<'target, 'static, Tgt>
741    where
742        Tgt: Target<'target>,
743    {
744        target.with_local_scope::<_, 3>(|target, mut frame| {
745            let ty_param = T::construct_type_with_env(&mut frame, env);
746            let n_param = N::construct_type_with_env(&mut frame, env);
747            let params = [ty_param, n_param];
748            unsafe {
749                Self::base_type(&frame)
750                    .unwrap()
751                    .apply_type_unchecked(&mut frame, params)
752                    .cast_unchecked::<DataType>()
753                    .wrap_with_env(target, env)
754            }
755        })
756    }
757
758    #[inline]
759    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
760    where
761        Tgt: Target<'target>,
762    {
763        let value = inline_static_ref!(STATIC, Value, "Base.AbstractSlices", target);
764        Some(value)
765    }
766}
767
768/// Construct a new `AbstractUnitRange` type object from the provided type parameters.
769pub struct AbstractUnitRange<T: ConstructType> {
770    _type: PhantomData<T>,
771}
772
773unsafe impl<T: ConstructType> ConstructType for AbstractUnitRange<T> {
774    type Static = AbstractUnitRange<T::Static>;
775
776    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
777    where
778        Tgt: Target<'target>,
779    {
780        target.with_local_scope::<_, 2>(|target, mut frame| {
781            let ty_param = T::construct_type(&mut frame);
782            let params = [ty_param];
783            unsafe {
784                Self::base_type(&frame)
785                    .unwrap()
786                    .apply_type_unchecked(&mut frame, params)
787                    .cast_unchecked::<DataType>()
788                    .rewrap(target)
789            }
790        })
791    }
792
793    fn construct_type_with_env_uncached<'target, Tgt>(
794        target: Tgt,
795        env: &TypeVarEnv,
796    ) -> ValueData<'target, 'static, Tgt>
797    where
798        Tgt: Target<'target>,
799    {
800        target.with_local_scope::<_, 2>(|target, mut frame| {
801            let ty_param = T::construct_type_with_env(&mut frame, env);
802            let params = [ty_param];
803            unsafe {
804                Self::base_type(&frame)
805                    .unwrap()
806                    .apply_type_unchecked(&mut frame, params)
807                    .cast_unchecked::<DataType>()
808                    .wrap_with_env(target, env)
809            }
810        })
811    }
812
813    #[inline]
814    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
815    where
816        Tgt: Target<'target>,
817    {
818        let value = inline_static_ref!(STATIC, Value, "Base.AbstractUnitRange", target);
819        Some(value)
820    }
821}
822
823unsafe impl<T: ConstructType> AbstractType for AbstractUnitRange<T> {}
824
825/// Construct a new `AbstractVector` type object from the provided type parameters.
826pub struct AbstractVector<T: ConstructType> {
827    _type: PhantomData<T>,
828}
829
830unsafe impl<T: ConstructType> AbstractType for AbstractVector<T> {}
831
832unsafe impl<T: ConstructType> ConstructType for AbstractVector<T> {
833    type Static = AbstractVector<T::Static>;
834
835    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
836    where
837        Tgt: Target<'target>,
838    {
839        target.with_local_scope::<_, 2>(|target, mut frame| {
840            let ty_param = T::construct_type(&mut frame);
841            let params = [ty_param];
842            unsafe {
843                Self::base_type(&frame)
844                    .unwrap()
845                    .apply_type_unchecked(&mut frame, params)
846                    .cast_unchecked::<DataType>()
847                    .rewrap(target)
848            }
849        })
850    }
851
852    fn construct_type_with_env_uncached<'target, Tgt>(
853        target: Tgt,
854        env: &TypeVarEnv,
855    ) -> ValueData<'target, 'static, Tgt>
856    where
857        Tgt: Target<'target>,
858    {
859        target.with_local_scope::<_, 2>(|target, mut frame| {
860            let ty_param = T::construct_type_with_env(&mut frame, env);
861            let params = [ty_param];
862            unsafe {
863                Self::base_type(&frame)
864                    .unwrap()
865                    .apply_type_unchecked(&mut frame, params)
866                    .cast_unchecked::<DataType>()
867                    .wrap_with_env(target, env)
868            }
869        })
870    }
871
872    #[inline]
873    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
874    where
875        Tgt: Target<'target>,
876    {
877        let value = inline_static_ref!(STATIC, Value, "Base.AbstractVector", target);
878        Some(value)
879    }
880}
881
882/// Construct a new `DenseMatrix` type object from the provided type parameters.
883pub struct DenseMatrix<T: ConstructType> {
884    _type: PhantomData<T>,
885}
886
887unsafe impl<T: ConstructType> AbstractType for DenseMatrix<T> {}
888
889unsafe impl<T: ConstructType> ConstructType for DenseMatrix<T> {
890    type Static = DenseMatrix<T::Static>;
891
892    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
893    where
894        Tgt: Target<'target>,
895    {
896        target.with_local_scope::<_, 2>(|target, mut frame| {
897            let ty_param = T::construct_type(&mut frame);
898            let params = [ty_param];
899            unsafe {
900                Self::base_type(&frame)
901                    .unwrap()
902                    .apply_type_unchecked(&mut frame, params)
903                    .cast_unchecked::<DataType>()
904                    .rewrap(target)
905            }
906        })
907    }
908
909    fn construct_type_with_env_uncached<'target, Tgt>(
910        target: Tgt,
911        env: &TypeVarEnv,
912    ) -> ValueData<'target, 'static, Tgt>
913    where
914        Tgt: Target<'target>,
915    {
916        target.with_local_scope::<_, 2>(|target, mut frame| {
917            let ty_param = T::construct_type_with_env(&mut frame, env);
918            let params = [ty_param];
919            unsafe {
920                Self::base_type(&frame)
921                    .unwrap()
922                    .apply_type_unchecked(&mut frame, params)
923                    .cast_unchecked::<DataType>()
924                    .wrap_with_env(target, env)
925            }
926        })
927    }
928
929    #[inline]
930    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
931    where
932        Tgt: Target<'target>,
933    {
934        let value = inline_static_ref!(STATIC, Value, "Base.DenseMatrix", target);
935        Some(value)
936    }
937}
938
939/// Construct a new `DenseVector` type object from the provided type parameters.
940pub struct DenseVector<T: ConstructType> {
941    _type: PhantomData<T>,
942}
943
944unsafe impl<T: ConstructType> AbstractType for DenseVector<T> {}
945
946unsafe impl<T: ConstructType> ConstructType for DenseVector<T> {
947    type Static = DenseVector<T::Static>;
948
949    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
950    where
951        Tgt: Target<'target>,
952    {
953        target.with_local_scope::<_, 2>(|target, mut frame| {
954            let ty_param = T::construct_type(&mut frame);
955            let params = [ty_param];
956            unsafe {
957                Self::base_type(&frame)
958                    .unwrap()
959                    .apply_type_unchecked(&mut frame, params)
960                    .cast_unchecked::<DataType>()
961                    .rewrap(target)
962            }
963        })
964    }
965
966    fn construct_type_with_env_uncached<'target, Tgt>(
967        target: Tgt,
968        env: &TypeVarEnv,
969    ) -> ValueData<'target, 'static, Tgt>
970    where
971        Tgt: Target<'target>,
972    {
973        target.with_local_scope::<_, 2>(|target, mut frame| {
974            let ty_param = T::construct_type_with_env(&mut frame, env);
975            let params = [ty_param];
976            unsafe {
977                Self::base_type(&frame)
978                    .unwrap()
979                    .apply_type_unchecked(&mut frame, params)
980                    .cast_unchecked::<DataType>()
981                    .wrap_with_env(target, env)
982            }
983        })
984    }
985
986    #[inline]
987    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
988    where
989        Tgt: Target<'target>,
990    {
991        let value = inline_static_ref!(STATIC, Value, "Base.DenseVector", target);
992        Some(value)
993    }
994}
995
996/// Construct a new `Enum` type object from the provided type parameters.
997pub struct Enum<T: ConstructType> {
998    _type: PhantomData<T>,
999}
1000
1001unsafe impl<T: ConstructType> AbstractType for Enum<T> {}
1002
1003unsafe impl<T: ConstructType> ConstructType for Enum<T> {
1004    type Static = Enum<T::Static>;
1005
1006    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
1007    where
1008        Tgt: Target<'target>,
1009    {
1010        target.with_local_scope::<_, 3>(|target, mut frame| {
1011            let ty_param = T::construct_type(&mut frame);
1012
1013            // Validate bound
1014            match ty_param.cast::<TypeVar>() {
1015                Ok(tvar) => unsafe {
1016                    let ub = tvar.upper_bound(&frame).as_value();
1017                    assert!(ub.subtype(Integer::construct_type(&mut frame)));
1018                },
1019                _ => {
1020                    assert!(ty_param.subtype(Integer::construct_type(&mut frame)));
1021                }
1022            }
1023
1024            let params = [ty_param];
1025
1026            unsafe {
1027                Self::base_type(&frame)
1028                    .unwrap()
1029                    .apply_type_unchecked(&mut frame, params)
1030                    .cast_unchecked::<DataType>()
1031                    .rewrap(target)
1032            }
1033        })
1034    }
1035
1036    fn construct_type_with_env_uncached<'target, Tgt>(
1037        target: Tgt,
1038        env: &TypeVarEnv,
1039    ) -> ValueData<'target, 'static, Tgt>
1040    where
1041        Tgt: Target<'target>,
1042    {
1043        target.with_local_scope::<_, 3>(|target, mut frame| {
1044            let ty_param = T::construct_type_with_env(&mut frame, env);
1045
1046            // Validate bound
1047            match ty_param.cast::<TypeVar>() {
1048                Ok(tvar) => unsafe {
1049                    let ub = tvar.upper_bound(&frame).as_value();
1050                    assert!(ub.subtype(Integer::construct_type_with_env(&mut frame, env)));
1051                },
1052                _ => {
1053                    assert!(ty_param.subtype(Integer::construct_type_with_env(&mut frame, env)));
1054                }
1055            }
1056
1057            let params = [ty_param];
1058
1059            unsafe {
1060                Self::base_type(&frame)
1061                    .unwrap()
1062                    .apply_type_unchecked(&mut frame, params)
1063                    .cast_unchecked::<DataType>()
1064                    .wrap_with_env(target, env)
1065            }
1066        })
1067    }
1068
1069    #[inline]
1070    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
1071    where
1072        Tgt: Target<'target>,
1073    {
1074        let value = inline_static_ref!(STATIC, Value, "Base.Enum", target);
1075        Some(value)
1076    }
1077}
1078
1079/// Construct a new `OrdinalRange` type object from the provided type parameters.
1080pub struct OrdinalRange<T: ConstructType, S: ConstructType> {
1081    _type: PhantomData<T>,
1082    _s: PhantomData<S>,
1083}
1084
1085unsafe impl<T: ConstructType, S: ConstructType> AbstractType for OrdinalRange<T, S> {}
1086
1087unsafe impl<T: ConstructType, S: ConstructType> ConstructType for OrdinalRange<T, S> {
1088    type Static = OrdinalRange<T::Static, S::Static>;
1089
1090    fn construct_type_uncached<'target, Tgt>(target: Tgt) -> ValueData<'target, 'static, Tgt>
1091    where
1092        Tgt: Target<'target>,
1093    {
1094        target.with_local_scope::<_, 3>(|target, mut frame| {
1095            let ty_param = T::construct_type(&mut frame);
1096            let n_param = S::construct_type(&mut frame);
1097            let params = [ty_param, n_param];
1098            unsafe {
1099                Self::base_type(&frame)
1100                    .unwrap()
1101                    .apply_type_unchecked(&mut frame, params)
1102                    .cast_unchecked::<DataType>()
1103                    .rewrap(target)
1104            }
1105        })
1106    }
1107
1108    fn construct_type_with_env_uncached<'target, Tgt>(
1109        target: Tgt,
1110        env: &TypeVarEnv,
1111    ) -> ValueData<'target, 'static, Tgt>
1112    where
1113        Tgt: Target<'target>,
1114    {
1115        target.with_local_scope::<_, 3>(|target, mut frame| {
1116            let ty_param = T::construct_type_with_env(&mut frame, env);
1117            let n_param = S::construct_type_with_env(&mut frame, env);
1118            let params = [ty_param, n_param];
1119            unsafe {
1120                Self::base_type(&frame)
1121                    .unwrap()
1122                    .apply_type_unchecked(&mut frame, params)
1123                    .cast_unchecked::<DataType>()
1124                    .wrap_with_env(target, env)
1125            }
1126        })
1127    }
1128
1129    #[inline]
1130    fn base_type<'target, Tgt>(target: &Tgt) -> Option<Value<'target, 'static>>
1131    where
1132        Tgt: Target<'target>,
1133    {
1134        let value = inline_static_ref!(STATIC, Value, "Base.OrdinalRange", target);
1135        Some(value)
1136    }
1137}
1138
1139/*
1140function print_vars(ty)
1141    while ty isa UnionAll
1142        println("  ", ty.var)
1143        ty = ty.body
1144    end
1145end
1146
1147function list_abstract_type()
1148    for name in names(Core)
1149        item = getglobal(Core, name)
1150        if isabstracttype(item)
1151            println("Core.", name)
1152            if item isa UnionAll
1153                print_vars(item)
1154            end
1155        end
1156    end
1157
1158    for name in names(Base)
1159        item = getglobal(Base, name)
1160        if isabstracttype(item)
1161            println("Base.", name)
1162            if item isa UnionAll
1163                print_vars(item)
1164            end
1165        end
1166    end
1167end
1168
1169
1170Abstract DataTypes:
1171
1172///Core.AbstractChar
1173///Core.AbstractFloat
1174///Core.AbstractString
1175///Core.Any
1176///Core.Exception
1177///Core.Function
1178///Core.IO
1179///Core.Integer
1180///Core.Number
1181///Core.Real
1182///Core.Signed
1183///Core.Unsigned
1184
1185///Base.AbstractDisplay
1186///Base.AbstractIrrational
1187///Base.AbstractMatch
1188///Base.AbstractPattern
1189///Base.IndexStyle
1190///
1191///
1192///Abstract UnionAlls:
1193///
1194///Core.AbstractArray{T,N}
1195///Core.DenseArray{T,N}
1196///Core.Ref{T}
1197///Core.Type{T}
1198///
1199///Base.AbstractChannel{T}
1200///Base.AbstractDict{K, V}
1201///Base.AbstractMatrix{T}
1202///Base.AbstractRange{T}
1203///Base.AbstractSet{T}
1204///Base.AbstractSlices{T,N}
1205///Base.AbstractUnitRange{T}
1206///Base.AbstractVector{T}
1207///Base.DenseMatrix{T}
1208///Base.DenseVector{T}
1209///Base.Enum{T<:Integer}
1210///Base.OrdinalRange{T,S}
1211///
1212/// TODO:
1213/// Base.AbstractLock
1214/// Base.IteratorSize
1215*/