Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kittens instance not found in 3.4.0 without -source:3.3 #19835

Closed
joan38 opened this issue Mar 1, 2024 · 11 comments
Closed

kittens instance not found in 3.4.0 without -source:3.3 #19835

joan38 opened this issue Mar 1, 2024 · 11 comments

Comments

@joan38
Copy link
Contributor

joan38 commented Mar 1, 2024

Compiler version

3.4.0

Minimized code

//> using scala 3.4.0
//> using dep org.typelevel::kittens:3.2.0

import cats.kernel.Monoid
import cats.derived.auto.monoid.given

case class B(a: Option[Int])
case class A(b: Option[B])

val _ = Monoid[A].empty

Output

[error] No given instance of type cats.derived.DerivedMonoid[scala$minus3$u002E4$minusbug$_.this.A] was found.

Expectation

Compiles fine in 3.3.3

@joan38 joan38 added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 1, 2024
@bishabosha
Copy link
Member

bishabosha commented Mar 1, 2024

workaround:

import scala.language.`3.3`

sounds like kittens has some inline defs that are affected by the type inference change, worth bringing this to them first, if there's no fix on their side, then we'll have to look again.

Here is the release notes of 3.4

Type inference has changed for inline methods in 3.4, which can cause a source incompatibility at the call site. The previous behaviour can be recovered in an affected file with

import scala.language.`3.3`

alternatively, the definition can be changed to transparent inline, but as this is a TASTy breaking change, it is not a default recommendation. (Also, inline should be preferred when possible over transparent inline for reduced binary size.)

@bishabosha
Copy link
Member

I got this error anyway:

scala> import cats.kernel.Monoid
     | import cats.derived.auto.monoid.given
     |
     | case class B(a: Option[Int])
     | case class A(b: Option[B])
     |
     | val _ = Monoid[A].empty
-- [E172] Type Error: ----------------------------------------------------------
  7 |val _ = Monoid[A].empty
    |                 ^
    |No given instance of type cats.derived.DerivedMonoid[A] was found.
    |I found:
    |
    |    cats.derived.DerivedMonoid.given_DerivedMonoid_A[A](
    |      {
    |        val gen$proxy1:
    |
    |            scala.deriving.Mirror.Product{
    |              type Kind = shapeless3.deriving².K0.type; type MirroredType = A;
    |                type MirroredMonoType = A; type MirroredElemTypes <: Tuple
    |            }
    |           &
    |            scala.deriving.Mirror.Product{
    |              type MirroredMonoType = A; type MirroredType = A;
    |                type MirroredLabel = ("A" : String);
    |                type MirroredElemTypes = Option[B] *: EmptyTuple.type;
    |                type MirroredElemLabels = ("b" : String) *: EmptyTuple.type
    |            }
    |
    |         =
    |          A.$asInstanceOf[
    |
    |              scala.deriving.Mirror.Product{
    |                type Kind = shapeless3.deriving².K0.type; type MirroredType = A;
    |                  type MirroredMonoType = A; type MirroredElemTypes <: Tuple
    |              }
    |             &
    |              scala.deriving.Mirror.Product{
    |                type MirroredMonoType = A; type MirroredType = A;
    |                  type MirroredLabel = ("A" : String);
    |                  type MirroredElemTypes = Option[B] *: EmptyTuple.type;
    |                  type MirroredElemLabels = ("b" : String) *: EmptyTuple.type
    |              }
    |
    |          ]
    |        shapeless3.deriving².internals.ErasedProductInstances1.apply[
    |          shapeless3.deriving².K0.type,
    |          cats.derived.Derived.Or[cats.kernel.Monoid[A]]](gen$proxy1,
    |          scala.compiletime.summonInline[
    |            cats.derived.Derived.Or[cats.kernel.Monoid[Option[B]]]]:Any
    |        ):
    |          shapeless3.deriving².internals.ErasedProductInstances[
    |            shapeless3.deriving².K0.type,
    |            cats.derived.Derived.Or[cats.kernel.Monoid[A]]]
    |        :
    |          shapeless3.deriving².K0.ProductInstances[
    |            [A²] =>> cats.derived.Derived.Or[cats.kernel.Monoid[A²]], A]
    |      }
    |    )
    |
    |But given instance mkProductInstances in object K0 does not match type => shapeless3.deriving².K0.ProductInstances[cats.derived.DerivedMonoid.Or, A]
    |
    |where:    A         is a class in the empty package
    |          A²        is a type variable with constraint
    |          deriving  is a package in package scala
    |          deriving² is a package in package shapeless3
    |.
    |
    |The following import might make progress towards fixing the problem:
    |
    |  import cats.derived.DerivedMonoid.Strict.product
    |
    |---------------------------------------------------------------------------
    |Inline stack trace
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from DerivedMonoid.scala:18
    |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    |This location contains code that was inlined from DerivedMonoid.scala:18
     ---------------------------------------------------------------------------
