Import Upstream version 20180207
[hcoop/debian/mlton.git] / doc / hacker-guide / notes.tex
CommitLineData
7f918cf1
CE
1
2\chap{Notes}{notes}
3
4This chapter contains random notes (usually old emails) on various
5subtle issues.
6
7\section{IntInf and Flattener}
8
9\begin{verbatim}
10From: "Stephen T. Weeks" <sweeks@intertrust.com>
11Date: Tue, 27 Jun 2000 18:52:19 -0700 (PDT)
12To: MLton@research.nj.nec.com
13Subject: safe for space ... and IntInf
14\end{verbatim}
15
16Your mail also came at a fortunate time, as I was trying to track down
17a seg fault I was getting in the smith-normal-form regression test.
18For stress testing, I turned off all the cps simplify passes (except
19for poly equal) and ran the regressions. smith-normal-form failed
20with a seg fault when compiled normally, and failed with an assertion
21failure in \verb+IntInf_do_neg+ when compiled -g. The assertion
22failure was right at the beginning, checking that the frontier is in
23the expected place.
24\begin{verbatim}
25 assert(frontier == (pointer)&bp->limbs[bp->card - 1]);
26\end{verbatim}
27I'd been tracking this bug for a couple hours when I received your
28mail about the flattener. Do you see the connection? :-) As a
29reminder, here is the code for \verb+bigNegate+
30\begin{verbatim}
31 fun bigNegate (arg: bigInt): bigInt =
32 if Prim.isSmall arg
33 then let val argw = Prim.toWord arg
34 in if argw = badw
35 then negBad
36 else Prim.fromWord (Word.- (0w2, argw))
37 end
38 else Prim.~ (arg, allocate (1 + bigSize arg))
39\end{verbatim}
40The problem is, when the flattener is turned off, there is an
41allocation in between the call to allocate and the \verb+Prim.~+ call. The
42argument tuple allocation screws everything up. So, we are relying on
43the flattener for correctness of the IntInf implementation. Any ideas
44on how to improve the implementation to remove this reliance, or at
45least put an assert somewhere to avoid falling prey to this bug again?
46