[m-rev.] diff: fix bug in simplify.m
Simon Taylor
stayl at cs.mu.OZ.AU
Wed May 15 00:35:31 AEST 2002
Estimated hours taken: 2.5
Fix a code generator abort reported by rafe.
compiler/simplify.m:
Recompute instmap deltas and rerun determinism analysis
after optimizing away part of an if-then-else, to avoid
a case where a conjunction with determinism `erroneous'
was being given determinism `det' (which was the
determinism of the enclosing if-then-else).
compiler/common.m:
Rerun determininsm analysis after optimizing away a
duplicate call or unification with determinism other
than `det'.
tests/valid/Mmakefile:
tests/valid/simplify_bug2.m:
Test case.
Index: compiler/common.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/common.m,v
retrieving revision 1.63
diff -u -u -r1.63 common.m
--- compiler/common.m 28 Mar 2002 03:42:49 -0000 1.63
+++ compiler/common.m 14 May 2002 08:29:10 -0000
@@ -168,7 +168,7 @@
)
;
Unification0 = deconstruct(Var, ConsId,
- ArgVars, UniModes, _, _),
+ ArgVars, UniModes, CanFail, _),
simplify_info_get_module_info(Info0, ModuleInfo),
(
% Don't optimise partially instantiated
@@ -194,10 +194,15 @@
OldStruct = structure(_, _, _, OldArgVars),
common__create_output_unifications(GoalInfo0, ArgVars,
OldArgVars, UniModes, Goals, Info0, Info1),
- simplify_info_set_requantify(Info1, Info2),
Goal = conj(Goals),
pd_cost__goal(Goal0 - GoalInfo0, Cost),
- simplify_info_incr_cost_delta(Info2, Cost, Info)
+ simplify_info_incr_cost_delta(Info1, Cost, Info2),
+ simplify_info_set_requantify(Info2, Info3),
+ ( CanFail = can_fail ->
+ simplify_info_set_rerun_det(Info3, Info)
+ ;
+ Info = Info3
+ )
;
Goal = Goal0,
common__record_cell(Var, ConsId, ArgVars, Info0, Info)
@@ -502,7 +507,13 @@
Structs1, SeenCalls0),
pd_cost__goal(Goal0 - GoalInfo, Cost),
simplify_info_incr_cost_delta(Info2, Cost, Info3),
- simplify_info_set_requantify(Info3, Info4)
+ simplify_info_set_requantify(Info3, Info4),
+ goal_info_get_determinism(GoalInfo, Detism0),
+ ( Detism0 \= det ->
+ simplify_info_set_rerun_det(Info4, Info5)
+ ;
+ Info5 = Info4
+ )
;
goal_info_get_context(GoalInfo, Context),
ThisCall = call_args(Context, InputArgs, OutputArgs),
@@ -511,7 +522,7 @@
CommonInfo = common(Eqv0, Structs0,
Structs1, SeenCalls),
Goal = Goal0,
- Info4 = Info0
+ Info5 = Info0
)
;
goal_info_get_context(GoalInfo, Context),
@@ -519,9 +530,9 @@
map__det_insert(SeenCalls0, SeenCall, [ThisCall], SeenCalls),
CommonInfo = common(Eqv0, Structs0, Structs1, SeenCalls),
Goal = Goal0,
- Info4 = Info0
+ Info5 = Info0
),
- simplify_info_set_common_info(Info4, CommonInfo, Info).
+ simplify_info_set_common_info(Info5, CommonInfo, Info).
%---------------------------------------------------------------------------%
Index: compiler/simplify.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/simplify.m,v
retrieving revision 1.102
diff -u -u -r1.102 simplify.m
--- compiler/simplify.m 28 Mar 2002 03:43:36 -0000 1.102
+++ compiler/simplify.m 14 May 2002 07:05:31 -0000
@@ -996,7 +996,9 @@
Info0, Info1),
goal_info_get_context(GoalInfo0, Context),
simplify_info_add_msg(Info1, ite_cond_cannot_fail(Context),
- Info)
+ Info2),
+ simplify_info_set_requantify(Info2, Info3),
+ simplify_info_set_rerun_det(Info3, Info)
; CondSolns0 = at_most_zero ->
% Optimize away the condition and the `then' part.
det_negation_det(CondDetism0, MaybeNegDetism),
@@ -1040,14 +1042,18 @@
Info0, Info1),
goal_info_get_context(GoalInfo0, Context),
simplify_info_add_msg(Info1, ite_cond_cannot_succeed(Context),
- Info)
+ Info2),
+ simplify_info_set_requantify(Info2, Info3),
+ simplify_info_set_rerun_det(Info3, Info)
; Else0 = disj([]) - _ ->
% (A -> C ; fail) is equivalent to (A, C)
goal_to_conj_list(Cond0, CondList),
goal_to_conj_list(Then0, ThenList),
list__append(CondList, ThenList, List),
simplify__goal(conj(List) - GoalInfo0, Goal - GoalInfo,
- Info0, Info)
+ Info0, Info1),
+ simplify_info_set_requantify(Info1, Info2),
+ simplify_info_set_rerun_det(Info2, Info)
;
%
% recursively simplify the sub-goals,
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.101
diff -u -u -r1.101 Mmakefile
--- tests/valid/Mmakefile 9 May 2002 05:00:54 -0000 1.101
+++ tests/valid/Mmakefile 14 May 2002 07:39:18 -0000
@@ -149,6 +149,7 @@
semidet_disj.m \
shape_type.m \
simplify_bug.m \
+ simplify_bug2.m \
soln_context.m \
some_switch.m \
spurious_purity_warning.m \
@@ -301,6 +302,7 @@
MCFLAGS-pred_with_no_modes = --infer-all
MCFLAGS-quantifier_warning = --halt-at-warn
MCFLAGS-simplify_bug = -O-1
+MCFLAGS-simplify_bug2 = -O3
MCFLAGS-spurious_purity_warning = --halt-at-warn
MCFLAGS-two_way_unif = -O-1
MCFLAGS-type_inf_ambig_test = --infer-all
Index: tests/valid/simplify_bug2.m
===================================================================
RCS file: tests/valid/simplify_bug2.m
diff -N tests/valid/simplify_bug2.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/valid/simplify_bug2.m 14 May 2002 07:39:02 -0000
@@ -0,0 +1,41 @@
+:- module simplify_bug2.
+
+:- interface.
+
+:- type type_info ---> type_info(c_pointer).
+:- type du_functor_descriptor ---> du_functor_descriptor(c_pointer).
+
+:- pred get_type_and_extra_args(type_info::in, P::in,
+ type_info::out) is det.
+
+:- implementation.
+
+:- import_module require.
+:- use_module std_util.
+
+get_type_and_extra_args(TypeInfoParams, PseudoTypeInfo, ArgTypeInfo) :-
+ (
+ typeinfo_is_variable(PseudoTypeInfo, VarNum)
+ ->
+ get_type_info_for_var(TypeInfoParams,
+ VarNum, ExpandedTypeInfo),
+ ( typeinfo_is_variable(ExpandedTypeInfo, _) ->
+ error("get_type_and_extra_args: unbound type variable")
+ ;
+ ArgTypeInfo = ExpandedTypeInfo
+ )
+ ;
+ error("get_type_and_extra_args")
+ ).
+
+:- pred get_type_info_for_var(type_info::in, int::in, type_info::out) is det.
+:- pragma no_inline(get_type_info_for_var/3).
+
+get_type_info_for_var(X, _, X).
+
+:- pred typeinfo_is_variable(T::in, int::out) is semidet.
+:- pragma no_inline(typeinfo_is_variable/2).
+
+typeinfo_is_variable(_, 42) :-
+ std_util__semidet_succeed.
+
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list