Skip to content

Commit 211430d

Browse files
authored
Defunctionalization with simple-sub Control-flow Analysis (#222)
1 parent 69738fa commit 211430d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1603
-2012
lines changed

compiler/shared/main/scala/mlscript/compiler/ClassLifter.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import scala.collection.mutable.Map as MutMap
88
import scala.collection.mutable.Set as MutSet
99
import scala.collection.mutable.ArrayBuffer as ArrayBuffer
1010
import mlscript.codegen.CodeGenError
11-
import mlscript.compiler.mono.MonomorphError
11+
12+
class CompilerError(error: String) extends Error(error)
1213

1314
class ClassLifter(logDebugMsg: Boolean = false) {
1415
type ClassName = String
@@ -249,7 +250,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
249250
val nE = liftTerm(expr)
250251
val nR = liftTerm(rhs)
251252
(IfThen(nE._1, nR._1), nE._2 ++ nR._2)
252-
case _ => throw MonomorphError(s"Unknown IfBody: ${body}")
253+
case _ => throw CompilerError(s"Unknown IfBody: ${body}")
253254
}
254255

255256
private def liftTuple(tup: Tup)(using ctx: LocalContext, cache: ClassCache, globFuncs: Map[Var, (Var, LocalContext)], outer: Option[ClassInfoCache]): (Tup, LocalContext) = {
@@ -399,7 +400,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
399400
case Sel(receiver, fieldName) =>
400401
val nRec = liftTerm(receiver)
401402
(Sel(nRec._1, fieldName), nRec._2)
402-
case Splc(fields) => throw MonomorphError(s"Unimplemented liftTerm: ${target}")
403+
case Splc(fields) => throw CompilerError(s"Unimplemented liftTerm: ${target}")
403404
case Subs(arr, idx) =>
404405
val (ltrm, lctx) = liftTerm(arr)
405406
val (rtrm, rctx) = liftTerm(idx)
@@ -412,7 +413,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
412413
val ret = liftTerm(lhs)
413414
val nTs = targs.map(liftType).unzip
414415
(TyApp(ret._1, nTs._1), nTs._2.fold(ret._2)(_ ++ _))
415-
case With(trm, fields) => throw MonomorphError(s"Unimplemented liftTerm: ${target}")
416+
case With(trm, fields) => throw CompilerError(s"Unimplemented liftTerm: ${target}")
416417
case New(Some((t: TypeName, prm: Tup)), TypingUnit(Nil)) =>
417418
val ret = liftConstr(t, prm)
418419
(New(Some((ret._1, ret._2)), TypingUnit(Nil)), ret._3)
@@ -432,7 +433,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
432433
val nSta = New(Some((nTpNm, Tup(Nil))), TypingUnit(Nil))
433434
val ret = liftEntities(List(anoCls, nSta))
434435
(Blk(ret._1), ret._2)
435-
case New(head, body) => throw MonomorphError(s"Unimplemented liftTerm: ${target}")
436+
case New(head, body) => throw CompilerError(s"Unimplemented liftTerm: ${target}")
436437
case Blk(stmts) =>
437438
val ret = liftEntities(stmts)
438439
(Blk(ret._1), ret._2)
@@ -447,7 +448,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
447448
val (bod2, ctx) = liftTerm(bod)
448449
val (sts2, ctx2) = liftEntities(sts)
449450
(Where(bod2, sts2), ctx2)
450-
case _: Eqn | _: Super | _: Rft | _: While | _: Quoted | _: Unquoted | _: Ann => throw MonomorphError(s"Unimplemented liftTerm: ${target}") // TODO
451+
case _: Eqn | _: Super | _: Rft | _: While | _: Quoted | _: Unquoted | _: Ann => throw CompilerError(s"Unimplemented liftTerm: ${target}") // TODO
451452
case patmat: AdtMatchWith => lastWords(s"Cannot liftTermNew ${patmat}")
452453
}
453454

@@ -484,7 +485,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
484485
((v, Fld(flags, tmp._1)), tmp._2)
485486
}.unzip
486487
(Rcd(ret._1), ret._2.fold(emptyCtx)(_ ++ _))
487-
case _ => throw MonomorphError(s"Unimplemented liftTermAsType: ${target}")
488+
case _ => throw CompilerError(s"Unimplemented liftTermAsType: ${target}")
488489
}
489490

490491
private def liftTypeName(target: TypeName)(using ctx: LocalContext, cache: ClassCache, globFuncs: Map[Var, (Var, LocalContext)], outer: Option[ClassInfoCache]): (TypeName, LocalContext) = {
@@ -578,7 +579,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
578579
val (body2, ctx) = liftType(body)
579580
PolyType(targs, body2) -> ctx
580581
case Top | Bot | _: Literal | _: TypeTag | _: TypeVar => target.asInstanceOf[Type] -> emptyCtx
581-
case _: Selection => throw MonomorphError(s"Unimplemented liftType: ${target}") // TODO
582+
case _: Selection => throw CompilerError(s"Unimplemented liftType: ${target}") // TODO
582583
}
583584

584585

@@ -602,7 +603,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
602603
}.unzip
603604
(func.copy(rhs = Right(PolyType(nTargs._1, nBody._1)))(func.declareLoc, func.virtualLoc, func.mutLoc, func.signature, func.outer, func.genField, func.annotations),
604605
nTargs._2.fold(nBody._2)(_ ++ _))
605-
case _ => throw MonomorphError(s"Unimplemented liftMemberFunc: ${func}") // TODO
606+
case _ => throw CompilerError(s"Unimplemented liftMemberFunc: ${func}") // TODO
606607
}
607608
}
608609

@@ -629,7 +630,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
629630
case (tn, ctx) => (L(tn), ctx)
630631
case R(tv) => R(tv) -> emptyCtx}).unzip
631632
NuFunDef(rec, globFuncs.get(nm).get._1, N, nTpVs, Right(PolyType(nTargs._1, nBody._1)))(N, N, N, N, N, true, Nil)
632-
case _ => throw MonomorphError(s"Unimplemented liftGlobalFunc: ${func}")
633+
case _ => throw CompilerError(s"Unimplemented liftGlobalFunc: ${func}")
633634
})
634635
}
635636

compiler/shared/main/scala/mlscript/compiler/Helpers.scala

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)