Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
44e2289
wip
ychenfo Jan 3, 2026
5243231
wip
ychenfo Jan 12, 2026
21e1f06
wip
ychenfo Jan 13, 2026
1be9024
wip
ychenfo Jan 13, 2026
fdf4feb
wip
ychenfo Jan 15, 2026
3e00ff5
wip
ychenfo Jan 24, 2026
c5c500c
wip
ychenfo Jan 27, 2026
a11de7a
wip
ychenfo Jan 27, 2026
683b7b4
wip
ychenfo Jan 31, 2026
70a8242
wip
ychenfo Jan 31, 2026
ffe10e8
wip
ychenfo Feb 1, 2026
3e9542b
wip
ychenfo Feb 1, 2026
d28dcee
wip
ychenfo Feb 3, 2026
9b88345
wip
ychenfo Feb 3, 2026
b656c93
wip
ychenfo Feb 4, 2026
43decef
wip
ychenfo Feb 4, 2026
15c1447
wip
ychenfo Feb 5, 2026
8cc80b5
wip
ychenfo Feb 5, 2026
8a1211e
wip: tuple
ychenfo Feb 5, 2026
e565bf0
wip
ychenfo Feb 6, 2026
27f943c
wip
ychenfo Feb 6, 2026
3703562
wip rewrite
ychenfo Feb 6, 2026
828308b
wip rewrite
ychenfo Feb 7, 2026
de4b1df
wip rewrite
ychenfo Feb 7, 2026
566dc42
wip free vars
ychenfo Feb 7, 2026
7f8c071
wip free vars
ychenfo Feb 7, 2026
63f55ac
wip free vars
ychenfo Feb 8, 2026
1bce834
wip free vars
ychenfo Feb 8, 2026
58389d7
wip scc group
ychenfo Feb 8, 2026
4fafefd
wip free vars
ychenfo Feb 8, 2026
34b99f5
wip refresh syms
ychenfo Feb 9, 2026
4c6c58e
wip
ychenfo Feb 11, 2026
c6e47af
wip refresh syms
ychenfo Feb 11, 2026
c9d0d45
wip prepare for merge
ychenfo Feb 12, 2026
619c2df
wip prepare for merge
ychenfo Feb 12, 2026
44ef5d7
Merge remote-tracking branch 'origin/hkmc2' into hkmc2-deforest-new-new
ychenfo Feb 12, 2026
fa8c33d
wip
ychenfo Feb 14, 2026
bd5a076
wip: fixing
ychenfo Feb 23, 2026
61d872a
wip: fixing
ychenfo Feb 24, 2026
7559d79
wip: fixing
ychenfo Feb 24, 2026
6d88961
wip: fixing
ychenfo Feb 26, 2026
42d6fac
wip: refreshing symbol
ychenfo Feb 27, 2026
7251b06
wip: rest funs
ychenfo Mar 1, 2026
69a26eb
wip: free vars
ychenfo Mar 1, 2026
d23b499
wip: rest funs
ychenfo Mar 2, 2026
dd18277
rest funs
ychenfo Mar 3, 2026
2c04248
wip: manual select
ychenfo Mar 3, 2026
9735c0c
wip: manual select
ychenfo Mar 3, 2026
70152b4
wip: cleanup
ychenfo Mar 4, 2026
51f19c5
wip: fix constraints collection
ychenfo Mar 4, 2026
91537e7
fix selections
ychenfo Mar 5, 2026
6ba67dc
wip: no print of fv
ychenfo Mar 5, 2026
80835bc
wip
ychenfo Mar 7, 2026
df3f6d1
wip: cleanup
ychenfo Mar 8, 2026
f3f3668
wip
ychenfo Mar 8, 2026
c63361f
wip
ychenfo Mar 8, 2026
80d1766
clean up tests
ychenfo Mar 8, 2026
b910dd5
clean up tests
ychenfo Mar 8, 2026
0be6e07
clean up tests
ychenfo Mar 8, 2026
3ed3734
clean up
ychenfo Mar 8, 2026
e810360
handle top level implicit ret and clean up
ychenfo Mar 8, 2026
0969312
need to override tracelogger.emitDbg...
ychenfo Mar 8, 2026
f77d268
Merge remote-tracking branch 'origin/hkmc2' into hkmc2-deforest-new-new
ychenfo Mar 8, 2026
72dd45c
fix nosymbol after merge
ychenfo Mar 8, 2026
6679cb9
minor
ychenfo Mar 8, 2026
d0c8192
Change from meeting
LPTK Mar 9, 2026
3853fd0
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 9, 2026
be637d7
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 10, 2026
30b93cd
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 10, 2026
c998ac9
Update difftests
LPTK Mar 10, 2026
eb5bc6a
Update tests
LPTK Mar 10, 2026
d3f230b
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 10, 2026
8081719
remove duplicated tests
ychenfo Mar 10, 2026
4a52345
cleanup tests; more comments in todos.mls; minor fix
ychenfo Mar 10, 2026
41be7f6
more cleanup tests
ychenfo Mar 10, 2026
88931c0
minor cleanup in LambdaRewriter
ychenfo Mar 10, 2026
b6bba8e
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 10, 2026
e92abef
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 11, 2026
d6d4cd5
use `Set.single` and more cleanup
ychenfo Mar 10, 2026
a60fc5b
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 11, 2026
7cea0d0
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 11, 2026
2897b1d
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 11, 2026
4f1d16c
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 12, 2026
a5ce41c
try to fix nondeterminism
ychenfo Mar 12, 2026
a4b9fbf
Merge branch 'hkmc2-deforest-new-new' of github.com:ychenfo/mlscript …
ychenfo Mar 12, 2026
add6296
fuse internal parts also
ychenfo Mar 13, 2026
03515cd
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 13, 2026
edc667e
update tests
ychenfo Mar 14, 2026
fce9118
Merge remote-tracking branch 'origin/hkmc2' into hkmc2-deforest-new-new
ychenfo Mar 14, 2026
12e39e3
cleanup test: remove some useless `main` wrappers that bloat fusion o…
ychenfo Mar 14, 2026
0ee28ad
Merge remote-tracking branch 'origin/hkmc2' into hkmc2-deforest-new-new
ychenfo Mar 14, 2026
04c92ae
Merge remote-tracking branch 'origin/hkmc2' into hkmc2-deforest-new-new
ychenfo Mar 15, 2026
a8038b7
review comments:
ychenfo Mar 15, 2026
4738e26
Changed my mind + minor tweak
LPTK Mar 15, 2026
78fc0d4
Merge branch 'hkmc2' into hkmc2-deforest-new-new
LPTK Mar 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/shared/main/scala/utils/algorithms.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ object algorithms {
)

// pre-process: assign each node an id
val edgesSet = edges.toSet
val nodesUniq = (edgesSet.flatMap { case (a, b) => Set(a, b) } ++ nodes.toSet).toList
val nodesUniq = {
Comment thread
LPTK marked this conversation as resolved.
val seen = collection.mutable.LinkedHashSet.empty[A]
for ((a, b) <- edges) { seen.add(a); seen.add(b) }
for (n <- nodes) seen.add(n)
seen.toList
}
val nodesN = nodesUniq.zipWithIndex.map { case (node, idx) => SccNode(node, idx) }
val nodeToIdx = nodesN.map(node => node.node -> node.id).toMap
val nodesIdx = nodesN.map { case node => node.id -> node }.toMap
Expand Down
7 changes: 7 additions & 0 deletions hkmc2/shared/src/main/scala/hkmc2/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ case class Config(
target: CompilationTarget,
rewriteWhileLoops: Bool,
tailRecOpt: Bool,
deforest: Opt[Deforest],
qqEnabled: Bool,
funcToCls: Bool
):
Expand Down Expand Up @@ -60,6 +61,7 @@ object Config:
rewriteWhileLoops = false,
stageCode = false,
tailRecOpt = true,
deforest = N,
qqEnabled = false,
funcToCls = false,
)
Expand Down Expand Up @@ -90,6 +92,11 @@ object Config:

case class LiftDefns() // there may be other settings in the future, having it as a case class now

