[MLton] Finding source code corresponding to failed type check of SSA after simplification

"'David Wang' via MLton-devel" <[email protected]> Wed, 10 Dec 2025 17:52:50 +0000
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <AS8PR03MB87160F97A86DE85B4C0FB34DCDA0A@AS8PR03MB8716.eurprd03.prod.outlook.com>
--===============6959608804040646072==
Content-Language: en-GB
Content-Type: multipart/alternative;
	boundary="_000_AS8PR03MB87160F97A86DE85B4C0FB34DCDA0AAS8PR03MB8716eurp_"

--_000_AS8PR03MB87160F97A86DE85B4C0FB34DCDA0AAS8PR03MB8716eurp_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Dear MLton developers,

I am writing to ask you for help to diagnose the cuase of a type-checking e=
rror that happens in an intermediate language<http://mlton.org/Intermediate=
Language> other than AST.

I am currently attempting to compile a project<https://github.com/david-wan=
g-0/temporal-planning-certification/tree/dev> using MLton.

When I set the `-const 'MLton.safe false'` option, it compiles, but crashes=
 with a segmentation fault before anything interesting happens.

When I omit the option, I get the following error, which I guess is related=
 (because replacing enough suspected lines in (.sml source files) with `rai=
se` statements will eventually make parts of the code run):
```
ssaSimplify:typeCheck starting
           ssaSimplify:typeCheck raised: Fail: TypeError (SSA): Ssa.TypeChe=
ck.primApp (Array_copyArray(dBMEntry_0) ((dBMEntry_0) array, word64, (word6=
4) array, word64, word64)) in val _: unit =3D prim Array_copyArray[dBMEntry=
_0] (x_2, global_0, x_1, global_0, x_0) in L_0 in x_3
```

I found out that there is a flag to print the simplified SSA<http://mlton.o=
rg/SSA> code (`-keep ssa`), but not one for the SSA output by ClosureConver=
t<http://mlton.org/ClosureConvert>.
Changing a few lines in a local copy of MLton allowed me to print the outpu=
t of ClosureConvert.
I added `val toFilePre =3D {display =3D Control.Layouts layouts, style =3D =
Control.ML, suffix =3D "ssa_pre"}` at https://github.com/MLton/mlton/blob/6=
1baac7108fbd91413f0537b7a42d9a1023455f4/mlton/ssa/ssa-tree.fun#L1778.
I also changed https://github.com/MLton/mlton/blob/61baac7108fbd91413f0537b=
7a42d9a1023455f4/mlton/main/compile.fun#L489 to print according to the valu=
e of the `keepSSA` variable.

I have the unsimplified SSA code and the simplified version in files.
I can't easily see which line causes the error, because indices in the erro=
r correspond to no indices in the SSA files.
I found out that the indices that identify variables and functions (`x_0`, =
`x_1`, `global_0`, etc.) are assigned when they are first converted to stri=
ngs by calls of `Layout.toString` for instance.
Is there a way to find out which lines of SSA (or preferably .sml source) c=
ode cause the error?

I also changed the code in https://github.com/MLton/mlton/blob/master/mlton=
/ssa/analyze.fun to print every statement that is being analyzed and output=
 that to a file to maybe find out more.
That way I get some idea of the order in which statements are checked in wh=
ich order, but not much more.

If I compile the SXML<http://mlton.org/SXML> files output by `-keep sxml`, =
I get a type error, but the type check after ClosureConvert passes when I c=
ompile directly from (.mlb, .sml, and .ML) source files.
The unsimplified SSA after ClosureConvert and before SSASimplifly seems to =
have no syntax errors, but MLton is taking a long time to process the file.=
 Is that because MLton expects simplified SSA input?

How do you suggest I continue in identifying the cause of the type-error in=
 the .sml source code?

With kind regards,

David Wang


--_000_AS8PR03MB87160F97A86DE85B4C0FB34DCDA0AAS8PR03MB8716eurp_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=
1">
<style type=3D"text/css" style=3D"display:none;"> P {margin-top:0;margin-bo=
ttom:0;} </style>
</head>
<body dir=3D"ltr">
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
Dear MLton developers,</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
I am writing to ask you for help to diagnose the cuase of a type-checking e=
rror that happens in an
<a style=3D"color: rgb(0, 0, 0);" title=3D"http://mlton.org/IntermediateLan=
guage" class=3D"OWAAutoLink" id=3D"OWAb7e0f176-032c-0f01-dfb4-26acb9ca3ceb"=
 href=3D"http://mlton.org/IntermediateLanguage">
intermediate language</a>&nbsp;other than AST.</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
I am currently attempting to compile a <a style=3D"color: rgb(0, 0, 0);" ti=
tle=3D"https://github.com/david-wang-0/temporal-planning-certification/tree=
/dev" class=3D"OWAAutoLink" id=3D"OWAec86ddab-7984-969c-7a3e-2e65693ffc7b" =
href=3D"https://github.com/david-wang-0/temporal-planning-certification/tre=
e/dev">
project</a>&nbsp;using MLton.&nbsp;</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
When I set the `-const 'MLton.safe false'` option, it compiles, but crashes=
 with a segmentation fault before anything interesting happens.</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
When I omit the option, I get the following error, which I guess is related=
 (because replacing enough suspected lines in (.sml source files) with `rai=
se` statements will eventually make parts of the code run):</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<b>```</b></div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<span style=3D"font-family: &quot;Aptos Mono&quot;, Aptos_EmbeddedFont, Apt=
os_MSFontService, monospace;"><b>ssaSimplify:typeCheck starting
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ssaSimpli=
fy:typeCheck raised: Fail: TypeError (SSA): Ssa.TypeCheck.primApp (Array_co=
pyArray(dBMEntry_0) ((dBMEntry_0) array, word64, (word64) array, word64, wo=
rd64)) in val _: unit =3D prim Array_copyArray[dBMEntry_0] (x_2, global_0, =
x_1, global_0,
 x_0) in L_0 in x_3</b></span><b><br>
</b></div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<b>```</b></div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<br>
</div>
<div style=3D"font-size: 12pt;" class=3D"elementToProof"><span style=3D"fon=
t-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetic=
a, sans-serif; color: rgb(0, 0, 0);">I found out that there is a flag to pr=
int the simplified
<a title=3D"http://mlton.org/SSA" href=3D"http://mlton.org/SSA">SSA</a>&nbs=
p;code (</span><span style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos=
_MSFontService, Calibri, Helvetica, sans-serif; color: rgb(0, 0, 0);">`</sp=
an><span style=3D"font-family: &quot;Aptos Mono&quot;, Aptos_EmbeddedFont, =
Aptos_MSFontService, monospace; color: rgb(0, 0, 0);">-keep
 ssa</span><span style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSF=
ontService, Calibri, Helvetica, sans-serif; color: rgb(0, 0, 0);">`)</span>=
<span style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService,=
 Calibri, Helvetica, sans-serif; color: rgb(0, 0, 0);">,
 but not one for the SSA output by <a title=3D"http://mlton.org/ClosureConv=
ert" class=3D"OWAAutoLink" id=3D"OWA9dc433fc-4c31-7d9a-049a-552c2b0ca50f" h=
ref=3D"http://mlton.org/ClosureConvert">
ClosureConvert</a>.&nbsp;</span></div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
Changing a few lines in a local copy of MLton allowed me to print the outpu=
t of ClosureConvert.</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt;" class=3D"elementToProof">
<span style=3D"color: rgb(0, 0, 0);">I added `</span><span style=3D"font-fa=
mily: &quot;Aptos Mono&quot;, Aptos_EmbeddedFont, Aptos_MSFontService, mono=
space; color: rgb(0, 0, 0);">val toFilePre&nbsp;=3D {display&nbsp;=3D Contr=
ol.Layouts layouts, style&nbsp;=3D Control.ML, suffix&nbsp;=3D &quot;ssa_pr=
e&quot;}</span><span style=3D"color: rgb(0, 0, 0);">`
 at </span><span style=3D"color: rgb(0, 0, 0);"><a class=3D"OWAAutoLink" id=
=3D"OWAdccf32ba-f354-d9cc-4ec8-1f083f4e0cc7" href=3D"https://github.com/MLt=
on/mlton/blob/61baac7108fbd91413f0537b7a42d9a1023455f4/mlton/ssa/ssa-tree.f=
un#L1778">https://github.com/MLton/mlton/blob/61baac7108fbd91413f0537b7a42d=
9a1023455f4/mlton/ssa/ssa-tree.fun#L1778</a>.&nbsp;</span></div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
I also changed <a class=3D"OWAAutoLink" id=3D"OWAe9ecdf91-a42b-00a6-85aa-48=
39816280e3" href=3D"https://github.com/MLton/mlton/blob/61baac7108fbd91413f=
0537b7a42d9a1023455f4/mlton/main/compile.fun#L489">
https://github.com/MLton/mlton/blob/61baac7108fbd91413f0537b7a42d9a1023455f=
4/mlton/main/compile.fun#L489</a>&nbsp;to print according to the value of t=
he `<span style=3D"font-family: &quot;Aptos Mono&quot;, Aptos_EmbeddedFont,=
 Aptos_MSFontService, monospace;">keepSSA</span>`
 variable.</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
I have the unsimplified SSA code and the simplified version in files.</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
I can't easily see which line causes the error, because indices in the erro=
r correspond to no indices in the SSA files.</div>
<div style=3D"font-size: 12pt; color: rgb(0, 0, 0);" class=3D"elementToProo=
f"><span style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontServi=
ce, Calibri, Helvetica, sans-serif;">I found out that the indices that iden=
tify variables and functions (`</span><span style=3D"font-family: &quot;Apt=
os Mono&quot;, Aptos_EmbeddedFont, Aptos_MSFontService, monospace;">x_0</sp=
an><span style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontServi=
ce, Calibri, Helvetica, sans-serif;">`,
 `</span><span style=3D"font-family: &quot;Aptos Mono&quot;, Aptos_Embedded=
Font, Aptos_MSFontService, monospace;">x_1</span><span style=3D"font-family=
: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-=
serif;">`, `</span><span style=3D"font-family: &quot;Aptos Mono&quot;, Apto=
s_EmbeddedFont, Aptos_MSFontService, monospace;">global_0</span><span style=
=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, H=
elvetica, sans-serif;">`,
 etc.) are assigned when they are first converted to strings by calls of `<=
/span><span style=3D"font-family: &quot;Aptos Mono&quot;, Aptos_EmbeddedFon=
t, Aptos_MSFontService, monospace;">Layout.toString</span><span style=3D"fo=
nt-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helveti=
ca, sans-serif;">`
 for instance.</span></div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
Is there a way to find out which lines of SSA (or preferably .sml source) c=
ode cause the error?</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
I also changed the code in <a class=3D"OWAAutoLink" id=3D"OWA3432a5c2-30fe-=
321e-b8b7-807c7f2463c6" href=3D"https://github.com/MLton/mlton/blob/master/=
mlton/ssa/analyze.fun">
https://github.com/MLton/mlton/blob/master/mlton/ssa/analyze.fun</a>&nbsp;t=
o print every statement that is being analyzed and output that to a file to=
 maybe find out more.</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
That way I get some idea of the order in which statements are checked in wh=
ich order, but not much more.&nbsp;</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<br>
</div>
<div style=3D"font-size: 12pt; color: rgb(0, 0, 0);" class=3D"elementToProo=
f"><span style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontServi=
ce, Calibri, Helvetica, sans-serif;">If I compile the
<a title=3D"http://mlton.org/SXML" class=3D"OWAAutoLink" id=3D"OWA67ea0378-=
f70a-53e5-7c24-58b57a5eb40d" href=3D"http://mlton.org/SXML">
SXML</a>&nbsp;files output by `</span><span style=3D"font-family: &quot;Apt=
os Mono&quot;, Aptos_EmbeddedFont, Aptos_MSFontService, monospace;">-keep s=
xml</span><span style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFo=
ntService, Calibri, Helvetica, sans-serif;">`, I get
 a type error, but the type check after ClosureConvert passes when I compil=
e directly from (.mlb, .sml, and .ML) source files.</span></div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
The unsimplified SSA after ClosureConvert and before SSASimplifly seems to =
have no syntax errors, but MLton is taking a long time to process the file.=
 Is that because MLton expects simplified SSA input?</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" clas=
s=3D"elementToProof">
How do you suggest I continue in identifying the cause of the type-error in=
 the .sml source code?</div>
<div id=3D"Signature">
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
With kind regards,</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
David Wang</div>
<div style=3D"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, =
Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
</div>
</body>
</html>

--_000_AS8PR03MB87160F97A86DE85B4C0FB34DCDA0AAS8PR03MB8716eurp_--


--===============6959608804040646072==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============6959608804040646072==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
MLton-devel mailing list
[email protected]; [email protected]
https://lists.sourceforge.net/lists/listinfo/mlton-devel

--===============6959608804040646072==--