Skip to content

Warn (or throw?) when a value class gets boxed #9504

@scabug

Description

@scabug

Proposal: Add a compiler flag that makes it easier to know when an AnyVal allocation occurs.

AnyVals can radically improve performance, but allocations can occur in surprising places (removing any performance gains). SIP-15 documents the conditions under which allocation occurs, but that can be hard to remember when browsing a complicated program. Compiler support for detecting allocations would help a lot.

A couple of possible flags are:

  • Warning - Generate a compiler warning when a use-site will require an AnyVal to be allocated.
  • Throw on Allocate - Add a flag that causes an exception to be thrown when an AnyVal is allocated. The resulting stack trace should allow the programmer to track down the allocation easily.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions