Skip to content

Commit 49014fe

Browse files
authored
Fix right-side can_add indexing in sls_seq_plugin edit-distance repair (#9773)
`seq_plugin::edit_distance_with_updates` used the left-string DP index when checking whether the right string could accept an insertion from the `d[i][j - 1]` transition. This miscomputed updateable edit distance and could suppress valid repair proposals when `i != j`. - **Bug fix** - Change the right-side insertion guard in `src/ast/sls/sls_seq_plugin.cpp` from `b.can_add(i - 1)` to `b.can_add(j - 1)`. - This aligns the mutability check with the DP transition being evaluated and with the existing update-generation logic below it. - **Regression coverage** - Add a focused test in `src/test/sls_seq_plugin.cpp` for an asymmetric variable/value layout on the right-hand side. - The test asserts that the repair logic admits the right-side add at `j - 1`, which is the case that the previous index mixup could reject. - **Reference** - The updated condition now matches the intended transition semantics: ```cpp if (d[i][j - 1] < u[i][j] && b.can_add(j - 1)) { m_string_updates.reset(); u[i][j] = d[i][j - 1]; } ``` --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent aa872bd commit 49014fe

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/ast/sls/sls_seq_plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ namespace sls {
912912
m_string_updates.reset();
913913
u[i][j] = d[i - 1][j];
914914
}
915-
if (d[i][j - 1] < u[i][j] && b.can_add(i - 1)) {
915+
if (d[i][j - 1] < u[i][j] && b.can_add(j - 1)) {
916916
m_string_updates.reset();
917917
u[i][j] = d[i][j - 1];
918918
}

src/test/sls_seq_plugin.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,28 @@ void tst_sls_seq_plugin() {
351351
app_ref eq(m.mk_eq(l, r), m);
352352
verbose_stream() << eq << "\n";
353353
ts.repair_down_str_eq_edit_distance_incremental(eq);
354+
355+
test_seq::string_instance lhs, rhs;
356+
lhs.s = zstring("a");
357+
lhs.is_value.push_back(false);
358+
lhs.prev_is_var.push_back(false);
359+
lhs.next_is_var.push_back(false);
360+
rhs.s = zstring("ab");
361+
rhs.is_value.push_back(true);
362+
rhs.prev_is_var.push_back(false);
363+
rhs.next_is_var.push_back(false);
364+
rhs.is_value.push_back(false);
365+
rhs.prev_is_var.push_back(false);
366+
rhs.next_is_var.push_back(false);
367+
368+
ENSURE(ts.edit_distance_with_updates(lhs, rhs) == 0);
369+
ENSURE(ts.m_string_updates.size() == 2);
370+
ENSURE(ts.m_string_updates[0].side == test_seq::side_t::right);
371+
ENSURE(ts.m_string_updates[0].op == test_seq::op_t::add);
372+
ENSURE(ts.m_string_updates[0].i == 0);
373+
ENSURE(ts.m_string_updates[0].j == 1);
374+
ENSURE(ts.m_string_updates[1].side == test_seq::side_t::right);
375+
ENSURE(ts.m_string_updates[1].op == test_seq::op_t::del);
376+
ENSURE(ts.m_string_updates[1].i == 1);
377+
ENSURE(ts.m_string_updates[1].j == 0);
354378
}

0 commit comments

Comments
 (0)