From: Matthew F. <fl...@ml...> - 2011-06-10 12:46:00
|
Regression tests with case expressions over weird-sized words. These regression tests demonstrate bugs with the handling of case expressions over weird-sized words. The weird-word1.sml regression test includes a case expression that enumerates 16 (of the 32) elements of Word5.word. This test triggers errors in the codegens and also an internal type error in the RSSA IL program. The root cause is that the constants in a case expression over weird-sized words are not rounded up to primitive-sized words in the SSA to RSSA conversion. [mtf@fenrir regression]$ mlton -codegen native weird-word1.sml WordX.mod [mtf@fenrir regression]$ mlton -codegen c weird-word1.sml WordSize.prim [mtf@fenrir regression]$ mlton -type-check true weird-word1.sml invalid transfer: switch {test = x_0, default = Some L_0, cases = ((0x0, L_16), (0x1, L_15), (0x2, L_14), (0x3, L_13), (0x4, L_12), (0x5, L_11), (0x6, L_10), (0x7, L_9), (0x8, L_8), (0x9, L_7), (0xA, L_6), (0xB, L_5), (0xC, L_4), (0xD, L_3), (0xE, L_2), (0xF, L_1))} invalid block: L_17 (x_0: [Word5, Bits3]) Jump = switch {test = x_0, default = Some L_0, cases = ((0x0, L_16), (0x1, L_15), (0x2, L_14), (0x3, L_13), (0x4, L_12), (0x5, L_11), (0x6, L_10), (0x7, L_9), (0x8, L_8), (0x9, L_7), (0xA, L_6), (0xB, L_5), (0xC, L_4), (0xD, L_3), (0xE, L_2), (0xF, L_1))} Rssa.typeCheck The weird-word2.sml regression test includes a case expression that enumerates 32 (of the 32) elements of Word5.word. This test triggers internal type errors in the SSA and SSA2 IL programs. The root cause is that the SSA and SSA2 type checkers demand a default case for all case expressions over words. [mtf@fenrir regression]$ mlton weird-word2.sml Ssa.TypeCheck.loopTransfer: case has no default [mtf@fenrir regression]$ mlton -type-check true weird-word2.sml Ssa.TypeCheck.loopTransfer: case has no default ---------------------------------------------------------------------- A mlton/trunk/regression/weird-word1.ok A mlton/trunk/regression/weird-word1.sml A mlton/trunk/regression/weird-word2.ok A mlton/trunk/regression/weird-word2.sml ---------------------------------------------------------------------- Added: mlton/trunk/regression/weird-word1.ok =================================================================== --- mlton/trunk/regression/weird-word1.ok 2011-06-10 19:45:57 UTC (rev 7539) +++ mlton/trunk/regression/weird-word1.ok 2011-06-10 19:45:59 UTC (rev 7540) @@ -0,0 +1 @@ +0wx8 Added: mlton/trunk/regression/weird-word1.sml =================================================================== --- mlton/trunk/regression/weird-word1.sml 2011-06-10 19:45:57 UTC (rev 7539) +++ mlton/trunk/regression/weird-word1.sml 2011-06-10 19:45:59 UTC (rev 7540) @@ -0,0 +1,26 @@ +fun fib (w: Word5.word) : Word5.word = + if w <= 0wx1 + then 0wx1 + else fib (w - 0wx1) + fib (w - 0wx2) + +val s = + case (fib 0wx5) of + 0wx0 => "0wx0" + | 0wx1 => "0wx1" + | 0wx2 => "0wx2" + | 0wx3 => "0wx3" + | 0wx4 => "0wx4" + | 0wx5 => "0wx5" + | 0wx6 => "0wx6" + | 0wx7 => "0wx7" + | 0wx8 => "0wx8" + | 0wx9 => "0wx9" + | 0wxA => "0wxA" + | 0wxB => "0wxB" + | 0wxC => "0wxC" + | 0wxD => "0wxD" + | 0wxE => "0wxE" + | 0wxF => "0wxF" + | _ => "zzz" + +val _ = print (concat [s, "\n"]) Added: mlton/trunk/regression/weird-word2.ok =================================================================== --- mlton/trunk/regression/weird-word2.ok 2011-06-10 19:45:57 UTC (rev 7539) +++ mlton/trunk/regression/weird-word2.ok 2011-06-10 19:45:59 UTC (rev 7540) @@ -0,0 +1 @@ +0wx8 Added: mlton/trunk/regression/weird-word2.sml =================================================================== --- mlton/trunk/regression/weird-word2.sml 2011-06-10 19:45:57 UTC (rev 7539) +++ mlton/trunk/regression/weird-word2.sml 2011-06-10 19:45:59 UTC (rev 7540) @@ -0,0 +1,41 @@ +fun fib (w: Word5.word) : Word5.word = + if w <= 0wx1 + then 0wx1 + else fib (w - 0wx1) + fib (w - 0wx2) + +val s = + case (fib 0wx5) of + 0wx0 => "0wx0" + | 0wx1 => "0wx1" + | 0wx2 => "0wx2" + | 0wx3 => "0wx3" + | 0wx4 => "0wx4" + | 0wx5 => "0wx5" + | 0wx6 => "0wx6" + | 0wx7 => "0wx7" + | 0wx8 => "0wx8" + | 0wx9 => "0wx9" + | 0wxA => "0wxA" + | 0wxB => "0wxB" + | 0wxC => "0wxC" + | 0wxD => "0wxD" + | 0wxE => "0wxE" + | 0wxF => "0wxF" + | 0wx10 => "0wx10" + | 0wx11 => "0wx11" + | 0wx12 => "0wx12" + | 0wx13 => "0wx13" + | 0wx14 => "0wx14" + | 0wx15 => "0wx15" + | 0wx16 => "0wx16" + | 0wx17 => "0wx17" + | 0wx18 => "0wx18" + | 0wx19 => "0wx19" + | 0wx1A => "0wx1A" + | 0wx1B => "0wx1B" + | 0wx1C => "0wx1C" + | 0wx1D => "0wx1D" + | 0wx1E => "0wx1E" + | 0wx1F => "0wx1F" + +val _ = print (concat [s, "\n"]) |