[m-rev.] for review: --trace shallow variable liveness problem

Peter Wang novalazy at gmail.com
Thu Jun 4 17:14:03 AEST 2009


I have a feeling that the "fix" is really working around another bug;
in that case this is a bug report.


Branches: main

Fix a compiler abort when compiling the given program with --trace shallow.

compiler/live_vars.m:
        Remove any call forward vars from the post-deaths set of a goal.
        In the test program, a typeinfo variable added to the forward vars set
        by maybe_add_typeinfo_liveness was already in the post-death set.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/livevars_shallow.m:
        Add test case.

diff --git a/compiler/live_vars.m b/compiler/live_vars.m
index 8dd3c4a..6e5edeb 100644
--- a/compiler/live_vars.m
+++ b/compiler/live_vars.m
@@ -485,13 +485,20 @@ build_live_sets_in_call(OutVars, GoalInfo0,
GoalInfo, ResumeVars0, AllocData,
         Detism = detism_erroneous,
         AllocData ^ ad_opt_no_return_calls = yes
     ->
-        NeedAcrossCall = need_across_call(set.init, set.init, set.init)
+        NeedAcrossCall = need_across_call(set.init, set.init, set.init),
+        GoalInfo1 = GoalInfo0
     ;
         NeedAcrossCall = need_across_call(ForwardVars, ResumeVars0,
-            !.NondetLiveness)
+            !.NondetLiveness),
+        % Make sure a variable doesn't appear in both the forward vars and
+        % post-death set.  (Perhaps the same thing needs to be done for
+        % other need_across_call sets?)
+        goal_info_get_post_deaths(GoalInfo0, PostDeaths0),
+        set.difference(PostDeaths0, ForwardVars, PostDeaths1),
+        goal_info_set_post_deaths(PostDeaths1, GoalInfo0, GoalInfo1)
     ),

-    record_call_site(NeedAcrossCall, GoalInfo0, GoalInfo, !StackAlloc),
+    record_call_site(NeedAcrossCall, GoalInfo1, GoalInfo, !StackAlloc),

     % If this is a nondet call, then all the stack slots we need
     % must be protected against reuse in following code.
diff --git a/tests/valid/Mercury.options b/tests/valid/Mercury.options
index 0fe580b..cc56453 100644
--- a/tests/valid/Mercury.options
+++ b/tests/valid/Mercury.options
@@ -96,6 +96,7 @@ MCFLAGS-intermod_user_sharing	= --intermodule-optimization
 MCFLAGS-intermod_user_sharing_2	= --intermodule-optimization
 MCFLAGS-lambda_inference	= --infer-all
 MCFLAGS-livevals_seq		= -O5 --opt-space
+MCFLAGS-livevars_shallow	= --grade none --trace shallow
 MCFLAGS-loop_inv_bug		= --common-struct --loop-invariants
 MCFLAGS-mc_bag			= --prop-mode-constraints
 MCFLAGS-mc_extra_nonlocals	= --prop-mode-constraints
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index 76ea6ad..716861e 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -155,6 +155,7 @@ OTHER_PROGS= \
 	lazy_list \
 	liveness_nonlocals \
 	livevals_seq \
+	livevars_shallow \
 	long_name \
 	loop \
 	loop_in_disj \
diff --git a/tests/valid/livevars_shallow.m b/tests/valid/livevars_shallow.m
new file mode 100644
index 0000000..e7763d4
--- /dev/null
+++ b/tests/valid/livevars_shallow.m
@@ -0,0 +1,54 @@
+%-----------------------------------------------------------------------------%
+% Regression test.
+% The compiler aborted on this module with --trace shallow.
+%
+% Software Error: continuation_info.m: Unexpected: find_typeinfos_for_tvars:
+% can't find rval for type_info var TypeInfo_for_AtomicTask
+%
+%-----------------------------------------------------------------------------%
+
+:- module livevars_shallow.
+:- interface.
+
+:- pred update({}::out) is det.
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- type net(AtomicTask)
+    --->    net.
+
+:- type task(AtomicTask)
+    --->    task.
+
+:- type task_type(AtomicTask)
+    --->    atomik
+    ;       composite.
+
+%-----------------------------------------------------------------------------%
+
+update(AtomicTasks) :-
+    Net = net : net(int),
+    classify_nodes(Net, AtomicTasks).
+
+:- pred classify_nodes(net(AtomicTask)::in, {}::out) is det.
+
+classify_nodes(_ : net(AtomicTask), AtomicTasks) :-
+    Task = task : task(AtomicTask),
+    TaskType = get_task_type(Task),
+    (
+        TaskType = atomik,
+        AtomicTasks = {}
+    ;
+        TaskType = composite,
+        AtomicTasks = {}
+    ).
+
+:- func get_task_type(task(AtomicTask)) = task_type(AtomicTask).
+
+get_task_type(_) = atomik.
+
+%-----------------------------------------------------------------------------%
+% vim: set sts=4 sw=4 et:
--------------------------------------------------------------------------
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