• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mattwparas / steel / 11924200389

20 Nov 2024 12:20AM UTC coverage: 46.725% (-0.2%) from 46.956%
11924200389

Pull #290

github

web-flow
Merge faebbd075 into a6f7286de
Pull Request #290: Fix provides within macros

37 of 263 new or added lines in 7 files covered. (14.07%)

27 existing lines in 11 files now uncovered.

12469 of 26686 relevant lines covered (46.72%)

483326.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/crates/steel-core/src/values/lists.rs
1
use std::cell::Cell;
2

3
use im_lists::handler::{DefaultDropHandler, DropHandler};
4

5
use crate::{
6
    gc::Gc,
7
    rvals::{FromSteelVal, IntoSteelVal},
8
    SteelVal,
9
};
10

11
// TODO:
12
// Builtin immutable pairs
13
#[derive(Clone, Hash)]
14
pub struct Pair {
15
    pub(crate) car: SteelVal,
16
    pub(crate) cdr: SteelVal,
17
}
18

19
impl Pair {
UNCOV
20
    pub fn cons(car: SteelVal, cdr: SteelVal) -> Self {
×
21
        Pair { car, cdr }
22
    }
23

24
    pub fn car(&self) -> SteelVal {
6,716✔
25
        self.car.clone()
6,716✔
26
    }
27

28
    pub fn cdr(&self) -> SteelVal {
194✔
29
        self.cdr.clone()
194✔
30
    }
31
}
32

33
impl From<Pair> for SteelVal {
34
    fn from(pair: Pair) -> Self {
137✔
35
        SteelVal::Pair(Gc::new(pair))
137✔
36
    }
37
}
38

39
impl std::fmt::Debug for Pair {
40
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
41
        write!(f, "({} . {})", &self.car, &self.cdr)
×
42
    }
43
}
44

45
#[cfg(feature = "without-drop-protection")]
46
type DropHandlerChoice = im_lists::handler::DefaultDropHandler;
47
#[cfg(not(feature = "without-drop-protection"))]
48
type DropHandlerChoice = list_drop_handler::ListDropHandler;
49

50
thread_local! {
51
    pub static DEPTH: Cell<usize> = Cell::new(0);
52
}
53

