zio / izumi-reflect

TypeTag without scala-reflect. Supports Scala 2 and Scala 3.
https://zio.dev/izumi-reflect
Other
141 stars 35 forks source link

conflicting tags materialised for Protoquill in scala 3.3.0-RC6 #391

Closed bishabosha closed 1 year ago

bishabosha commented 1 year ago

see https://github.com/zio/zio/issues/8130 (I was asked to reopen here), and https://github.com/softwaremill/realworld-tapir-zio/issues/107

pshirshov commented 1 year ago

This is actually strange, A[=B] must be a subtype of A[+B], I guess the representation does not represent what's actually wrong there. We will have a look.

pshirshov commented 1 year ago

@bishabosha : could you make a minimal isolated repro please?

neko-kai commented 1 year ago

@bishabosha This is caused by a change/regression in one of the latest Scala 3.3 commits, HKTypeLambda#declaredVariances (private API used here - there's no public way to get variance of type parameters) is not returning the correct variance for some reason, causing all tags to be generated as invariant.

This change happened somewhere between the latest RC6 and scala-3.3.1-RC1-bin-20230331-7262437-NIGHTLY which is a tested version that doesn't appear to have this problem.

@pshirshov

This is actually strange, A[=B] must be a subtype of A[+B], I guess the representation does not represent what's actually wrong there.

It's a subtype, but not equal wrt equals/=:= and also not equal as a binary string, so them not being exactly the same is probably triggering that failure.

pshirshov commented 1 year ago

I guess that should be immediately reported...

neko-kai commented 1 year ago

@bishabosha No need for a repro, since this reproduces with just Tag[List[Int]] on 3.3.0-RC6, but also I'm not exactly sure this can be fixed on our side. I would expect either declaredVariances to have kept working or another API to replace it. (There is a ticket for a public API - https://github.com/lampepfl/dotty/issues/16734)

pshirshov commented 1 year ago

I'm wondering why did this happen. Isn't our IR included into the community build?

bishabosha commented 1 year ago

I'm wondering why did this happen. Isn't our IR included into the community build?

the last update to that was 2021 (the one that's a git submodule)

neko-kai commented 1 year ago

@bishabosha Is there an expectation for us to send PRs to update the version in community build to keep it up to date? We're also in VirtusLab's community build, but that couldn't detect this change because they don't run the tests in that build - compilation succeeds in this case.

bishabosha commented 1 year ago

Is there an expectation for us to send PRs to update the version in community build to keep it up to date?

We don't have any process for keeping the dotty community-build projects up to date - so any help from the original maintainers is appreciated.

I would guess the reason is that a lot of these projects were ad-hoc forks made before the projects themselves had migrated to scala 3, now that they are publishing for scala 3 theoretically its less effort.

bishabosha commented 1 year ago

Is this something that can be "worked around" by having less powerful type lambdas? otherwise this should probably be escalated as a dotty bug even though you relied on non-public api

bishabosha commented 1 year ago

@neko-kai does this help? https://github.com/lampepfl/dotty/pull/17554 - it seems that variances should be computed by inspecting occurrences of the type parameters in the hk lambda's structure

neko-kai commented 1 year ago

@bishabosha I'll try that

neko-kai commented 1 year ago

@adamgfraser I'd recommend to release a new ZIO version with update to izumi-reflect 2.3.8 to avoid users getting hit by this regression if they update to Scala 3.3.0

https://github.com/zio/izumi-reflect/releases/tag/v2.3.8

adamgfraser commented 1 year ago

@neko-kai Will do!