[m-rev.] for review: don't apply a lambda optimisation in erlang grade
Peter Wang
wangp at students.csse.unimelb.edu.au
Thu Aug 23 17:21:32 AEST 2007
Estimated hours taken: 1
Branches: main
Fix a bug in the following optimisation of model_non lambdas:
% Optimize a special case: replace
% `(pred(Y1, Y2, ...) is Detism :-
% p(X1, X2, ..., Y1, Y2, ...))'
% where `p' has determinism `Detism' with
% `p(X1, X2, ...)'
%
For the LLDS back-end the optimisation was also applied when `p' is model_det
but the lambda is model_non. However it was incorrectly applied for the
erlang grade as well.
compiler/lambda.m:
Don't apply the optimisation in the case above.
tests/hard_coded/Mmakefile:
tests/hard_coded/nondet_lambda.exp:
tests/hard_coded/nondet_lambda.m:
Add a test case.
Index: compiler/lambda.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/lambda.m,v
retrieving revision 1.130
diff -u -r1.130 lambda.m
--- compiler/lambda.m 7 Aug 2007 07:09:56 -0000 1.130
+++ compiler/lambda.m 23 Aug 2007 07:20:58 -0000
@@ -395,19 +395,31 @@
Call_CodeModel = proc_info_interface_code_model(Call_ProcInfo),
determinism_to_code_model(Detism, CodeModel),
module_info_get_globals(ModuleInfo0, Globals),
+ globals.get_target(Globals, Target),
globals.lookup_bool_option(Globals, highlevel_code, HighLevelCode),
(
- HighLevelCode = no,
+ ( Target = target_c
+ ; Target = target_il
+ ; Target = target_java
+ ; Target = target_asm
+ ; Target = target_x86_64
+ ),
(
- CodeModel = Call_CodeModel
+ HighLevelCode = no,
+ (
+ CodeModel = Call_CodeModel
+ ;
+ CodeModel = model_non,
+ Call_CodeModel = model_det
+ )
;
- CodeModel = model_non,
- Call_CodeModel = model_det
+ HighLevelCode = yes,
+ Call_PredOrFunc = pred_info_is_pred_or_func(Call_PredInfo),
+ PredOrFunc = Call_PredOrFunc,
+ CodeModel = Call_CodeModel
)
;
- HighLevelCode = yes,
- Call_PredOrFunc = pred_info_is_pred_or_func(Call_PredInfo),
- PredOrFunc = Call_PredOrFunc,
+ Target = target_erlang,
CodeModel = Call_CodeModel
),
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.330
diff -u -r1.330 Mmakefile
--- tests/hard_coded/Mmakefile 20 Aug 2007 03:36:18 -0000 1.330
+++ tests/hard_coded/Mmakefile 23 Aug 2007 07:20:58 -0000
@@ -152,6 +152,7 @@
nonascii \
nondet_copy_out \
nondet_ctrl_vn \
+ nondet_lambda \
nullary_ho_func \
one_member \
opt_dup_bug \
Index: tests/hard_coded/nondet_lambda.exp
===================================================================
RCS file: tests/hard_coded/nondet_lambda.exp
diff -N tests/hard_coded/nondet_lambda.exp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/nondet_lambda.exp 23 Aug 2007 07:20:58 -0000
@@ -0,0 +1 @@
+42
Index: tests/hard_coded/nondet_lambda.m
===================================================================
RCS file: tests/hard_coded/nondet_lambda.m
diff -N tests/hard_coded/nondet_lambda.m
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/hard_coded/nondet_lambda.m 23 Aug 2007 07:20:58 -0000
@@ -0,0 +1,23 @@
+:- module nondet_lambda.
+:- interface.
+
+:- import_module io.
+
+:- pred main(io::di, io::uo) is cc_multi.
+
+:- implementation.
+
+main(!IO) :-
+ % The compiler was incorrectly simplifying this to `F = bar' in the erlang
+ % grade.
+ F = (pred(X::out) is nondet :- bar(X)),
+ ( F(Y) ->
+ io__write(Y, !IO),
+ io__write_string("\n", !IO)
+ ;
+ true
+ ).
+
+:- pred bar(int).
+:- mode bar(out) is det.
+bar(42).
--------------------------------------------------------------------------
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