54
#[cfg(not(feature = "without-drop-protection"))]
55
mod list_drop_handler {
56

57
    use std::collections::VecDeque;
58

59
    use super::*;
60

61
    pub struct ListDropHandler;
62

63
    use crate::rvals::cycles::{drop_impls::DROP_BUFFER, IterativeDropHandler};
64

65
    impl DropHandler<im_lists::list::GenericList<SteelVal, PointerType, 4, 2, Self>>
66
        for ListDropHandler
67
    {
68
        fn drop_handler(obj: &mut im_lists::list::GenericList<SteelVal, PointerType, 4, 2, Self>) {
1,551,468✔
69
            if obj.strong_count() == 1 {
1,551,468✔
70
                if obj.is_empty() {
624,415✔
71
                    return;
461,950✔
72
                }
73

74
                if DROP_BUFFER
162,465✔
75
                    .try_with(|drop_buffer| {
324,930✔
76
                        if let Ok(mut drop_buffer) = drop_buffer.try_borrow_mut() {
324,908✔
77
                            // Optimistically check what these values are. If they're
78
                            // primitives, then we can just skip pushing them back
79
                            // entirely.
80
                            for value in std::mem::take(obj).draining_iterator() {
634,690✔
81
                                match &value {
634,690✔
82
                                    SteelVal::BoolV(_)
83
                                    | SteelVal::NumV(_)
84
                                    | SteelVal::IntV(_)
85
                                    | SteelVal::CharV(_)
86
                                    | SteelVal::Void
87
                                    | SteelVal::StringV(_)
88
                                    | SteelVal::FuncV(_)
89
                                    | SteelVal::SymbolV(_)
90
                                    | SteelVal::FutureFunc(_)
91
                                    | SteelVal::FutureV(_)
92
                                    | SteelVal::BoxedFunction(_)
93
                                    | SteelVal::MutFunc(_)
94
                                    | SteelVal::BuiltIn(_)
95
                                    | SteelVal::BigNum(_) => continue,
451,988✔
96
                                    _ => {
182,702✔
97
                                        drop_buffer.push_back(value);
182,702✔
98
                                    }
99
                                }
100
                            }
101

102
                            IterativeDropHandler::bfs(&mut drop_buffer);
162,443✔
103
                        } else {
104
                            let mut drop_buffer = VecDeque::new();
22✔
105

106
                            for value in std::mem::take(obj).draining_iterator() {
68✔
107
                                match &value {
46✔
108
                                    SteelVal::BoolV(_)
109
                                    | SteelVal::NumV(_)
110
                                    | SteelVal::IntV(_)
111
                                    | SteelVal::CharV(_)
112
                                    | SteelVal::Void
113
                                    | SteelVal::StringV(_)
114
                                    | SteelVal::FuncV(_)
115
                                    | SteelVal::SymbolV(_)
116
                                    | SteelVal::FutureFunc(_)
117
                                    | SteelVal::FutureV(_)
118
                                    | SteelVal::BoxedFunction(_)
119
                                    | SteelVal::MutFunc(_)
120
                                    | SteelVal::BuiltIn(_)
121
                                    | SteelVal::BigNum(_) => continue,
39✔
122
                                    _ => {
7✔
123
                                        drop_buffer.push_back(value);
7✔
124
                                    }
125
                                }
126
                            }
127

128
                            IterativeDropHandler::bfs(&mut drop_buffer);
22✔
129
                        }
130
                    })
131
                    .is_err()
132
                {
133
                    let mut drop_buffer = VecDeque::new();
×
134
                    for value in std::mem::take(obj).draining_iterator() {
×
135
                        match &value {
×
136
                            SteelVal::BoolV(_)
137
                            | SteelVal::NumV(_)
138
                            | SteelVal::IntV(_)
139
                            | SteelVal::CharV(_)
140
                            | SteelVal::Void
141
                            | SteelVal::StringV(_)
142
                            | SteelVal::FuncV(_)
143
                            | SteelVal::SymbolV(_)
144
                            | SteelVal::FutureFunc(_)
145
                            | SteelVal::FutureV(_)
146
                            | SteelVal::BoxedFunction(_)
147
                            | SteelVal::MutFunc(_)
148
                            | SteelVal::BuiltIn(_)
149
                            | SteelVal::BigNum(_) => continue,
×
150
                            _ => {
×
151
                                drop_buffer.push_back(value);
×
152
                            }
153
                        }
154
                    }
155

156
                    IterativeDropHandler::bfs(&mut drop_buffer);
×
157
                }
158
            }
159
        }
160
    }
161
}
162

163
#[cfg(not(feature = "sync"))]
164
type PointerType = im_lists::shared::RcPointer;
165

166
#[cfg(feature = "sync")]
167
type PointerType = im_lists::shared::ArcPointer;
168

169
pub type SteelList<T> = im_lists::list::GenericList<T, PointerType, 4, 2, DefaultDropHandler>;
170

171
pub type List<T> = im_lists::list::GenericList<T, PointerType, 4, 2, DropHandlerChoice>;
172

173
pub type ConsumingIterator<T> =
174
    im_lists::list::ConsumingIter<T, PointerType, 4, 2, DropHandlerChoice>;
175

176
impl<T: FromSteelVal + Clone, D: im_lists::handler::DropHandler<Self>> FromSteelVal
177
    for im_lists::list::GenericList<T, PointerType, 4, 2, D>
178
{
179
    fn from_steelval(val: &SteelVal) -> crate::rvals::Result<Self> {
18✔
180
        if let SteelVal::ListV(l) = val {
36✔
181
            l.iter().map(T::from_steelval).collect()
×
182
        } else {
183
            stop!(TypeMismatch => "Unable to convert SteelVal to List, found: {}", val);
×
184
        }
185
    }
186
}
187

188
impl<T: IntoSteelVal + Clone, D: im_lists::handler::DropHandler<Self>> IntoSteelVal
189
    for im_lists::list::GenericList<T, PointerType, 4, 2, D>
190
{
191
    fn into_steelval(self) -> crate::rvals::Result<SteelVal> {
10,590✔
192
        self.into_iter()
10,590✔
193
            .map(|x| x.into_steelval())
21,971✔
194
            .collect::<crate::rvals::Result<List<_>>>()
195
            .map(SteelVal::ListV)
10,590✔
196
    }
197
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc