Version
v110.71
Operating System
OS Version
No response
Processor
Any
Component
Core system
Severity
Minor
Description of the problem
The compiler crashes with the message
Recover.get: 334
Error: Compiler bug: Recover: Recover.recover.get
while in specialize phase
unexpected exception (bug?) in SML/NJ: Io [Io: openAppend failed on "flint.core", Win32TextPrimIO:openApp: failed]
raised at: Basis/Implementation/IO/text-io-fn.sml:792.25-792.75
../compiler/Basics/stats/stats.sml:198.40
../compiler/TopLevel/interact/evalloop.sml:44.55
when entering the expression shown below. (It also crashes when
loading a file containing that expression via use, or when using
compilation manager to compile the file.)
Transcript
Standard ML of New Jersey v110.71 [built: Thu Sep 17 08:50:14 2009]
- let fun split_ST3_SK3_SK1_ST3 (x55, x56, x57, x58, x59) = split_ST2_SK3_SK1_ST3 (op + (x55, 1), x56, x57, x58, x59)
and yield_SK2_ST3_SK1_ST3 (x50, x51, x52, x53, x54) = split_ST3_SK3_SK1_ST3 (x50, x51, x52, x53, x54)
and split_ST2_SK2_ST3_SK1 (x46, x47, x48, x49) = if op > (x46, x47) then [] else yield_SK2_ST3_SK1_ST3 (x48, x49, x46, x46, x47)
and split_ST3_SK2_ST3_SK1 (x42, x43, x44, x45) = split_ST2_SK2_ST3_SK1 (op + (x42, 1), x43, x44, x45)
and split_ST1_ST3_ST3_SK1 (x38, x39, x40, x41) = split_ST3_SK2_ST3_SK1 (x38, x39, x40, x41)
and yield_SK1_ST1_ST3_ST3 (x33, x34, x35, x36, x37) = op :: (x33, split_ST1_ST3_ST3_SK1 (x34, x35, x36, x37))
and yield_SK3_SK1_ST3_ST3 (x27, x28, x29, x30, x31, x32) = yield_SK1_ST1_ST3_ST3 ((x27, x30), x28, x29, x31, x32)
and split_ST2_SK3_SK1_ST3 (x22, x23, x24, x25, x26) = if op > (x22, x23) then [] else yield_SK3_SK1_ST3_ST3 (x24, x25, x26, x22, x22, x23)
and split_ST4_SK3_SK1_ST3 (x17, x18, x19, x20, x21) = split_ST2_SK3_SK1_ST3 (x17, x18, x19, x20, x21)
and yield_SK2_ST4_SK1_ST3 (x12, x13, x14, x15, x16) = split_ST4_SK3_SK1_ST3 (x12, x13, x14, x15, x16)
and split_ST2_SK2_ST4_SK1 (x8, x9, x10, x11) = if op > (x8, x9) then [] else yield_SK2_ST4_SK1_ST3 (x10, x11, x8, x8, x9)
and split_ST4_SK2_ST4_SK1 (x4, x5, x6, x7) = split_ST2_SK2_ST4_SK1 (x4, x5, x6, x7)
and split_ST5_ST4_ST4_SK1 (x0, x1, x2, x3) = split_ST4_SK2_ST4_SK1 (x0, x1, x2, x3)
in split_ST5_ST4_ST4_SK1 (0, 10, 20, 30)
end;
Recover.get: 4
Error: Compiler bug: Recover: Recover.recover.get
while in specialize phase
unexpected exception (bug?) in SML/NJ: Io [Io: openAppend failed on \"flint.core\", Win32TextPrimIO:openApp: failed]
raised at: Basis/Implementation/IO/text-io-fn.sml:792.25-792.75
../compiler/Basics/stats/stats.sml:198.40
../compiler/TopLevel/interact/evalloop.sml:44.55
-
Expected Behavior
No response
Steps to Reproduce
let fun split_ST3_SK3_SK1_ST3 (x55, x56, x57, x58, x59) = split_ST2_SK3_SK1_ST3 (op + (x55, 1), x56, x57, x58, x59)
and yield_SK2_ST3_SK1_ST3 (x50, x51, x52, x53, x54) = split_ST3_SK3_SK1_ST3 (x50, x51, x52, x53, x54)
and split_ST2_SK2_ST3_SK1 (x46, x47, x48, x49) = if op > (x46, x47) then [] else yield_SK2_ST3_SK1_ST3 (x48, x49, x46, x46, x47)
and split_ST3_SK2_ST3_SK1 (x42, x43, x44, x45) = split_ST2_SK2_ST3_SK1 (op + (x42, 1), x43, x44, x45)
and split_ST1_ST3_ST3_SK1 (x38, x39, x40, x41) = split_ST3_SK2_ST3_SK1 (x38, x39, x40, x41)
and yield_SK1_ST1_ST3_ST3 (x33, x34, x35, x36, x37) = op :: (x33, split_ST1_ST3_ST3_SK1 (x34, x35, x36, x37))
and yield_SK3_SK1_ST3_ST3 (x27, x28, x29, x30, x31, x32) = yield_SK1_ST1_ST3_ST3 ((x27, x30), x28, x29, x31, x32)
and split_ST2_SK3_SK1_ST3 (x22, x23, x24, x25, x26) = if op > (x22, x23) then [] else yield_SK3_SK1_ST3_ST3 (x24, x25, x26, x22, x22, x23)
and split_ST4_SK3_SK1_ST3 (x17, x18, x19, x20, x21) = split_ST2_SK3_SK1_ST3 (x17, x18, x19, x20, x21)
and yield_SK2_ST4_SK1_ST3 (x12, x13, x14, x15, x16) = split_ST4_SK3_SK1_ST3 (x12, x13, x14, x15, x16)
and split_ST2_SK2_ST4_SK1 (x8, x9, x10, x11) = if op > (x8, x9) then [] else yield_SK2_ST4_SK1_ST3 (x10, x11, x8, x8, x9)
and split_ST4_SK2_ST4_SK1 (x4, x5, x6, x7) = split_ST2_SK2_ST4_SK1 (x4, x5, x6, x7)
and split_ST5_ST4_ST4_SK1 (x0, x1, x2, x3) = split_ST4_SK2_ST4_SK1 (x0, x1, x2, x3)
in split_ST5_ST4_ST4_SK1 (0, 10, 20, 30)
end
Additional Information
No response
Email address
[email protected]
Comments from smlnj-gforge
Original smlnj-gforge bug number 45
Submitted via web form by Morten Rhiger [email protected] on 2009-11-02 at 14:1100
Keywords: flint.core, Win32TextPrimIO, openApp
comment by @larsbergstrom on 2009-13-12 03:1300 +000 UTC
Not Windows-specific - reproduces on OSX too: ~ Standard ML of New Jersey v110.71 [built: Sat Nov 21 16:40:08 2009] ~ - use "/Users/larsberg/Desktop/foo.txt"; ~ [opening /Users/larsberg/Desktop/foo.txt] ~ Recover.get: 4 ~ Error: Compiler bug: Recover: Recover.recover.get ~ ~ while in specialize phase ~ raised at: ../compiler/Basics/errormsg/errormsg.sml:52.14-52.19 ~ ../compiler/FLINT/opt/recover.sml:123.44 ~ ../compiler/Basics/stats/stats.sml:198.40 ~ ~ uncaught exception Error ~ raised at: ../compiler/Basics/errormsg/errormsg.sml:52.14-52.19 ~ ../compiler/FLINT/opt/recover.sml:123.44 ~ ../compiler/Basics/stats/stats.sml:198.40 ~ ../compiler/FLINT/main/flintcomp.sml:183.13 ~ ../compiler/Basics/stats/stats.sml:198.40 ~ ../compiler/TopLevel/interact/evalloop.sml:44.55 ~ ../compiler/TopLevel/interact/evalloop.sml:296.17-296.20 ~ -
comment by @JohnReppy on 2015-01-23 22:0100 +000 UTC
This bug still exists in 110.78 on Mac OS X. The final message is a bit different: ~ ~ Recover.get: 4 ~ Error: Compiler bug: Recover: Recover.recover.get ~ ~ while in specialize phase ~ raised at: ../compiler/Basics/errormsg/errormsg.sml:52.14-52.19 ~ ../compiler/FLINT/opt/recover.sml:123.44 ~ ../compiler/Basics/stats/stats.sml:198.40 ~
comment by @JohnReppy on 2015-51-23 22:5100 +000 UTC
The bug is because of an attempt to lookup a variable that isn't bound. Turning on Control.FLINT.print shows that the problem is in contraction. Specifically, after contraction, we have the following residual code ~ ~ ==================== ~ [After fcontract ...] ~ ~ v424{1} : (FCT) = ~ FN([v612{0} : ???], ~ FIX(v197{2,2} : (RFUN rr) = ~ FN([v539{3} : I, ~ v540{2} : I, ~ v541{1} : I, ~ v542{1} : I, ~ v543{2} : I], ~ IF PRIMOP(>, <I,I> -rr-> , []) [v539,v540] ~ THEN ~ v526{1} = RECORD [] ~ v525{1} = CON(nil, [TT<I,I>], v526) ~ RETURN [v525] ~ ELSE ~ v508{1} = RECORD [v541,v539] ~ v470{3} = PRIMOP(+, <I,I> -rr-> , []) [v542,(I)1] ~ [v493{1}] = APP(v192,[v470,v543,v539,v540]) ~ v364{1} = RECORD [v508,v493] ~ v494{1} = CON(::, [TT<I,I>], v364) ~ RETURN [v494])) ~ [v189{1}] = IF PRIMOP(>, <I,I> -rr-> , []) [(I)0,(I)10] ~ THEN ~ v572{1} = RECORD [] ~ v571{1} = CON(nil, [TT<I,I>], v572) ~ RETURN [v571] ~ ELSE ~ APP(v197,[(I)20,(I)30,(I)0,(I)0,(I)10]) ~ v611{1} = STRUCT [v189] ~ RETURN [v611]) ~ ~ Recover.get: 192 ~ Error: Compiler bug: Recover: Recover.recover.get ~ ==================== ~ ~ Notice that the function v192 is applied, but not bound anywhere. Its binding has been removed by the contraction phase. I think that v192 corresponds to split_ST2_SK3_SK1_ST3 in the source. ~
comment by @JohnReppy on 2015-29-24 00:2900 +000 UTC
I have reduced the example by hand-eta reducing all but one of the available eta reductions. Eliminating the remaining eta reduction will cause the bug to disappear. The reduced version of the bug is loaded as an attachment, as is a transcript of the debug output.
comment by @JohnReppy on 2015-29-24 20:2900 +000 UTC
Fixed for 110.79. ~ ~ The problem turns out to be a bad interaction between eta contraction and simple inlining. The situation is that we have a function v5 (split_4 in the source) that is mapped by eta contraction to a function v4 (split_3). The function v4 contains a call to v3, while another function, v6, contains a non-tail application of v5. During inlining, we first contract v4 and inline the call to v3; we then contract v6 and inline the call to v5, but it is mapped to the old definition of v4! The result is a residual program that contains a call to v3, but where v3 has been deleted as unused. ~ ~ To fix this problem, I modified the fcApp function so that when it maps its argument function f to Fun(g, ...) and g is a different LVar than f, then I recursively call fcApp on g with the same argument list.