bug icon indicating copy to clipboard operation
bug copied to clipboard

Optimizer preserves tuple for match failure case

Open som-snytt opened this issue 1 year ago • 3 comments

Reproduction steps

Scala version: 2.13.12

  def t8790(i: Int, j: Int) =
    (i, j) match {
      case (42, 27) => i+j
      //case _ => ???
    }
  def slow(x: Int, y: Int): String = (x, y) match {
    case (7, 8) => "You got it!"
    case _ => "No such luck."
  }

Problem

Under -opt:local, the tuple is not eliminated if it is used for the match error. However, it is always allocated instead of only in the failure case.

It would be nice to warn -Wopt if a tuple allocation is not eliminated.

som-snytt avatar Jan 20 '24 22:01 som-snytt