[m-rev.] for review: fix det string switch in MLDS grades

Peter Wang novalazy at gmail.com
Thu Sep 13 15:00:15 AEST 2007


Estimated hours taken: 1
Branches: main

compiler/ml_string_switch.m:
	Fix a compiler abort when generating code for determistic string
	switches.

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


Index: compiler/ml_string_switch.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ml_string_switch.m,v
retrieving revision 1.32
diff -u -r1.32 ml_string_switch.m
--- compiler/ml_string_switch.m	21 Aug 2007 17:40:32 -0000	1.32
+++ compiler/ml_string_switch.m	13 Sep 2007 04:46:28 -0000
@@ -103,7 +103,21 @@
     switch_util.calc_hash_slots(HashValsList, HashValsMap, HashSlotsMap),
 
     % Generate the code for when the hash lookup fails.
-    ml_gen_failure(CodeModel, Context, FailStatements, !Info),
+    (
+        CodeModel = model_det,
+        FailComment =
+            statement(ml_stmt_atomic(comment("switch cannot fail")),
+                MLDS_Context),
+        FailStatements = []
+    ;
+        ( CodeModel = model_semi
+        ; CodeModel = model_non
+        ),
+        FailComment =
+            statement(ml_stmt_atomic(comment("no match, so fail")),
+                MLDS_Context),
+        ml_gen_failure(CodeModel, Context, FailStatements, !Info)
+    ),
 
     % Generate the code etc. for the hash table.
     gen_hash_slots(0, TableSize, HashSlotsMap, CodeModel,
@@ -196,9 +210,6 @@
                 yes), % This is a do...while loop.
             MLDS_Context)
         ],
-    FailComment =
-        statement(ml_stmt_atomic(comment("no match, so fail")),
-            MLDS_Context),
     EndLabelStatement = statement(ml_stmt_label(EndLabel), MLDS_Context),
     EndComment =
         statement(ml_stmt_atomic(comment("end of hashed string switch")),
Index: tests/valid/Mmakefile
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/valid/Mmakefile,v
retrieving revision 1.193
diff -u -r1.193 Mmakefile
--- tests/valid/Mmakefile	13 Aug 2007 03:02:01 -0000	1.193
+++ tests/valid/Mmakefile	13 Sep 2007 04:46:29 -0000
@@ -75,6 +75,7 @@
 	deforest_rerun_det \
 	det_condition \
 	det_inference \
+	det_string_switch \
 	det_switch \
 	double_vn \
 	easy_nondet_test \
Index: tests/valid/det_string_switch.m
===================================================================
RCS file: tests/valid/det_string_switch.m
diff -N tests/valid/det_string_switch.m
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ tests/valid/det_string_switch.m	13 Sep 2007 04:46:29 -0000
@@ -0,0 +1,34 @@
+% This is a regression test for a bug in MLDS code generation where it would
+% abort while generating the code of a deterministic string switch.
+%
+% Uncaught Mercury exception:
+% Software Error: ml_code_util.m: Unexpected: ml_gen_failure: `fail' has determinism `det'
+
+:- module det_string_switch.
+:- interface.
+
+:- import_module io.
+
+% Need this many cases to make a string switch.
+:- inst bar
+    --->    "a"
+    ;       "b"
+    ;       "c"
+    ;       "d"
+    ;       "e"
+    ;       "f"
+    ;       "g"
+    ;       "h".
+
+:- pred foo(string::in(bar), io::di, io::uo) is det.
+
+:- implementation.
+
+foo("a", !IO).
+foo("b", !IO).
+foo("c", !IO).
+foo("d", !IO). 
+foo("e", !IO).
+foo("f", !IO).
+foo("g", !IO).
+foo("h", !IO).

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