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

find-member recursion #18263

Closed
soronpo opened this issue Jul 21, 2023 · 6 comments · Fixed by #18527
Closed

find-member recursion #18263

soronpo opened this issue Jul 21, 2023 · 6 comments · Fixed by #18527

Comments

@soronpo
Copy link
Contributor

soronpo commented Jul 21, 2023

Not completely sure there is a bug. I found this trying to minimize a regression that yielded this bug, but eventually got an example that fails on all 3.x.x releases.

Compiler version

3.x.x

Minimized code

sealed trait Scope
sealed trait Domain extends Scope
object Domain extends Domain

trait Baz[T]
def baz(using ck: Scope): Baz[ck.type] = ???

class Foo extends scala.reflect.Selectable:
  type TScope = Domain
  final protected given TScope = Domain

object ID:
  val internal1 = new Foo:
    val ii = new Foo:
      val x = baz
  val z = internal1.ii.x //error

Output

Recursion limit exceeded.
Maybe there is an illegal cyclic reference?
If that's not the case, you could also try to increase the stacksize using the -Xss JVM option.
A recurring operation is (inner to outer):

  find-member Foo#given_TScope
  find-member Foo#given_TScope
  find-member Foo#given_TScope
  find-member Foo#given_TScope
  find-member Foo#given_TScope
  find-member Foo#given_TScope
  find-member Foo#given_TScope
  find-member Foo#given_TScope
  find-member Foo#given_TScope
  find-member Foo#given_TScope
  ...

  find-member Foo#given_TScope
  find-member Foo#given_TScope

Expectation

No error.

@soronpo soronpo added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 21, 2023
@jchyb jchyb added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 21, 2023
@Kordyjan
Copy link
Contributor

@soronpo I have same questions as in #18253:

Did it happen in https://github.com/DFiantHDL/DFiant or another project? Which branch was that?

@SethTisue
Copy link
Member

SethTisue commented Aug 18, 2023

It's a bug. This should compile.

Dale is working with the following only slightly minimized form:

final class Bar
final class Inv[T]
class Foo extends scala.reflect.Selectable:
  type Boo = Bar
  final given Boo = new Bar

class Test:
  def mkInv(using bar: Bar): Inv[bar.type] = new Inv()

  def test: Unit =
    val foo1     /* : Foo { val foo2: { z1 => Foo { val inv1: Inv[(z1.given_Boo : z1.Boo)] }}} */ = new Foo:
      val foo2   /* :                 { z1 => Foo { val inv1: Inv[(z1.given_Boo : z1.Boo)] }}  */ = new Foo:
        val inv1 /* :                                         Inv[(   given_Boo :    Boo)]     */ = mkInv /* (this.given_Boo) */
    val inv2 = foo1.foo2.inv1 // error
    ()

Note the added comments with the inferred structural types. This has to do with RecType, as the types involved are recursive.

@SethTisue
Copy link
Member

The workaround is to replace foo1.foo2.inv1 with { val tmp = foo1.foo2; tmp.inv1 }

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Aug 31, 2023

I'm not exactly sure if this minimizations are correct. The bisect of reproducer from #18495 (duplicate of this issue) based on the actual library in which this bug was found pointed to ded5d25 so the last good nightly was 3.3.1-RC1-bin-20230504-0e00420-NIGHTLY.
However, these minimization fails with mentioned nightly version so maybe there might be something missing

@soronpo
Copy link
Contributor Author

soronpo commented Aug 31, 2023

I'm not exactly sure if this minimizations are correct. The bisect of reproducer from #18495 (duplicate of this issue) based on the actual library in which this bug was found pointed to ded5d25 so the last good nightly was 3.3.1-RC1-bin-20230504-0e00420-NIGHTLY.
However, these minimization fails with mentioned nightly version so maybe there might be something missing

You are right, but I think this is a case where "two wrongs make a right". This minimization shows a bug that always existed. The change in the compiler in ded5d25 just caused the bug to surface for the LTS release and the DFiant library use-case.

@dwijnand
Copy link
Member

dwijnand commented Sep 4, 2023

Speaking to Martin, we should be able to consider a refined val as stable, as in val foo1: Foo { val foo2: ... } = ???; foo1.foo2.inv should consider foo1.foo2 as a stable prefix. I'll try that patch to "isStable", or whatever it's called.

@dwijnand dwijnand linked a pull request Sep 8, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants