Skip to content

Commit

Permalink
Update scalafmt-core to 3.8.1 (#1189)
Browse files Browse the repository at this point in the history
* Update scalafmt-core to 3.8.1

* Reformat with scalafmt 3.8.1

Executed command: scalafmt --non-interactive

* Add 'Reformat with scalafmt 3.8.1' to .git-blame-ignore-revs
  • Loading branch information
scala-steward authored Mar 30, 2024
1 parent 18efb84 commit c91e397
Show file tree
Hide file tree
Showing 28 changed files with 255 additions and 191 deletions.
4 changes: 3 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
5d76a9ad664aa4f4b63d8a7c92d678d73f8e6516
5d76a9ad664aa4f4b63d8a7c92d678d73f8e6516
# Scala Steward: Reformat with scalafmt 3.8.1
5e945c5ea79bb8c78eded88c66bcfc5d846e2c61
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.0"
version = "3.8.1"

rewrite.rules = [RedundantBraces, SortModifiers, Imports]
rewrite.redundantBraces.generalExpressions = false
Expand Down
3 changes: 2 additions & 1 deletion cli/src/test/scala/org/bykn/bosatsu/PathModuleTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class PathModuleTest extends AnyFunSuite {

test("test direct run of a file") {
val deps = List("Nat", "List", "Bool", "Rand", "Properties", "BinNat")
val inputs = deps.map { n => s"--input test_workspace/${n}.bosatsu"}.mkString(" ")
val inputs =
deps.map(n => s"--input test_workspace/${n}.bosatsu").mkString(" ")
val out = run(
s"test $inputs --test_file test_workspace/Queue.bosatsu"
.split("\\s+")
Expand Down
12 changes: 5 additions & 7 deletions core/src/main/scala/org/bykn/bosatsu/Declaration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,8 @@ object Declaration {
val withIndent = Parser.newline *> Parser.spaces.string.flatMap {
indent => recIndy(indent)
}
maybeSpace.with1 *> (withIndent | noIndent).map { d =>
(r: Region) => Parens(d)(r)
maybeSpace.with1 *> (withIndent | noIndent).map { d => (r: Region) =>
Parens(d)(r)
} <* maybeSpacesAndLines
}

Expand Down Expand Up @@ -1432,8 +1432,8 @@ object Declaration {
}

def repFn[A](fn: P[A => A]): P0[A => A] =
fn.rep0.map { opList =>
(a: A) => opList.foldLeft(a)((arg, fn) => fn(arg))
fn.rep0.map { opList => (a: A) =>
opList.foldLeft(a)((arg, fn) => fn(arg))
}

(allNonBind ~ repFn(dotApply.orElse(applySuffix)))
Expand Down Expand Up @@ -1497,9 +1497,7 @@ object Declaration {
.infixOps1(nb))

// This already parses as many as it can, so we don't need repFn
val form = ops.map { fn =>
(d: NonBinding) => convert(fn(d))
}
val form = ops.map(fn => (d: NonBinding) => convert(fn(d)))

nb.maybeAp(form)
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/org/bykn/bosatsu/DefRecursionCheck.scala
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ object DefRecursionCheck {
val fna: E[State => E[(State, A)]] = fa.runF
val fnb: E[State => E[(State, B)]] = fb.runF

new cats.data.IndexedStateT((fna, fnb).parMapN { (fn1, fn2) =>
(state: State) =>
new cats.data.IndexedStateT((fna, fnb).parMapN {
(fn1, fn2) => (state: State) =>
fn1(state) match {
case Right((s2, a)) =>
fn2(s2).map { case (st, b) => (st, (a, b)) }
Expand Down
4 changes: 1 addition & 3 deletions core/src/main/scala/org/bykn/bosatsu/ListLang.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ object ListLang {
P.string("in") *> spacesAndLines *> pa <* maybeSpacesAndLines,
filterExpr.?
)
.mapN { (b, i, f) =>
(e: F[A]) => Comprehension(e, b, i, f)
}
.mapN((b, i, f) => (e: F[A]) => Comprehension(e, b, i, f))

val commaCons = P.char(',') *> maybeSpacesAndLines *> consTail
val inner = commaCons.orElse(spacesAndLines.soft *> commaCons.orElse(comp))
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/org/bykn/bosatsu/ListUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private[bosatsu] object ListUtil {
// since a :: tailnel will have to allocate twice vs 1 time.
def revCons(item: ::[A], tail: List[A]): NonEmptyList[A] =
item.tail match {
case nel: ::[A] => revCons(nel, item.head :: tail)
case nel: ::[A] => revCons(nel, item.head :: tail)
case _: Nil.type => NonEmptyList(item.head, tail)
}
@annotation.tailrec
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/scala/org/bykn/bosatsu/Operators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ object Operators {
val chain: P[NonEmptyList[(String, A)]] =
P.repSep(opA, min = 1, sep = Parser.maybeSpace)

chain.map { rest =>
(a: A) =>
toFormula(Sym(a), rest.toList.map { case (o, s) => (o, Sym(s)) })
chain.map { rest => (a: A) =>
toFormula(Sym(a), rest.toList.map { case (o, s) => (o, Sym(s)) })
}
}

Expand Down
23 changes: 10 additions & 13 deletions core/src/main/scala/org/bykn/bosatsu/Package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,14 @@ object Package {
Doc.intercalate(Doc.empty, p :: i :: e :: b)
}


def headerParser(defaultPack: Option[PackageName]): P0[Header] = {
val spaceComment: P0[Unit] =
(Parser.spaces.? ~ CommentStatement.commentPart.?).void

val eol = spaceComment <* Parser.termination
val parsePack = Padding
.parser(
(P.string("package")
.soft ~ spaces) *> PackageName.parser <* eol,
(P.string("package").soft ~ spaces) *> PackageName.parser <* eol,
spaceComment
)
.map(_.padded)
Expand All @@ -209,7 +207,8 @@ object Package {
case Some(p) => parsePack.?.map(_.getOrElse(p))
}

val im = Padding.parser(Import.parser <* eol, spaceComment).map(_.padded).rep0
val im =
Padding.parser(Import.parser <* eol, spaceComment).map(_.padded).rep0
val ex = Padding
.parser(
(P.string("export")
Expand Down Expand Up @@ -260,7 +259,8 @@ object Package {
val optProg = SourceConverter
.toProgram(p, imps.map(i => i.copy(pack = i.pack.name)), stmts)
.leftMap { scerrs =>
scerrs.groupByNem(_.region)
scerrs
.groupByNem(_.region)
.transform { (region, errs) =>
val uniqs = ListUtil.distinctByHashSet(errs.toNonEmptyList)
PackageError.SourceConverterErrorsIn(region, uniqs, p): PackageError
Expand Down Expand Up @@ -292,8 +292,7 @@ object Package {
necError
.map(PackageError.KindInferenceError(p, _, typeDefRegions))
.toNonEmptyList,
infDTs =>
ParsedTypeEnv(infDTs, parsedTypeEnv.externalDefs)
infDTs => ParsedTypeEnv(infDTs, parsedTypeEnv.externalDefs)
)

inferVarianceParsed.flatMap { parsedTypeEnv =>
Expand Down Expand Up @@ -342,13 +341,11 @@ object Package {
}

val theseExternals =
parsedTypeEnv
.externalDefs
.collect { case (pack, b, t) if pack === p =>
parsedTypeEnv.externalDefs.collect {
case (pack, b, t) if pack === p =>
// by construction this has to have all the regions
(b, (t, extDefRegions(b)))
}
.toMap
(b, (t, extDefRegions(b)))
}.toMap

val inferenceEither = Infer
.typeCheckLets(p, lets, theseExternals)
Expand Down
53 changes: 34 additions & 19 deletions core/src/main/scala/org/bykn/bosatsu/PackageCustoms.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ object PackageCustoms {
private type VSet = Set[(PackageName, Identifier)]
private type VState[X] = State[VSet, X]

private def usedGlobals[A](pack: Package.Typed[A]): Set[(PackageName, Identifier)] = {
private def usedGlobals[A](
pack: Package.Typed[A]
): Set[(PackageName, Identifier)] = {
val usedValuesSt: VState[Unit] =
pack.program.lets.traverse_ { case (_, _, te) => TypedExpr.usedGlobals(te) }
pack.program.lets.traverse_ { case (_, _, te) =>
TypedExpr.usedGlobals(te)
}

usedValuesSt.runS(Set.empty).value
}
Expand Down Expand Up @@ -209,7 +213,9 @@ object PackageCustoms {
}
}

private def noUselessBinds[A: HasRegion](pack: Package.Typed[A]): ValidatedNec[PackageError, Unit] = {
private def noUselessBinds[A: HasRegion](
pack: Package.Typed[A]
): ValidatedNec[PackageError, Unit] = {
type Node = Either[pack.exports.type, Bindable]
implicit val ordNode: Ordering[Node] =
new Ordering[Node] {
Expand All @@ -221,9 +227,9 @@ object PackageCustoms {
case Right(by) =>
Ordering[Identifier].compare(bx, by)
}
case Left(_) =>
case Left(_) =>
y match {
case Left(_) => 0
case Left(_) => 0
case Right(_) => -1
}
}
Expand All @@ -233,8 +239,11 @@ object PackageCustoms {
val roots: List[Node] =
(exports ::
Package.testValue(pack).map { case (b, _, _) => Right(b) }.toList :::
Package.mainValue(pack).map { case (b, _, _) => Right(b) }.toList).distinct

Package
.mainValue(pack)
.map { case (b, _, _) => Right(b) }
.toList).distinct

val bindMap: Map[Bindable, TypedExpr[A]] =
pack.program.lets.iterator.map { case (b, _, te) => (b, te) }.toMap

Expand All @@ -245,28 +254,34 @@ object PackageCustoms {

def depsOf(n: Node): Iterable[Node] =
n match {
case Left(_) => pack.exports.flatMap {
case ExportedName.Binding(n, _) => Right(n) :: Nil
case _ => Nil
}
case Left(_) =>
pack.exports.flatMap {
case ExportedName.Binding(n, _) => Right(n) :: Nil
case _ => Nil
}
case Right(value) =>
bindMap.get(value) match {
case None => Nil
case None => Nil
case Some(te) => internalDeps(te).map(Right(_))
}
}
val canReach: SortedSet[Node] = Dag.transitiveSet(roots)(depsOf _)

val unused = pack.program.lets.filter {
case (bn, _, _) => !canReach.contains(Right(bn))
val unused = pack.program.lets.filter { case (bn, _, _) =>
!canReach.contains(Right(bn))
}

NonEmptyList.fromList(unused) match {
case None => Validated.unit
case Some(value) =>
Validated.invalidNec(PackageError.UnusedLets(pack.name, value.map { case (b, r, te) =>
(b, r, te, HasRegion.region(te))
}))
case Some(value) =>
Validated.invalidNec(
PackageError.UnusedLets(
pack.name,
value.map { case (b, r, te) =>
(b, r, te, HasRegion.region(te))
}
)
)
}
}
}
}
44 changes: 27 additions & 17 deletions core/src/main/scala/org/bykn/bosatsu/PackageError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -594,41 +594,49 @@ object PackageError {

val (missing, notMissing) = errs.toList.partitionMap {
case ma: SourceConverter.MissingArg => Left(ma)
case notMa => Right(notMa)
case notMa => Right(notMa)
}
val mdocs = missing.groupBy { ma => (ma.name, ma.syntax) }
val mdocs = missing
.groupBy(ma => (ma.name, ma.syntax))
.toList
.sortBy { case ((name, _), _) => name }
.map { case ((_, syn), mas) =>
val allMissing = mas.map(_.missing)
val allMissing = mas.map(_.missing)

val missingDoc = Doc.intercalate(Doc.comma + Doc.space,
allMissing.sorted.map { m => Doc.text(m.asString) })
val missingDoc = Doc.intercalate(
Doc.comma + Doc.space,
allMissing.sorted.map(m => Doc.text(m.asString))
)

val fieldStr = if (allMissing.lengthCompare(1) == 0) "field" else "fields"
val fieldStr =
if (allMissing.lengthCompare(1) == 0) "field" else "fields"

val hint =
syn match {
case SourceConverter.ConstructorSyntax.Pat(_) =>
Doc.line + Doc.text("if you want to ignore those fields, add a ... to signify ignoring missing.")
Doc.line + Doc.text(
"if you want to ignore those fields, add a ... to signify ignoring missing."
)
case _ =>
// we can't ignore fields when constructing
Doc.empty
}
(Doc.text(s"missing $fieldStr: ") + missingDoc + Doc.line + Doc.text("in") +
Doc.line + syn.toDoc + hint
).nested(4)
(Doc.text(s"missing $fieldStr: ") + missingDoc + Doc.line + Doc.text(
"in"
) +
Doc.line + syn.toDoc + hint).nested(4)
}

val mdoc = Doc.intercalate(Doc.hardLine, mdocs)
val notMDoc = Doc.intercalate(Doc.hardLine, notMissing.map { se => Doc.text(se.message) })
val notMDoc = Doc.intercalate(
Doc.hardLine,
notMissing.map(se => Doc.text(se.message))
)
val msg = if (missing.nonEmpty) {
if (notMissing.nonEmpty) {
mdoc + Doc.hardLine + notMDoc
}
else mdoc
}
else {
} else mdoc
} else {
notMDoc
}

Expand Down Expand Up @@ -903,15 +911,17 @@ object PackageError {

case class UnusedLets(
inPack: PackageName,
unusedLets: NonEmptyList[(Identifier.Bindable, RecursionKind, TypedExpr[Any], Region)]
unusedLets: NonEmptyList[
(Identifier.Bindable, RecursionKind, TypedExpr[Any], Region)
]
) extends PackageError {
def message(
sourceMap: Map[PackageName, (LocationMap, String)],
errColor: Colorize
) =
UnusedLetError(
inPack,
unusedLets.map { case (b, _, _, r) => (b, r)}
unusedLets.map { case (b, _, _, r) => (b, r) }
).message(sourceMap, errColor)
}
}
12 changes: 3 additions & 9 deletions core/src/main/scala/org/bykn/bosatsu/Pattern.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1211,9 +1211,7 @@ object Pattern {
((maybeSpace.with1 *> P.string(
"as"
) <* Parser.spaces).backtrack *> Identifier.bindableParser)
.map { n =>
(pat: Parsed) => Named(n, pat)
}
.map(n => (pat: Parsed) => Named(n, pat))

val withAs: P[Parsed] =
(nonAnnotated ~ namedOp.rep0)
Expand All @@ -1226,15 +1224,11 @@ object Pattern {
.nonEmptyListOfWsSep(maybeSpace, bar, allowTrailing = false)

(maybeSpace.with1.soft *> bar *> maybeSpace *> unionRest)
.map { ne =>
(pat: Parsed) => union(pat, ne.toList)
}
.map(ne => (pat: Parsed) => union(pat, ne.toList))
}
val typeAnnotOp: P[Parsed => Parsed] =
TypeRef.annotationParser
.map { tpe =>
(pat: Parsed) => Annotation(pat, tpe)
}
.map(tpe => (pat: Parsed) => Annotation(pat, tpe))

// We only allow type annotation not at the top level, must be inside
// Struct or parens
Expand Down
Loading

0 comments on commit c91e397

Please sign in to comment.