Home My Page Projects Code Snippets Project Openings SML/NJ Bugs
Summary Activity Tracker Lists

[#45] Compiler bug in specialize phase

Date:
2009-12-02 14:11
Priority:
3
State:
Closed
Submitted by:
Bug Submitter (webuser)
Assigned to:
David MacQueen (dbm)
Machine Architecture:
All
Operating System:
All
Component:
Compiler
Resolution:
Fixed
Severity:
Minor
OS Version:
SML/NJ Version:
v110.71
Keywords:
flint.core, Win32TextPrimIO, openApp
URL:
Transcript (of reproduction):
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 -
Source (for reproduction):
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
Summary:
Compiler bug in specialize phase

Detailed description
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.)
Submitted via web form by Morten Rhiger <morten.rhiger@gmail.com>

Comments:

Message  ↓
Date: 2015-09-24 20:29
Sender: John Reppy

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.

Date: 2015-09-24 00:29
Sender: John Reppy

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.

Date: 2015-09-23 22:51
Sender: John Reppy

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-> <B>, []) [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-> <I>, []) [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-> <B>, []) [(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.

Date: 2015-09-23 22:01
Sender: John Reppy

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

Date: 2009-12-12 03:13
Sender: Lars Bergstrom

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
-

Attached Files:

Attachments:
Size Name Date By Download
966 bytesbug-45.sml2015-09-24 00:29jhrbug-45.sml
4 KiBtranscript-45.txt2015-09-24 00:29jhrtranscript-45.txt

Changes

Field Old Value Date By
ResolutionNone2015-09-24 20:29jhr
status_idOpen2015-09-24 20:29jhr
close_dateNone2015-09-24 20:29jhr
File Added10: bug-45.sml2015-09-24 00:29jhr
File Added11: transcript-45.txt2015-09-24 00:29jhr
summaryCompiler bug in \2015-09-23 22:01jhr
detailsThe 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.) Submitted via web form by Morten Rhiger <morten.rhiger@gmail.com> 2015-09-23 22:01jhr
Machine ArchitectureNone2015-09-23 22:01jhr
assigned_tonone2011-04-08 16:53jhr
Operating SystemWindows XP2009-12-12 03:13larsberg