Disable automatic derivation by default
See original GitHub issue#304 was closed for an unrelated reason, however the issue remains.
(copied from https://github.com/pureconfig/pureconfig/issues/304#issuecomment-407960683).
Automatic derivation makes the field names etc. part of the API, which is not ideal. My team uses the explicit approach in similar cases (JSON codecs, etc.) - any encoding should be performed by an explicitly specified codec, and missing codec should cause a compilation error. Thus we need an option to disable automatic derivation entirely.
One way to achieve that (which is what circe
project does) would be to remove DerivedReaders
/DerivedWriters
from ConfigReader
/ConfigWriter
objects, and make them accessible through an explicit import of some package object. We can even move those to a separate module, getting rid of the shapeless
dependency in core
. This would make this library a lot more flexible, at the cost of adding an import to the existing code.
UPD: to clarify, this issue is about shapeless-powered derivation for arbitrary ADTs. Map
/Option
/TraversableOnce
typeclass instances should remain available by default.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:33 (16 by maintainers)
Top GitHub Comments
BTW, to add some numbers on this. In just our functional tests (15 files) of just one project, this bug is making us take 82s instead of 8s to compile.
I have monkey patched the
Derived*
classes to remove theimplicit
keyword, effectively disabling shapeless yet retaining binary compatibility.I am in the process of writing a magnolia based deriver for
ConfigReader
, to be semi-auto combined with@deriving
, that I expect to deliver a (max) 90% reduction in compiletime.I’m going to use this as an example in my book about why full auto (and especially shapeless) should never be enabled by default on a typeclass 😉
BTW, for the benefit of anybody who is wondering how I fixed this in my work codebase:
DerivedReaders.scala
from this repo into your projectimplicit def
withdef
andimplicit final
withfinal
everywhere in this file.orphans.scala
(note that I’ve removed superfluousLazy
andDerivation
wrappers. BTW, yourF
doesn’t need to extendTraversable
.)magnolia.scala
deriving.conf
inresources