[m-rev.] for review: fix nested atomic transactions and or_else alternatives

Ben Mellor bmellor at csse.unimelb.edu.au
Mon Feb 23 11:24:52 AEDT 2009


Fix two bugs preventing the use of or_else alternatives to atomic
transaction scopes and nested atomic scopes.

The main issue was the assumption that the inner stm interface variables
were the same for the main goal and the or_else goals, but quantification
renames these variables to be distinct. The names of these variables for each
or_else alternative are now stored in the atomic_goal structure.


library/stm_builtin.m
    Rename stm_from_outer_to_inner_io and stm_from_inner_to_outer_io, dropping
    the _io suffix. They are used when the outer type is stm as well as io.

compiler/hlds_goal.m
    Add a field to the atomic_goal structure to hold the names of the STM
    interface variables used in each or_else alternative, since quantification
    renames these variables to be distinct from those used in the main atomic
    goal.

compiler/purity.m
    Insert calls to the (renamed) dummy predicates stm_from_outer_to_inner and
    stm_from_inner_to_outer regardless of the type of the outer variable,
    instead of using the nonexistent stm_from_*_to_*_stm versions when the
    outer type is stm. Also use the inner STM interface variables specific to
    each or_else alternative when generating these calls.

compiler/quantification.m
    Explicitly rename the inner STM interface variables in each of the or_else
    alternatives before calling implicitly_quantify_disj, so that the new names
    of these variables can be stored in the atomic_goal structure.

compiler/typecheck.m
    Ensure all the inner STM interface variables are typed stm, not just the
    ones in the main goal.

compiler/add_clause.m
compiler/assertion.m
compiler/build_mode_constraints.m
compiler/cse_detection.m
compiler/delay_partial_inst.m
compiler/dependency_graph.m
compiler/det_analysis.m
compiler/det_report.m
compiler/equiv_type_hlds.m
compiler/format_call.m
compiler/goal_form.m
compiler/goal_path.m
compiler/goal_util.m
compiler/hlds_out.m
compiler/intermod.m
compiler/lambda.m
compiler/make_hlds_warn.m
compiler/mode_util.m
compiler/modes.m
compiler/ordering_mode_constraints.m
compiler/polymorphism.m
compiler/post_typecheck.m
compiler/prop_mode_constraints.m
compiler/simplify.m
compiler/stm_expand.m
compiler/stratify.m
compiler/structure_reuse.lfu.m
compiler/switch_detection.m
compiler/unique_modes.m
compiler/unused_imports.m
    Updated to reflect the extra field in atomic_goal.



Index: compiler/add_clause.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/add_clause.m,v
retrieving revision 1.52
diff -u -r1.52 add_clause.m
--- compiler/add_clause.m	19 Feb 2009 03:49:16 -0000	1.52
+++ compiler/add_clause.m	20 Feb 2009 05:23:22 -0000
@@ -768,7 +768,7 @@
     ),
     !:NumAdded = !.NumAdded + 1 + OrElseNumAdded,
     ShortHand = atomic_goal(unknown_atomic_goal_type, Outer, Inner,
-        MaybeOutputVars, HLDSMainGoal, HLDSOrElseGoals),
+        MaybeOutputVars, HLDSMainGoal, HLDSOrElseGoals, []),
     GoalExpr = shorthand(ShortHand),
     goal_info_init(Context, GoalInfo),
     HLDSGoal = hlds_goal(GoalExpr, GoalInfo),
Index: compiler/assertion.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/assertion.m,v
retrieving revision 1.63
diff -u -r1.63 assertion.m
--- compiler/assertion.m	23 Dec 2008 01:37:29 -0000	1.63
+++ compiler/assertion.m	20 Feb 2009 05:23:22 -0000
@@ -709,11 +709,11 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, Vars, 
-                MainGoal0, OrElseAlternatives0),
+                MainGoal0, OrElseAlternatives0, OrElseInners),
             normalise_goal(MainGoal0, MainGoal),
             normalise_goals(OrElseAlternatives0, OrElseAlternatives),
             ShortHand = atomic_goal(GoalType, Outer, Inner, Vars, MainGoal,
-                OrElseAlternatives)
+                OrElseAlternatives, OrElseInners)
         ;
             ShortHand0 = bi_implication(LHS0, RHS0),
             normalise_goal(LHS0, LHS),
Index: compiler/build_mode_constraints.m
===================================================================
RCS
file: /home/mercury/mercury1/repository/mercury/compiler/build_mode_constraints.m,v
retrieving revision 1.32 diff -u -r1.32 build_mode_constraints.m
--- compiler/build_mode_constraints.m	4 Sep 2008 11:40:59 -0000
1.32 +++ compiler/build_mode_constraints.m	20 Feb 2009 05:23:22 -0000
@@ -336,7 +336,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, _, _),
+            ShortHand = atomic_goal(_, _, _, _, _, _, _),
             sorry(this_file, "add_mc_vars_for_goal: NYI: atomic_goal")
         ;
             ShortHand = bi_implication(_, _),
@@ -661,7 +661,7 @@
     ;
         GoalExpr = shorthand(Shorthand),
         (
-            Shorthand = atomic_goal(_, _, _, _, _, _),
+            Shorthand = atomic_goal(_, _, _, _, _, _, _),
             % Should record that
             % - OuterDI is definitely not produced inside this goal
             % - InnerDI is definitely produced by this goal
Index: compiler/cse_detection.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/cse_detection.m,v
retrieving revision 1.119
diff -u -r1.119 cse_detection.m
--- compiler/cse_detection.m	23 Dec 2008 01:37:30 -0000	1.119
+++ compiler/cse_detection.m	20 Feb 2009 05:23:22 -0000
@@ -326,12 +326,12 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(AtomicGoalType, Outer, Inner,
-                MaybeOutputVars, MainGoal0, OrElseGoals0),
+                MaybeOutputVars, MainGoal0, OrElseGoals0, OrElseInners),
             detect_cse_in_goal(MainGoal0, MainGoal, !CseInfo, InstMap0, Redo1),
             detect_cse_in_independent_goals(OrElseGoals0, OrElseGoals,
                 !CseInfo, InstMap0, Redo2),
             ShortHand = atomic_goal(AtomicGoalType, Outer, Inner,
-                MaybeOutputVars, MainGoal, OrElseGoals),
+                MaybeOutputVars, MainGoal, OrElseGoals, OrElseInners),
             bool.or(Redo1, Redo2, Redo)
         ;
             ShortHand0 = bi_implication(_, _),
Index: compiler/delay_partial_inst.m
===================================================================
RCS
file: /home/mercury/mercury1/repository/mercury/compiler/delay_partial_inst.m,v
retrieving revision 1.10 diff -u -r1.10 delay_partial_inst.m
--- compiler/delay_partial_inst.m	23 Dec 2008 01:37:31 -0000	1.10
+++ compiler/delay_partial_inst.m	20 Feb 2009 05:23:22 -0000
@@ -431,7 +431,7 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             % XXX Is it ok to ignore the updated ConstructMaps,
             % and if yes, why? This should be documented.
             delay_partial_inst_in_goal(InstMap0, MainGoal0, MainGoal,
@@ -439,7 +439,7 @@
             delay_partial_inst_in_goals(InstMap0, OrElseGoals0, OrElseGoals,
                 !.ConstructMap, _, !DelayInfo),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, OrElseInners),
             GoalExpr = shorthand(ShortHand),
             Goal = hlds_goal(GoalExpr, GoalInfo0)
         ;
Index: compiler/dependency_graph.m
===================================================================
RCS
file: /home/mercury/mercury1/repository/mercury/compiler/dependency_graph.m,v
retrieving revision 1.101 diff -u -r1.101 dependency_graph.m
--- compiler/dependency_graph.m	23 Dec 2008 01:37:31 -0000	1.101
+++ compiler/dependency_graph.m	20 Feb 2009 05:23:22 -0000
@@ -423,7 +423,7 @@
         GoalExpr = shorthand(ShortHand),
         (
             ShortHand = atomic_goal(_GoalType, _Outer, _Inner, _Vars,
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, _OrElseInners),
             add_dependency_arcs_in_goal(Caller, MainGoal, !DepGraph),
             add_dependency_arcs_in_list(Caller, OrElseGoals, !DepGraph)
         ;
Index: compiler/det_analysis.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/det_analysis.m,v
retrieving revision 1.217
diff -u -r1.217 det_analysis.m
--- compiler/det_analysis.m	19 Feb 2009 03:49:17 -0000	1.217
+++ compiler/det_analysis.m	20 Feb 2009 05:23:22 -0000
@@ -630,13 +630,13 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Inner, Outer, Vars, MainGoal0,
-                OrElseGoals0),
+                OrElseGoals0, OrElseInners),
             det_infer_atomic(MainGoal0, MainGoal, OrElseGoals0, OrElseGoals,
                 InstMap0, SolnContext, RightFailingContexts,
                 MaybePromiseEqvSolutionSets, Detism, !DetInfo, !Specs),
             GoalFailingContexts = [],
             ShortHand = atomic_goal(GoalType, Inner, Outer, Vars, MainGoal,
-                OrElseGoals)
+                OrElseGoals, OrElseInners)
         ;
             ShortHand0 = bi_implication(_, _),
             % These should have been expanded out by now.
Index: compiler/det_report.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/det_report.m,v
retrieving revision 1.144
diff -u -r1.144 det_report.m
--- compiler/det_report.m	23 Dec 2008 01:37:31 -0000	1.144
+++ compiler/det_report.m	20 Feb 2009 05:23:22 -0000
@@ -688,7 +688,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             det_diagnose_goal(MainGoal, InstMap0, Desired,
                 SwitchContexts, !DetInfo, MainMsgs),
             det_diagnose_orelse_goals(OrElseGoals, InstMap0, Desired,
Index: compiler/equiv_type_hlds.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/equiv_type_hlds.m,v
retrieving revision 1.52
diff -u -r1.52 equiv_type_hlds.m
--- compiler/equiv_type_hlds.m	23 Dec 2008 01:37:32 -0000	1.52
+++ compiler/equiv_type_hlds.m	20 Feb 2009 05:23:22 -0000
@@ -944,7 +944,7 @@
     GoalExpr0 = shorthand(ShortHand0),
     (
         ShortHand0 = atomic_goal(GoalType, Outer, Inner,
-            MaybeOutputVars, MainGoal0, OrElseGoals0),
+            MaybeOutputVars, MainGoal0, OrElseGoals0, OrElseInners),
         replace_in_goal(EqvMap, MainGoal0, MainGoal, Changed1, !Info),
         replace_in_list(replace_in_goal(EqvMap), OrElseGoals0,
             OrElseGoals, Changed2, !Info),
@@ -952,7 +952,7 @@
         (
             Changed = yes,
             ShortHand = atomic_goal(GoalType, Outer, Inner,
-                MaybeOutputVars, MainGoal, OrElseGoals),
+                MaybeOutputVars, MainGoal, OrElseGoals, OrElseInners),
             GoalExpr = shorthand(ShortHand)
         ;
             Changed = no,
Index: compiler/format_call.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/format_call.m,v
retrieving revision 1.14
diff -u -r1.14 format_call.m
--- compiler/format_call.m	23 Dec 2008 01:37:32 -0000	1.14
+++ compiler/format_call.m	20 Feb 2009 05:23:22 -0000
@@ -480,7 +480,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             traverse_disj([MainGoal | OrElseGoals], CurId,
                 !FormatCallSites, !Counter, !ConjMaps, !PredMap, !RelevantVars,
                 ModuleInfo)
Index: compiler/goal_form.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/goal_form.m,v
retrieving revision 1.45
diff -u -r1.45 goal_form.m
--- compiler/goal_form.m	23 Dec 2008 01:37:32 -0000	1.45
+++ compiler/goal_form.m	20 Feb 2009 05:23:22 -0000
@@ -274,7 +274,7 @@
             ShortHand = bi_implication(GoalA, GoalB),
             goals_can_throw([GoalA, GoalB], Result, !ModuleInfo)
         ;
-            ShortHand = atomic_goal(_, _, _, _, _, _),
+            ShortHand = atomic_goal(_, _, _, _, _, _, _),
             % Atomic goals currently throw an exception to signal a rollback so
             % it is pretty safe to say that any goal inside an atomic goal
             % can throw an exception.
@@ -450,7 +450,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             MainGoalCanLoop = goal_can_loop_func(MaybeModuleInfo, MainGoal),
             OrElseCanLoop = goal_list_can_loop(MaybeModuleInfo, OrElseGoals),
             CanLoop = MainGoalCanLoop `or` OrElseCanLoop
@@ -577,7 +577,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, _, _),
+            ShortHand = atomic_goal(_, _, _, _, _, _, _),
             CanThrow = yes
         ;
             ShortHand = bi_implication(_, _),
@@ -746,7 +746,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, _, _),
+            ShortHand = atomic_goal(_, _, _, _, _, _, _),
             May = yes
         ;
             ShortHand = bi_implication(GoalA, GoalB),
@@ -908,7 +908,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             count_recursive_calls_disj([MainGoal | OrElseGoals],
                 PredId, ProcId, Min, Max)
         ;
