Skip to content

Commit 0bc226d

Browse files
docs: update Scala 3 and derivation policy guidance
1 parent e48a37a commit 0bc226d

10 files changed

Lines changed: 53 additions & 40 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
passphrase: ${{ secrets.GPG_PASSPHRASE }}
2424
- uses: coursier/setup-action@v3.0.2
2525
with:
26-
# Chimney 2.x targets -release 17 (Scala 3) / -release 11 (Scala 2.13) and its Scala 3.8 compiler
26+
# Chimney 2.x targets -release 17 (Scala 3) / -release 11 (Scala 2.13) and its Scala 3.9 compiler
2727
# bridge is compiled for Java 17, so publishing must run on JDK 17+ (the old JDK 8 fails with
2828
# UnsupportedClassVersionError). The -release flags keep the emitted artifacts JDK 11/17 compatible.
2929
jvm: 'temurin:17'

.scala-steward.conf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# add try-chimney to defaults from https://github.com/scala-steward-org/scala-steward/blob/main/docs/repo-specific-configuration.md
22
updates.fileExtensions = [".mill-version",".sbt",".sbt.shared",".sc",".scala",".scalafmt.conf",".yml","build.properties","mill-version","pom.xml","try-chimney.sh"]
33

4-
# Per-artifact pins leak (Steward tracks binary-suffixed variants like scala3-library_sjs1_3),
5-
# so pin the whole group. Allows 3.9.x patch bumps; blocks cross-minor (3.9→3.10) and
6-
# Scala 2.13 bumps (2.13.x doesn't match the prefix, same effect as the old ignore).
7-
updates.pin = [
8-
{ groupId = "org.scala-lang", version = "3.9." }
4+
# Keep the Scala 3.9.0 and Scala 2.13 compiler/stdlib lines pinned and manage their updates manually.
5+
# Version pins are unreliable in a multi-version build because Steward can unify the two Scala lines,
6+
# while per-artifact ignores leak through binary-suffixed variants such as scala3-library_sjs1_3.
7+
# Ignoring the whole group reliably protects both supported compiler lines.
8+
updates.ignore = [
9+
{ groupId = "org.scala-lang" }
910
]
1011
pullRequests.grouping = [
1112
{ name="scala-versions", "title"="Scala compiler updates", "filter"=[{"group" = "org.scala-lang"}, {"group" = "org.scoverage"}] }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[![Scaladoc 2.13](https://javadoc.io/badge2/io.scalaland/chimney_2.13/scaladoc%202.13.svg)](https://javadoc.io/doc/io.scalaland/chimney_2.13)
1616
[![Scaladoc 3](https://javadoc.io/badge2/io.scalaland/chimney_3/scaladoc%203.svg)](https://javadoc.io/doc/io.scalaland/chimney_3)
1717

18-
The battle-tested Scala library for data transformations. Supported for (2.13, 3.8.4+) x (JVM, Scala.js, Scala Native).
18+
The battle-tested Scala library for data transformations. Supported for (2.13, 3.9.0+) x (JVM, Scala.js, Scala Native).
1919
On the JVM, Scala 2.13 artifacts require JDK 11+ and Scala 3 artifacts require JDK 17+. Powered by [Hearth](https://github.com/kubuszok/hearth).
2020

2121
Chimney documentation is available at https://chimney.readthedocs.io. Read the Docs keeps it versioned in case you need

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ lazy val chimneyCats = projectMatrix
458458
// Hearth StandardMacroExtension with IsCollection/IsMap providers for cats.data types (NonEmptyList, Chain, ...).
459459
// Test-scoped: it is consulted at MACRO-EXPANSION time of the TEST sources (ServiceLoader on the compile
460460
// classpath of the code being derived) - the specs prove cats collections derive WITHOUT chimney-cats implicits.
461-
// NOTE: kindlings' Scala 3 artifacts are built with Scala 3.8.x (TASTy 28.8) - loading them requires chimney to
462-
// build with Scala 3.8+ (older compilers throw "Forward incompatible TASTy file" from hearth's extension loading).
461+
// NOTE: kindlings' Scala 3 artifacts are built with Scala 3.9.x (TASTy 28.9) - loading them requires chimney to
462+
// build with Scala 3.9+ (older compilers throw "Forward incompatible TASTy file" from hearth's extension loading).
463463
// Since hearth#325 (0.4.1) an unloadable extension jar is SKIPPED gracefully instead of poisoning every derivation
464464
// in the module - but the specs here obviously still need the extension to actually load.
465465
libraryDependencies += "com.kubuszok" %% "kindlings-cats-integration" % versions.kindlingsCatsIntegration % Test

chimney-cats/src/test/scala/io/scalaland/chimney/cats/CatsDataSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import io.scalaland.chimney.utils.OptionUtils.*
2525
* - `NonEmptyMap`/`NonEmptySet` require `cats.Order` of the key/element to be summonable at MACRO-EXPANSION time
2626
* (1.x required `Ordering` at implicit-summoning time - same effective requirement, different mechanism).
2727
*
28-
* Kindlings' Scala 3 artifacts are built with Scala 3.8.x (TASTy 28.8) - readable now that chimney builds with Scala
29-
* 3.8.4+, so this spec is SHARED between both Scala versions.
28+
* Kindlings' Scala 3 artifacts are built with Scala 3.9.x (TASTy 28.9) - readable now that chimney builds with Scala
29+
* 3.9.0+, so this spec is SHARED between both Scala versions.
3030
*/
3131
class CatsDataSpec extends ChimneySpec {
3232

docs/docs/cheatsheet.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ This section is short summary of all Chimney features (described in more detail
6262
compilation time) and avoids unnecessary boxing with `partial.Result`.
6363

6464
Chimney 2.x no longer provides `io.scalaland.chimney.auto._`. Automatic derivation is provided from the type-class
65-
companions, while `syntax._` and `inlined._` let you choose which extension methods to import.
65+
companions, while `syntax._` and `inlined._` let you choose which extension methods to import. Use the
66+
[derivation policy](cookbook.md#derivation-policy-restricting-where-derivation-may-happen) to restrict structural
67+
derivation to designated scopes.
6668

6769
!!! example "Partial Results"
6870

docs/docs/cookbook.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,9 @@ are described in each type's section.
751751
had a bad experience (long compilation times, poor performance) with the automatic derivation, please note that
752752
Chimney derivation DOES NOT work the same way, so your experiences are unlikely to carry over to Chimney.
753753

754-
Please, read the section below, as it will explain why replacing `import io.scalaland.chimney.dsl._` with
755-
`Transformer.derive` + `import io.scalaland.chimney.syntax._` + `import io.scalaland.chimney.auto._` (the last one only available on 1.x line)
756-
might actually *degrade* the performance, instead of improving it.
754+
Please read the section below: it explains why Chimney's automatic derivation does not have the usual performance
755+
problem. On Chimney 2.x, `io.scalaland.chimney.auto._` no longer exists; if you need to restrict where automatic
756+
derivation may happen, use the [derivation policy](#derivation-policy-restricting-where-derivation-may-happen).
757757

758758
In depth explanation why automatic derivation is slow (when it's slow!) and how Chimney avoided such slowdown can be
759759
found in [*Slow-Auto, Inconvenient-Semi: escaping false dichotomy with sanely-automatic derivation*](https://mateuszkubuszok.github.io/SlowAutoInconvenientSemi/)
@@ -819,26 +819,27 @@ The last property is a reason many projects encourage the usage of semiautomatic
819819
and many libraries provide automatic derivation as a quick and dirty way of doing things
820820
requiring an opt-in.
821821

822-
Chimney's defaults for (good) historical reasons mix these 2 modes (and one more, which
823-
will describe in a moment), but (_due to popular demand_) it also allows you to selectively
824-
use these imports
822+
On the 1.x line, Chimney's defaults mixed these two modes (and one more, described below), but also allowed users to
823+
compose these imports selectively:
825824

826825
!!! example
827826

828827
```scala
829-
import io.scalaland.chimney.auto._ // Not available on Chimney 2.+, see below
828+
import io.scalaland.chimney.auto._ // 1.x only
830829
import io.scalaland.chimney.inlined._
831830
import io.scalaland.chimney.syntax._
832831
```
833832

834-
instead of `io.scalaland.chimney.dsl` to achieve a similar behavior:
833+
instead of `io.scalaland.chimney.dsl` to achieve a similar behavior. On 2.x, `syntax._` and `inlined._` remain
834+
available, while automatic derivation is provided directly by the `Transformer`, `PartialTransformer`, and `Patcher`
835+
companions:
835836

836837
- if you `import io.scalaland.chimney.syntax._` it will expose only extension
837838
methods working with type classes (`Transformer`, `PartialTransformer` and `Patcher`),
838839
but with no derivation
839840

840-
- if you `import io.scalaland.chimney.auto._` it will only provide implicit instances
841-
generated through derivation.
841+
- on 1.x, `import io.scalaland.chimney.auto._` provided implicit instances generated through derivation. This
842+
separate import does not exist on 2.x.
842843

843844
Semiautomatic derivation was available for a long time using methods:
844845

@@ -955,9 +956,8 @@ or there is none and macro will handle recursion internally.
955956
This also allows to replace a bunch of anonymous instances calling one another with a single
956957
instance - limitting the number of allocations and improving performance.
957958

958-
However, with `import io.scalaland.chimney.auto._` the same semantics as in other
959-
libraries is used: `implicit def` returns `Transformer`, so if derivation with defaults
960-
is possible it will always be triggered.
959+
Prior to 2.0.0, `import io.scalaland.chimney.auto._` used the same semantics as automatic derivation in other
960+
libraries: an `implicit def` returned a `Transformer`, so derivation with defaults was triggered whenever possible.
961961

962962
!!! important
963963

@@ -983,7 +983,7 @@ is possible it will always be triggered.
983983
```scala
984984
trait TypeClass[A]
985985
object TypeClass {
986-
inline given derived[A]: AutoDerived[A] =
986+
inline given derived[A]: TypeClass[A] =
987987
${ macroUsingSimmonIgnoring[A] }
988988
// Inside it uses:
989989
// Expr.summonIgnoring[TypeClass[A]](
@@ -994,7 +994,7 @@ is possible it will always be triggered.
994994
extension [A](value: A) def foo(using TypeClass[A]) = ...
995995
```
996996

997-
For that reason `import io.scalaland.chimney.auto._` does not exists on Chimney 2.0.0 for Scala 3.
997+
For that reason `import io.scalaland.chimney.auto._` does not exist on Chimney 2.0.0 for Scala 3.
998998

999999
And thanks to porting the solution from Scala 3.7.0 to 2.13.17, Scala 2.13 could have align the API
10001000
again - removing `import io.scalaland.chimney.auto._` as well in the process. (The other consequence
@@ -1008,7 +1008,7 @@ provide `implicitConflictResolution` flag.
10081008

10091009
!!! note
10101010

1011-
In other words, replicating the setup where you do:
1011+
In other words, on Chimney 1.x, replicating the setup where you do:
10121012

10131013
```scala
10141014
implicit val transformer: Transformer[From, To] = locally {
@@ -1030,11 +1030,10 @@ provide `implicitConflictResolution` flag.
10301030

10311031
For the reasons above the recommendations are as follows:
10321032

1033-
- if you care about performance, use either inlined derivation (`.into.transform`, for a one-time-usage) or
1034-
semi-automatic derivation with recursion handled in the macro(`.derive`/`.define.build*` + `syntax._`, without
1035-
importing `auto._`)
1036-
- only use `import auto._` when you want predictable behavior similar to other libraries
1037-
(predictably bad)
1033+
- if you care about performance, use either inlined derivation (`.into.transform`, for a one-time usage) or
1034+
semiautomatic derivation with recursion handled in the macro (`.derive`/`.define.build*` + `syntax._`)
1035+
- on Chimney 2.x, use the [derivation policy](#derivation-policy-restricting-where-derivation-may-happen) when you
1036+
need to prevent ad-hoc structural derivation outside designated scopes
10381037
- use unit tests to ensure, that your code does what it should do
10391038
- use benchmarks to ensure it is reasonably fast
10401039
- and keep on using `import dsl._` until you have some good proof that (recursive) semi-automatic derivation is needed
@@ -1051,6 +1050,10 @@ canonical mapping is defined in one designated place rather than materialized ad
10511050
**derivation policy** provides this without a separate semi-automatic API: it is a compile-time switch configured
10521051
entirely through `-Xmacro-settings`.
10531052

1053+
On Chimney 2.x this is the replacement for controlling automatic derivation through selective
1054+
`import io.scalaland.chimney.auto._` imports. The `auto` package no longer exists; derivation is available through the
1055+
unified type classes, and this policy decides where their macros may generate new structural transformations.
1056+
10541057
The policy gates only **structural derivation** — generating new transformation code for a `case class` or a `sealed`
10551058
hierarchy / `enum`. Everything else keeps working unconditionally: pre-existing implicits (your hand-written
10561059
`Transformer`s), subtype upcasts, options, eithers, collections, value classes.
@@ -1549,8 +1552,9 @@ With it on the classpath you can:
15491552
!!! warning "Scala 3 status"
15501553

15511554
A macro extension must be **loadable by the compiler that expands the macro**, so its TASTy version matters:
1552-
`kindlings-cats-integration` `{{ libraries.kindlings }}`'s Scala 3 artifacts are built with Scala 3.8, which is
1553-
why Chimney `2.0.0` itself is built with Scala 3.8.4+ - the integration works on **both** Scala 2.13 and Scala 3.
1555+
`kindlings-cats-integration` `{{ libraries.kindlings }}`'s Scala 3 artifacts are built with Scala 3.9.0, which is
1556+
why Chimney `2.0.0` itself is built with Scala 3.9.0 (TASTy 28.9) - the integration works on **both** Scala 2.13
1557+
and Scala 3.
15541558

15551559
!!! example "Converting from Cats collections"
15561560

docs/docs/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Quick Start
22

3-
Chimney is supported for Scala **2.13**, **3.8.4+** on [**JVM**](https://www.scala-lang.org/),
3+
Chimney is supported for Scala **2.13**, **3.9.0+** on [**JVM**](https://www.scala-lang.org/),
44
[**Scala.js**](https://www.scala-js.org/) and [**Scala Native**](https://scala-native.org/) with full feature parity
55
between each version.
66

docs/docs/troubleshooting.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ If you:
4444

4545
Scala 2.12 support was dropped, so if you want to migrate to 2.x, we recommend migrating to 1.x before.
4646

47-
On Scala 3 the minimal supported compiler version was raised from 3.3 (LTS) to **3.8.4** - the artifacts are built
48-
with Scala 3.8.4 (TASTy 28.8), so older Scala 3 compilers cannot consume them.
47+
On Scala 3 the minimum supported compiler version was raised from 3.3 (LTS) to **3.9.0** - the artifacts are built
48+
with Scala 3.9.0 (TASTy 28.9), so older Scala 3 compilers cannot consume them.
4949

5050
On the JVM, JDK requirements were raised: Scala 2.13 artifacts require **JDK 11+** and Scala 3 artifacts require
5151
**JDK 17+** (Chimney's macros are built on top of [Hearth](https://scala-hearth.readthedocs.io/), which is JDK 11+).
@@ -56,7 +56,13 @@ Chimney 2.0.0 no longer requires distinction between:
5656
- `PartialTransformer` and `PartialTransformer.AutoDerived`
5757
- `Patcher` and `Patcher.AutoDerived`
5858

59-
to make migration easier, `AutoDerived` still exist but as a type alias.
59+
To make migration easier, the `AutoDerived` names still exist as type aliases.
60+
61+
The separate `import io.scalaland.chimney.auto._` was also removed. Automatic derivation is now provided by the same
62+
`Transformer`, `PartialTransformer`, and `Patcher` types used for explicitly defined instances. If you previously
63+
controlled automatic derivation by importing `auto._` only in selected scopes, configure the
64+
[derivation policy](cookbook.md#derivation-policy-restricting-where-derivation-may-happen) instead. It can allow
65+
structural derivation only in designated packages, objects, or classes, with an optional local opt-in import.
6066

6167
Breaking changes in API:
6268

scripts/test-snippets.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//> using scala 3.3.8
1+
//> using scala 3.9.0
22
//> using dep com.kubuszok::scala-cli-md-spec:0.2.1
33
//> using dep org.virtuslab::scala-yaml:0.3.3
44

0 commit comments

Comments
 (0)