[m-rev.] diff: fix a bug in ite generation in erlang backend
Peter Wang
novalazy at gmail.com
Wed Oct 3 13:29:38 AEST 2007
Estimated hours taken: 2
Branches: main
Fix a bug in the generation of if-then-else goals in the Erlang backend.
The calculation of the variables bound by the then branch was wrong for
model_semi conditions -- it included variables bound in the condition.
compiler/erl_code_gen.m:
Fix the calculation of variables bound by then branches.
tests/valid/Mmakefile:
tests/valid/erl_ite_vars.m:
Add test case.
Index: compiler/erl_code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/erl_code_gen.m,v
retrieving revision 1.26
diff -u -r1.26 erl_code_gen.m
--- compiler/erl_code_gen.m 27 Aug 2007 06:07:36 -0000 1.26
+++ compiler/erl_code_gen.m 3 Oct 2007 03:29:49 -0000
@@ -1042,10 +1042,9 @@
CondCodeModel = model_semi,
% Find the non-local variables bound in the condition.
- % The instmap before Then should really be
- % InstMap0 + instmap_delta(Cond) but this is okay.
erl_bound_nonlocals_in_goal(!.Info, InstMap0, Cond, CondVars),
- erl_bound_nonlocals_in_goal(!.Info, InstMap0, Then, ThenVars),
+ update_instmap(Cond, InstMap0, InstMap0PostCond),
+ erl_bound_nonlocals_in_goal(!.Info, InstMap0PostCond, Then, ThenVars),
erl_bound_nonlocals_in_goal(!.Info, InstMap0, Else, ElseVars),
CondVarsList = set.to_sorted_list(CondVars),
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.195
diff -u -r1.195 Mmakefile
--- tests/valid/Mmakefile 17 Sep 2007 07:16:09 -0000 1.195
+++ tests/valid/Mmakefile 3 Oct 2007 03:29:48 -0000
@@ -82,6 +82,7 @@
easy_nondet_test_2 \
empty_bound_inst_list \
empty_switch \
+ erl_ite_vars \
error \
eval \
existential_cons \
Index: tests/valid/erl_ite_vars.m
===================================================================
RCS file: tests/valid/erl_ite_vars.m
diff -N tests/valid/erl_ite_vars.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/valid/erl_ite_vars.m 3 Oct 2007 03:29:49 -0000
@@ -0,0 +1,36 @@
+% This is a regression test for a bug in the generation of if-then-else goals
+% in the Erlang backend. The calculation of the variables bound by the then
+% branch was wrong -- it included variables bound in the condition.
+
+:- module erl_ite_vars.
+:- interface.
+
+:- import_module list.
+
+:- type baz
+ ---> and(baz, baz)
+ ; bar(string)
+ ; quux(string).
+
+:- pred foo(list(string)::in, list(string)::out, baz::out) is semidet.
+
+:- implementation.
+
+foo(List, Rest, Expression):-
+ ( List = ["(", "(" | R] ->
+ foo(["(" | R], Rem, Exp)
+ ;
+ List = ["(", "bar", Name | _],
+ Rem = [],
+ Exp = bar(Name)
+ ;
+ List = ["(", "quux", Name, ")" | Rem],
+ Exp = quux(Name)
+ ),
+ ( Rem = ["," | Next] ->
+ foo(Next, Rest, RestExp),
+ Expression = and(Exp, RestExp)
+ ;
+ Rest = [],
+ Expression = Exp
+ ).
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list