Index: compiler/goal_path.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/goal_path.m,v
retrieving revision 1.52
diff -u -r1.52 goal_path.m
--- compiler/goal_path.m	23 Dec 2008 01:37:32 -0000	1.52
+++ compiler/goal_path.m	20 Feb 2009 05:23:22 -0000
@@ -217,12 +217,12 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             fill_goal_slots(goal_path_add_at_end(Path0, step_atomic_main), 
                 SlotInfo, MainGoal0, MainGoal),
             fill_orelse_slots(Path0, 0, SlotInfo, OrElseGoals0, OrElseGoals),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals)
+                MainGoal, OrElseGoals, OrElseInners)
         ;
             ShortHand0 = bi_implication(_, _),
             % These should have been expanded out by now.
Index: compiler/goal_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/goal_util.m,v
retrieving revision 1.165
diff -u -r1.165 goal_util.m
--- compiler/goal_util.m	19 Feb 2009 03:49:17 -0000	1.165
+++ compiler/goal_util.m	20 Feb 2009 05:23:22 -0000
@@ -602,7 +602,7 @@
         GoalExpr = shorthand(Shorthand),
         (
             Shorthand = atomic_goal(_, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, _),
             Outer = atomic_interface_vars(OuterDI, OuterUO),
             svset.insert(OuterDI, !Set),
             svset.insert(OuterUO, !Set),
@@ -753,13 +753,13 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             attach_features_to_all_goals(Features, InFromGroundTerm,
                 MainGoal0, MainGoal),
             attach_features_to_goals(Features, InFromGroundTerm,
                 OrElseGoals0, OrElseGoals),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals)
+                MainGoal, OrElseGoals, OrElseInners)
         ;
             ShortHand0 = bi_implication(GoalA0, GoalB0),
             attach_features_to_all_goals(Features, InFromGroundTerm,
@@ -868,7 +868,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, _, _),
+            ShortHand = atomic_goal(_, _, _, _, _, _, _),
             IsLeaf = is_not_leaf
         ;
             ShortHand = bi_implication(GoalA, GoalB),
@@ -1001,7 +1001,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             goal_size(MainGoal, Size1),
             goals_size(OrElseGoals, Size2),
             Size = Size1 + Size2 + 1
@@ -1200,7 +1200,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             goal_calls_proc_in_list_2(MainGoal, PredProcIds, !CalledSet),
             goal_list_calls_proc_in_list_2(OrElseGoals, PredProcIds,
                 !CalledSet)
@@ -1841,11 +1841,11 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             MainGoal = maybe_strip_equality_pretest(MainGoal0),
             OrElseGoals = list.map(maybe_strip_equality_pretest, OrElseGoals0),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, OrElseInners),
             GoalExpr = shorthand(ShortHand),
             Goal = hlds_goal(GoalExpr, GoalInfo0)
         ;
Index: compiler/hlds_goal.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_goal.m,v
retrieving revision 1.204
diff -u -r1.204 hlds_goal.m
--- compiler/hlds_goal.m	19 Feb 2009 03:49:17 -0000	1.204
+++ compiler/hlds_goal.m	20 Feb 2009 05:23:22 -0000
@@ -276,8 +276,13 @@
                 atomic_main_goal    :: hlds_goal,
 
                 % Any later or_else alternative goals.
-                orelse_alternatives :: list(hlds_goal)
+                orelse_alternatives :: list(hlds_goal),
 
+                % The same as atomic_inner, but for each corresponding goal
+                % in orelse_alternatives. Begins as an empty list, but is
+                % filled in when quantification renames the inner stm state
+                % variables apart in each of the or_else alternatives.
+                orelse_inners       :: list(atomic_interface_vars)
             ).
 
 :- type atomic_interface_vars
@@ -2390,7 +2395,7 @@
         Expr0 = shorthand(Shorthand0),
         (
             Shorthand0 = atomic_goal(GoalType0, Outer0, Inner0,
-                MaybeOutputVars0, MainGoal0, OrElseGoals0),
+                MaybeOutputVars0, MainGoal0, OrElseGoals0, OrElseInners),
             GoalType = GoalType0,
             Outer0 = atomic_interface_vars(OuterDI0, OuterUO0),
             rename_var(Must, Subn, OuterDI0, OuterDI),
@@ -2411,7 +2416,7 @@
             rename_vars_in_goal(Must, Subn, MainGoal0, MainGoal),
             rename_vars_in_goals(Must, Subn, OrElseGoals0, OrElseGoals),
             Shorthand = atomic_goal(GoalType, Outer, Inner,
-                MaybeOutputVars, MainGoal, OrElseGoals)
+                MaybeOutputVars, MainGoal, OrElseGoals, OrElseInners)
         ;
             Shorthand0 = bi_implication(LeftGoal0, RightGoal0),
             rename_vars_in_goal(Must, Subn, LeftGoal0, LeftGoal),
@@ -2835,7 +2840,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, _, _),
+            ShortHand = atomic_goal(_, _, _, _, _, _, _),
             HasForeign = yes
         ;
             ShortHand = bi_implication(GoalA, GoalB),
@@ -2895,7 +2900,7 @@
         HasSubGoals = has_subgoals
     ;
         GoalExpr = shorthand(ShortHand),
-        ( ShortHand = atomic_goal(_, _, _, _, _, _)
+        ( ShortHand = atomic_goal(_, _, _, _, _, _, _)
         ; ShortHand = bi_implication(_, _)
         ),
         HasSubGoals = has_subgoals
@@ -3002,11 +3007,11 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             set_goal_contexts(Context, MainGoal0, MainGoal),
             list.map(set_goal_contexts(Context), OrElseGoals0, OrElseGoals),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals)
+                MainGoal, OrElseGoals, OrElseInners)
         ;
             ShortHand0 = bi_implication(LHS0, RHS0),
             set_goal_contexts(Context, LHS0, LHS),
Index: compiler/hlds_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/hlds_out.m,v
retrieving revision 1.461
diff -u -r1.461 hlds_out.m
--- compiler/hlds_out.m	19 Feb 2009 03:49:17 -0000	1.461
+++ compiler/hlds_out.m	20 Feb 2009 05:23:22 -0000
@@ -2200,7 +2200,7 @@
         Indent, Follow, TypeQual, !IO) :-
     (
         ShortHand = atomic_goal(_GoalType, Outer, Inner, MaybeOutputVars,
-            MainGoal, OrElseGoals),
+            MainGoal, OrElseGoals, _OrElseInners),
         write_indent(Indent, !IO),
         io.write_string("atomic [", !IO),
         write_atomic_interface_vars("outer", Outer, VarSet, AppendVarNums,
Index: compiler/intermod.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/intermod.m,v
retrieving revision 1.241
diff -u -r1.241 intermod.m
--- compiler/intermod.m	14 Jan 2009 08:38:45 -0000	1.241
+++ compiler/intermod.m	20 Feb 2009 05:23:22 -0000
@@ -558,13 +558,13 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             intermod_traverse_goal(MainGoal0, MainGoal, DoWrite1, !Info),
             intermod_traverse_list_of_goals(OrElseGoals0, OrElseGoals,
DoWrite2, !Info),
             bool.and(DoWrite1, DoWrite2, DoWrite),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals)
+                MainGoal, OrElseGoals, OrElseInners)
         ;
             ShortHand0 = bi_implication(_, _),
             % These should have been expanded out by now.
Index: compiler/lambda.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.137
diff -u -r1.137 lambda.m
--- compiler/lambda.m	23 Dec 2008 01:37:35 -0000	1.137
+++ compiler/lambda.m	20 Feb 2009 05:23:22 -0000
@@ -266,11 +266,11 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             lambda_process_goal(MainGoal0, MainGoal, !Info),
             lambda_process_goal_list(OrElseGoals0, OrElseGoals, !Info),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars, 
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, OrElseInners),
             GoalExpr = shorthand(ShortHand)
         ;
             ShortHand0 = bi_implication(_, _),
Index: compiler/make_hlds_warn.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/make_hlds_warn.m,v
retrieving revision 1.29
diff -u -r1.29 make_hlds_warn.m
--- compiler/make_hlds_warn.m	23 Dec 2008 01:37:36 -0000	1.29
+++ compiler/make_hlds_warn.m	20 Feb 2009 05:23:22 -0000
@@ -213,7 +213,7 @@
             % XXX STM We need to look at how we should handle Outer, Inner and
             % MaybeOutputVars.
             ShortHand = atomic_goal(_GoalType, _Outer, Inner,
-                _MaybeOutputVars, MainGoal, OrElseGoals),
+                _MaybeOutputVars, MainGoal, OrElseGoals, _OrElseInners),
             Inner = atomic_interface_vars(InnerDI, InnerUO),
             set.insert_list(QuantVars, [InnerDI, InnerUO], InsideQuantVars),
             warn_singletons_in_goal(MainGoal, InsideQuantVars, VarSet,
Index: compiler/mode_util.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/mode_util.m,v
retrieving revision 1.208
diff -u -r1.208 mode_util.m
--- compiler/mode_util.m	28 Jan 2009 06:57:46 -0000	1.208
+++ compiler/mode_util.m	20 Feb 2009 05:23:22 -0000
@@ -1195,7 +1195,7 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars, 
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             Goals0 = [MainGoal0 | OrElseGoals0],
             NonLocals = goal_info_get_nonlocals(GoalInfo),
             recompute_instmap_delta_disj(RecomputeAtomic, Goals0, Goals,
@@ -1208,7 +1208,7 @@
                 Goals = [MainGoal | OrElseGoals]
             ),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals)
+                MainGoal, OrElseGoals, OrElseInners)
         ;
             ShortHand0 = bi_implication(_, _),
             % These should have been expanded out by now.
Index: compiler/modes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/modes.m,v
retrieving revision 1.374
diff -u -r1.374 modes.m
--- compiler/modes.m	19 Feb 2009 03:49:17 -0000	1.374
+++ compiler/modes.m	20 Feb 2009 05:23:22 -0000
@@ -2004,7 +2004,7 @@
 modecheck_goal_shorthand(ShortHand0, GoalInfo0, GoalExpr, !ModeInfo, !IO) :-
     (
         ShortHand0 = atomic_goal(_, Outer, Inner, MaybeOutputVars,
-            MainGoal0, OrElseGoals0),
+            MainGoal0, OrElseGoals0, OrElseInners),
 
         % The uniqueness of the Outer and Inner variables are handled by the
         % addition of calls to the fake predicates "stm_inner_to_outer_io" and
@@ -2074,7 +2074,7 @@
             "modecheck_goal_shorthand atomic_goal: Invalid inner var type"),
 
         ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-            MainGoal, OrElseGoals),
+            MainGoal, OrElseGoals, OrElseInners),
         GoalExpr = shorthand(ShortHand),
         mode_checkpoint(exit, "atomic", !ModeInfo, !IO)
     ;
Index: compiler/ordering_mode_constraints.m
===================================================================
RCS
file: /home/mercury/mercury1/repository/mercury/compiler/ordering_mode_constraints.m,v
retrieving revision 1.20 diff -u -r1.20 ordering_mode_constraints.m
--- compiler/ordering_mode_constraints.m	23 Dec 2008 01:37:38
-0000	1.20 +++ compiler/ordering_mode_constraints.m	20 Feb 2009
05:23:22 -0000 @@ -800,7 +800,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             Goals = [MainGoal | OrElseGoals],
             list.foldl(dump_goal_goal_paths(SubGoalIndent), Goals, !IO)
         ;
Index: compiler/polymorphism.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/polymorphism.m,v
retrieving revision 1.337
diff -u -r1.337 polymorphism.m
--- compiler/polymorphism.m	12 Jan 2009 02:01:03 -0000	1.337
+++ compiler/polymorphism.m	20 Feb 2009 05:23:22 -0000
@@ -1181,11 +1181,11 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, Vars, 
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             polymorphism_process_goal(MainGoal0, MainGoal, !Info),
             polymorphism_process_goal_list(OrElseGoals0, OrElseGoals, !Info),
             ShortHand = atomic_goal(GoalType, Outer, Inner, Vars, 
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, OrElseInners),
             GoalExpr = shorthand(ShortHand),
             Goal = hlds_goal(GoalExpr, GoalInfo0)
         ;
Index: compiler/post_typecheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/post_typecheck.m,v
retrieving revision 1.130
diff -u -r1.130 post_typecheck.m
--- compiler/post_typecheck.m	14 Jan 2009 08:38:46 -0000	1.130
+++ compiler/post_typecheck.m	20 Feb 2009 05:23:22 -0000
@@ -643,7 +643,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             in_interface_check(ModuleInfo, PredInfo, MainGoal, !Specs),
             in_interface_check_list(ModuleInfo, PredInfo, OrElseGoals, !Specs)
         ;
Index: compiler/prop_mode_constraints.m
===================================================================
RCS
file: /home/mercury/mercury1/repository/mercury/compiler/prop_mode_constraints.m,v
retrieving revision 1.20 diff -u -r1.20 prop_mode_constraints.m
--- compiler/prop_mode_constraints.m	23 Dec 2008 01:37:39 -0000
1.20 +++ compiler/prop_mode_constraints.m	20 Feb 2009 05:23:22 -0000
@@ -363,13 +363,13 @@
         !.GoalExpr = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             ensure_unique_arguments_in_goal(MainGoal0, MainGoal, !SeenSoFar,
                 !Varset, !Vartypes),
             list.map_foldl3(ensure_unique_arguments_in_goal,
                 OrElseGoals0, OrElseGoals, !SeenSoFar, !Varset, !Vartypes),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, OrElseInners),
             !:GoalExpr = shorthand(ShortHand)
         ;
             ShortHand0 = bi_implication(_, _),
