Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 3.8.0 #1153

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.8.0
12bd519e9e132dd6ce125b4af67f5af9e4eda59e
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.5.9"
version = "3.8.0"
runner.dialect = scala212
fileOverride {
"glob:**/core/src/test/scala/**" {
Expand Down
20 changes: 12 additions & 8 deletions base/src/main/scala/org/bykn/bosatsu/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class Macro(val c: Context) {
if (f.exists()) {
val res = Source.fromFile(s, "UTF-8").getLines().mkString("\n")
Some(c.Expr[String](q"$res"))
}
else {
} else {
None
}
}
catch {
} catch {
case NonFatal(err) =>
c.abort(c.enclosingPosition, s"could not read existing file: $s. Exception: $err")
c.abort(
c.enclosingPosition,
s"could not read existing file: $s. Exception: $err"
)
}

file.tree match {
Expand All @@ -34,11 +35,14 @@ class Macro(val c: Context) {
.getOrElse {
c.abort(
c.enclosingPosition,
s"no file found at: $s. working directory is ${System.getProperty("user.dir")}")
s"no file found at: $s. working directory is ${System.getProperty("user.dir")}"
)
}
case otherTree =>
c.abort(c.enclosingPosition, s"expected string literal, found: $otherTree")
c.abort(
c.enclosingPosition,
s"expected string literal, found: $otherTree"
)
}
}
}

31 changes: 23 additions & 8 deletions bench/src/main/scala/org/bykn/bosatsu/TestBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class TestBench {
// don't use threads in the benchmark which will complicate matters
import DirectEC.directEC

private def prepPackages(packages: List[String], mainPackS: String): (PackageMap.Inferred, PackageName) = {
private def prepPackages(
packages: List[String],
mainPackS: String
): (PackageMap.Inferred, PackageName) = {
val mainPack = PackageName.parse(mainPackS).get

val parsed = packages.zipWithIndex.traverse { case (pack, i) =>
Expand All @@ -28,23 +31,32 @@ class TestBench {
val d = p.showContext(LocationMap.Colorize.None)
System.err.println(d.render(100))
}
sys.error("failed to parse") //errs.toString)
sys.error("failed to parse") // errs.toString)
}

implicit val show: Show[(String, LocationMap)] = Show.show { case (s, _) => s }
PackageMap.resolveThenInfer(PackageMap.withPredefA(("predef", LocationMap("")), parsedPaths), Nil).strictToValidated match {
implicit val show: Show[(String, LocationMap)] = Show.show { case (s, _) =>
s
}
PackageMap
.resolveThenInfer(
PackageMap.withPredefA(("predef", LocationMap("")), parsedPaths),
Nil
)
.strictToValidated match {
case Validated.Valid(packMap) =>
(packMap, mainPack)
case other => sys.error(s"expected clean compilation: $other")
}
}

def gauss(n: Int) = prepPackages(
List(s"""
List(s"""
package Gauss

gauss$n = range($n).foldLeft(0, add)
"""), "Gauss")
"""),
"Gauss"
)

val compiled0: (PackageMap.Inferred, PackageName) =
gauss(10)
Expand All @@ -69,7 +81,8 @@ gauss$n = range($n).foldLeft(0, add)
}

val compiled2 =
prepPackages(List("""
prepPackages(
List("""
package Euler4

def operator >(a, b):
Expand Down Expand Up @@ -132,7 +145,9 @@ max_pal_opt = max_of(99, \n1 -> first_of(99, product_palindrome(n1)))
max_pal = match max_pal_opt:
Some(m): m
None: 0
"""), "Euler4")
"""),
"Euler4"
)

@Benchmark def bench2(): Unit = {
val c = compiled2
Expand Down
51 changes: 29 additions & 22 deletions cli/src/main/scala/org/bykn/bosatsu/PathModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ object PathModule extends MainModule[IO] {
def readInterfaces(paths: List[Path]): IO[List[Package.Interface]] =
ProtoConverter.readInterfaces(paths)

def writeInterfaces(interfaces: List[Package.Interface], path: Path): IO[Unit] =
def writeInterfaces(
interfaces: List[Package.Interface],
path: Path
): IO[Unit] =
ProtoConverter.writeInterfaces(interfaces, path)

def writePackages[A](packages: List[Package.Typed[A]], path: Path): IO[Unit] =
Expand All @@ -54,14 +57,14 @@ object PathModule extends MainModule[IO] {
Some(IO {
f.listFiles.iterator.map(_.toPath).toList
})
}
else None
} else None
}
}
}

def hasExtension(str: String): Path => Boolean =
{ (path: Path) => path.toString.endsWith(str) }
def hasExtension(str: String): Path => Boolean = { (path: Path) =>
path.toString.endsWith(str)
}

def print(str: => String): IO[Unit] =
IO(println(str))
Expand All @@ -71,7 +74,7 @@ object PathModule extends MainModule[IO] {
def report(io: IO[Output]): IO[ExitCode] =
io.attempt.flatMap {
case Right(out) => reportOutput(out)
case Left(err) => reportException(err).as(ExitCode.Error)
case Left(err) => reportException(err).as(ExitCode.Error)
}

def reportOutput(out: Output): IO[ExitCode] =
Expand All @@ -84,25 +87,27 @@ object PathModule extends MainModule[IO] {
print(testReport.doc.render(80)).as(code)
case Output.EvaluationResult(_, tpe, resDoc) =>
val tDoc = rankn.Type.fullyResolvedDocument.document(tpe)
val doc = resDoc.value + (Doc.lineOrEmpty + Doc.text(": ") + tDoc).nested(4)
val doc =
resDoc.value + (Doc.lineOrEmpty + Doc.text(": ") + tDoc).nested(4)
print(doc.render(100)).as(ExitCode.Success)
case Output.JsonOutput(json, pathOpt) =>
val jdoc = json.toDoc
(pathOpt match {
case Some(path) => CodeGenWrite.writeDoc(path, jdoc)
case None => IO(println(jdoc.renderTrim(80)))
case None => IO(println(jdoc.renderTrim(80)))
}).as(ExitCode.Success)

case Output.TranspileOut(outs, base) =>
def path(p: List[String]): Path =
p.foldLeft(base)(_.resolve(_))

outs.toList.map { case (p, d) =>
(p, CodeGenWrite.writeDoc(path(p.toList), d))
}
.sortBy(_._1)
.traverse_ { case (_, w) => w }
.as(ExitCode.Success)
outs.toList
.map { case (p, d) =>
(p, CodeGenWrite.writeDoc(path(p.toList), d))
}
.sortBy(_._1)
.traverse_ { case (_, w) => w }
.as(ExitCode.Success)

case Output.CompileOut(packList, ifout, output) =>
val ifres = ifout match {
Expand All @@ -128,15 +133,16 @@ object PathModule extends MainModule[IO] {
output match {
case None =>
IO.blocking {
doc.renderStreamTrim(80)
doc
.renderStreamTrim(80)
.iterator
.foreach(System.out.print)

System.out.println("")
}
.as(ExitCode.Success)
}.as(ExitCode.Success)
case Some(p) =>
CodeGenWrite.writeDoc(p, doc)
CodeGenWrite
.writeDoc(p, doc)
.as(ExitCode.Success)
}
}
Expand All @@ -154,7 +160,8 @@ object PathModule extends MainModule[IO] {
import scala.jdk.CollectionConverters._

def getP(p: Path): Option[PackageName] = {
val subPath = p.relativize(packFile)
val subPath = p
.relativize(packFile)
.asScala
.map { part =>
part.toString.toLowerCase.capitalize
Expand All @@ -164,17 +171,17 @@ object PathModule extends MainModule[IO] {
val dropExtension = """(.*)\.[^.]*$""".r
val toParse = subPath match {
case dropExtension(prefix) => prefix
case _ => subPath
case _ => subPath
}
PackageName.parse(toParse)
}

@annotation.tailrec
def loop(roots: List[Path]): Option[PackageName] =
roots match {
case Nil => None
case Nil => None
case h :: _ if packFile.startsWith(h) => getP(h)
case _ :: t => loop(t)
case _ :: t => loop(t)
}

if (packFile.toString.isEmpty) None
Expand Down
Loading
Loading