[m-dev.] diff: fix tabling nonlocals bug
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Apr 3 21:11:21 AEST 2000
Estimated hours taken: 2
compiler/table_gen.m:
Fix a bug: it was computing the non-locals set incorrectly,
in cases where the goal for the tabled predicate did not
use all of the head variables for that predicate.
tests/tabling/Mmakefile:
tests/tabling/unused_args.m:
tests/tabling/unused_args.exp:
Add a regression test for this bug.
Workspace: /home/mercury0/fjh/mercury
Index: compiler/table_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/table_gen.m,v
retrieving revision 1.17
diff -u -d -r1.17 table_gen.m
--- compiler/table_gen.m 2000/03/13 02:23:08 1.17
+++ compiler/table_gen.m 2000/04/03 10:56:34
@@ -301,8 +301,12 @@
table_gen__create_new_det_goal(EvalMethod, OrigGoal, PredId, ProcId,
HeadVars, HeadVarModes, VarTypes0, VarTypes,
VarSet0, VarSet, TableInfo0, TableInfo, Goal) :-
+ % even if the original goal doesn't use all of the headvars,
+ % the code generated by the tabling transformation does,
+ % so we need to compute the nonlocals from the headvars rather
+ % than getting it from the nonlocals field in the original goal
+ set__list_to_set(HeadVars, OrigNonLocals),
OrigGoal = _ - OrigGoalInfo,
- goal_info_get_nonlocals(OrigGoalInfo, OrigNonLocals),
goal_info_get_instmap_delta(OrigGoalInfo, OrigInstMapDelta),
goal_info_get_context(OrigGoalInfo, Context),
@@ -392,8 +396,12 @@
table_gen__create_new_semi_goal(EvalMethod, OrigGoal, PredId, ProcId,
HeadVars, HeadVarModes, VarTypes0, VarTypes,
VarSet0, VarSet, TableInfo0, TableInfo, Goal) :-
+ % even if the original goal doesn't use all of the headvars,
+ % the code generated by the tabling transformation does,
+ % so we need to compute the nonlocals from the headvars rather
+ % than getting it from the nonlocals field in the original goal
+ set__list_to_set(HeadVars, OrigNonLocals),
OrigGoal = _ - OrigGoalInfo,
- goal_info_get_nonlocals(OrigGoalInfo, OrigNonLocals),
goal_info_get_instmap_delta(OrigGoalInfo, OrigInstMapDelta),
goal_info_get_context(OrigGoalInfo, Context),
@@ -538,8 +546,12 @@
table_gen__create_new_non_goal(EvalMethod, OrigGoal, PredId, ProcId,
HeadVars, HeadVarModes, VarTypes0, VarTypes,
VarSet0, VarSet, TableInfo0, TableInfo, Goal) :-
+ % even if the original goal doesn't use all of the headvars,
+ % the code generated by the tabling transformation does,
+ % so we need to compute the nonlocals from the headvars rather
+ % than getting it from the nonlocals field in the original goal
+ set__list_to_set(HeadVars, OrigNonLocals),
OrigGoal = _ - OrigGoalInfo,
- goal_info_get_nonlocals(OrigGoalInfo, OrigNonLocals),
goal_info_get_instmap_delta(OrigGoalInfo, OrigInstMapDelta),
goal_info_get_context(OrigGoalInfo, Context),
Index: tests/tabling/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/tabling/Mmakefile,v
retrieving revision 1.10
diff -u -d -r1.10 Mmakefile
--- tests/tabling/Mmakefile 2000/01/03 08:53:10 1.10
+++ tests/tabling/Mmakefile 2000/04/03 11:08:46
@@ -15,7 +15,8 @@
fib_float \
fib_list \
fib_string \
- loopcheck
+ loopcheck \
+ unused_args
NONDET_PROGS = \
coup \
cvs diff: tests/tabling/unused_args.exp is a new entry, no comparison available
cvs diff: tests/tabling/unused_args.m is a new entry, no comparison available
==================================================
new file tests/tabling/unused_args.exp
==================================================
foo
bar
foo_fail failed, as expected
foo
bar
foo_fail failed, as expected
foo
bar
foo_fail failed, as expected
==================================================
new file tests/tabling/unused_args.m
==================================================
% Regression test.
% Versions rotd-2000-04-03 and earlier
% got a software error when compiling this test.
:- module unused_args.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
:- import_module std_util.
main -->
test, test, test.
:- pred test(io__state::di, io__state::uo) is det.
:- pragma no_inline(test/2).
test -->
{ foo_unused_args(42, Z) },
print(Z), nl,
( { foo_unused_args_semi(42, Y) } ->
print(Y), nl
;
io__write_string("foo_unused_args failed\n")
),
( { foo_fail(X) } ->
print(X), nl
;
io__write_string("foo_fail failed, as expected\n")
).
:- pred foo_unused_args(int::in, string::out) is det.
:- pragma memo(foo_unused_args/2).
foo_unused_args(_, "foo").
:- pred foo_unused_args_semi(int::in, string::out) is semidet.
:- pragma memo(foo_unused_args_semi/2).
foo_unused_args_semi(_, "bar") :- semidet_succeed.
:- pred foo_fail(string::out) is semidet.
:- pragma memo(foo_fail/1).
foo_fail(_) :- fail.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list