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
use crate::{Platform, TargetFeatures};
use cfg_expr::targets::ALL_BUILTINS;
use proptest::collection::hash_set;
use proptest::prelude::*;
use proptest::sample::select;
impl<'a> Platform<'a> {
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    pub fn strategy(
        target_features: impl Strategy<Value = TargetFeatures<'a>> + 'a,
    ) -> impl Strategy<Value = Platform<'a>> + 'a {
        let flags = hash_set(flag_strategy(), 0..3);
        (0..ALL_BUILTINS.len(), target_features, flags).prop_map(|(idx, target_features, flags)| {
            let mut platform =
                Platform::new(ALL_BUILTINS[idx].triple, target_features).expect("known triple");
            platform.add_flags(flags);
            platform
        })
    }
    
    
    
    pub fn filtered_strategy(
        triple_filter: impl Fn(&'static str) -> bool,
        target_features: impl Strategy<Value = TargetFeatures<'a>> + 'a,
    ) -> impl Strategy<Value = Platform<'a>> + 'a {
        let filtered: Vec<_> = ALL_BUILTINS
            .iter()
            .filter(|target_info| triple_filter(target_info.triple))
            .collect();
        let flags = hash_set(flag_strategy(), 0..3);
        (0..filtered.len(), target_features, flags).prop_map(
            move |(idx, target_features, flags)| {
                let mut platform =
                    Platform::new(filtered[idx].triple, target_features).expect("known triple");
                platform.add_flags(flags);
                platform
            },
        )
    }
}
pub fn flag_strategy() -> impl Strategy<Value = &'static str> {
    static KNOWN_FLAGS: &[&str] = &["cargo_web", "test-flag", "abc", "foo", "bar", "flag-test"];
    select(KNOWN_FLAGS)
}
impl Arbitrary for TargetFeatures<'static> {
    type Parameters = ();
    type Strategy = BoxedStrategy<Self>;
    fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
        
        static KNOWN_FEATURES: &[&str] = &[
            "aes", "avx", "avx2", "bmi1", "bmi2", "fma", "rdrand", "sha", "sse", "sse2", "sse3",
            "sse4.1", "sse4.2", "ssse3", "xsave", "xsavec", "xsaveopt", "xsaves",
        ];
        prop_oneof![
            Just(TargetFeatures::Unknown),
            Just(TargetFeatures::All),
            hash_set(select(KNOWN_FEATURES), 0..8).prop_map(TargetFeatures::Features),
        ]
        .boxed()
    }
}