Index: compiler/purity.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/purity.m,v
retrieving revision 1.126
diff -u -r1.126 purity.m
--- compiler/purity.m	19 Feb 2009 03:49:18 -0000	1.126
+++ compiler/purity.m	20 Feb 2009 05:23:22 -0000
@@ -201,6 +201,7 @@
 :- import_module string.
 :- import_module term.
 :- import_module varset.
+:- import_module assoc_list.
 
 %-----------------------------------------------------------------------------%
 %
@@ -739,19 +740,18 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             RunPostTypecheck = !.Info ^ pi_run_post_typecheck,
             (
                 RunPostTypecheck = run_post_typecheck,
                 VarSet = !.Info ^ pi_varset,
                 VarTypes = !.Info ^ pi_vartypes,
                 Outer = atomic_interface_vars(OuterDI, OuterUO),
-                Inner = atomic_interface_vars(InnerDI, InnerUO),
                 Context = goal_info_get_context(GoalInfo),
                 check_outer_var_type(Context, VarTypes, VarSet, OuterDI,
-                    OuterDIType, OuterDITypeSpecs),
+                    _OuterDIType, OuterDITypeSpecs),
                 check_outer_var_type(Context, VarTypes, VarSet, OuterUO,
-                    OuterUOType, OuterUOTypeSpecs),
+                    _OuterUOType, OuterUOTypeSpecs),
                 OuterTypeSpecs = OuterDITypeSpecs ++ OuterUOTypeSpecs,
                 (
                     OuterTypeSpecs = [_ | _],
@@ -760,49 +760,19 @@
                     OrElseGoals1 = OrElseGoals0
                 ;
                     OuterTypeSpecs = [],
+                    AtomicGoalsAndInners = assoc_list.from_corresponding_lists(
+                        [MainGoal0 | OrElseGoals0],
+                        [Inner | OrElseInners]),
+                    list.map_foldl(wrap_inner_outer_goals(Outer),
+                        AtomicGoalsAndInners, AllAtomicGoals1, !Info),
                     (
-                        (
-                            OuterDIType = io_state_type,
-                            OuterUOType = io_state_type
-                        ->
-                            OuterToInnerPred = "stm_from_outer_to_inner_io",
-                            InnerToOuterPred = "stm_from_inner_to_outer_io"
-                        ;
-                            OuterDIType = stm_atomic_type,
-                            OuterUOType = stm_atomic_type
-                        ->
-                            OuterToInnerPred = "stm_from_outer_to_inner_stm",
-                            InnerToOuterPred = "stm_from_inner_to_outer_stm"
-                        ;
-                            fail
-                        )
-                    ->
-                        ModuleInfo = !.Info ^ pi_module_info,
-                        generate_simple_call(mercury_stm_builtin_module,
-                            OuterToInnerPred, pf_predicate, only_mode,
-                            detism_det, purity_pure, [OuterDI, InnerDI], [],
-                            [OuterDI - ground(clobbered, none),
-                                InnerDI - ground(unique, none)],
-                            ModuleInfo, Context, OuterToInnerGoal),
-                        generate_simple_call(mercury_stm_builtin_module,
-                            InnerToOuterPred, pf_predicate, only_mode,
-                            detism_det, purity_pure, [InnerUO, OuterUO], [],
-                            [InnerUO - ground(clobbered, none),
-                                OuterUO - ground(unique, none)],
-                            ModuleInfo, Context, InnerToOuterGoal),
-                        wrap_inner_outer_goals(Outer, Inner,
-                            OuterToInnerGoal, InnerToOuterGoal,
-                            MainGoal0, MainGoal1, !Info),
-                        list.map_foldl(wrap_inner_outer_goals(Outer, Inner,
-                            OuterToInnerGoal, InnerToOuterGoal),
-                            OrElseGoals0, OrElseGoals1, !Info),
-                        !Info ^ pi_requant := need_to_requantify
+                        AllAtomicGoals1 = [MainGoal1 | OrElseGoals1]
                     ;
-                        MisMatchSpec = mismatched_outer_var_types(Context),
-                        purity_info_add_message(MisMatchSpec, !Info),
-                        MainGoal1 = MainGoal0,
-                        OrElseGoals1 = OrElseGoals0
-                    )
+                        AllAtomicGoals1 = [],
+                        unexpected(this_file,
+                            "compute_expr_purity: AllAtomicGoals1 = []")
+                    ),
+                    !Info ^ pi_requant := need_to_requantify
                 )
             ;
                 RunPostTypecheck = do_not_run_post_typecheck,
@@ -825,7 +795,7 @@
                 ContainsTrace = contains_no_trace_goal
             ),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, OrElseInners),
             GoalExpr = shorthand(ShortHand)
         ;
             ShortHand0 = bi_implication(_, _),
@@ -834,13 +804,11 @@
         )
     ).
 
-:- pred wrap_inner_outer_goals(
-    atomic_interface_vars::in, atomic_interface_vars::in,
-    hlds_goal::in, hlds_goal::in, hlds_goal::in, hlds_goal::out,
+:- pred wrap_inner_outer_goals(atomic_interface_vars::in,
+    pair(hlds_goal, atomic_interface_vars)::in, hlds_goal::out,
     purity_info::in, purity_info::out) is det.
 
-wrap_inner_outer_goals(Outer, Inner, OuterToInnerGoal, InnerToOuterGoal,
-        Goal0, Goal, !Info) :-
+wrap_inner_outer_goals(Outer, Goal0 - Inner, Goal, !Info) :-
     % Generate an error if the outer variables are in the nonlocals of the
     % original goal, since they are not supposed to be used in the goal.
     %
@@ -889,6 +857,23 @@
         purity_info_add_message(Spec2, !Info)
     ),
 
+    % generate the outer_to_inner and inner_to_outer goals
+    OuterToInnerPred = "stm_from_outer_to_inner",
+    InnerToOuterPred = "stm_from_inner_to_outer",
+    ModuleInfo = !.Info^pi_module_info,
+    generate_simple_call(mercury_stm_builtin_module,
+        OuterToInnerPred, pf_predicate, only_mode,
+        detism_det, purity_pure, [OuterDI, InnerDI], [],
+        [OuterDI - ground(clobbered, none),
+            InnerDI - ground(unique, none)],
+        ModuleInfo, Context, OuterToInnerGoal),
+    generate_simple_call(mercury_stm_builtin_module,
+        InnerToOuterPred, pf_predicate, only_mode,
+        detism_det, purity_pure, [InnerUO, OuterUO], [],
+        [InnerUO - ground(clobbered, none),
+            OuterUO - ground(unique, none)],
+        ModuleInfo, Context, InnerToOuterGoal),
+
     WrapExpr = conj(plain_conj, [OuterToInnerGoal, Goal0, InnerToOuterGoal]),
     % After the addition of OuterToInnerGoal and InnerToOuterGoal,
     % OuterDI and OuterUO will definitely be used by the code inside the new
Index: compiler/quantification.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/quantification.m,v
retrieving revision 1.131
diff -u -r1.131 quantification.m
--- compiler/quantification.m	19 Feb 2009 03:49:18 -0000	1.131
+++ compiler/quantification.m	20 Feb 2009 05:23:22 -0000
@@ -561,10 +561,22 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
-            Outer = atomic_interface_vars(OuterDI, OuterUO),
-            Inner = atomic_interface_vars(InnerDI, InnerUO),
-            AllAtomicGoals0 = [MainGoal0 | OrElseGoals0],
+                MainGoal0, OrElseGoals0, OrElseInners0),
+            % The call to implicitly_quantify_disj causes the inner STM
+            % interface variables to be renamed in any or_else goals, but
+            % doing it first explicitly allows the new names of these
+            % variables to be stored.
+            (
+                OrElseInners0 = [],
+                rename_or_else_inner_vars(NonLocalsToRecompute, Inner,
+                    OrElseGoals0, OrElseGoals1, OrElseInners, !Info)
+            ;
+                OrElseInners0 = [_ | _],
+                OrElseInners = OrElseInners0,
+                OrElseGoals1 = OrElseGoals0,
+                !:Info = !.Info
+            ),
+            AllAtomicGoals0 = [MainGoal0 | OrElseGoals1],
             NonLocalVarSets0 = [],
             implicitly_quantify_disj(AllAtomicGoals0, AllAtomicGoals,
                 NonLocalsToRecompute, !Info,
@@ -580,6 +592,8 @@
             union_list(NonLocalVarSets, NonLocalVars0),
             (
                 GoalType = unknown_atomic_goal_type,
+                Outer = atomic_interface_vars(OuterDI, OuterUO),
+                Inner = atomic_interface_vars(InnerDI, InnerUO),
                 insert_list(NonLocalVars0, [OuterDI, OuterUO], NonLocalVars1),
                 delete_list(NonLocalVars1, [InnerDI, InnerUO], NonLocalVars)
             ;
@@ -590,7 +604,7 @@
             ),
             set_nonlocals(NonLocalVars, !Info),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, OrElseInners),
             GoalExpr = shorthand(ShortHand)
         ;
             ShortHand0 = bi_implication(LHS, RHS),
@@ -601,6 +615,29 @@
             PossiblyNonLocalGoalVars0)
     ).
 
+:- pred rename_or_else_inner_vars(nonlocals_to_recompute,
+    atomic_interface_vars, list(hlds_goal), list(hlds_goal),
+    list(atomic_interface_vars), quant_info, quant_info).
+:- mode rename_or_else_inner_vars(in(ordinary_nonlocals), in, in, out, out,
+                                  in, out) is det.
+:- mode rename_or_else_inner_vars(in(code_gen_nonlocals), in, in, out, out,
+                                  in, out) is det.
+
+rename_or_else_inner_vars(_, _, [], [], [], !Info).
+rename_or_else_inner_vars(NonLocalsToRecompute, Inner,
+    [OrElseGoal0 | OrElseGoals0], OrElseGoals, OrElseInners, !Info) :-
+    Inner = atomic_interface_vars(InnerDI, InnerUO),
+    RenameVars = list_to_set([InnerDI, InnerUO]),
+    rename_apart(RenameVars, RenameMap, NonLocalsToRecompute, OrElseGoal0,
+                 OrElseGoal, !Info),
+    OrElseInnerDI = map.lookup(RenameMap, InnerDI),
+    OrElseInnerUO = map.lookup(RenameMap, InnerUO),
+    OrElseInner = atomic_interface_vars(OrElseInnerDI, OrElseInnerUO),
+    rename_or_else_inner_vars(NonLocalsToRecompute, Inner, OrElseGoals0,
+                              OrElseGoalsTail, OrElseInnersTail, !Info),
+    OrElseInners = [OrElseInner | OrElseInnersTail],
+    OrElseGoals = [OrElseGoal | OrElseGoalsTail].
+
 :- pred implicitly_quantify_goal_quant_info_scope(scope_reason, hlds_goal,
     hlds_goal_expr, hlds_goal_info, nonlocals_to_recompute, set_of_var,
     quant_info, quant_info).
@@ -1408,7 +1445,7 @@
         GoalExpr = shorthand(ShortHand),
         (
             ShortHand = atomic_goal(_GoalType, Outer, Inner,
-                _MaybeOutputVars, MainGoal, OrElseGoals),
+                _MaybeOutputVars, MainGoal, OrElseGoals, _OrElseInners),
             % XXX STM
             Outer = atomic_interface_vars(OuterDI, OuterUO),
             Inner = atomic_interface_vars(InnerDI, InnerUO),
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.236
diff -u -r1.236 simplify.m
--- compiler/simplify.m	19 Feb 2009 03:49:18 -0000	1.236
+++ compiler/simplify.m	20 Feb 2009 05:23:22 -0000
@@ -912,10 +912,10 @@
         !.GoalExpr = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner,
-                MaybeOutputVars, MainGoal, OrElseGoals),
+                MaybeOutputVars, MainGoal, OrElseGoals, OrElseInners),
             simplify_goal_atomic_goal(GoalType, Outer, Inner,
-                MaybeOutputVars, MainGoal, OrElseGoals, !:GoalExpr, !GoalInfo,
-                !Info)
+                MaybeOutputVars, MainGoal, OrElseGoals, OrElseInners,
+                !:GoalExpr, !GoalInfo, !Info)
         ;
             ShortHand0 = bi_implication(_, _),
             % These should have been expanded out by now.
@@ -1660,7 +1660,7 @@
     ;
         CondExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, _, _),
+            ShortHand = atomic_goal(_, _, _, _, _, _, _),
             !:CondCanSwitch = cond_cannot_switch
         ;
             ShortHand = bi_implication(_, _),
@@ -2080,11 +2080,12 @@
 :- pred simplify_goal_atomic_goal(atomic_goal_type::in,
     atomic_interface_vars::in, atomic_interface_vars::in,
     maybe(list(prog_var))::in, hlds_goal::in, list(hlds_goal)::in,
+    list(atomic_interface_vars)::in,
     hlds_goal_expr::out, hlds_goal_info::in, hlds_goal_info::out,
     simplify_info::in, simplify_info::out) is det.
 
 simplify_goal_atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-        MainGoal0, OrElseGoals0, GoalExpr, !GoalInfo, !Info) :-
+        MainGoal0, OrElseGoals0, OrElseInners, GoalExpr, !GoalInfo, !Info) :-
     % XXX STM: At the moment we do not simplify the inner goals as there is
     % a chance that the outer and inner variables will change which will
     % cause problems during expansion of STM constructs.  This will be
@@ -2094,7 +2095,7 @@
     % simplify_goal(MainGoal0, MainGoal, !Info),
     % simplify_or_else_goals(OrElseGoals0, OrElseGoals, !Info),
     ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-        MainGoal, OrElseGoals),
+        MainGoal, OrElseGoals, OrElseInners),
     GoalExpr = shorthand(ShortHand).
 
 :- pred simplify_or_else_goals(list(hlds_goal)::in, list(hlds_goal)::out,
@@ -3442,12 +3443,12 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             goal_contains_trace(MainGoal0, MainGoal, MainContainsTrace),
             goal_list_contains_trace(OrElseGoals0, OrElseGoals,
                 contains_no_trace_goal, OrElseContainsTrace),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, OrElseInners),
             GoalExpr = shorthand(ShortHand),
             ContainsTrace = worst_contains_trace(MainContainsTrace,
                 OrElseContainsTrace)
@@ -3895,7 +3896,7 @@
 will_flush(scope(_, _), _) = no.
 will_flush(shorthand(ShortHand), _) = WillFlush :-
     (
-        ShortHand = atomic_goal(_, _, _, _, _MainGoal, _OrElseGoals),
+        ShortHand = atomic_goal(_, _, _, _, _MainGoal, _OrElseGoals, _),
         WillFlush = yes
     ;
         ShortHand = bi_implication(_, _),
Index: compiler/stm_expand.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stm_expand.m,v
retrieving revision 1.3
diff -u -r1.3 stm_expand.m
--- compiler/stm_expand.m	19 Feb 2009 03:49:18 -0000	1.3
+++ compiler/stm_expand.m	20 Feb 2009 05:23:22 -0000
@@ -365,7 +365,7 @@
         (
             % XXX STM: Why do we ignore _MaybeOutputVars?
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, _MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, _OrElseInners),
 
             GoalDisj0 = [MainGoal0 | OrElseGoals0],
             stm_process_disj(Instmap, GoalDisj0, GoalDisj, !Info),
Index: compiler/stratify.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/stratify.m,v
retrieving revision 1.68
diff -u -r1.68 stratify.m
--- compiler/stratify.m	23 Dec 2008 01:37:40 -0000	1.68
+++ compiler/stratify.m	20 Feb 2009 05:23:22 -0000
@@ -225,7 +225,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             first_order_check_goal(MainGoal, Negated, WholeScc,
                 ThisPredProcId, Error, !ModuleInfo, !IO),
             first_order_check_goals(OrElseGoals, Negated, WholeScc,
@@ -389,7 +389,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             higher_order_check_goal(MainGoal, Negated, WholeScc,
                 ThisPredProcId, HighOrderLoops, Error, !ModuleInfo, !IO),
             higher_order_check_goals(OrElseGoals, Negated, WholeScc,
@@ -814,7 +814,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             stratify_analyze_goal(MainGoal, !Calls, !HasAT, !CallsHO),
             stratify_analyze_goals(OrElseGoals, !Calls, !HasAT, !CallsHO)
         ;
@@ -929,7 +929,7 @@
     ;
         GoalExpr = shorthand(ShortHand),
         (
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             get_called_procs(MainGoal, !Calls),
             get_called_procs_goals(OrElseGoals, !Calls)
         ;
Index: compiler/structure_reuse.lfu.m
===================================================================
RCS
file: /home/mercury/mercury1/repository/mercury/compiler/structure_reuse.lfu.m,v
retrieving revision 1.12 diff -u -r1.12 structure_reuse.lfu.m
--- compiler/structure_reuse.lfu.m	23 Dec 2008 01:37:41 -0000	1.12
+++ compiler/structure_reuse.lfu.m	20 Feb 2009 05:23:22 -0000
@@ -291,11 +291,11 @@
         Expr0 = shorthand(Shorthand0),
         (
             Shorthand0 = atomic_goal(GoalType, Outer, Inner,
-                MaybeOutputVars, MainGoal0, OrElseGoals0),
+                MaybeOutputVars, MainGoal0, OrElseGoals0, OrElseInners),
             add_vars_to_lfu_in_goal(ForceInUse, MainGoal0, MainGoal),
             add_vars_to_lfu_in_goals(ForceInUse, OrElseGoals0, OrElseGoals),
             Shorthand = atomic_goal(GoalType, Outer, Inner,
-                MaybeOutputVars, MainGoal, OrElseGoals)
+                MaybeOutputVars, MainGoal, OrElseGoals, OrElseInners)
         ;
             Shorthand0 = bi_implication(LeftGoal0, RightGoal0),
             add_vars_to_lfu_in_goal(ForceInUse, LeftGoal0, LeftGoal),
Index: compiler/switch_detection.m
===================================================================
RCS
file: /home/mercury/mercury1/repository/mercury/compiler/switch_detection.m,v
retrieving revision 1.143 diff -u -r1.143 switch_detection.m
--- compiler/switch_detection.m	16 Jan 2009 02:31:26 -0000	1.143
+++ compiler/switch_detection.m	20 Feb 2009 05:23:22 -0000
@@ -311,13 +311,13 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             detect_switches_in_goal(VarTypes, AllowMulti, InstMap0,
                 MainGoal0, MainGoal, !ModuleInfo, !Requant),
             detect_switches_in_orelse(VarTypes, AllowMulti, InstMap0,
                 OrElseGoals0, OrElseGoals, !ModuleInfo, !Requant),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals),
+                MainGoal, OrElseGoals, OrElseInners),
             GoalExpr = shorthand(ShortHand)
         ;
             ShortHand0 = bi_implication(_, _),
@@ -977,7 +977,7 @@
     ;
         GoalExpr0 = shorthand(ShortHand0),
         (
-            ShortHand0 = atomic_goal(_, _, _, _, _, _),
+            ShortHand0 = atomic_goal(_, _, _, _, _, _, _),
             Goal = Goal0,
             FoundDeconstruct = given_up_search
         ;
Index: compiler/typecheck.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/typecheck.m,v
retrieving revision 1.436
diff -u -r1.436 typecheck.m
--- compiler/typecheck.m	19 Feb 2009 03:49:18 -0000	1.436
+++ compiler/typecheck.m	21 Feb 2009 01:41:03 -0000
@@ -1245,7 +1245,7 @@
             ShortHand = bi_implication(LHS, RHS)
         ;
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners),
             trace [io(!IO)] (
                 type_checkpoint("atomic_goal", !.Info, !IO)
             ),
@@ -1259,10 +1259,11 @@
             typecheck_goal(MainGoal0, MainGoal, !Info),
             typecheck_goal_list(OrElseGoals0, OrElseGoals, !Info),
 
+            InnerVars = atomic_interface_list_to_var_list(
+                [Inner | OrElseInners]),
             Outer = atomic_interface_vars(OuterDI, OuterUO),
-            Inner = atomic_interface_vars(InnerDI, InnerUO),
-            ensure_vars_have_a_type([OuterDI, OuterUO, InnerDI, InnerUO],
-                !Info),
+            InterfaceVars = [OuterDI, OuterUO | InnerVars],
+            ensure_vars_have_a_type(InterfaceVars, !Info),
 
             % The outer variables must either be both I/O states of STM states.
             % Checking that here could double the number of type assign sets.
@@ -1270,16 +1271,23 @@
             % the predicate body, in post_typecheck. The code in the
             % post_typecheck pass (actually in purity.m) will do this
             % if the GoalType is unknown_atomic_goal_type.
-            typecheck_var_has_type(InnerDI, stm_atomic_type, !Info),
-            typecheck_var_has_type(InnerUO, stm_atomic_type, !Info),
+            foldl((pred(Var::in, Info0::in, Info::out) is det :-
+                    typecheck_var_has_type(Var, stm_atomic_type, Info0, Info)),
+                InnerVars, !Info),
             expect(unify(GoalType, unknown_atomic_goal_type), this_file,
                 "typecheck_goal_2: GoalType != unknown_atomic_goal_type"),
             ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal, OrElseGoals)
