Scala Programming Language
  1. Scala Programming Language
  2. SI-6898

Document that AnyVal "box" and "unbox" are implemented by BoxesRunTime

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-RC5
    • Fix Version/s: Scala 2.11.0-M3
    • Component/s: Documentation and API
    • Labels:
      None

      Description

      As discussed in SI-6710 and on scala-lang [1], the "box" and "unbox" methods of AnyVal classes (except Unit) are not actually implemented by the code in AnyVal [2].

      Instead, the real implementation comes from BoxesRunTime (e.g. [3]). This is functionally different, creating potential for confusion.

      As per the scala-lang discussion and SI-6710, changing the AnyVal code itself would have too much potential impact and thus be too risky. Documenting the behaviour would be a safer option.

      From Paul Phillips' comment:

      "If we're not using it in generated code and don't intend to, the ideal change is probably to deprecate it and then remove it. Next best (and to do regardless) is to document the behavior and the fact that it isn't actually used by the compiler." [4]

      Source code of AnyVal classes and screenshots of documentation after

      ant all.clean
      ant build
      ./tools/codegen-anyvals
      ANT_OPTS="-Xms512M -Xmx1024M -Xss1M -XX:MaxPermSize=128M" ant docs
      

      attached.

      [1] https://groups.google.com/d/topic/scala-language/kBQnJ3XuKeM/discussion
      [2] https://github.com/scala/scala/blob/master/src/compiler/scala/tools/cmd/gen/AnyVals.scala#L2321
      [3] https://github.com/scala/scala/blob/master/src/library/scala/runtime/BoxesRunTime.java#L87
      [4] https://groups.google.com/d/msg/scala-language/kBQnJ3XuKeM/qvLnORIiXqAJ

      1. Boolean-doc.png
        37 kB
      2. Byte-doc.png
        33 kB
      3. Char-doc.png
        32 kB
      4. Double.png
        24 kB
      5. Float-doc.png
        26 kB
      6. Int-doc.png
        29 kB
      7. Long-doc.png
        28 kB
      8. Short-doc.png
        32 kB
      9. Unit-doc.png
        19 kB

        Activity

        Show
        Andrew Phillips added a comment - Commit at https://github.com/demobox/scala/commit/719b86a3869f222bb37790faa4b6e9105cde4b1d
        Hide
        Lars Hupel added a comment -

        Is there any reason why the unbox methods shouldn't be deprecated for 2.11?

        Show
        Lars Hupel added a comment - Is there any reason why the unbox methods shouldn't be deprecated for 2.11?
        Hide
        Andrew Phillips added a comment -

        Submitted pull request based on suggestion by Josh Suereth:

        https://github.com/scala/scala/pull/2284

        Show
        Andrew Phillips added a comment - Submitted pull request based on suggestion by Josh Suereth : https://github.com/scala/scala/pull/2284

          People

          • Assignee:
            Andrew Phillips
            Reporter:
            Andrew Phillips
          • Votes:
            6 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development