[m-rev.] diff: fix minor bug in if-then-else code generation in erlang

Peter Wang wangp at students.csse.unimelb.edu.au
Mon Aug 27 16:09:33 AEST 2007


Estimated hours taken: 0.5
Branches: main

compiler/erl_code_gen.m:
	If the condition of an if-then-else has determinism `failure' then
	don't output Erlang code for the then branch to avoid unbound variable
	errors.

Index: compiler/erl_code_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/erl_code_gen.m,v
retrieving revision 1.25
diff -u -r1.25 erl_code_gen.m
--- compiler/erl_code_gen.m	17 Aug 2007 02:08:38 -0000	1.25
+++ compiler/erl_code_gen.m	27 Aug 2007 05:42:27 -0000
@@ -1080,10 +1080,17 @@
         erl_bind_unbound_vars(!.Info, ThenVars, Else, InstMap0,
             ElseStatement0, ElseStatement),
 
-        IfStatement0 = elds_case_expr(CondStatement, [TrueCase, FalseCase]),
-        TrueCase  = elds_case(CondVarsTerm, ThenStatement),
-        FalseCase = elds_case(elds_anon_var, ElseStatement),
-        maybe_simplify_nested_cases(IfStatement0, IfStatement),
+        CondDeterminism = goal_info_get_determinism(CondGoalInfo),
+        ( CondDeterminism = detism_failure ->
+            % If the condition cannot succeed then just concatenate the
+            % condition and the else branch.
+            IfStatement = join_exprs(CondStatement, ElseStatement)
+        ;
+            CaseExpr = elds_case_expr(CondStatement, [TrueCase, FalseCase]),
+            TrueCase = elds_case(CondVarsTerm, ThenStatement),
+            FalseCase = elds_case(elds_anon_var, ElseStatement),
+            maybe_simplify_nested_cases(CaseExpr, IfStatement)
+        ),
         Statement = maybe_join_exprs1(MaybeMakeClosure, IfStatement)
     ;
         CondCodeModel = 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