Skip to content

Regression in jcouyang/dhall-generic for implicit search #20298

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

Closed
WojciechMazur opened this issue Apr 30, 2024 · 2 comments
Closed

Regression in jcouyang/dhall-generic for implicit search #20298

WojciechMazur opened this issue Apr 30, 2024 · 2 comments
Assignees
Labels
area:implicits related to implicits itype:bug

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Apr 30, 2024

Based on OpenCB failures in jcouyang/dhall-generic - build logs

The compiler fails to search for implicit instances defined in companion of the typeclass. It requires explicit import at the place of usage

Compiler version

Last good release: 3.5.0-RC1-bin-20240406-521ce95-NIGHTLY
First bad release: 3.5.0-RC1-bin-20240408-1e8a653-NIGHTLY

The compilation errors when building compiler prevented gathering the exact commit that coused regression it can be any of:
d2a6392
1dc5b99
321d0d2
1e8a653

The project-wise bisect nominated 90c3fbd as the cause of the regression

Minimized code

Needs to be defined as 2 compilation units
I was able to reproducer Decoder[Empty] in single file, but the other cases required definitions and usage to be split in previous Scala versions.

// 1_defns.scala
import scala.compiletime.*
import scala.deriving.*

sealed trait Decoder[T]
object Decoder:
  inline given summonEmptyTuple[H]: Tuple.Map[EmptyTuple.type, Decoder] = EmptyTuple
  inline given summonTuple[H, T <: Tuple](using
      hd: Decoder[H],
      td: Tuple.Map[T, Decoder]
  ): Tuple.Map[H *: T, Decoder] = hd *: td
  inline given derived[T](using
      m: Mirror.Of[T],
      d: Tuple.Map[m.MirroredElemTypes, Decoder]
  ): Decoder[T] = ???
  given Decoder[Double] = ???
// 2_usage.scala
case class Empty()
object Empty {
  val fails = Decoder.derived[Empty]
}

enum Shape:
  case Rectangle(width: Double, height: Double)
  case Circle(radius: Double)

object Shape:
  val fails1 = Decoder.derived[Rectangle]
  val fails2 = Decoder.derived[Shape]

Output

-- [E172] Type Error: /Users/wmazur/projects/sandbox/repro.test.scala:4:39 -----
4 |  val instance = Decoder.derived[Empty]
  |                                       ^
  |No given instance of type Tuple.Map[m.MirroredElemTypes, Decoder] was found for parameter d of given instance derived in object Decoder
  |
  |Note: a match type could not be fully reduced:
  |
  |  trying to reduce  Tuple.Map[m.MirroredElemTypes, Decoder]
  |  failed since selector m.MirroredElemTypes
  |  does not match  case EmptyTuple => EmptyTuple
  |  and cannot be shown to be disjoint from it either.
  |  Therefore, reduction cannot advance to the remaining case
  |
  |    case h *: t => Decoder[h] *: Tuple.Map[t, Decoder]
-- [E172] Type Error: /Users/wmazur/projects/sandbox/repro.test.scala:12:38 ----
12 |  val rec = Decoder.derived[Rectangle]
   |                                      ^
   |No given instance of type Tuple.Map[m.MirroredElemTypes, Decoder] was found for parameter d of given instance derived in object Decoder.
   |I found:
   |
   |    Decoder.summonTuple[Double, Double *: EmptyTuple.type](
   |      Decoder.given_Decoder_Double,
   |      Decoder.summonTuple[Double, EmptyTuple.type](Decoder.given_Decoder_Double,
   |        /* missing */summon[Tuple.Map[EmptyTuple.type, Decoder]])
   |    )
   |
   |But no implicit values were found that match type Tuple.Map[EmptyTuple.type, Decoder].
   |
   |Note: a match type could not be fully reduced:
   |
   |  trying to reduce  Tuple.Map[m.MirroredElemTypes, Decoder]
   |  failed since selector m.MirroredElemTypes
   |  does not match  case EmptyTuple => EmptyTuple
   |  and cannot be shown to be disjoint from it either.
   |  Therefore, reduction cannot advance to the remaining case
   |
   |    case h *: t => Decoder[h] *: Tuple.Map[t, Decoder]
3 errors found

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:implicits related to implicits regression This worked in a previous version but doesn't anymore labels Apr 30, 2024
@EugeneFlesselle
Copy link
Contributor

I believe this is an expected error. Or at least, we intended for it to be an error in #20077.
The i15183 test looks to be a very similar minimisation as above, it was changed in the PR to account for the fix in determining implicit scope.

TLDR the regression is necessary for the implicit scope to be the same for joint vs separate compilation.
I believe it would be fixed here too by adding an import Decoder.given in 2_usage.scala.

@Gedochao Gedochao removed the regression This worked in a previous version but doesn't anymore label May 13, 2024
@Gedochao
Copy link
Contributor

Alright, there's nothing we can fix on our side, it seems.
Code changes will be necessary.
Closing this.

@Gedochao Gedochao closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits itype:bug
Projects
None yet
Development

No branches or pull requests

3 participants