Skip to content

Commit

Permalink
run scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Sep 20, 2024
1 parent 661dddc commit ebb5971
Show file tree
Hide file tree
Showing 28 changed files with 385 additions and 202 deletions.
3 changes: 2 additions & 1 deletion bsp/src/mill/bsp/BspServerResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ object BspServerResult {
upickle.default.macroRW

// GENERATED CODE BY ci/scripts/manual_mirror_gen.sc - DO NOT EDIT
private type SingletonMirrorProxy[T <: AnyRef & Singleton] = Mirror.SingletonProxy { val value: T }
private type SingletonMirrorProxy[T <: AnyRef & Singleton] =
Mirror.SingletonProxy { val value: T }
private def genSingletonMirror[T <: AnyRef & Singleton](ref: T): SingletonMirrorProxy[T] =
new Mirror.SingletonProxy(ref).asInstanceOf[SingletonMirrorProxy[T]]
private given Mirror_ReloadWorkspace: SingletonMirrorProxy[ReloadWorkspace.type] =
Expand Down
6 changes: 4 additions & 2 deletions contrib/docker/src/mill/contrib/docker/DockerModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ trait DockerModule { outer: JavaModule =>
)
.call(stdout = os.Inherit, stderr = os.Inherit)
}
log.info(s"Docker build completed ${if (result.exitCode == 0) "successfully"
else "unsuccessfully"} with ${result.exitCode}")
log.info(s"Docker build completed ${
if (result.exitCode == 0) "successfully"
else "unsuccessfully"
} with ${result.exitCode}")
tags()
}

Expand Down
50 changes: 26 additions & 24 deletions idea/src/mill/idea/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -772,14 +772,14 @@ case class GenIdeaImpl(
<library name={name} type="Scala">
<properties>
{
if (languageLevel.isDefined)
<language-level>{languageLevel.get}</language-level>
else {
// Scala 3: I assume there is some missing implicit conversion from `()` to NodeSeq,
// so use an explicit seq.
NodeSeq.Empty
}
}
if (languageLevel.isDefined)
<language-level>{languageLevel.get}</language-level>
else {
// Scala 3: I assume there is some missing implicit conversion from `()` to NodeSeq,
// so use an explicit seq.
NodeSeq.Empty
}
}
<compiler-classpath>
{
scalaCompilerClassPath.iterator.toSeq.sortBy(_.wrapped).map(p =>
Expand All @@ -788,14 +788,16 @@ case class GenIdeaImpl(
}
</compiler-classpath>
{
if (compilerBridgeJar.isDefined)
<compiler-bridge-binary-jar>{relativeFileUrl(compilerBridgeJar.get)}</compiler-bridge-binary-jar>
else {
// Scala 3: I assume there is some missing implicit conversion from `()` to NodeSeq,
// so use an explicit seq.
NodeSeq.Empty
}
}
if (compilerBridgeJar.isDefined)
<compiler-bridge-binary-jar>{
relativeFileUrl(compilerBridgeJar.get)
}</compiler-bridge-binary-jar>
else {
// Scala 3: I assume there is some missing implicit conversion from `()` to NodeSeq,
// so use an explicit seq.
NodeSeq.Empty
}
}
</properties>
</library>
</component>
Expand All @@ -812,16 +814,16 @@ case class GenIdeaImpl(
<root url={relativeJarUrl(path)}/>
</CLASSES>
{
if (sources.isDefined) {
<SOURCES>
if (sources.isDefined) {
<SOURCES>
<root url={relativeJarUrl(sources.get)}/>
</SOURCES>
} else {
// Scala 3: I assume there is some missing implicit conversion from `()` to NodeSeq,
// so use an explicit seq.
NodeSeq.Empty
}
}
} else {
// Scala 3: I assume there is some missing implicit conversion from `()` to NodeSeq,
// so use an explicit seq.
NodeSeq.Empty
}
}
</library>
</component>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ object RootModuleCompileErrorTests extends UtestIntegrationTestSuite {
// For now these error messages still show generated/mangled code; not ideal, but it'll do
assert(res.err.contains("""build.mill:7:50"""))
assert(res.err.contains("""Not found: type UnknownRootModule"""))
assert(res.err.contains("""abstract class package_ extends RootModule with UnknownRootModule {"""))
assert(res.err.contains(""" ^^^^^^^^^^^^^^^^^"""))
assert(res.err.contains(
"""abstract class package_ extends RootModule with UnknownRootModule {"""
))
assert(
res.err.contains(""" ^^^^^^^^^^^^^^^^^""")
)
}

locally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import scala.concurrent.Future
import scala.concurrent.ExecutionContext
import java.util.concurrent.atomic.AtomicReference

/**Trait that provides a `skip` method that can be used to skip a test, the test will pass.
/**
* Trait that provides a `skip` method that can be used to skip a test, the test will pass.
* Used to assert that a test still compiles, and is intended to be re-enabled later,
* but is temporarily prevented from running for a suitable reason.
* At the end of a suite, print a summary of the number of skipped tests, and their names.
Expand All @@ -17,20 +18,26 @@ trait UTestIgnore(name: String) extends utest.TestSuite {

val skipList = AtomicReference(List.empty[String])

private final class SkipException(val name: String) extends Exception with scala.util.control.NoStackTrace
private final class SkipException(val name: String) extends Exception
with scala.util.control.NoStackTrace

def skip(op: => Any)(using path: utest.framework.TestPath): Nothing = {
throw new SkipException(name + "." + path.value.mkString("."))
}

private def red(str: String) = Console.RED + str + Console.RESET

override def utestWrap(path: Seq[String], runBody: => Future[Any])(implicit ec: ExecutionContext): Future[Any] = {
super.utestWrap(path, runBody.recoverWith {
case e: SkipException =>
skipList.updateAndGet(e.name :: _)
Future.successful(())
})
override def utestWrap(path: Seq[String], runBody: => Future[Any])(implicit
ec: ExecutionContext
): Future[Any] = {
super.utestWrap(
path,
runBody.recoverWith {
case e: SkipException =>
skipList.updateAndGet(e.name :: _)
Future.successful(())
}
)
}

override def utestAfterAll(): Unit = {
Expand All @@ -46,7 +53,7 @@ trait UTestIgnore(name: String) extends utest.TestSuite {
}

object MillPluginClasspathTest extends UtestIntegrationTestSuite
with UTestIgnore("mill.integration.MillPluginClasspathTest") {
with UTestIgnore("mill.integration.MillPluginClasspathTest") {

val embeddedModules: Seq[(String, String)] = Seq(
("com.lihaoyi", "mill-main-client"),
Expand Down
6 changes: 4 additions & 2 deletions integration/ide/gen-idea/src/GenIdeaUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ object GenIdeaUtils {
)
}
println(
s"Checking ${expectedResourcePath.relativeTo(workspacePath)} ... ${if (check.isSuccess) "OK"
else "FAILED"}"
s"Checking ${expectedResourcePath.relativeTo(workspacePath)} ... ${
if (check.isSuccess) "OK"
else "FAILED"
}"
)
check.get
}
Expand Down
5 changes: 3 additions & 2 deletions main/api/src/mill/api/JarManifest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ object JarManifest {

final def fromProduct(p: scala.Product): JarManifest = {
val _1: Map[String, String] = p.productElement(0).asInstanceOf[Map[String, String]]
val _2: Map[String, Map[String, String]] = p.productElement(1).asInstanceOf[Map[String, Map[String, String]]]
val _2: Map[String, Map[String, String]] =
p.productElement(1).asInstanceOf[Map[String, Map[String, String]]]

JarManifest.apply(_1,_2)
JarManifest.apply(_1, _2)
}
}

Expand Down
2 changes: 1 addition & 1 deletion main/api/src/mill/api/Retry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ case class Retry(
if (timeoutMillis == -1) t(retryCount)
else {
val result = Promise[T]
val thread = new Thread({() =>
val thread = new Thread({ () =>
result.complete(scala.util.Try(t(retryCount)))
}: Runnable)
thread.start()
Expand Down
4 changes: 3 additions & 1 deletion main/codesig/src/ResolvedCalls.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ object ResolvedCalls {
val externalSamDefiners = externalSummary
.directMethods
.map { case (k, v) => (k, v.collect { case (sig, true) => sig }) }
.collect { case (k, Seq[MethodSig](v)) => (k, v) } // Scala 3.5.0-RC6 - can not infer MethodSig here
.collect { case (k, Seq[MethodSig](v)) =>
(k, v)
} // Scala 3.5.0-RC6 - can not infer MethodSig here

val allSamDefiners = localSamDefiners ++ externalSamDefiners

Expand Down
6 changes: 5 additions & 1 deletion main/codesig/src/SpanningForest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ object SpanningForest {
.groupMap(_._1)(_._2)

ResolvedCalls.breadthFirst(rootChangedNodeIndices) { index =>
val nextIndices = downstreamGraphEdges.getOrElse(index, Array[Int]()) // needed to add explicit type for Scala 3.5.0-RC6
val nextIndices =
downstreamGraphEdges.getOrElse(
index,
Array[Int]()
) // needed to add explicit type for Scala 3.5.0-RC6
// We build up the spanningForest during a normal breadth first search,
// using the `nodeMapping` to quickly find an vertice's tree node so we
// can add children to it. We need to duplicate the `seen.contains` logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class Word(s: String) extends Phrase
class Pair(lhs: Phrase, rhs: Phrase) extends Phrase

object Parser {
def prefix[__ : P] = P("hello" | "goodbye").!.map(new Word(_))
def prefix[_X: P] = P("hello" | "goodbye").!.map(new Word(_))

def suffix[__ : P] = P("world" | "seattle").!.map(new Word(_))
def suffix[_X: P] = P("world" | "seattle").!.map(new Word(_))

def ws[__ : P] = P(" ".rep(1))
def ws[_X: P] = P(" ".rep(1))

def parened[__ : P] = P("(" ~ parser ~ ")")
def parened[_X: P] = P("(" ~ parser ~ ")")

def parser[__ : P]: P[Phrase] = P((parened | prefix) ~ ws ~ (parened | suffix)).map {
def parser[_X: P]: P[Phrase] = P((parened | prefix) ~ ws ~ (parened | suffix)).map {
case (lhs, rhs) => new Pair(lhs, rhs)
}
}
Expand Down
51 changes: 33 additions & 18 deletions main/define/src/mill/define/Applicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,21 @@ object Applicative {
def traverseCtx[I, R](xs: Seq[W[I]])(f: (IndexedSeq[I], Ctx) => Z[R]): T[R]
}

def impl[M[_]: Type, Q[_]: Type, Z[_]: Type, T: Type, Ctx: Type](using Quotes)(caller: Expr[Applyer[Q, M, Z, Ctx]], t: Expr[Z[T]]): Expr[M[T]] = {
def impl[M[_]: Type, Q[_]: Type, Z[_]: Type, T: Type, Ctx: Type](using
Quotes
)(caller: Expr[Applyer[Q, M, Z, Ctx]], t: Expr[Z[T]]): Expr[M[T]] = {
import quotes.reflect.*
impl0(using quotes)(caller.asTerm, t.asTerm)(using Type.of[M], Type.of[Q], Type.of[Z], Type.of[T], Type.of[Ctx])
impl0(using quotes)(caller.asTerm, t.asTerm)(using
Type.of[M],
Type.of[Q],
Type.of[Z],
Type.of[T],
Type.of[Ctx]
)
}
def impl0[M[_]: Type, Q[_]: Type, Z[_]: Type, T: Type, Ctx: Type](using Quotes)(caller: quotes.reflect.Tree, t: quotes.reflect.Tree): Expr[M[T]] = {
def impl0[M[_]: Type, Q[_]: Type, Z[_]: Type, T: Type, Ctx: Type](using
Quotes
)(caller: quotes.reflect.Tree, t: quotes.reflect.Tree): Expr[M[T]] = {
import quotes.reflect.*

val targetApplySym = TypeRepr.of[Applyable[Nothing, ?]].typeSymbol.methodMember("apply").head
Expand All @@ -58,28 +68,32 @@ object Applicative {
override def foldTree(x: Set[Symbol], tree: Tree)(owner: Symbol): Set[Symbol] = tree match
case tree: Definition => foldOverTree(x + tree.symbol, tree)(owner)
case tree => foldOverTree(x, tree)(owner)
}.foldTree(Set.empty, tree)(Symbol.spliceOwner)
}.foldTree(Set.empty, tree)(Symbol.spliceOwner)

def visitAllTrees(tree: Tree)(f: Tree => Unit): Unit =
new TreeTraverser {
override def traverseTree(tree: Tree)(owner: Symbol): Unit =
f(tree)
traverseTreeChildren(tree)(owner)
}.traverseTree(tree)(Symbol.spliceOwner)
}.traverseTree(tree)(Symbol.spliceOwner)

val defs = extractDefs(t)

var hasErrors = false

def transformed(itemsRef: Expr[IndexedSeq[Any]], ctxRef: Expr[Ctx]): (Expr[Z[T]], Expr[List[Q[Any]]]) = {
def transformed(
itemsRef: Expr[IndexedSeq[Any]],
ctxRef: Expr[Ctx]
): (Expr[Z[T]], Expr[List[Q[Any]]]) = {
val exprs = collection.mutable.Buffer.empty[Tree]
val treeMap = new TreeMap {

override def transformTerm(tree: Term)(owner: Symbol): Term = tree match
// case t @ '{$fun.apply()($handler)}
case t @ Apply(Apply(sel @ Select(fun, "apply"), Nil), List(handler)) if sel.symbol == targetApplySym =>
case t @ Apply(Apply(sel @ Select(fun, "apply"), Nil), List(handler))
if sel.symbol == targetApplySym =>
val localDefs = extractDefs(fun)
visitAllTrees(t){ x =>
visitAllTrees(t) { x =>
val sym = x.symbol
if (sym != Symbol.noSymbol && defs(sym) && !localDefs(sym)) {
hasErrors = true
Expand All @@ -101,9 +115,10 @@ object Applicative {
// val itemsIdent = Ident(itemsSym)
// exprs.append(q"$fun")
exprs += fun
'{$itemsRef(${Expr(exprs.size - 1)}).asInstanceOf[tt]}.asTerm
case t if t.symbol.exists
&& t.symbol.annotations.exists(_.tpe =:= TypeRepr.of[mill.api.Ctx.ImplicitStub]) =>
'{ $itemsRef(${ Expr(exprs.size - 1) }).asInstanceOf[tt] }.asTerm
case t
if t.symbol.exists
&& t.symbol.annotations.exists(_.tpe =:= TypeRepr.of[mill.api.Ctx.ImplicitStub]) =>
// val tempIdent = Ident(ctxSym)
// c.internal.setType(tempIdent, t.tpe)
// c.internal.setFlag(ctxSym, (1L << 44).asInstanceOf[c.universe.FlagSet])
Expand All @@ -124,19 +139,19 @@ object Applicative {
val (callback, exprsList) = {
var exprsExpr: Expr[List[Q[Any]]] | Null = null
val cb = '{ (items: IndexedSeq[Any], ctx: Ctx) =>
${
val (body, exprs) = transformed('items, 'ctx)
exprsExpr = exprs
body
}
${
val (body, exprs) = transformed('items, 'ctx)
exprsExpr = exprs
body
}
}
(cb, exprsExpr.nn)
}

if hasErrors then
'{throw new RuntimeException("stub implementation - macro expansion had errors")}
'{ throw new RuntimeException("stub implementation - macro expansion had errors") }
else
'{${callerExpr}.traverseCtx[Any, T]($exprsList)($callback)}
'{ ${ callerExpr }.traverseCtx[Any, T]($exprsList)($callback) }
}

}
Loading

0 comments on commit ebb5971

Please sign in to comment.