case class Deforest(val debug: Boolean)

object Deforest:
val default = Deforest(true)

end Config


2 changes: 2 additions & 0 deletions hkmc2/shared/src/main/scala/hkmc2/Uid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ object Uid:
curUid
def reset = curUid = -1
object Symbol extends Handler[semantics.Symbol]
object Result extends Handler[codegen.Result]
object StratVar extends Handler[codegen.deforest.StratVar]

extension [T] (x: Uid[T])
def <=(rhs: Uid[T]) = x <= rhs
Expand Down
4 changes: 3 additions & 1 deletion hkmc2/shared/src/main/scala/hkmc2/codegen/Block.scala
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ final case class FunDefn(
val asPath = Value.Ref(sym, S(dSym))
object FunDefn:
def withFreshSymbol(owner: Opt[InnerSymbol], sym: BlockMemberSymbol, params: Ls[ParamList], body: Block)(forceTailRec: Bool)(using State) =
FunDefn(owner, sym, TermSymbol(syntax.Fun, owner, Tree.Ident(sym.nme)), params, body)(forceTailRec)
val tSym = TermSymbol(syntax.Fun, owner, Tree.Ident(sym.nme))
sym.tsym = S(tSym)
FunDefn(owner, sym, tSym, params, body)(forceTailRec)

final case class ValDefn(
tsym: TermSymbol,
Expand Down
12 changes: 5 additions & 7 deletions hkmc2/shared/src/main/scala/hkmc2/codegen/LambdaRewriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ object LambdaRewriter:
def desugar(b: Block)(using State) =
val transformer = new BlockTransformer(SymbolSubst()):
override def applyResult(r: Result)(k: Result => Block): Block = r match
case lam: Lambda =>
case lam: Lambda =>
val sym = BlockMemberSymbol("lambda", Nil, nameIsMeaningful = false)
val tSym = TermSymbol.fromFunBms(sym, N)
val lamDefn =
val Lambda(params, body) = super.applyLam(lam)
FunDefn(N, sym, tSym, params :: Nil, body)(false)
Scoped(Set(sym), Define(lamDefn, k(Value.Ref(sym, S(tSym)))))
val Lambda(params, body) = super.applyLam(lam)
val lamDefn = FunDefn.withFreshSymbol(N, sym, params :: Nil, body)(false)
Scoped(Set.single(sym), Define(lamDefn, k(lamDefn.asPath)))
case _ => super.applyResult(r)(k)

override def applyBlock(b: Block): Block = b match
Expand All @@ -32,7 +30,7 @@ object LambdaRewriter:
.define(defn)
.assign(lhs, defn.asPath)
.rest(applyBlock(rest))
Scoped(Set(newSym), blk)
Scoped(Set.single(newSym), blk)
case _ => super.applyBlock(b)

transformer.applyBlock(b)
Expand Down
20 changes: 19 additions & 1 deletion hkmc2/shared/src/main/scala/hkmc2/codegen/Lowering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,27 @@ class Lowering()(using Config, TL, Raise, State, Ctx):

val desug = LambdaRewriter.desugar(blk)

val deforested =
val outterTl = tl
config.deforest match
case None => desug
case Some(dCfg) =>
/*
// * For some weird reason (Scala bug?),
// * the version below leads to a stack overflows during its initialization
given TraceLogger with
override def doTrace: Bool = dCfg.debug
override def emitDbg(str: Str): Unit = outterTl.emitDbg(s"deforest > $str")
*/
(new TraceLogger:
override def doTrace: Bool = dCfg.debug
override def emitDbg(str: Str): Unit = outterTl.emitDbg(s"deforest > $str")
).givenIn:
deforest.Deforest(Program(imps.map(imp => imp.sym -> imp.str), desug)).main

val handlerPaths = new HandlerPaths

val withHandlers1 = config.effectHandlers.fold(desug): opt =>
val withHandlers1 = config.effectHandlers.fold(deforested): opt =>
HandlerLowering(handlerPaths, opt).translateHandleBlocks(desug)

val shouldFlattenScopes = config.effectHandlers.isDefined
Expand Down
Loading
Loading