Skip to content

Stack overflow in LabelDef phase when pattern matching on many nested cases #3857

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
smarter opened this issue Jan 16, 2018 · 1 comment · Fixed by #3994
Closed

Stack overflow in LabelDef phase when pattern matching on many nested cases #3857

smarter opened this issue Jan 16, 2018 · 1 comment · Fixed by #3994

Comments

@smarter
Copy link
Member

smarter commented Jan 16, 2018

Same symptom and cause as #2903 but dotty-staging@88b6fb3 doesn't help here:

object foo {
  abstract sealed class num
  final case class One() extends num
  final case class Bit0(a: num) extends num
  final case class Bit1(a: num) extends num

  abstract sealed class abschar
  final case class zero_char() extends abschar
  final case class Char(a: num) extends abschar

  def integer_of_char(x0: abschar): BigInt = x0 match {
    case Char(Bit0(Bit1(Bit0(Bit1(Bit0(One())))))) => BigInt(42)
    case Char(Bit1(Bit0(Bit0(Bit1(Bit0(One())))))) => BigInt(41)
    case Char(Bit0(Bit0(Bit0(Bit1(Bit0(One())))))) => BigInt(40)
    case Char(Bit1(Bit1(Bit1(Bit0(Bit0(One())))))) => BigInt(39)
    case Char(Bit0(Bit1(Bit1(Bit0(Bit0(One())))))) => BigInt(38)
    case Char(Bit1(Bit0(Bit1(Bit0(Bit0(One())))))) => BigInt(37)
    case Char(Bit0(Bit0(Bit1(Bit0(Bit0(One())))))) => BigInt(36)
    case Char(Bit1(Bit1(Bit0(Bit0(Bit0(One())))))) => BigInt(35)
    case Char(Bit0(Bit1(Bit0(Bit0(Bit0(One())))))) => BigInt(34)
    case Char(Bit1(Bit0(Bit0(Bit0(Bit0(One())))))) => BigInt(33)
    case Char(Bit0(Bit0(Bit0(Bit0(Bit0(One())))))) => BigInt(32)
    case Char(Bit1(Bit1(Bit1(Bit1(One()))))) => BigInt(31)
    case Char(Bit0(Bit1(Bit1(Bit1(One()))))) => BigInt(30)
    case Char(Bit1(Bit0(Bit1(Bit1(One()))))) => BigInt(29)
    case Char(Bit0(Bit0(Bit1(Bit1(One()))))) => BigInt(28)
    case Char(Bit1(Bit1(Bit0(Bit1(One()))))) => BigInt(27)
    case Char(Bit0(Bit1(Bit0(Bit1(One()))))) => BigInt(26)
    case Char(Bit1(Bit0(Bit0(Bit1(One()))))) => BigInt(25)
    case Char(Bit0(Bit0(Bit0(Bit1(One()))))) => BigInt(24)
    case Char(Bit1(Bit1(Bit1(Bit0(One()))))) => BigInt(23)
    case Char(Bit0(Bit1(Bit1(Bit0(One()))))) => BigInt(22)
    case Char(Bit1(Bit0(Bit1(Bit0(One()))))) => BigInt(21)
    case Char(Bit0(Bit0(Bit1(Bit0(One()))))) => BigInt(20)
    case Char(Bit1(Bit1(Bit0(Bit0(One()))))) => BigInt(19)
    case Char(Bit0(Bit1(Bit0(Bit0(One()))))) => BigInt(18)
    case Char(Bit1(Bit0(Bit0(Bit0(One()))))) => BigInt(17)
    case Char(Bit0(Bit0(Bit0(Bit0(One()))))) => BigInt(16)
    case Char(Bit1(Bit1(Bit1(One())))) => BigInt(15)
    case Char(Bit0(Bit1(Bit1(One())))) => BigInt(14)
    case Char(Bit1(Bit0(Bit1(One())))) => BigInt(13)
    case Char(Bit0(Bit0(Bit1(One())))) => BigInt(12)
    case Char(Bit1(Bit1(Bit0(One())))) => BigInt(11)
    case Char(Bit0(Bit1(Bit0(One())))) => BigInt(10)
    case Char(Bit1(Bit0(Bit0(One())))) => BigInt(9)
    case Char(Bit0(Bit0(Bit0(One())))) => BigInt(8)
    case Char(Bit1(Bit1(One()))) => BigInt(7)
    case Char(Bit0(Bit1(One()))) => BigInt(6)
    case Char(Bit1(Bit0(One()))) => BigInt(5)
    case Char(Bit0(Bit0(One()))) => BigInt(4)
    case Char(Bit1(One())) => BigInt(3)
    case Char(Bit0(One())) => BigInt(2)
    case Char(One()) => BigInt(1)
    case zero_char() => BigInt(0)
  }
}

Simplified from https://github.com/scala/scala/pull/6236/files#diff-48613ae0b277c9d6a67ba198ba2dc673

@nicolasstucki
Copy link
Contributor

This is the anti-pattern that can't be optimised by the fix for #2903. We will need some more drastic change to fix this one.

@liufengyun liufengyun self-assigned this Feb 13, 2018
liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 13, 2018
nicolasstucki added a commit that referenced this issue Feb 20, 2018
Fix #3857: partial fix to generate more shallow tree in LabelDef
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.

3 participants