Skip to content

Commit e20b787

Browse files
committed
Merge branch 'mlscript' into hkmc2
# Conflicts: # .github/workflows/scala.yml # build.sbt # compiler/shared/main/scala/mlscript/compiler/mono/Monomorph.scala # compiler/shared/main/scala/mlscript/compiler/mono/specializer/BoundedTerm.scala # project/build.properties # project/plugins.sbt
2 parents ac5e2e0 + a7504bb commit e20b787

File tree

274 files changed

+28193
-14742
lines changed

Some content is hidden

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

274 files changed

+28193
-14742
lines changed

.github/workflows/nix.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Cpp Backend CI with Nix
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ mlscript ]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Install Nix
14+
uses: DeterminateSystems/nix-installer-action@main
15+
- uses: rrbutani/use-nix-shell-action@v1
16+
with:
17+
devShell: .#default
18+
- name: Install TypeScript
19+
run: npm ci
20+
- name: Run test
21+
run: sbt -J-Xmx4096M -J-Xss4M test
22+
- name: Check no changes
23+
run: |
24+
git update-index -q --refresh
25+
git diff-files -p --exit-code

.github/workflows/scala.yml

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

bin/mlscript-opt.js

Lines changed: 3125 additions & 3025 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.sbt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ enablePlugins(ScalaJSPlugin)
55
val scala3Version = "3.6.1"
66
val directoryWatcherVersion = "0.18.0"
77

8-
ThisBuild / scalaVersion := "2.13.13"
8+
ThisBuild / scalaVersion := "2.13.14"
99
ThisBuild / version := "0.1.0-SNAPSHOT"
1010
ThisBuild / organization := "hkust-taco.github.io"
1111
ThisBuild / organizationName := "HKUST-TACO"
@@ -97,7 +97,7 @@ lazy val mlscript = crossProject(JSPlatform, JVMPlatform).in(file("."))
9797
)
9898
.jsSettings(
9999
scalaJSUseMainModuleInitializer := true,
100-
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.1.0",
100+
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.2.0",
101101
)
102102
.dependsOn(core)
103103

@@ -129,6 +129,8 @@ lazy val compiler = crossProject(JSPlatform, JVMPlatform).in(file("compiler"))
129129
sourceDirectory := baseDirectory.value.getParentFile()/"shared",
130130
watchSources += WatchSource(
131131
baseDirectory.value.getParentFile()/"shared"/"test"/"diff", "*.mls", NothingFilter),
132+
watchSources += WatchSource(
133+
baseDirectory.value.getParentFile()/"shared"/"test"/"diff-ir", "*.mls", NothingFilter),
132134
)
133135
.dependsOn(mlscript % "compile->compile;test->test")
134136

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

Lines changed: 27 additions & 18 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
@@ -227,14 +228,14 @@ class ClassLifter(logDebugMsg: Boolean = false) {
227228
}
228229

229230
private def liftCaseBranch(brn: CaseBranches)(using ctx: LocalContext, cache: ClassCache, globFuncs: Map[Var, (Var, LocalContext)], outer: Option[ClassInfoCache]): (CaseBranches, LocalContext) = brn match{
230-
case Case(v: Var, body, rest) =>
231+
case k @ Case(v: Var, body, rest) =>
231232
val nTrm = liftTerm(body)(using ctx.addV(v))
232233
val nRest = liftCaseBranch(rest)
233-
(Case(v, nTrm._1, nRest._1), nTrm._2 ++ nRest._2)
234-
case Case(pat, body, rest) =>
234+
(Case(v, nTrm._1, nRest._1)(k.refined), nTrm._2 ++ nRest._2)
235+
case k @ Case(pat, body, rest) =>
235236
val nTrm = liftTerm(body)
236237
val nRest = liftCaseBranch(rest)
237-
(Case(pat, nTrm._1, nRest._1), nTrm._2 ++ nRest._2)
238+
(Case(pat, nTrm._1, nRest._1)(k.refined), nTrm._2 ++ nRest._2)
238239
case Wildcard(body) =>
239240
val nTrm = liftTerm(body)
240241
(Wildcard(nTrm._1), nTrm._2)
@@ -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) = {
@@ -509,7 +510,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
509510
val nlhs = liftType(lb)
510511
val nrhs = liftType(ub)
511512
Bounds(nlhs._1, nrhs._1) -> (nlhs._2 ++ nrhs._2)
512-
case Constrained(base: Type, bounds, where) =>
513+
case Constrained(base: Type, bounds, where, tscs) =>
513514
val (nTargs, nCtx) = bounds.map { case (tv, Bounds(lb, ub)) =>
514515
val nlhs = liftType(lb)
515516
val nrhs = liftType(ub)
@@ -520,10 +521,18 @@ class ClassLifter(logDebugMsg: Boolean = false) {
520521
val nrhs = liftType(ub)
521522
Bounds(nlhs._1, nrhs._1) -> (nlhs._2 ++ nrhs._2)
522523
}.unzip
524+
val (tscs0, nCtx3) = tscs.map { case (tvs, cs) =>
525+
val (ntvs,c0) = tvs.map { case (p,v) =>
526+
val (nv, c) = liftType(v)
527+
(p,nv) -> c
528+
}.unzip
529+
val (ncs,c1) = cs.map(_.map(liftType).unzip).unzip
530+
(ntvs,ncs) -> (c0 ++ c1.flatten)
531+
}.unzip
523532
val (nBase, bCtx) = liftType(base)
524-
Constrained(nBase, nTargs, bounds2) ->
525-
((nCtx ++ nCtx2).fold(emptyCtx)(_ ++ _) ++ bCtx)
526-
case Constrained(_, _, _) => die
533+
Constrained(nBase, nTargs, bounds2, tscs0) ->
534+
((nCtx ++ nCtx2 ++ nCtx3.flatten).fold(emptyCtx)(_ ++ _) ++ bCtx)
535+
case Constrained(_, _, _, _) => die
527536
case Function(lhs, rhs) =>
528537
val nlhs = liftType(lhs)
529538
val nrhs = liftType(rhs)
@@ -578,7 +587,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
578587
val (body2, ctx) = liftType(body)
579588
PolyType(targs, body2) -> ctx
580589
case Top | Bot | _: Literal | _: TypeTag | _: TypeVar => target.asInstanceOf[Type] -> emptyCtx
581-
case _: Selection => throw MonomorphError(s"Unimplemented liftType: ${target}") // TODO
590+
case _: Selection => throw CompilerError(s"Unimplemented liftType: ${target}") // TODO
582591
}
583592

584593

@@ -602,7 +611,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
602611
}.unzip
603612
(func.copy(rhs = Right(PolyType(nTargs._1, nBody._1)))(func.declareLoc, func.virtualLoc, func.mutLoc, func.signature, func.outer, func.genField, func.annotations),
604613
nTargs._2.fold(nBody._2)(_ ++ _))
605-
case _ => throw MonomorphError(s"Unimplemented liftMemberFunc: ${func}") // TODO
614+
case _ => throw CompilerError(s"Unimplemented liftMemberFunc: ${func}") // TODO
606615
}
607616
}
608617

@@ -629,7 +638,7 @@ class ClassLifter(logDebugMsg: Boolean = false) {
629638
case (tn, ctx) => (L(tn), ctx)
630639
case R(tv) => R(tv) -> emptyCtx}).unzip
631640
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}")
641+
case _ => throw CompilerError(s"Unimplemented liftGlobalFunc: ${func}")
633642
})
634643
}
635644

compiler/shared/main/scala/mlscript/compiler/optimizer/Document.scala renamed to compiler/shared/main/scala/mlscript/compiler/Document.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package mlscript.compiler.optimizer
1+
package mlscript.compiler.utils
22

33
enum Document:
44
case Indented(content: Document)
@@ -10,7 +10,7 @@ enum Document:
1010
def <:>(other: Document) = line(List(this, other))
1111
def <#>(other: Document) = line(List(this, other), sep = "")
1212

13-
override def toString(): String = print
13+
override def toString: String = print
1414

1515
def print: String = {
1616
val sb = StringBuffer()

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

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

0 commit comments

Comments
 (0)