Skip to content

Commit d7f7d29

Browse files
committed
Suggested changes
1 parent c9d9025 commit d7f7d29

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import scala.collection.mutable.Set as MutSet
99
import scala.collection.mutable.ArrayBuffer as ArrayBuffer
1010
import mlscript.codegen.CodeGenError
1111

12-
class MonomorphError(error: String) extends Error(error)
12+
class CompilerError(error: String) extends Error(error)
1313

1414
class ClassLifter(logDebugMsg: Boolean = false) {
1515
type ClassName = String
@@ -250,7 +250,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
250250
val nE = liftTerm(expr)
251251
val nR = liftTerm(rhs)
252252
(IfThen(nE._1, nR._1), nE._2 ++ nR._2)
253-
case _ => throw MonomorphError(s"Unknown IfBody: ${body}")
253+
case _ => throw CompilerError(s"Unknown IfBody: ${body}")
254254
}
255255

256256
private def liftTuple(tup: Tup)(using ctx: LocalContext, cache: ClassCache, globFuncs: Map[Var, (Var, LocalContext)], outer: Option[ClassInfoCache]): (Tup, LocalContext) = {
@@ -400,7 +400,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
400400
case Sel(receiver, fieldName) =>
401401
val nRec = liftTerm(receiver)
402402
(Sel(nRec._1, fieldName), nRec._2)
403-
case Splc(fields) => throw MonomorphError(s"Unimplemented liftTerm: ${target}")
403+
case Splc(fields) => throw CompilerError(s"Unimplemented liftTerm: ${target}")
404404
case Subs(arr, idx) =>
405405
val (ltrm, lctx) = liftTerm(arr)
406406
val (rtrm, rctx) = liftTerm(idx)
@@ -413,7 +413,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
413413
val ret = liftTerm(lhs)
414414
val nTs = targs.map(liftType).unzip
415415
(TyApp(ret._1, nTs._1), nTs._2.fold(ret._2)(_ ++ _))
416-
case With(trm, fields) => throw MonomorphError(s"Unimplemented liftTerm: ${target}")
416+
case With(trm, fields) => throw CompilerError(s"Unimplemented liftTerm: ${target}")
417417
case New(Some((t: TypeName, prm: Tup)), TypingUnit(Nil)) =>
418418
val ret = liftConstr(t, prm)
419419
(New(Some((ret._1, ret._2)), TypingUnit(Nil)), ret._3)
@@ -433,7 +433,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
433433
val nSta = New(Some((nTpNm, Tup(Nil))), TypingUnit(Nil))
434434
val ret = liftEntities(List(anoCls, nSta))
435435
(Blk(ret._1), ret._2)
436-
case New(head, body) => throw MonomorphError(s"Unimplemented liftTerm: ${target}")
436+
case New(head, body) => throw CompilerError(s"Unimplemented liftTerm: ${target}")
437437
case Blk(stmts) =>
438438
val ret = liftEntities(stmts)
439439
(Blk(ret._1), ret._2)
@@ -448,7 +448,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
448448
val (bod2, ctx) = liftTerm(bod)
449449
val (sts2, ctx2) = liftEntities(sts)
450450
(Where(bod2, sts2), ctx2)
451-
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
452452
case patmat: AdtMatchWith => lastWords(s"Cannot liftTermNew ${patmat}")
453453
}
454454

@@ -485,7 +485,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
485485
((v, Fld(flags, tmp._1)), tmp._2)
486486
}.unzip
487487
(Rcd(ret._1), ret._2.fold(emptyCtx)(_ ++ _))
488-
case _ => throw MonomorphError(s"Unimplemented liftTermAsType: ${target}")
488+
case _ => throw CompilerError(s"Unimplemented liftTermAsType: ${target}")
489489
}
490490

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

585585

@@ -603,7 +603,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
603603
}.unzip
604604
(func.copy(rhs = Right(PolyType(nTargs._1, nBody._1)))(func.declareLoc, func.virtualLoc, func.mutLoc, func.signature, func.outer, func.genField, func.annotations),
605605
nTargs._2.fold(nBody._2)(_ ++ _))
606-
case _ => throw MonomorphError(s"Unimplemented liftMemberFunc: ${func}") // TODO
606+
case _ => throw CompilerError(s"Unimplemented liftMemberFunc: ${func}") // TODO
607607
}
608608
}
609609

@@ -630,7 +630,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
630630
case (tn, ctx) => (L(tn), ctx)
631631
case R(tv) => R(tv) -> emptyCtx}).unzip
632632
NuFunDef(rec, globFuncs.get(nm).get._1, N, nTpVs, Right(PolyType(nTargs._1, nBody._1)))(N, N, N, N, N, true, Nil)
633-
case _ => throw MonomorphError(s"Unimplemented liftGlobalFunc: ${func}")
633+
case _ => throw CompilerError(s"Unimplemented liftGlobalFunc: ${func}")
634634
})
635635
}
636636

