[m-rev.] for review: handling of unused arguments in ml_gen_wrapper_arg_lvals

Peter Wang novalazy at gmail.com
Fri May 22 15:08:58 AEST 2009


Bootchecked in hlc.gc.

Branches: main

compiler/ml_closure_gen.m:
        Fix a bug where `ml_gen_wrapper_arg_lvals' treated unused arguments
        like output arguments.  This caused the Java code generator to abort
        on some code.

tests/valid/Mmakefile:
tests/valid/wrapper_arg_lvals.m:
        Add test case.

diff --git a/compiler/ml_closure_gen.m b/compiler/ml_closure_gen.m
index 12c1639..a1deadb 100644
--- a/compiler/ml_closure_gen.m
+++ b/compiler/ml_closure_gen.m
@@ -1030,14 +1030,14 @@ ml_gen_wrapper_arg_lvals(Names, Types, Modes,
PredOrFunc, CodeModel, Context,
         ml_gen_info_get_module_info(!.Info, ModuleInfo),
         mode_to_arg_mode(ModuleInfo, Mode, Type, ArgMode),
         (
-            ArgMode = top_in,
+            ( ArgMode = top_in
+            ; ArgMode = top_unused
+            ),
             Lval = VarLval,
             CopyOutLvals = CopyOutLvalsTail,
             Defns = DefnsTail
         ;
-            ( ArgMode = top_out
-            ; ArgMode = top_unused
-            ),
+            ArgMode = top_out,
             % Handle output variables.
             ml_gen_info_get_globals(!.Info, Globals),
             CopyOut = get_copy_out_option(Globals, CodeModel),
diff --git a/tests/valid/Mmakefile b/tests/valid/Mmakefile
index f8cb0a4..73838a3 100644
--- a/tests/valid/Mmakefile
+++ b/tests/valid/Mmakefile
@@ -239,6 +239,7 @@ OTHER_PROGS= \
 	unreachable_code \
 	unused_args_test2 \
 	vn_float \
+	wrapper_arg_lvals \
 	zero_arity

 C_INTERFACE_PROGS = \
diff --git a/tests/valid/wrapper_arg_lvals.m b/tests/valid/wrapper_arg_lvals.m
new file mode 100644
index 0000000..c83bf18
--- /dev/null
+++ b/tests/valid/wrapper_arg_lvals.m
@@ -0,0 +1,30 @@
+% ml_gen_wrapper_arg_lvals was incorrectly determining `unused' arguments to be
+% output variables.  This led to a compiler abort when compiling this module to
+% Java.
+%
+% Software Error: assoc_list.from_corresponding_lists: lists have
different lengths.
+%         Key list type: list.list(ml_backend.mlds.mlds_type)
+%         Key list length: 1
+%         Value list type: list.list(ml_backend.mlds.mlds_rval)
+%         Value list length: 2
+
+:- module wrapper_arg_lvals.
+:- interface.
+
+:- typeclass tc(T, V) where [
+    pred bananas(T::unused, V::out) is det
+].
+
+:- instance tc(int, string).
+
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+
+:- implementation.
+
+:- instance tc(int, string) where [
+    bananas(_, "no bananas today")
+].
+
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=8 sts=4 sw=4 et
--------------------------------------------------------------------------
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