Skip to content

Commit

Permalink
Fix error message on failed unification
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
layus committed Aug 29, 2018
1 parent 6c5ac7c commit 9176004
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions platform-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(BASE_FUNCTORS
#"finalize.oz" "gc.oz"
"state.oz" "thread.oz"
#"vm.oz" #FIXME vm tests are buggy, see #313.
"unify.oz"
"reflection.oz" "serializer.oz"
)
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/base")
Expand Down
28 changes: 28 additions & 0 deletions platform-test/base/unify.oz
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
functor
import
VM
export
Return
define
Return = unify([vmlist(proc {$}
try
{VM.list} = unit
fail
catch failure(debug:d(info:[eq(unit _)] ...) ...) then
skip
end
end
keys:[unify])
order(proc {$}
fun {Const X} [1 2 X] end
in
try
{Const 1} = {Const 2}
fail
catch failure(debug:d(info:[eq(1 2)] ...) ...) then
skip
end
end
keys:[unify])
])
end
12 changes: 10 additions & 2 deletions vm/vm/main/unify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,16 @@ bool StructuralDualWalk::processPair(VM vm, RichNode left, RichNode right) {
}

void StructuralDualWalk::rebind(VM vm, RichNode left, RichNode right) {
rebindTrail.push_back(vm, left.makeBackup());
left.reinit(vm, right);
// XXX: The test is to work around `a.reinit(vm, b)` where `b` is sometimes
// modified. It is better to reinit Unstable nodes than Stable ones anyway.
// See #312 for details.
if (right.isStable()) {
rebindTrail.push_back(vm, left.makeBackup());
left.reinit(vm, right);
} else {
rebindTrail.push_back(vm, right.makeBackup());
right.reinit(vm, left);
}
}

void StructuralDualWalk::cleanupOnFailure(VM vm) {
Expand Down

0 comments on commit 9176004

Please sign in to comment.