Skip to content

Commit 5b4ada3

Browse files
committed
Fix bottom-up terminating early
1 parent e610f29 commit 5b4ada3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Diff for: src/bottom_up_iterator.jl

+14-7
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function combine(iter::BottomUpIterator, state)
180180
non_terminal_shapes = UniformHole.(partition(Hole(nonterminals), grammar), ([],))
181181

182182
# if we have exceeded the maximum number of programs to generate
183-
if max_in_bank >= state[:max]
183+
if max_in_bank >= state[:max_combination_depth]
184184
return nothing, nothing
185185
end
186186

@@ -241,9 +241,7 @@ end
241241
242242
Returns the initial state for the first `combine` call
243243
"""
244-
function init_combine_structure(iter::BottomUpIterator)
245-
Dict(:max => 4)
246-
end
244+
function init_combine_structure end
247245

248246

249247
"""
@@ -293,7 +291,7 @@ function _get_next_program(iter::BottomUpIterator, state::GenericBUState)
293291
end
294292
end
295293

296-
function derivation_heuristic(::BottomUpIterator, indices::Vector{Int})
294+
function derivation_heuristic(::BottomUpIterator, indices::Vector{Integer})
297295
return sort(indices);
298296
end
299297

@@ -346,14 +344,19 @@ function Base.iterate(iter::BottomUpIterator, state::GenericBUState)
346344
#program is `nothing`, so we stop
347345
return nothing
348346
elseif typeof(program_combination) == AccessAddress
347+
@error "Should never reach this branch with uniform trees"
349348
# we only need to access the program, it is already in the bank
350349
program = retrieve(iter, program_combination)
351350
solver = iter.solver
352351
uniform_solver = UniformSolver(get_grammar(solver), get_tree(solver), with_statistics=solver.statistics)
353352
new_state.current_uniform_iterator = UniformIterator(uniform_solver, iter)
354353
next_solution = next_solution!(state.current_uniform_iterator)
355354

356-
return next_solution, new_state
355+
if depth(next_solution) > iter.solver.max_depth
356+
return nothing
357+
else
358+
return next_solution, new_state
359+
end
357360
else
358361
# we have to combine programs from the bank
359362
# updates iter.solver with the combined program
@@ -371,7 +374,11 @@ function Base.iterate(iter::BottomUpIterator, state::GenericBUState)
371374
next_solution = next_solution!(state.current_uniform_iterator)
372375
# take the program (uniform tree) convert to UniformIterator, and add to state
373376
# return the first concrete tree from the UniformIterator in the state (and the updated state)
374-
return next_solution, new_state
377+
if depth(next_solution) > iter.solver.max_depth
378+
return nothing
379+
else
380+
return next_solution, new_state
381+
end
375382
else
376383
return Base.iterate(iter, new_state)
377384
end

0 commit comments

Comments
 (0)