1 error found

@bishabosha bishabosha changed the title No given instance in 3.4.0 kittens instance not found in 3.4.0 without -source:3.3 Mar 1, 2024
@bishabosha bishabosha added stat:wontfix and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 1, 2024
@bishabosha bishabosha closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2024
@joroKr21
Copy link
Member

joroKr21 commented Mar 1, 2024

Type inference has changed how?

@bishabosha
Copy link
Member

bishabosha commented Mar 1, 2024

Type inference has changed how?

see here #19253

@joroKr21
Copy link
Member

joroKr21 commented Mar 8, 2024

I really don't follow what's the issue.

Here is the definition of mkProductInstances

  inline given mkProductInstances[F[_], T](using gen: ProductGeneric[T]): ProductInstances[F, T] =
    ErasedProductInstances[K0.type, F[T], LiftP[F, gen.MirroredElemTypes]](gen)

This that it doesn't match is simply not true:

    |But given instance mkProductInstances in object K0 does not match type => shapeless3.deriving².K0.ProductInstances[cats.derived.DerivedMonoid.Or, A]
    |
    |where:    A         is a class in the empty package
    |          A²        is a type variable with constraint
    |          deriving  is a package in package scala
    |          deriving² is a package in package shapeless3

@joroKr21
Copy link
Member

joroKr21 commented Mar 8, 2024

Btw, are there any instructions how to a project to the community build? I tried to do it but it didn't work.
It would be great to be notified sooner about these changes and also kittens is a good stress test for givens.

@bishabosha
Copy link
Member

Btw, are there any instructions how to a project to the community build? I tried to do it but it didn't work.

maybe you can look at this PR which handles source dependencies: #10639

@SethTisue
Copy link
Member

fwiw, there's been talk internally recently about making the open community build results easier for library maintainers to find and monitor. I hope that will happen

now that the open community build (https://github.com/VirtusLab/community-build3) is in such robust shape, it's unclear to me whether further additions to the small in-repo community build are desired. these repos are part of PR validation, which helps catch problems early, but just throwing projects in willy-nilly doesn't scale; not sure what the current happy medium is considered to be

@joroKr21 at minimum, you should check the kittens entry at https://github.com/VirtusLab/community-build3/blob/master/.github/workflows/buildConfig.json to see if it looks appropriate

@joroKr21
Copy link
Member

joroKr21 commented Mar 8, 2024

Thanks, the kittens build is indeed running and is red but I didn't know about it

@SethTisue
Copy link
Member

cc @WojciechMazur

@WojciechMazur
Copy link
Contributor

There is a new version of typelevel/kittens 3.3.0 which fixes the issue.
I'll file a regression issue with reproducer to check if we can somehow support the implicit resultion when using libraries compiled with the fix.
The typelevel/kittens failed builds were noticed before, but the compilation errors were classified as expected at that time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants