Skip to content

Commit db1f03e

Browse files
committed
Fix a bug when compiling a trivial loop
1 parent 8ec3457 commit db1f03e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/cps/inline.sml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ struct
5959
and goStat (C.Let {decs, cont}, acc) =
6060
goStat (cont, List.foldl goDec acc decs)
6161
| goStat (C.App _, acc) = acc
62-
| goStat (C.AppCont {applied = _, args}, acc) = args :: acc
62+
| goStat (C.AppCont {applied, args}, acc) =
63+
if applied = retCont then args :: acc else acc
6364
| goStat (C.If {cond = _, thenCont, elseCont}, acc) =
6465
goStat (elseCont, goStat (thenCont, acc))
6566
| goStat
@@ -1294,6 +1295,12 @@ struct
12941295
Syntax.SourceName.merge
12951296
(acc, v, TypedSyntax.getVIdName n)
12961297
| _ => acc) acc (resultNames, r)
1298+
handle ListPair.UnequalLengths =>
1299+
raise Fail
1300+
("inliner: number of results mismatch in function application ("
1301+
^ TypedSyntax.print_VId applied ^ ","
1302+
^ Int.toString (List.length resultNames)
1303+
^ "," ^ Int.toString (List.length r) ^ ")")
12971304
in
12981305
List.foldl go TypedSyntax.VIdMap.empty results
12991306
end

test/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ should_compile += $(addprefix should_compile/,\
101101
generalization1.sml \
102102
generalization2.sml \
103103
record.sml \
104+
trivial_loop.sml \
104105
)
105106
should_not_compile += $(addprefix should_not_compile/,\
106107
fixity.sml \
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fun f () = f ();
2+
f ();

0 commit comments

Comments
 (0)