Skip to content

Instantly share code, notes, and snippets.

@Skyb0rg007
Last active March 4, 2025 21:23
Show Gist options
  • Save Skyb0rg007/b5524b52e295eb5242c4e62e0f21f3e7 to your computer and use it in GitHub Desktop.
Save Skyb0rg007/b5524b52e295eb5242c4e62e0f21f3e7 to your computer and use it in GitHub Desktop.
SML/NJ Compiler Bug
datatype 'a nested =
Nest of 'a * 'a list nested
| Epsilon
fun sumListWith f lst = let
fun go ([], acc) = acc
| go (x :: xs, acc) = go (xs, f x + acc)
in
go (lst, 0)
end
fun go (_ : 'a -> int, Epsilon : 'a nested, acc : int) : int = acc
| go (f, Nest (x, xs), acc) = let
val go' : ('a list -> int) * 'a list nested * int -> int = Unsafe.cast go
in
go' (sumListWith f, xs, f x + acc)
end
fun sum n = go (fn x => x, n, 0)
val nested : int nested = Nest (1, Nest ([2, 3, 4], Nest ([[5, 6], [7], [8, 9]], Epsilon)))
val nestedSum = sum nested
Standard ML of New Jersey v110.79 [built: Sat Oct 26 12:27:04 2019]
- = [autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
[autoloading done]
datatype 'a nested = Epsilon | Nest of 'a * 'a list nested
val sumListWith = fn : ('a -> int) -> 'a list -> int
val go = fn : ('a -> int) * 'a nested * int -> int
val sum = fn : int nested -> int
val nested = Nest (1,Nest ([#,#,#],Nest #)) : int nested
val nestedSum = 45 : int
Standard ML of New Jersey [Version 110.99.7.1; 64-bit; January 17, 2025]
- = [autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
[autoloading done]
Error: Compiler bug: Contract: UsageMap on v366
****** pass1 ******
v317(v339[C],v206[FN],v207[PV]) =
v341(v94[PV],v95[I]) =
if boxed(v94) [v349] then
v94.0 -> v67[PV]
v94.1 -> v68[PV]
v347(v346[I]) =
iadd63(v346,v95) -> v86[I]
v341(v68,v86)
v206(v347,v67)
else
v339(v95)
v341(v207,(I63t)0)
v13(v351[C],v305[PR1]) =
v319(v352[C],v318[FN]) =
v321(v353[C],v320[PV]) =
v317(v353,v318,v320)
v352(v321)
v351(v319)
v323(v355[C],v258[PR1]) =
v258.0 -> v170[I]
v330(v358[C],v119[FN],v120[PV],v121[I]) =
if boxed(v120) [v378] then
v120.0 -> v52[PV]
v120.1 -> v53[PV]
v328(v372[C],v329[PV]) =
v317(v366,v119,v270)
v376(v374[I]) =
iadd63(v374,v121) -> v110[I]
if i63=(v170,(I63t)2) [v365] then
v279(v366[C],v265[PV]) =
v265.0 -> v270[PV]
v317(v366,v119,v270)
v330(v358,v279,v53,v110)
else
if i63=(v170,(I63t)3) [v369] then
v282(v370[C],v267[PV]) =
cast(v328) -> v281[FN]
v267.0 -> v273[R64]
wrap_f64(v273) -> v275[PV]
v267.1 -> v274[R64]
wrap_f64(v274) -> v276[PV]
v281(v370,v275,v276)
v330(v358,v282,v53,v110)
else
cast(v328) -> v283[FN]
v330(v358,v283,v53,v110)
v119(v376,v52)
else
v358(v121)
v355(v330)
{(I63t)0} -> v286
v388(v381[FN]) =
v23(v382[C],v33[PV]) =
v123(v383[C],v34[I]) =
v383(v34)
v381(v382,v123,v33,(I63t)0)
{(I63t)4,(I63t)0} -> v136
{(I63t)3,v136} -> v134
{(I63t)2,v134} -> v132
{(I63t)6,(I63t)0} -> v145
{(I63t)5,v145} -> v143
{(I63t)7,(I63t)0} -> v151
{(I63t)9,(I63t)0} -> v159
{(I63t)8,v159} -> v157
{v157,(I63t)0} -> v155
{v151,v155} -> v149
{v143,v149} -> v141
{v141,(I63t)0} -> v32
{v132,v32} -> v31
{(I63t)1,v31} -> v30
v185(v385[C],v186[I]) =
v385(v186)
v387(v386[I]) =
{v323,v30,v386,v23,v13} -> v169
v338(v169)
v381(v387,v185,v30,(I63t)0)
v323(v388,v286)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment