Skip to content

Commit 9176004

Browse files
committed
Fix error message on failed unification
Sometimes, unification fails with a nonsensical error message like this. %***************************** failure ************************** %** %** Tell: [1] = [1] It appears that rebinding is not properly undone, and the two values are still aliased when producing the error message. Hence the confusing output. XXX: This fix works but I have no idea why.
1 parent 6c5ac7c commit 9176004

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

platform-test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(BASE_FUNCTORS
1313
#"finalize.oz" "gc.oz"
1414
"state.oz" "thread.oz"
1515
#"vm.oz" #FIXME vm tests are buggy, see #313.
16+
"unify.oz"
1617
"reflection.oz" "serializer.oz"
1718
)
1819
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/base")

platform-test/base/unify.oz

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
functor
2+
import
3+
VM
4+
export
5+
Return
6+
define
7+
Return = unify([vmlist(proc {$}
8+
try
9+
{VM.list} = unit
10+
fail
11+
catch failure(debug:d(info:[eq(unit _)] ...) ...) then
12+
skip
13+
end
14+
end
15+
keys:[unify])
16+
order(proc {$}
17+
fun {Const X} [1 2 X] end
18+
in
19+
try
20+
{Const 1} = {Const 2}
21+
fail
22+
catch failure(debug:d(info:[eq(1 2)] ...) ...) then
23+
skip
24+
end
25+
end
26+
keys:[unify])
27+
])
28+
end

vm/vm/main/unify.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,16 @@ bool StructuralDualWalk::processPair(VM vm, RichNode left, RichNode right) {
465465
}
466466

467467
void StructuralDualWalk::rebind(VM vm, RichNode left, RichNode right) {
468-
rebindTrail.push_back(vm, left.makeBackup());
469-
left.reinit(vm, right);
468+
// XXX: The test is to work around `a.reinit(vm, b)` where `b` is sometimes
469+
// modified. It is better to reinit Unstable nodes than Stable ones anyway.
470+
// See #312 for details.
471+
if (right.isStable()) {
472+
rebindTrail.push_back(vm, left.makeBackup());
473+
left.reinit(vm, right);
474+
} else {
475+
rebindTrail.push_back(vm, right.makeBackup());
476+
right.reinit(vm, left);
477+
}
470478
}
471479

472480
void StructuralDualWalk::cleanupOnFailure(VM vm) {

0 commit comments

Comments
 (0)