[m-dev.] for review: fix bug with quantification & instmap deltas
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Jun 10 04:14:20 AEST 1999
Estimated hours taken: 1
Fix a bug that caused a variable not found error when compiling
library/term_io.m with intermodule optimization in my local version
of the Mercury compiler (which has various changes for existential types).
The problem was that when liveness.m calls requantify_proc,
quantification.m discovers that a variable is now local to a subgoal,
but leaves the instmap delta on the containing goal unchanged, still
containing a (now bogus) entry for that variable.
I think the same problem could occur without my existenial types changes,
but constructing a test case to exercise this bug is difficult.
compiler/quantification.m:
Ensure that the instmap delta is restricted to only contain
entries for variables that occur in the goal's nonlocals.
Workspace: /home/mercury0/fjh/mercury-other
Index: compiler/quantification.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/quantification.m,v
retrieving revision 1.64
diff -u -u -2 -0 -r1.64 quantification.m
--- quantification.m 1999/03/13 01:29:10 1.64
+++ quantification.m 1999/06/09 18:08:47
@@ -51,42 +51,45 @@
%-----------------------------------------------------------------------------%
:- implementation.
+
+:- import_module instmap, goal_util.
+
:- import_module term, varset.
-:- import_module std_util, bool, goal_util, require.
+:- import_module std_util, bool, require.
% The `outside vars', `lambda outside vars', and `quant vars'
% fields are inputs; the `nonlocals' field is output; and
@@ -151,41 +154,50 @@
implicitly_quantify_goal(Goal0 - GoalInfo0, Goal - GoalInfo) -->
quantification__get_seen(SeenVars),
{ goal_info_get_context(GoalInfo0, Context) },
implicitly_quantify_goal_2(Goal0, Context, Goal1),
quantification__get_nonlocals(NonLocalVars),
(
% If there are any variables that are local to the goal
% which we have come across before, then we rename them
% apart.
{ quantification__goal_vars(Goal0 - GoalInfo0, GoalVars0) },
{ set__difference(GoalVars0, NonLocalVars, LocalVars) },
{ set__intersect(SeenVars, LocalVars, RenameVars) },
{ \+ set__empty(RenameVars) }
->
quantification__rename_apart(RenameVars, _, Goal1 - GoalInfo0,
Goal - GoalInfo1)
;
{ Goal = Goal1 },
{ GoalInfo1 = GoalInfo0 }
),
- { goal_info_set_nonlocals(GoalInfo1, NonLocalVars, GoalInfo) }.
+ { goal_info_set_nonlocals(GoalInfo1, NonLocalVars, GoalInfo2) },
+ %
+ % If the non-locals set has shrunk (e.g. because some optimization
+ % optimizes away the other occurrences of a variable, causing it
+ % to become local when previously it was non-local),
+ % then we may need to likewise shrink the instmap delta.
+ %
+ { goal_info_get_instmap_delta(GoalInfo2, InstMapDelta0) },
+ { instmap_delta_restrict(InstMapDelta0, NonLocalVars, InstMapDelta) },
+ { goal_info_set_instmap_delta(GoalInfo2, InstMapDelta, GoalInfo) }.
:- pred implicitly_quantify_goal_2(hlds_goal_expr, prog_context,
hlds_goal_expr, quant_info, quant_info).
:- mode implicitly_quantify_goal_2(in, in, out, in, out) is det.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list