Skip to content

Commit

Permalink
Update Scala and Wartremover versions
Browse files Browse the repository at this point in the history
  • Loading branch information
LPTK committed Nov 22, 2023
1 parent 1d3811c commit 8894b74
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 57 deletions.
18 changes: 8 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import Wart._

enablePlugins(ScalaJSPlugin)

ThisBuild / scalaVersion := "2.13.9"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "io.lptk"
ThisBuild / organizationName := "LPTK"
ThisBuild / scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-unchecked",
)

lazy val root = project.in(file("."))
.aggregate(mlscriptJS, mlscriptJVM, ts2mlsTest, compilerJVM)
Expand All @@ -18,9 +23,6 @@ lazy val mlscript = crossProject(JSPlatform, JVMPlatform).in(file("."))
.settings(
name := "mlscript",
scalacOptions ++= Seq(
"-deprecation",
"-feature",
"-unchecked",
"-language:higherKinds",
"-Ywarn-value-discard",
"-Ypatmat-exhaust-depth:160",
Expand All @@ -36,7 +38,8 @@ lazy val mlscript = crossProject(JSPlatform, JVMPlatform).in(file("."))
StringPlusAny, Any, ToString,
JavaSerializable, Serializable, Product, ToString,
LeakingSealed, Overloading,
Option2Iterable, IterableOps, ListAppend
Option2Iterable, IterableOps, ListAppend, SeqApply,
TripleQuestionMark,
),
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.12" % Test,
libraryDependencies += "com.lihaoyi" %%% "sourcecode" % "0.3.0",
Expand All @@ -60,10 +63,6 @@ lazy val mlscriptJS = mlscript.js
lazy val ts2mls = crossProject(JSPlatform, JVMPlatform).in(file("ts2mls"))
.settings(
name := "ts2mls",
scalaVersion := "2.13.8",
scalacOptions ++= Seq(
"-deprecation"
)
)
.jvmSettings()
.jsSettings(
Expand All @@ -76,7 +75,6 @@ lazy val ts2mlsJVM = ts2mls.jvm

lazy val ts2mlsTest = project.in(file("ts2mls"))
.settings(
scalaVersion := "2.13.8",
Test / test := ((ts2mlsJVM / Test / test) dependsOn (ts2mlsJS / Test / test)).value
)

Expand Down
42 changes: 12 additions & 30 deletions compiler/shared/main/scala/mlscript/compiler/Helpers.scala
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
package mlscript.compiler
package mlscript
package compiler

import mlscript.{App, Asc, Assign, Bind, Blk, Bra, CaseOf, Lam, Let, Lit,
New, Rcd, Sel, Subs, Term, Test, Tup, With, Var, Fld, FldFlags, If, PolyType}
import mlscript.{IfBody, IfThen, IfElse, IfLet, IfOpApp, IfOpsApp, IfBlock}
import mlscript.UnitLit
import mlscript.codegen.Helpers.inspect as showStructure
import mlscript.compiler.mono.MonomorphError
import mlscript.NuTypeDef
import mlscript.NuFunDef
import mlscript.compiler.mono.{Monomorph, MonomorphError}
import scala.collection.mutable.ArrayBuffer
import mlscript.CaseBranches
import mlscript.Case
import mlscript.NoCases
import mlscript.Wildcard
import mlscript.DecLit
import mlscript.IntLit
import mlscript.StrLit
import mlscript.AppliedType
import mlscript.TypeName
import mlscript.TypeDefKind
import mlscript.compiler.mono.Monomorph

object Helpers:
/**
Expand Down Expand Up @@ -54,10 +38,10 @@ object Helpers:
val params = toFuncParams(args).toList
Expr.Lambda(params, term2Expr(body))
case App(App(Var("."), self), App(Var(method), args: Tup)) =>
Expr.Apply(Expr.Select(term2Expr(self), Expr.Ref(method)), List.from(toFuncArgs(args).map(term2Expr)))
Expr.Apply(Expr.Select(term2Expr(self), Expr.Ref(method)), List.from(toFuncArgs(args).iterator.map(term2Expr)))
case App(lhs, rhs) =>
val callee = term2Expr(lhs)
val arguments = toFuncArgs(rhs).map(term2Expr).toList
val arguments = toFuncArgs(rhs).iterator.map(term2Expr).toList
Expr.Apply(callee, arguments)
case Tup(fields) =>
Expr.Tuple(fields.map {
Expand Down Expand Up @@ -127,7 +111,7 @@ object Helpers:
val typeName = constructor match
case AppliedType(TypeName(name), _) => name
case TypeName(name) => name
Expr.New(TypeName(typeName), toFuncArgs(args).map(term2Expr).toList)
Expr.New(TypeName(typeName), toFuncArgs(args).iterator.map(term2Expr).toList)
// case Blk(unit) => Expr.Isolated(trans2Expr(TypingUnit(unit)))
case If(body, alternate) => body match
case IfThen(condition, consequent) =>
Expand Down Expand Up @@ -172,7 +156,12 @@ object Helpers:
})
val typeDecl: Item.TypeDecl = Item.TypeDecl(
Expr.Ref(className.name), // name
kind, // kind
kind match // kind
case Als => TypeDeclKind.Alias
case Cls => TypeDeclKind.Class
case Trt => TypeDeclKind.Trait
case _ => throw MonomorphError(s"Unsupported TypeDefKind conversion ${kind}")
,
tparams.map(_._2), // typeParams
toFuncParams(params.getOrElse(Tup(Nil))).toList, // params
parents.map {
Expand All @@ -187,10 +176,3 @@ object Helpers:
)
typeDecl

private given Conversion[TypeDefKind, TypeDeclKind] with
import mlscript.{Als, Cls, Trt}
def apply(kind: TypeDefKind): TypeDeclKind = kind match
case Als => TypeDeclKind.Alias
case Cls => TypeDeclKind.Class
case Trt => TypeDeclKind.Trait
case _ => throw MonomorphError(s"Unsupported TypeDefKind conversion ${kind}")
2 changes: 1 addition & 1 deletion js/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object Main {
if (l =:= endLineNum) endLineCol else curLine.length + 1
val front = curLine.slice(0, c - 1)
val middle = underline(curLine.slice(c - 1, lastCol - 1))
val back = curLine.slice(lastCol - 1, curLine.size)
val back = curLine.slice(lastCol - 1, curLine.length)
output(s"$prepre$pre\t$front$middle$back")
c = 1
l += 1
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.0.6")
addSbtPlugin("org.wartremover" % "sbt-wartremover" % "3.1.5")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.11.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
5 changes: 2 additions & 3 deletions shared/src/main/scala/mlscript/NewParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ abstract class NewParser(origin: Origin, tokens: Ls[Stroken -> Loc], newDefs: Bo
case class ModifierSet(mods: Map[Str, Loc]) {
def handle(mod: Str): (Opt[Loc], ModifierSet) =
mods.get(mod) -> copy(mods = mods - mod)
def done: Unit = mods.foreach {
case (mod, loc) =>
err(msg"Unrecognized modifier `${mod}` in this position" -> S(loc) :: Nil)
def done: Unit = mods.foreachEntry { (mod, loc) =>
err(msg"Unrecognized modifier `${mod}` in this position" -> S(loc) :: Nil)
}
}
object ModifierSet {
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/mlscript/NuTypeDefs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class NuTypeDefs extends ConstraintSolver { self: Typer =>
}
}()
}
members.foreach {
members.foreachEntry {
case (_, m: NuParam) if m.isType =>
case (_, m) => Trav.applyMem(PolMap.pos)(m)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@ final class TsTypegenCodeBuilder {

// add body fields
classFieldsAndType
.map {case (fieldVar, fieldTypes) =>
.map { case (fieldVar, fieldTypes) =>
val fieldTypesCode = toTypegenInheritedFields(fieldTypes)
(SourceCode(fieldVar.name), fieldTypesCode)
}
.foreach({ case (fieldVar, fieldType) => {
.foreachEntry { (fieldVar, fieldType) => {
classDeclaration += SourceCode(" ") ++ fieldVar ++ SourceCode.colon ++ fieldType
}})
}}

// constructor needs all fields including super classes
val allFieldsAndTypes = (classFieldsAndType ++
Expand Down
12 changes: 6 additions & 6 deletions shared/src/main/scala/mlscript/ucs/Desugarer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,12 @@ class Desugarer extends TypeDefs { self: Typer =>
if (exhaustivenessMap.isEmpty)
printlnUCS(" * <No entries>")
else
exhaustivenessMap.foreach { case (symbol, patternMap) =>
exhaustivenessMap.foreachEntry { (symbol, patternMap) =>
printlnUCS(s" * Patterns of $symbol")
if (patternMap.isEmpty)
printlnUCS(s" + <No patterns>")
else
patternMap.foreach { case (pattern, locations) =>
patternMap.foreachEntry { (pattern, locations) =>
val first = pattern match {
case Left(tupleArity) => s"()^$tupleArity"
case Right(litOrCls) => litOrCls.toString()
Expand Down Expand Up @@ -706,15 +706,15 @@ class Desugarer extends TypeDefs { self: Typer =>
printlnUCS("The match has a default branch. So, it is always safe.")
case S(patternMap) =>
printlnUCS(s"The exhaustiveness map is")
exhaustivenessMap.foreach { case (key, matches) =>
exhaustivenessMap.foreachEntry { (key, matches) =>
printlnUCS(s"- $key -> ${matches.keysIterator.mkString(", ")}")
}
printlnUCS(s"The scrutinee key is ${getScurtineeKey(scrutinee)}")
printlnUCS("Pattern map of the scrutinee:")
if (patternMap.isEmpty)
printlnUCS("<Empty>")
else
patternMap.foreach { case (key, mutCase) => printlnUCS(s"- $key => $mutCase")}
patternMap.foreachEntry { (key, mutCase) => printlnUCS(s"- $key => $mutCase")}
// Compute all classes that can be covered by this match.
val coveredClassNames = Set.from[String](branches.iterator.flatMap {
case MutCase.Literal(_, _) => Nil
Expand Down Expand Up @@ -742,7 +742,7 @@ class Desugarer extends TypeDefs { self: Typer =>
case R(_) -> _ => true // Literals. Don't remove.
}
printlnUCS("Missing cases")
missingCases.foreach { case (key, m) =>
missingCases.foreachEntry { (key, m) =>
printlnUCS(s"- $key -> ${m}")
}
if (!missingCases.isEmpty) {
Expand Down Expand Up @@ -1030,7 +1030,7 @@ object Desugarer {
if (graph.isEmpty)
print(" + <Empty>")
else
graph.foreach { case (source, targets) =>
graph.foreachEntry { (source, targets) =>
print(s" + $source $arrow " + {
if (targets.isEmpty) s"{}"
else targets.mkString("{ ", ", ", " }")
Expand Down
5 changes: 3 additions & 2 deletions shared/src/test/scala/mlscript/DiffTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class DiffTests
def postProcess(mode: ModeType, basePath: Ls[Str], testName: Str, unit: TypingUnit): Ls[Str] = Nil


@SuppressWarnings(Array("org.wartremover.warts.RedundantIsInstanceOf"))
private val inParallel = isInstanceOf[ParallelTestExecution]

import DiffTests._
Expand Down Expand Up @@ -1068,8 +1069,8 @@ class DiffTests
val timeStr = (((endTime - beginTime) / 1000 / 100).toDouble / 10.0).toString
val testColor = if (testFailed) Console.RED else Console.GREEN

val resStr = s"${" " * (35 - testStr.size)}${testColor}${
" " * (6 - timeStr.size)}$timeStr ms${Console.RESET}"
val resStr = s"${" " * (35 - testStr.length)}${testColor}${
" " * (6 - timeStr.length)}$timeStr ms${Console.RESET}"

if (inParallel) println(s"${Console.CYAN}Processed${Console.RESET} $testStr$resStr")
else println(resStr)
Expand Down

0 comments on commit 8894b74

Please sign in to comment.