8000 [2.13 regression] Scala 2.13 miscompiles Spark: it forgets to emit a field leading to a NoSuchFieldError at runtime · Issue #12002 · scala/bug · GitHub
[go: up one dir, main page]

Skip to content
[2.13 regression] Scala 2.13 miscompiles Spark: it forgets to emit a field leading to a NoSuchFieldError at runtime #12002
@smarter

Description

@smarter

reproduction steps

This is using Scala 2.13.2 (Scala 2.13.{0, 1} had a bug preventing Spark from compiling) and a fork of Spark to get it to compile with 2.13 (see SPARK-25075):

git clone https://github.com/smarter/spark/ -b scala-2.13-miscompile
cd spark
sbt core/compile

problem

The class HighlyCompresse 7D7F dMapStatus has a field numNonEmptyBlocks: https://github.com/smarter/spark/blob/ecfee82fda5f0403024ff64f16bc767b8d1e3e3d/core/src/main/scala/org/apache/spark/scheduler/MapStatus.scala#L165
This field is only used in the constructor of the class: https://github.com/smarter/spark/blob/ecfee82fda5f0403024ff64f16bc767b8d1e3e3d/core/src/main/scala/org/apache/spark/scheduler/MapStatus.scala#L174
... but scalac doesn't emit any field for it, even though it emits a getfield call for its usage in the constructor:

$ javap -p -v core/target/scala-2.13/classes/org/apache/spark/scheduler/HighlyCompressedMapStatus.class|grep numNonEmptyBlocks
  #304 = Utf8               numNonEmptyBlocks
  #306 = NameAndType        #304:#118     // numNonEmptyBlocks:I
  #307 = Fieldref           #2.#306       // org/apache/spark/scheduler/HighlyCompressedMapStatus.numNonEmptyBlocks:I
        65: getfield      #307                // Field numNonEmptyBlocks:I
            0      95     2 numNonEmptyBlocks   I
      numNonEmptyBlocks              final

If I add a private def foo: Int = numNonEmptyBlocks to the class, then the field does show up:

$ javap -p -v core/target/scala-2.13/classes/org/apache/spark/scheduler/HighlyCompressedMapStatus.class|grep numNonEmptyBlocks
   #20 = Utf8               numNonEmptyBlocks
   #50 = NameAndType        #20:#21       // numNonEmptyBlocks:I
   #51 = Fieldref           #2.#50        // org/apache/spark/scheduler/HighlyCompressedMapStatus.numNonEmptyBlocks:I
  private int numNonEmptyBlocks;
         1: getfield      #51                 // Field numNonEmptyBlocks:I
         7: putfield      #51                 // Field numNonEmptyBlocks:I
        70: getfield      #51                 // Field numNonEmptyBlocks:I
            0     100     2 numNonEmptyBlocks   I
      numNonEmptyBlocks              final

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0