Skip to content

Conversation

@aviralgarg05
Copy link

Fix unnecessary CHECKCAST in untupled function parameters (#24997)

Summary

This PR fixes an issue where automatic parameter untupling (e.g., (number, _) => number) introduced unnecessary CHECKCAST instructions for unused wildcard parameters.

Previously, the compiler generated ValDef bindings for every element of the tuple, even if they were named _. This forced an extraction and a type check for unused elements. By filtering out wildcard parameters during desugaring, we avoid these unnecessary operations, making the generated bytecode as efficient as explicit pattern matching (case (number, _) => number).

Changes

  • Desugar.scala: Modified makeTupledFunction to only generate ValDef bindings for parameters that are not wildcards (nme.WILDCARD).
  • DottyBytecodeTests.scala: Added a new test case i24997 to verify that automatic untupling and explicit case-based untupling produce equivalent bytecode without extra casts.

Verification

Ran the new bytecode test:

sbt "scala3-compiler-bootstrapped/testOnly dotty.tools.backend.jvm.DottyBytecodeTests -- i24997"

@som-snytt
Copy link
Contributor

LGTM! The CLA check has instructions https://contribute.akka.io/contribute/cla/scala

@aviralgarg05
Copy link
Author

LGTM! The CLA check has instructions https://contribute.akka.io/contribute/cla/scala

Yes will that once all workflows are done, will fix all workflows that fail, altogether!!

@aviralgarg05
Copy link
Author

LGTM! The CLA check has instructions https://contribute.akka.io/contribute/cla/scala

Done this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants