Skip to content
Open
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.10.1
28caa87ed17db338c17593cf340864cbc9bfb6ef
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ fileOverride {

style = defaultWithAlign
maxColumn = 120
version = 3.5.9
version = 3.10.1
2 changes: 1 addition & 1 deletion benchmark/build.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
enablePlugins(JmhPlugin)
enablePlugins(JmhPlugin)
2 changes: 1 addition & 1 deletion macros/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publishTo := sonatypePublishToBundle.value
licenses := Seq("APL2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt"))

homepage := Some(url("https://github.com/metarank/cfor"))
scmInfo := Some(
scmInfo := Some(
ScmInfo(
url("https://github.com/metarank/cfor"),
"scm:git@github.com:metarank/cfor.git"
Expand Down
6 changes: 3 additions & 3 deletions macros/src/main/scala-2/io/github/metarank/cfor/Syntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class InlineUtil[C <: Context with Singleton](val c: C) {
}

case tt: TypeTree if tt.original != null =>
//super.transform(TypeTree().setOriginal(transform(tt.original)))
// super.transform(TypeTree().setOriginal(transform(tt.original)))
super.transform(setOrig(c)(TypeTree(), transform(tt.original)))
case _ =>
super.transform(tree)
Expand Down Expand Up @@ -216,7 +216,7 @@ object Syntax {
isLiteral(step) match {
case Some(k) if k > 0 => strideUpUntil(i, j, k)
case Some(k) if k < 0 => strideDownUntil(i, j, -k)
case Some(k) =>
case Some(k) =>
c.error(c.enclosingPosition, "zero stride")
q"()"
case None =>
Expand All @@ -228,7 +228,7 @@ object Syntax {
isLiteral(step) match {
case Some(k) if k > 0 => strideUpTo(i, j, k)
case Some(k) if k < 0 => strideDownTo(i, j, -k)
case Some(k) =>
case Some(k) =>
c.error(c.enclosingPosition, "zero stride")
q"()"
case None =>
Expand Down
21 changes: 9 additions & 12 deletions macros/src/main/scala-3/io/github/metarank/cfor/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.collection.immutable.NumericRange
type RangeLike = Range | NumericRange[Long]

type RangeElem[X <: RangeLike] = X match
case Range => Int
case Range => Int
case NumericRange[Long] => Long

inline def cfor[A](inline init: A)(inline test: A => Boolean, inline next: A => A)(inline body: A => Unit): Unit =
Expand All @@ -17,7 +17,6 @@ inline def cfor[A](inline array: Array[A])(body: A => Unit): Unit =
inline def cfor[R <: RangeLike](inline r: R)(inline body: RangeElem[R] => Unit): Unit =
${ cforRangeMacroGen('r, 'body) }


//--------------------------------------------------------------------------
//
// Code from below are based on file
Expand Down Expand Up @@ -46,7 +45,7 @@ import scala.PartialFunction.cond
import scala.quoted.*

private def cforImpl[R: Type](init: Expr[R], test: Expr[R => Boolean], next: Expr[R => R], body: Expr[R => Unit])(using
Quotes
Quotes
): Expr[Unit] =
import quotes.reflect.*

Expand All @@ -61,7 +60,7 @@ private def cforImpl[R: Type](init: Expr[R], test: Expr[R => Boolean], next: Exp
end cforImpl

private def cforRangeMacroGen[R <: RangeLike: Type](r: Expr[R], body: Expr[RangeElem[R] => Unit])(using
quotes: Quotes
quotes: Quotes
): Expr[Unit] =
import quotes.reflect.*

Expand Down Expand Up @@ -139,14 +138,12 @@ private object RangeForImpl:

end RangeForImpl


/**
* Equivalent to `'{ val name: A => B = $rhs; ${in('name)} }`, except when `rhs` is a function literal, then equivalent
* to `in(rhs)`.
*
* This allows inlined function arguments to perform side-effects only once before their first evaluation, while still
* avoiding the creation of closures for function literal arguments.
*/
/** Equivalent to `'{ val name: A => B = $rhs; ${in('name)} }`, except when `rhs` is a function literal, then equivalent
* to `in(rhs)`.
*
* This allows inlined function arguments to perform side-effects only once before their first evaluation, while still
* avoiding the creation of closures for function literal arguments.
*/
private def letFunc[A, B, C](using Quotes)(name: String, rhs: Expr[A => B])(in: Expr[A => B] => Expr[C]): Expr[C] =
import quotes.reflect.*

Expand Down
10 changes: 5 additions & 5 deletions macros/src/test/scala/io/github/metarank/cfor/CforTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class CforTest extends AnyFlatSpec with Matchers {
}

it should "functions with side effects function values in cfor" in {
val b = mutable.ArrayBuffer.empty[Int]
var v = 0
val b = mutable.ArrayBuffer.empty[Int]
var v = 0
def test: Int => Boolean = { v += 1; _ < 3 }
def incr: Int => Int = { v += 10; _ + 1 }
def body: Int => Unit = {
def incr: Int => Int = { v += 10; _ + 1 }
def body: Int => Unit = {
v += 100
x => {
b += x
Expand Down Expand Up @@ -144,7 +144,7 @@ class CforTest extends AnyFlatSpec with Matchers {

it should "functions with side effects in cfor(arr)" in {
var sum = 0
var v = 0
var v = 0
val arr = Array(0, 1, 2, 3, 4)
cfor(arr) {
v += 100
Expand Down
Loading