Giter VIP home page Giter VIP logo

Comments (8)

milessabin avatar milessabin commented on May 30, 2024

It appears that RC6 is having trouble with the ImageSize enumeration.

I'm still investigating the root cause, but in the meantime I think that providing an explicit Arbitrary instance for ImageSize should be a workaround.

from scalacheck-shapeless.

milessabin avatar milessabin commented on May 30, 2024

OK, I think I see what's happening here, although I don't entirely understand why the behaviour has changed between RC4 and RC6.

We can reproduce the problem with,

case class Foo(size: ImageSize)
implicitly[Arbitrary[Foo]]

The problem is with ScalaChecks definition of arbContainer2 ... this pattern will match an HList (with C[_, _] as ::[_, _] and the head and tail as T and U respectively). In context, T is ImageSize and U is HNil, ie. the generic representation of Foo.

In attempting to resolve the implicit arguments of arbContainer2 the typechecker will start by attempting to resolve an arbitrary instance for (ImageSize, HNil). Either directly or indirectly this will loop back through the generic derivation and attempt to derive an instance for ImageSize :: HNil :: HNil, which again matches arbContainer2 and we're off on a non-terminating regression.

I think it should be possible to fix this in scalacheck-shapeless somehow, probably by masking or deprioritizing arbContainer2 somehow. Most likely ScalaCheck could also be tweaked slightly to resolve the problem, but I don't think it would be reasonable to expect ScalaCheck to change to accommodate this scenario (/cc @rickynils)

The question for me is whether or not I can or should change shapeless to fix this. Ultimately that boils down to whether I can come up with a more sophisticated form of divergence checking which would catch this case without also excluding the kinds of recursion that we want to support. I don't currently have a clear idea of how to go about doing that.

I have, I suppose, been pretty much saying that using Lazy means you're sure that the implicit resolution will converge, hence divergence checking should be suspended. The risk is that if you call that wrong then typechecking can loop, and that's what's happened here.

Thoughts on how best to proceed would be very welcome ...

from scalacheck-shapeless.

milessabin avatar milessabin commented on May 30, 2024

FWIW, I think the fix in ScalaCheck would be to move the implicit argument a: Arbitrary[(T, U)] after the argument b: Buildable[(T,U),C[T,U]] in the definition of arbContainer2. b won't resolve because there's no Buildable for shapeless.:: (at least, I presume there isn't), so resolution of implicit arguments would stop there and not consider Arbitrary[(T, U)] at all. /cc @rickynils.

from scalacheck-shapeless.

milessabin avatar milessabin commented on May 30, 2024

In fact, that might be a clue to a fix in scalacheck-shapeless ... the fix might be to duplicate arbContainer2 in object Shapeless modified as described in my previous comment.

from scalacheck-shapeless.

milessabin avatar milessabin commented on May 30, 2024

@inthenow has verified locally that my suggested change in ScalaCheck does resolve the problem. So the change in scalacheck-shapeless should be good too.

from scalacheck-shapeless.

alexarchambault avatar alexarchambault commented on May 30, 2024

Thanks for having looked at this @milessabin and @inthenow ! (I was kind of busy with other projects of mine, I delayed looking at it). I'll try the workaround you suggest soon.

from scalacheck-shapeless.

 avatar commented on May 30, 2024

@alexarchambault np. Btw, The new release of scalacheck has even better scalajs support, as shapeless itself now has. Had you considered cross-compiling this project to support scalajs? As an example, you could start with machinest

from scalacheck-shapeless.

alexarchambault avatar alexarchambault commented on May 30, 2024

Added Foo and ImageSize to the tests here: https://github.com/alexarchambault/scalacheck-shapeless/tree/topic/issue7

I'd like to have a more careful look at that, but with cached implicits, I got no divergence / infinite loop, just failed implicit derivation without https://github.com/alexarchambault/scalacheck-shapeless/blob/topic/issue7/src/test/scala/org/scalacheck/Definitions.scala#L65-L66

@inthenow I'll give scalajs a try if I can find some time to do it, looks like a good idea. (Thanks for the hint and the link.)

from scalacheck-shapeless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.