[m-rev.] for review 2/2: Fix bug300

Paul Bone paul at bone.id.au
Wed Oct 2 20:25:08 AEST 2013


Fix bug300

The last call modulo construction (LCMC) transformation ignores from ground
term scopes, this is incorrect when the from ground term scope makes ground
one of the variables whose construction we're trying to move before a
recursive call.  This can occur when the from ground term scope occurs in a
non-recursive case (and possible alternative recursive cases).  This was
only affecting non-C grades because the C grades transform the from ground
term scopes into single unification before LCMC is performed.

We fix this bug by performing the LCMC transformation on a from ground term
(FGT) scope by treating the scope as a construction unification goal.  This
is correct because such a goal is always the last goal in the FGT scope.  We
only process scopes that bind one of the variables whose construction we're
trying to optimize.

compiler/lco.m:
    As above.
---
 compiler/lco.m | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/compiler/lco.m b/compiler/lco.m
index 8374eb4..d022f95 100644
--- a/compiler/lco.m
+++ b/compiler/lco.m
@@ -1431,13 +1431,25 @@ lco_transform_variant_goal(ModuleInfo, VariantMap, VarToAddr, InstMap0,
     ;
         GoalExpr0 = scope(Reason, SubGoal0),
         (
-            Reason = from_ground_term(_, FGT),
+            Reason = from_ground_term(FGTVar, FGT),
             ( FGT = from_ground_term_construct
             ; FGT = from_ground_term_deconstruct
             )
         ->
-            GoalExpr = GoalExpr0,
-            Changed = no
+            (
+                member(FGTVarPair, VarToAddr),
+                FGTVarPair = FGTVar - _
+            ->
+                % We can treat such a scope as an atomic goal, since all we
+                % care about is with either is that it makes the variable
+                % we're interested in ground.
+                lco_transform_variant_atomic_goal(ModuleInfo, VarToAddr,
+                    InstMap0, GoalInfo0, GoalExpr0, GoalExpr, Changed,
+                    !ProcInfo)
+            ;
+                GoalExpr = GoalExpr0,
+                Changed = no
+            )
         ;
             lco_transform_variant_goal(ModuleInfo, VariantMap, VarToAddr,
                 InstMap0, SubGoal0, SubGoal, Changed, !ProcInfo),
-- 
1.8.4.rc3




More information about the reviews mailing list