[m-rev.] for post-commit review: fix recompute_instmap_delta of generic calls

Peter Wang novalazy at gmail.com
Thu Aug 28 13:12:10 AEST 2008


Estimated hours taken: 3
Branches: main

compiler/mode_util.m:
	`recompute_instmap_delta' was producing a `reachable' instmap_delta for
	a generic call with no solutions.  Fix this.

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

diff --git a/compiler/mode_util.m b/compiler/mode_util.m
index 77a09c8..c5445ad 100644
--- a/compiler/mode_util.m
+++ b/compiler/mode_util.m
@@ -1124,9 +1124,13 @@ recompute_instmap_delta_2(RecomputeAtomic, GoalExpr0, GoalExpr, GoalInfo,
             InstMap0, InstMapDelta, !RI),
         GoalExpr = scope(Reason, SubGoal)
     ;
-        GoalExpr0 = generic_call(_Details, Vars, Modes, _Detism),
-        ModuleInfo = !.RI ^ ri_module_info,
-        instmap_delta_from_mode_list(Vars, Modes, ModuleInfo, InstMapDelta),
+        GoalExpr0 = generic_call(_Details, Vars, Modes, Detism),
+        ( determinism_components(Detism, _, at_most_zero) ->
+            instmap_delta_init_unreachable(InstMapDelta)
+        ;
+            ModuleInfo = !.RI ^ ri_module_info,
+            instmap_delta_from_mode_list(Vars, Modes, ModuleInfo, InstMapDelta)
+        ),
         GoalExpr = GoalExpr0
     ;
         GoalExpr0 = plain_call(PredId, ProcId, Args, _BI, _UC, _Name),
diff --git a/tests/valid/Mercury.options b/tests/valid/Mercury.options
index 57782e0..0e63e0d 100644
--- a/tests/valid/Mercury.options
+++ b/tests/valid/Mercury.options
@@ -47,6 +47,7 @@ MCFLAGS-ho_and_type_spec_bug = -O4
 MCFLAGS-ho_and_type_spec_bug2 = -O3 --no-inlining
 MCFLAGS-impure_detism           = -O5 --deep-profiling
 MCFLAGS-inhibit_warn_test       = --inhibit-warnings --halt-at-warn
+MCFLAGS-instmap_generic_failure	= --local-constraint-propagation
 MCFLAGS-intermod_bug_nested	= --intermodule-optimization
 MCFLAGS-intermod_bug_nested.parser	= --intermodule-optimization
 MCFLAGS-intermod_dcg_bug2	= --intermodule-optimization
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index 1f11506..a9d10c9 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -118,6 +118,7 @@ OTHER_PROGS= \
 	indexing \
 	inhibit_warn_test \
 	inlining_bug \
+	instmap_generic_failure \
 	inst_perf_bug_1 \
 	int64 \
 	intermod_bug_nested \
diff --git a/tests/valid/instmap_generic_failure.m b/tests/valid/instmap_generic_failure.m
new file mode 100644
index 0000000..e01e6b6
--- /dev/null
+++ b/tests/valid/instmap_generic_failure.m
@@ -0,0 +1,22 @@
+% Regression test.  The compiler incorrectly computed the instmap delta of
+% generic calls with no solutions.
+
+:- module instmap_generic_failure.
+:- interface.
+
+:- import_module list.
+
+:- pred int_to_ascii(pred(int, int), int, list(int), list(int)).
+:- mode int_to_ascii(in(pred(in, out) is failure), in, in, out) is semidet.
+
+:- implementation.
+
+:- import_module int.
+
+int_to_ascii(ConvertNonAscii, U, Old, New) :-
+    ( U < 128 ->
+        New = [U | Old]
+    ;
+        ConvertNonAscii(U, S),  % failure
+        New = [S | Old]
+    ).


--------------------------------------------------------------------------
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