[m-rev.] for review: unused arg determinism bug fix
Peter Ross
petdr at cs.mu.OZ.AU
Wed Feb 13 00:49:29 AEDT 2002
Hi,
For Simon to review.
===================================================================
Estimated hours taken: 4
Branches: main
Fix a bug where unused argument procedures were being called from the
wrong code_model in their parent procedure. This bug only shows up on
the MLDS backends.
compiler/unused_args.m:
Use the declared determinism for determining the determinism of a
call to a unused argument procedure, not the actual determinism.
tests/valid/Mmakefile:
tests/valid/unused_arg_determinism.exp:
tests/valid/unused_arg_determinism.m:
Test case.
Index: compiler/unused_args.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/compiler/unused_args.m,v
retrieving revision 1.73
diff -u -r1.73 unused_args.m
--- compiler/unused_args.m 7 Apr 2001 14:05:03 -0000 1.73
+++ compiler/unused_args.m 12 Feb 2002 13:35:09 -0000
@@ -982,6 +982,18 @@
proc_info_headvars(OldProc0, HeadVars),
proc_info_goal(OldProc0, Goal0),
Goal0 = _GoalExpr - GoalInfo0,
+
+ % We must use the declared determinism for determining
+ % the determinism of the version of the goal with its
+ % arguments removed.
+ proc_info_declared_determinism(OldProc0, MaybeDeterminism),
+ ( MaybeDeterminism = yes(DeclaredDeterminism),
+ Determinism = DeclaredDeterminism
+ ; MaybeDeterminism = no,
+ proc_info_inferred_determinism(OldProc0, Determinism)
+ ),
+ goal_info_set_determinism(GoalInfo0, Determinism, GoalInfo1),
+
proc_info_vartypes(OldProc0, VarTypes0),
set__list_to_set(HeadVars, NonLocals),
map__apply_to_list(HeadVars, VarTypes0, VarTypeList),
@@ -992,7 +1004,7 @@
remove_listof_elements(HeadVars, 1, UnusedArgs, NewHeadVars),
GoalExpr = call(NewPredId, NewProcId, NewHeadVars,
not_builtin, no, qualified(PredModule, PredName)),
- Goal1 = GoalExpr - GoalInfo0,
+ Goal1 = GoalExpr - GoalInfo1,
implicitly_quantify_goal(Goal1, Varset0, VarTypes1,
NonLocals, Goal, Varset, VarTypes, _),
proc_info_set_goal(OldProc0, Goal, OldProc1),
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/tests/valid/Mmakefile,v
retrieving revision 1.95
diff -u -r1.95 Mmakefile
--- tests/valid/Mmakefile 4 Jan 2002 05:56:40 -0000 1.95
+++ tests/valid/Mmakefile 12 Feb 2002 13:15:31 -0000
@@ -166,6 +166,7 @@
uniq_mode_inf_bug.m \
unreachable_code.m \
unused_args_test2.m \
+ unused_arg_determinism.m \
vn_float.m \
zero_arity.m
@@ -297,6 +298,7 @@
MCFLAGS-typeclass_det_warning = --halt-at-warn
MCFLAGS-unify_typeinfo_bug = -O3 --no-special-preds
MCFLAGS-uniq_mode_inf_bug = --infer-all
+MCFLAGS-unused_arg_determinism = -O5 # --no-warn-inferred-erroneous
MCFLAGS-vn_float = -O5
MCFLAGS-zero_arity = --infer-modes
Index: tests/valid/unused_arg_determinism.exp
===================================================================
RCS file: tests/valid/unused_arg_determinism.exp
diff -N tests/valid/unused_arg_determinism.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/valid/unused_arg_determinism.exp 12 Feb 2002 13:12:16 -0000
@@ -0,0 +1,4 @@
+Uncaught exception:
+Software Error: sorry, `foo' not implemented
+for this target language (or compiler back-end).
+Stack dump not available in this grade.
Index: tests/valid/unused_arg_determinism.m
===================================================================
RCS file: tests/valid/unused_arg_determinism.m
diff -N tests/valid/unused_arg_determinism.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/valid/unused_arg_determinism.m 12 Feb 2002 13:10:38 -0000
@@ -0,0 +1,25 @@
+ % foo is declared semidet but is actually erroneous.
+ % Unused argument elimination used to generate a call to the
+ % unused version in a model_det context instead of the correct
+ % model_semi context.
+:- module unused_arg_determinism.
+:- interface.
+:- import_module io.
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- type t.
+:- func foo(t) = t.
+:- mode foo(in) = out is semidet.
+
+:- implementation.
+:- type t ---> t ; u.
+main -->
+ ( { X = foo(t) } ->
+ io__write(X)
+ ;
+ io__write_string("failure")
+ ),
+ io__nl.
+
+foo(_) = _ :-
+ private_builtin__sorry("foo").
----
Peter Ross
PhD Student University of Melbourne
http://www.cs.mu.oz.au/~petdr/
--------------------------------------------------------------------------
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