Comments (23)
I am having issues with this too. Could a safecopy dev please take a look? Thanks a lot!
from safecopy.
Same problem here.
from safecopy.
So I ended up doing an acid-state migration on an older GHC version to a setup where I call the TH function deriveSafeCopy
for every newtype
. This works but is unfortunately not as clean.
from safecopy.
The acid-state example in The Happstack Book and some of the acid-state repository examples don't compile with GHC-7.8.3. The error messages say coercion is impossible because Data.SafeCopy.SafeCopy.Kind is nominal while two arguments differ. Simon Peyton-Jones explains what changed with the GHC-7.8.x in a video presentation at "https://skillsmatter.com/skillscasts/5296-safe-zero-cost-coercions-in-haskell".
The compiler messages says"Possible fix: use a standalone 'deriving instance' declaration . . ." Has anyone had any success implementing this suggestion? I wanted to use acid-state but the example code doesn't compile with the new GHC and I don't want to use GHC 7.x because the problem is not a bug in GHC-7.8.3; the problem stems from a bug having been fixed (see the Jones presentation). How are people dealing with this situation? Is the solution so trivial that nobody has bothered to mention it here? Are people removing "newtype" from their code, or using "unsafeCoerce", or what?
from safecopy.
@dschalk As I mentioned in my last comment I've been using the Template Haskell functions instead, so I still create newtype
wrappers but then instead call deriveSafeCopy
on the types. See this commit for a minor example.
from safecopy.
Thanks. This works for me too.
from safecopy.
The problem with this seems to be that it changes the serialization in an incompatible way. At least I can't load the on-disk state anymore after this change, and it's not clear how to write a migration path for that as the old code does not compile anymore.
from safecopy.
I solved it too now by migrating with an older version of GHC, and then removing the old types to make it compile again with newer GHC.
Maybe the docs should have at least a warning about using GeneralizedNewtypeDeriving, and the examples should stop using it.
from safecopy.
@dschalk @tazjin I'm a bit confused. WIll switching to standalone deriving not work? I've got a lot of code that used GND and I'm trying to figure out if i should use standalone instance or TH without having to go through a major migration headache.
from safecopy.
@MichaelXavier during my testing standalone deriving did not work for all instances, and for those it did it changed the representation somehow to make a migration necessary nonetheless. In the end I just used deriveSafeCopy for every type and migrated them all to that then.
from safecopy.
@sdroege since "migrated" is an overloaded term in this context I want to clarify: using standalone instances created in some cases byte-incompatible safecopy whereas code that was previously using GND that you changed to deriveSafeCopy always produced byte-compatible safecopy?
from safecopy.
@MichaelXavier No, sorry. Both deriveSafeCopy and standalone instances created byte-incompatible instances, but standalone instances did not work for all types for me (got compiler errors for some). So I settled with using deriveSafeCopy for everything and migrated the old GND instances to the new byte-incompatible deriveSafeCopy instances.
from safecopy.
Jeeze. We could really use some comment from the package authors. This can cause a whole lot of damage. I'm in the process of adding safecopy tests to all of my projects that use it and I guess hand-writing dozens of safecopy instances.
from safecopy.
Would really love to hear comments from the package authors on this. This is holding up our migration of a large code base from 7.6 to 7.8. We have dozens of newtypes with GND and it would be a major headache to manually migrate them. Even if we put in the work, what's even scarier is the potential for mistakes and data corruption in production.
from safecopy.
I'm not sure what kind of comment you want. Either someone writes a bit of TH code to mimic GND or you'll have to write the instances by hand. It sucks that you can no longer use GND but it's not the end of the world.
from safecopy.
Can the library provide a migration path for this? Thankfully 7.8 raises a compile time error when this is encountered, so the user has to stop and think. It would be much better if the docs for this library had a section on this and provided a function that mimicked the GND. The alternative is the user guesses the right thing to do (standalone instance derive according to GHC's suggestion) and breaks safecopy on all their newtypes silently.
from safecopy.
Yes, I would like that very much. Since several people (including you) are affected by this, surely we won't have to wait too long for a pull request. :)
from safecopy.
I quite interested in when standalone deriving isn't the same as ordinary deriving. It would be helpful if @ozataman added a test case.
Edit: Oops, meant @sdroege, not @ozataman.
from safecopy.
@ozataman and I work together. Part of our upgrade involves getting a test suite around safecopy instances to test this. We haven't had the time yet to get back to that project the last week or so. @sdroege since you have experienced this incompatibility firsthand, do you think you could produce an example of standalone producing different output? Maybe its confined to certain types that were GNDed.
from safecopy.
See this commit for the case where it broke for me (just a little toy project in case someone is wondering):
sdroege/duckduckbot@d5a2f79
deriveSafeCopy worked on both but broke the serialization format, standalone deriving caused a compiler error (with ghc 7.8.3)
I won't have time to look into this in the next days, so if it's urgent for anybody please take those information and try to reproduce it. Otherwise I'll try to have some time for this in the following weeks.
from safecopy.
That is expected. The TH code is very different from GND. The interesting case is when standalone deriving is different from ordinary deriving.
from safecopy.
Sure, the problem for me was more that standalone deriving did not compile at all
from safecopy.
@lemmih I've finally gotten back to this and I can confirm in my case that standalone deriving produces the exact same error:
Could not coerce from ‘Kind Text’ to ‘Kind TextWrapper’
because the first type argument of ‘Kind’ has role Nominal,
but the arguments ‘Text’ and ‘TextWrapper’ differ
arising from a use of ‘GHC.Prim.coerce’
In the expression: GHC.Prim.coerce (kind :: Kind Text) :: Kind TextWrapper
In an equation for ‘kind’:
kind = GHC.Prim.coerce (kind :: Kind Text) :: Kind TextWrapper
When typechecking the code for ‘kind’
in a standalone derived instance for ‘SafeCopy TextWrapper’:
To see the code I am typechecking, use -ddump-deriv
In the instance declaration for ‘SafeCopy TextWrapper’
I've been playing around with some ways to generically implement these safecopy instances to delegate to the wrapped type's implementation but because Contained does not export anything and is not a Functor, I can't see a way I could wrap the existing implementation. Instead I have to look up the implementation and then re-implement, inserting the newtype Constructor as needed.
from safecopy.
Related Issues (20)
- Can't migrate when you have 2 consecutive fields of the same type and then one of them changes type HOT 2
- Loose time package constraint HOT 1
- Test suite failure with time-1.6.0.1 (duplicate instances) HOT 1
- Unnecessary constraint in generated SafeCopy instance HOT 3
- extended_extension comment is actually the extended_base comment
- s/unkown/unknown/ HOT 1
- Cannot build on ghc 8.2 HOT 1
- template-haskell constraint for ghc-8.4.1 HOT 2
- Better error messages
- errorTypeName method has sensible default implementation HOT 1
- incompatible with GHC 8.6 HOT 4
- safecopy added dependency on generic-data which is only GHC >= 8.0 HOT 6
- Fix compilation with template-haskell-2.15 (GHC-8.8) HOT 4
- Need GGetCopy and GPutCopy instances for V1 HOT 1
- Hello world is not complete HOT 2
- Need changes for GHC-9.0 HOT 3
- PolyKinds breaks phantom newtype deriving with non obvious error message HOT 2
- Support GHC 9.4
- deriveSafeCopy not working for mutual recursive data-types in GHC 9.2.4 HOT 3
- Support GHC 9.6 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from safecopy.