[m-rev.] diff: fix cc_nondet_disj (erlang)

Peter Wang wangp at students.csse.unimelb.edu.au
Wed Jun 20 15:53:35 AEST 2007


Estimated hours taken: 1.5
Branches: main

compiler/erl_code_gen.m:
	Fix the way we generate code for semidet goals in model_det
	disjunctions in Erlang.  The previous scheme resulted in variables not
	being bound in the test case cc_nondet_disj.m.

Index: compiler/erl_code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/erl_code_gen.m,v
retrieving revision 1.14
diff -u -r1.14 erl_code_gen.m
--- compiler/erl_code_gen.m	19 Jun 2007 01:10:52 -0000	1.14
+++ compiler/erl_code_gen.m	20 Jun 2007 05:16:13 -0000
@@ -1212,11 +1212,17 @@
         %   model_semi goal:
         %       <Goal ; Goals>
         %   ===>
-        %       case <Goal> of
-        %           fail -> <Goals> ;
-        %           Any  -> Anything
+        %       case
+        %           <Goal [[ {NonLocals, ...} ]]>
+        %       of
+        %           {NonLocals, ...} ->
+        %               <SuccessExpr> ;
+        %           fail ->
+        %               <Goals [[ SuccessExpr ]]>
         %       end
         %
+        %   where NonLocals are variables bound by Goal.
+        %
         % TODO This can lead to contorted code when <Goal> itself is a `case'
         % expression.  In that case it would be better for <Goals> to appear in
         % the failure case of <Goal> directly.
@@ -1234,25 +1240,22 @@
         ;
             FirstCodeModel = model_semi,

-            % If the outer code model is model_det then we might not have a
-            % success expression.  Then make up one while generating the
-            % model_semi first goal.  It doesn't matter what the value is,
-            % otherwise MaybeSuccessExpr wouldn't have been `no'.
-            %
-            erl_fix_success_expr(InstMap, First, MaybeSuccessExpr,
-                MaybeSuccessExprForFirst, !Info),
-            SuccessExprFirst = expr_or_void(MaybeSuccessExprForFirst),
-            erl_gen_goal(model_semi, InstMap, First, yes(SuccessExprFirst),
-                FirstStatement0, !Info),
+            erl_bound_nonlocals_in_goal(!.Info, InstMap, First, FirstVarsSet),
+            FirstVars = set.to_sorted_list(FirstVarsSet),
+            FirstVarsTerm = elds_tuple(exprs_from_vars(FirstVars)),
+
+            % Generate code for the first goal, making it return a tuple of the
+            % nonlocal variables it binds on success.
+            erl_gen_goal(model_semi, InstMap, First,
+                yes(elds_term(FirstVarsTerm)), FirstStatement0, !Info),
+
+            % Generate the rest of the disjunction.
             erl_gen_disjunct(Rest, CodeModel, InstMap, Context,
                 MaybeSuccessExpr, RestStatement, !Info),

             % Need to do some renaming otherwise FirstStatement and
             % RestStatement end up binding the same variables which triggers a
             % (spurious) warning from the Erlang compiler.
-            %
-            erl_bound_nonlocals_in_goal(!.Info, InstMap, First, FirstVarsSet),
-            FirstVars = set.to_sorted_list(FirstVarsSet),
             erl_create_renaming(FirstVars, Subn, !Info),
             erl_rename_vars_in_expr(Subn, FirstStatement0, FirstStatement),

@@ -1265,12 +1268,13 @@
                 % matter that some variables aren't bound in other branches).
                 Statement = join_exprs(FirstStatement0, RestStatement)
             ;
-                erl_gen_info_new_named_var("Any", AnyVar, !Info),
+                erl_fix_success_expr(InstMap, First, MaybeSuccessExpr,
+                    MaybeSuccessExprForFirst, !Info),
                 Statement = elds_case_expr(FirstStatement,
-                    [FailCase, OtherCase]),
-                FailCase  = elds_case(elds_fail, RestStatement),
-                OtherCase = elds_case(term_from_var(AnyVar),
-                    expr_from_var(AnyVar))
+                    [SucceedCase, FailCase]),
+                SucceedCase = elds_case(FirstVarsTerm,
+                    expr_or_void(MaybeSuccessExprForFirst)),
+                FailCase = elds_case(elds_fail, RestStatement)
             )
         ;
             FirstCodeModel = model_non,
--------------------------------------------------------------------------
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