Skip to content

Commit 90ccd87

Browse files
committed
reformat with scalafmt 3.8.6
1 parent 1e734fd commit 90ccd87

File tree

86 files changed

+4651
-2898
lines changed

Some content is hidden

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

86 files changed

+4651
-2898
lines changed

cli/src/main/scala/org/bykn/bosatsu/IOPlatformIO.scala

+79-51
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,29 @@ object IOPlatformIO extends PlatformIO[IO, JPath] {
2929

3030
def pathToString(p: Path): String = p.toString
3131

32-
private def systemCmd[A](cmd: String, args: List[String], bldr: java.lang.ProcessBuilder)(fn: java.lang.Process => A): IO[A] = IO.blocking {
32+
private def systemCmd[A](
33+
cmd: String,
34+
args: List[String],
35+
bldr: java.lang.ProcessBuilder
36+
)(fn: java.lang.Process => A): IO[A] = IO.blocking {
3337
// Start the process
3438
val process = bldr.start()
3539
val result = fn(process)
3640
// Wait for the process to complete and check the exit value
3741
val exitCode = process.waitFor()
3842
if (exitCode != 0) {
39-
throw new RuntimeException(s"command $cmd ${args.mkString(" ")} failed with exit code: $exitCode")
43+
throw new RuntimeException(
44+
s"command $cmd ${args.mkString(" ")} failed with exit code: $exitCode"
45+
)
4046
}
4147

4248
result
4349
}
4450

45-
private def processBldr(cmd: String, args: List[String]): IO[java.lang.ProcessBuilder] = IO {
51+
private def processBldr(
52+
cmd: String,
53+
args: List[String]
54+
): IO[java.lang.ProcessBuilder] = IO {
4655
val processBuilder = new java.lang.ProcessBuilder()
4756
val command = new java.util.ArrayList[String]()
4857
(cmd :: args).foreach(command.add(_))
@@ -52,7 +61,6 @@ object IOPlatformIO extends PlatformIO[IO, JPath] {
5261

5362
def system(cmd: String, args: List[String]): IO[Unit] =
5463
processBldr(cmd, args).flatMap { processBuilder =>
55-
5664
// Redirect output and error streams
5765
processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT)
5866
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT)
@@ -62,13 +70,14 @@ object IOPlatformIO extends PlatformIO[IO, JPath] {
6270
val gitShaHead: IO[String] = {
6371
val args = "rev-parse" :: "HEAD" :: Nil
6472
processBldr("git", args).flatMap { processBuilder =>
65-
6673
// Combine stdout and stderr, and pipe the combined output for capturing
6774
processBuilder.redirectErrorStream(true)
6875
processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE)
69-
systemCmd("git", args, processBuilder) { process =>
76+
systemCmd("git", args, processBuilder) { process =>
7077
// Prepare to read the combined output
71-
val reader = new java.io.BufferedReader(new java.io.InputStreamReader(process.getInputStream))
78+
val reader = new java.io.BufferedReader(
79+
new java.io.InputStreamReader(process.getInputStream)
80+
)
7281
val output = new StringBuilder
7382
var line: String = null
7483

@@ -88,7 +97,8 @@ object IOPlatformIO extends PlatformIO[IO, JPath] {
8897
override val parallelF: cats.Parallel[IO] = IO.parallelForIO
8998

9099
private val parResource: Resource[IO, Par.EC] =
91-
Resource.make(IO(Par.newService()))(es => IO(Par.shutdownService(es)))
100+
Resource
101+
.make(IO(Par.newService()))(es => IO(Par.shutdownService(es)))
92102
.map(Par.ecFromService(_))
93103

94104
def withEC[A](fn: Par.EC => IO[A]): IO[A] =
@@ -129,8 +139,11 @@ object IOPlatformIO extends PlatformIO[IO, JPath] {
129139
}
130140

131141
def readHashed[A <: GeneratedMessage, H](
132-
path: Path
133-
)(implicit gmc: GeneratedMessageCompanion[A], algo: Algo[H]): IO[Hashed[H, A]] =
142+
path: Path
143+
)(implicit
144+
gmc: GeneratedMessageCompanion[A],
145+
algo: Algo[H]
146+
): IO[Hashed[H, A]] =
134147
IO.blocking {
135148
val bytes = Files.readAllBytes(path)
136149
val a = gmc.parseFrom(bytes)
@@ -155,13 +168,13 @@ object IOPlatformIO extends PlatformIO[IO, JPath] {
155168
ifacePaths.traverse(read[proto.Interfaces](_)),
156169
packagePaths.traverse(read[proto.Packages](_))
157170
).flatMapN { (ifs, packs) =>
158-
IO.fromTry(
159-
ProtoConverter.packagesFromProto(
160-
ifs.flatMap(_.interfaces),
161-
packs.flatMap(_.packages)
162-
)
171+
IO.fromTry(
172+
ProtoConverter.packagesFromProto(
173+
ifs.flatMap(_.interfaces),
174+
packs.flatMap(_.packages)
163175
)
164-
}
176+
)
177+
}
165178

166179
def readInterfaces(paths: List[Path]): IO[List[Package.Interface]] =
167180
readInterfacesAndPackages(paths, Nil).map(_._1)
@@ -172,7 +185,12 @@ object IOPlatformIO extends PlatformIO[IO, JPath] {
172185
def readLibrary(path: Path): IO[Hashed[Algo.Blake3, proto.Library]] =
173186
readHashed[proto.Library, Algo.Blake3](path)
174187

175-
def fetchHash[A](algo: Algo[A], hash: HashValue[A], path: Path, uri: String): F[Unit] = {
188+
def fetchHash[A](
189+
algo: Algo[A],
190+
hash: HashValue[A],
191+
path: Path,
192+
uri: String
193+
): F[Unit] = {
176194
// Create a Blaze client resource
177195
import org.http4s._
178196
import fs2.io.file.{Files, Path => Fs2Path, CopyFlags, CopyFlag}
@@ -201,41 +219,51 @@ object IOPlatformIO extends PlatformIO[IO, JPath] {
201219
)
202220

203221
parent.traverse_(p => filesIO.createDirectories(Fs2Path.fromNioPath(p))) *>
204-
(clientResource,
205-
tempFileRes,
206-
Resource.eval(IO(Uri.unsafeFromString(uri)))
207-
).tupled.use { case (client, tempPath, uri) =>
208-
// Create an HTTP GET request
209-
val request = Request[IO](method = Method.GET, uri = uri)
210-
211-
// Stream the response body and write it to the specified file path
212-
client.stream(request)
213-
.flatMap { response =>
214-
if (response.status.isSuccess) {
215-
response.body
216-
} else {
217-
fs2.Stream.raiseError[IO](new Exception(s"Failed to download from $uri: ${response.status}"))
218-
}
219-
}
220-
.broadcastThrough(
221-
Files[IO].writeAll(tempPath),
222-
hashFile
223-
)
224-
.compile
225-
.lastOrError
226-
.flatMap { computedHash =>
227-
if (computedHash == hash) {
228-
// move it atomically to output
229-
filesIO.move(
230-
source = Fs2Path.fromNioPath(tempPath),
231-
target = Fs2Path.fromNioPath(path),
232-
CopyFlags(CopyFlag.AtomicMove))
222+
(
223+
clientResource,
224+
tempFileRes,
225+
Resource.eval(IO(Uri.unsafeFromString(uri)))
226+
).tupled.use { case (client, tempPath, uri) =>
227+
// Create an HTTP GET request
228+
val request = Request[IO](method = Method.GET, uri = uri)
229+
230+
// Stream the response body and write it to the specified file path
231+
client
232+
.stream(request)
233+
.flatMap { response =>
234+
if (response.status.isSuccess) {
235+
response.body
236+
} else {
237+
fs2.Stream.raiseError[IO](
238+
new Exception(
239+
s"Failed to download from $uri: ${response.status}"
240+
)
241+
)
242+
}
233243
}
234-
else {
235-
IO.raiseError(new Exception(s"from $uri expected hash to be ${hash.toIdent(algo)} but found ${computedHash.toIdent(algo)}"))
244+
.broadcastThrough(
245+
Files[IO].writeAll(tempPath),
246+
hashFile
247+
)
248+
.compile
249+
.lastOrError
250+
.flatMap { computedHash =>
251+
if (computedHash == hash) {
252+
// move it atomically to output
253+
filesIO.move(
254+
source = Fs2Path.fromNioPath(tempPath),
255+
target = Fs2Path.fromNioPath(path),
256+
CopyFlags(CopyFlag.AtomicMove)
257+
)
258+
} else {
259+
IO.raiseError(
260+
new Exception(
261+
s"from $uri expected hash to be ${hash.toIdent(algo)} but found ${computedHash.toIdent(algo)}"
262+
)
263+
)
264+
}
236265
}
237-
}
238-
}
266+
}
239267
}
240268

241269
def writeInterfaces(
@@ -312,4 +340,4 @@ object IOPlatformIO extends PlatformIO[IO, JPath] {
312340
System.out.println("")
313341
}
314342

315-
}
343+
}

cli/src/main/scala/org/bykn/bosatsu/Main.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Main extends IOApp {
77
def fromToolExit(ec: tool.ExitCode): ExitCode =
88
ec match {
99
case tool.ExitCode.Success => ExitCode.Success
10-
case tool.ExitCode.Error => ExitCode.Error
10+
case tool.ExitCode.Error => ExitCode.Error
1111
}
1212
def run(args: List[String]): IO[ExitCode] =
1313
PathModule.runAndReport(args) match {

cli/src/test/scala/org/bykn/bosatsu/IOPlatformIOTest.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class IOPlatformIOTest extends munit.ScalaCheckSuite {
1616
l.sortBy(_.name.asString) == r
1717
}
1818

19-
2019
def testWithTempFile(fn: Path => IO[Unit]): Unit = {
2120
val tempRes = Resource.make(IO.blocking {
2221
val f = File.createTempFile("proto_test", ".proto")
@@ -60,4 +59,4 @@ class IOPlatformIOTest extends munit.ScalaCheckSuite {
6059
}
6160
}
6261

63-
}
62+
}

cli/src/test/scala/org/bykn/bosatsu/codegen/clang/ClangGenTest.scala

+20-9
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,51 @@ class ClangGenTest extends munit.FunSuite {
1212
val digest = md.digest(content.getBytes("UTF-8"))
1313
digest.map("%02x".format(_)).mkString
1414
}
15-
def testFilesCompilesToHash(path0: String, paths: String*)(hashHex: String)(implicit loc: munit.Location) = {
15+
def testFilesCompilesToHash(path0: String, paths: String*)(
16+
hashHex: String
17+
)(implicit loc: munit.Location) = {
1618
val pm: PackageMap.Typed[Any] = TestUtils.compileFile(path0, paths*)
1719
/*
1820
val exCode = ClangGen.generateExternalsStub(pm)
1921
println(exCode.render(80))
2022
sys.error("stop")
21-
*/
23+
*/
2224
val matchlessMap = MatchlessFromTypedExpr.compile(pm)
2325
val topoSort = pm.topoSort.toSuccess.get
24-
val sortedEnv = cats.Functor[Vector].compose[NonEmptyList].map(topoSort) { pn =>
25-
(pn, matchlessMap(pn))
26-
}
26+
val sortedEnv =
27+
cats.Functor[Vector].compose[NonEmptyList].map(topoSort) { pn =>
28+
(pn, matchlessMap(pn))
29+
}
2730

2831
val res = ClangGen.renderMain(
2932
sortedEnv = sortedEnv,
3033
externals = ClangGen.ExternalResolver.FromJvmExternals,
31-
value = (PackageName.PredefName, Identifier.Name("range"), Code.Ident("run_main"))
34+
value = (
35+
PackageName.PredefName,
36+
Identifier.Name("range"),
37+
Code.Ident("run_main")
38+
)
3239
)
3340

3441
res match {
3542
case Right(d) =>
3643
val everything = d.render(80)
3744
val hashed = md5HashToHex(everything)
38-
assertEquals(hashed, hashHex, s"compilation didn't match. Compiled code:\n\n${"//" * 40}\n\n$everything")
45+
assertEquals(
46+
hashed,
47+
hashHex,
48+
s"compilation didn't match. Compiled code:\n\n${"//" * 40}\n\n$everything"
49+
)
3950
case Left(e) => fail(e.toString)
4051
}
4152
}
4253

4354
test("test_workspace/Ackermann.bosatsu") {
44-
/*
55+
/*
4556
To inspect the code, change the hash, and it will print the code out
4657
*/
4758
testFilesCompilesToHash("test_workspace/Ackermann.bosatsu")(
4859
"ccbf676b90cf04397c908d23f86b6434"
4960
)
5061
}
51-
}
62+
}

cli/src/test/scala/org/bykn/bosatsu/codegen/python/CodeTest.scala

+12-5
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ else:
307307
forAll(genExpr(4)) { x =>
308308
val sx = x.simplify
309309
val res = x.evalAnd(Code.Const.False)
310-
assert((res == Code.Const.False) || ((res == sx) && (sx == Code.Const.Zero)))
310+
assert(
311+
(res == Code.Const.False) || ((res == sx) && (sx == Code.Const.Zero))
312+
)
311313
assert(Code.Const.False.evalAnd(x) == Code.Const.False)
312314
}
313315
}
@@ -525,15 +527,20 @@ else:
525527
case whoKnows =>
526528
if (tern == whoKnows) {
527529
(t.simplify, f.simplify) match {
528-
case (Code.Const.One | Code.Const.True, Code.Const.False | Code.Const.Zero) =>
530+
case (
531+
Code.Const.One | Code.Const.True,
532+
Code.Const.False | Code.Const.Zero
533+
) =>
529534
()
530535
case tf =>
531536
fail(s"$tern == $whoKnows but (t,f) = $tf")
532537
}
533-
}
534-
else {
538+
} else {
535539
(t.simplify, f.simplify) match {
536-
case (Code.Const.False | Code.Const.Zero, Code.Const.One | Code.Const.True) =>
540+
case (
541+
Code.Const.False | Code.Const.Zero,
542+
Code.Const.One | Code.Const.True
543+
) =>
537544
val not = Code.Not(whoKnows).simplify
538545
assert(tern == not)
539546
case (ts, fs) =>

cli/src/test/scala/org/bykn/bosatsu/codegen/python/PythonGenTest.scala

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ package org.bykn.bosatsu.codegen.python
33
import cats.Show
44
import java.io.{ByteArrayInputStream, InputStream}
55
import java.util.concurrent.Semaphore
6-
import org.bykn.bosatsu.{
7-
MatchlessFromTypedExpr,
8-
PackageName,
9-
TestUtils
10-
}
6+
import org.bykn.bosatsu.{MatchlessFromTypedExpr, PackageName, TestUtils}
117
import org.scalacheck.Gen
128
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks.{
139
forAll,

0 commit comments

Comments
 (0)