Skip to content

Optimizer preserves tuple for match failure case #12930

Open
@som-snytt

Description

@som-snytt

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions