@@ -107,6 +107,9 @@ impl Chunker {
107
107
let mut call_stack_undo = vec ! [ ] ;
108
108
let mut chunk_len_undo = 0 ;
109
109
let mut num_unclosed_ifs_undo = 0 ;
110
+
111
+ let max_depth = 3 ;
112
+ let mut depth = 0 ;
110
113
111
114
loop {
112
115
let builder = match self . call_stack . pop ( ) {
@@ -148,10 +151,11 @@ impl Chunker {
148
151
chunk_len_undo += block_len;
149
152
num_unclosed_ifs_undo += script_unclosed_ifs;
150
153
}
154
+ depth = 0 ;
151
155
num_unclosed_ifs += script_unclosed_ifs;
152
156
chunk_len += block_len;
153
157
} else if chunk_len + block_len > self . target_chunk_size
154
- && ( chunk_len < self . target_chunk_size - self . tolerance || chunk_len == 0 )
158
+ && ( chunk_len < self . target_chunk_size - self . tolerance || chunk_len == 0 || depth <= max_depth )
155
159
{
156
160
//println!("[INFO] Chunking a call now.");
157
161
// Case 3: Current builder too large and there is no acceptable solution yet
@@ -177,14 +181,16 @@ impl Chunker {
177
181
}
178
182
}
179
183
}
180
- assert ! ( contains_call, "No support for chunking up ScriptBufs" ) ;
184
+ assert ! ( contains_call || depth <= max_depth, "No support for chunking up ScriptBufs, depth: {}" , depth) ;
185
+ depth += 1 ;
181
186
} else {
182
187
call_stack_undo. push ( Box :: new ( builder) ) ;
183
188
break ;
184
189
}
185
190
}
186
191
187
192
// Undo the lately added scripts if we are not closing all ifs with them.
193
+ // TODO: This is an issue because we may remove way more than necessary.
188
194
if num_unclosed_ifs != 0 {
189
195
println ! ( "[INFO] Unable to close all ifs. Undoing the added scripts to the point where num_unclosed_ifs was 0." ) ;
190
196
num_unclosed_ifs -= num_unclosed_ifs_undo;
0 commit comments