compiler/shared/main/scala/mlscript/compiler/simpledef/Simpledef.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type Cnstr = ProdStrat -> ConsStrat
1818
* Lastly, we rewrite selection terms by generating pattern matches on their possible inputs.
1919
*/
2020

21-
2221
enum ProdStrat(using val euid: TermId) {
2322
case NoProd()(using TermId)
2423
case ProdObj(ctor: Option[Var], fields: Ls[Var -> ProdStrat], parents: Ls[ProdStrat] = Nil)(using TermId) extends ProdStrat, ProdObjImpl
@@ -45,8 +44,8 @@ trait ProdObjImpl { self: ProdObj =>
4544

4645
class Context(
4746
variables: Map[Var, ProdVar],
48-
classes: Map[Var, ProdObj])
49-
{
47+
classes: Map[Var, ProdObj],
48+
) {
5049
def apply(v: Var): ProdVar =
5150
variables(v)
5251
def ++(other: IterableOnce[(Var, ProdVar)]): Context =
@@ -271,7 +270,7 @@ class SimpleDef(debug: Debug) {
271270
apply(TypingUnit(stmts))._2
272271
case Bra(false, term) =>
273272
process(term)
274-
case CaseOf(trm, cases) => //TODO
273+
case CaseOf(trm, cases) => // TODO: Complete constraining in conjunction with processCases
275274
???
276275
case Eqn(lhs, rhs) =>
277276
process(lhs)
@@ -281,7 +280,7 @@ class SimpleDef(debug: Debug) {
281280
debug.outdent()
282281
registerTermToType(t, res)
283282

284-
//TODO
283+
// TODO: Complete constraining for CaseBranches after implementing negative types and intersections
285284
def processCases(scrut: ProdVar, cs: CaseBranches)(using ctx: Context, resCons: ConsVar): Unit =
286285
cs match
287286
case Wildcard(body) =>

compiler/shared/test/scala/mlscript/compiler/Test.scala

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class DiffTestCompiler extends DiffTests {
3737
val pd = SimpleDef(treeDebug)
3838
pd(rstUnit)
3939
val defuncAST = pd.rewriteProgram(rstUnit)
40-
//output(s"${defuncAST}\n")
4140
output(defuncAST.showDbg.replace(";", "\n"))
4241
output("End simpledef\n")
4342
return (outputBuilder.toString().linesIterator.toList, Some(defuncAST))
@@ -48,6 +47,21 @@ class DiffTestCompiler extends DiffTests {
4847
(outputBuilder.toString().linesIterator.toList, None)
4948
}
5049

50+
override def postTypingProcess(mode: ModeType, basePath: List[Str], testName: Str, unit: TypingUnit, output: Str => Unit): (List[Str], Option[TypingUnit]) =
51+
val outputBuilder = StringBuilder()
52+
53+
if(mode.simpledef || basePath.contains("Defunctionalize")) {
54+
output("\nSimpledef:")
55+
val treeDebug = new TreeDebug(if mode.dbgSimpledef then output else (str) => ())
56+
val pd = SimpleDef(treeDebug)
57+
pd(unit)
58+
val defuncAST = pd.rewriteProgram(unit)
59+
output(defuncAST.showDbg.replace(";", "\n"))
60+
output("End simpledef\n")
61+
return (outputBuilder.toString().linesIterator.toList, Some(defuncAST))
62+
}
63+
(outputBuilder.toString().linesIterator.toList, None)
64+
5165
override protected lazy val files = allFiles.filter { file =>
5266
val fileName = file.baseName
5367
validExt(file.ext) && filter(file.relativeTo(pwd))

shared/src/test/scala/mlscript/DiffTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class DiffTests
5858

5959
/** Hook for dependent projects, like the monomorphizer. */
6060
def postProcess(mode: ModeType, basePath: Ls[Str], testName: Str, unit: TypingUnit, output: Str => Unit): (Ls[Str], Option[TypingUnit]) = (Nil, None)
61+
def postTypingProcess(mode: ModeType, basePath: Ls[Str], testName: Str, unit: TypingUnit, output: Str => Unit): (Ls[Str], Option[TypingUnit]) = (Nil, None)
6162

6263

6364
@SuppressWarnings(Array("org.wartremover.warts.RedundantIsInstanceOf"))
@@ -913,7 +914,7 @@ class DiffTests
913914
import codeGenTestHelpers._
914915
val pp =
915916
if (mode.postProcessAfterTyping) {
916-
Pgrm(postProcess(mode, basePath, testName, TypingUnit(p.tops), output)._2.fold(???)(_.entities))
917+
Pgrm(postTypingProcess(mode, basePath, testName, TypingUnit(p.tops), output)._2.fold(???)(_.entities))
917918
} else {
918919
p
919920
}

0 commit comments

Comments
 (0)