@@ -71,6 +71,12 @@ pub fn recur(is_leaf: SigNode, children: SigNode, combine: SigNode, env: &mut Ui
71
71
scalar_child,
72
72
} ) = stack. pop ( )
73
73
{
74
+ env. respect_execution_limit ( ) ?;
75
+ if stack. len ( ) > 1_000_000 {
76
+ return Err ( env. error (
77
+ "recur reached more than 1 million nodes at once. The base case may be incorrect." ,
78
+ ) ) ;
79
+ }
74
80
// println!("value: {value:?}, parent: {parent:?}, child_nodes: {child_nodes:?}");
75
81
if let Some ( child_nodes) = child_nodes {
76
82
env. push_all (
@@ -144,21 +150,23 @@ pub fn recur(is_leaf: SigNode, children: SigNode, combine: SigNode, env: &mut Ui
144
150
env. push ( value. clone ( ) ) ;
145
151
env. exec ( children. clone ( ) ) ?;
146
152
let children = env. pop ( "child nodes" ) ?;
147
- let index = stack. len ( ) ;
148
- // println!("{value:?} has children {children:?}");
149
- stack. push ( RecNode {
150
- parent,
151
- value,
152
- child_nodes : Some ( Vec :: new ( ) ) ,
153
- scalar_child : children. rank ( ) == 0 ,
154
- } ) ;
155
- for value in children. into_rows ( ) {
153
+ if children. row_count ( ) > 0 {
154
+ let index = stack. len ( ) ;
155
+ // println!("{value:?} has children {children:?}");
156
156
stack. push ( RecNode {
157
- parent : Some ( index ) ,
157
+ parent,
158
158
value,
159
- child_nodes : None ,
160
- scalar_child : false ,
159
+ child_nodes : Some ( Vec :: new ( ) ) ,
160
+ scalar_child : children . rank ( ) == 0 ,
161
161
} ) ;
162
+ for value in children. into_rows ( ) {
163
+ stack. push ( RecNode {
164
+ parent : Some ( index) ,
165
+ value,
166
+ child_nodes : None ,
167
+ scalar_child : false ,
168
+ } ) ;
169
+ }
162
170
}
163
171
}
164
172
}
0 commit comments