+                MainGoal, OrElseGoals, OrElseInners)
         ),
         GoalExpr = shorthand(ShortHand)
     ).
 
+:- func atomic_interface_list_to_var_list(list(atomic_interface_vars)) =
+    list(prog_var).
+atomic_interface_list_to_var_list([]) = [].
+atomic_interface_list_to_var_list([atomic_interface_vars(I, O) | Interfaces]) =
+    [I, O | atomic_interface_list_to_var_list(Interfaces)].
+
 %-----------------------------------------------------------------------------%
 
 :- pred typecheck_goal_list(list(hlds_goal)::in, list(hlds_goal)::out,
Index: compiler/unique_modes.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unique_modes.m,v
retrieving revision 1.128
diff -u -r1.128 unique_modes.m
--- compiler/unique_modes.m	23 Dec 2008 01:37:42 -0000	1.128
+++ compiler/unique_modes.m	20 Feb 2009 05:23:22 -0000
@@ -314,10 +314,10 @@
         GoalExpr0 = shorthand(ShortHand0),
         (
             ShortHand0 = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-                MainGoal0, OrElseGoals0),
+                MainGoal0, OrElseGoals0, OrElseInners0),
             unique_modes_check_goal_atomic_goal(GoalType, Outer, Inner,
-                MaybeOutputVars, MainGoal0, OrElseGoals0, GoalInfo0, GoalExpr,
-                !ModeInfo, !IO)
+                MaybeOutputVars, MainGoal0, OrElseGoals0, OrElseInners0,
+                GoalInfo0, GoalExpr, !ModeInfo, !IO)
         ;
             ShortHand0 = bi_implication(_, _),
             % These should have been expanded out by now.
@@ -638,11 +638,13 @@
 :- pred unique_modes_check_goal_atomic_goal(atomic_goal_type::in,
     atomic_interface_vars::in, atomic_interface_vars::in,
     maybe(list(prog_var))::in, hlds_goal::in, list(hlds_goal)::in,
+    list(atomic_interface_vars)::in,
     hlds_goal_info::in, hlds_goal_expr::out,
     mode_info::in, mode_info::out, io::di, io::uo) is det.
 
 unique_modes_check_goal_atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-        MainGoal0, OrElseGoals0, GoalInfo0, GoalExpr, !ModeInfo, !IO) :-
+        MainGoal0, OrElseGoals0, OrElseInners, GoalInfo0, GoalExpr, !ModeInfo,
+        !IO) :-
     mode_checkpoint(enter, "atomic_goal", !ModeInfo, !IO),
     (
         OrElseGoals0 = [],
@@ -676,7 +678,7 @@
         instmap_merge(NonLocals, InstMapList, merge_disj, !ModeInfo)
     ),
     ShortHand = atomic_goal(GoalType, Outer, Inner, MaybeOutputVars,
-        MainGoal, OrElseGoals),
+        MainGoal, OrElseGoals, OrElseInners),
     GoalExpr = shorthand(ShortHand),
     mode_checkpoint(exit, "atomic_goal", !ModeInfo, !IO).
 
Index: compiler/unused_imports.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/unused_imports.m,v
retrieving revision 1.17
diff -u -r1.17 unused_imports.m
--- compiler/unused_imports.m	23 Dec 2008 01:37:42 -0000	1.17
+++ compiler/unused_imports.m	20 Feb 2009 05:23:22 -0000
@@ -429,7 +429,7 @@
             hlds_goal_used_modules(GoalA, !UsedModules),
             hlds_goal_used_modules(GoalB, !UsedModules)
         ;
-            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals),
+            ShortHand = atomic_goal(_, _, _, _, MainGoal, OrElseGoals, _),
             hlds_goal_used_modules(MainGoal, !UsedModules),
             list.foldl(hlds_goal_used_modules, OrElseGoals, !UsedModules)
         )
Index: library/stm_builtin.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/stm_builtin.m,v
retrieving revision 1.13
diff -u -r1.13 stm_builtin.m
--- library/stm_builtin.m	27 Feb 2008 07:23:56 -0000	1.13
+++ library/stm_builtin.m	20 Feb 2009 05:23:22 -0000
@@ -190,8 +190,8 @@
     % Used to enforce the uniqueness of outer and inner variables.
     % Will be removed before stm_expansion.
     %
-:- pred stm_from_outer_to_inner_io(T::di, stm::uo) is det.
-:- pred stm_from_inner_to_outer_io(stm::di, T::uo) is det.
+:- pred stm_from_outer_to_inner(T::di, stm::uo) is det.
+:- pred stm_from_inner_to_outer(stm::di, T::uo) is det.
 
     % Changes the value of a transaction variable without going through
     % the log. USE ONLY FOR DEBUGGING PURPOSES.
@@ -351,7 +351,7 @@
 ").
 
 :- pragma foreign_proc("C",
-    stm_from_outer_to_inner_io(IO::di, STM::uo),
+    stm_from_outer_to_inner(IO::di, STM::uo),
     [promise_pure, will_not_call_mercury, thread_safe],
 "
     STM = NULL;
@@ -359,7 +359,7 @@
 ").
 
 :- pragma foreign_proc("C",
-    stm_from_inner_to_outer_io(STM0::di, IO::uo),
+    stm_from_inner_to_outer(STM0::di, IO::uo),
     [promise_pure, will_not_call_mercury, thread_safe],
 "
     STM0 = NULL;
--------------------------------------------------------------------------
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