Repository: JetBrains/kotlin
File: plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/jvm/SerializableCodegenImpl.kt (Kotlin)

Code before:
                dup()
                iconst(i)
                iconst(goldenMaskArray[i])
                astore(OPT_MASK_TYPE)
            }
            load(descVar, descType)
            invokestatic(
                "kotlinx/serialization/internal/$PLUGIN_UTILS_LIBRARY_CLASS", THROW_MISSING_FIELD_EXCEPTION_METHOD,
                "([I[ILkotlinx/serialization/descriptors/$SERIAL_DESCRIPTOR_CLASS;)V", false
            )
        }
        visitLabel(allPresentsLabel)
    }

    private fun getGoldenMaskArray(): IntArray {
        val maskSlotCount = properties.serializableProperties.bitMaskSlotCount()
        val goldenMaskArray = IntArray(maskSlotCount)

        for (i in properties.serializableProperties.indices) {
            if (!properties.serializableProperties[i].optional) {
                val slotNumber = i / 32
                val bitInSlot = i % 32
                goldenMaskArray[slotNumber] = goldenMaskArray[slotNumber] or (1 shl bitInSlot)
            }
        }
        return goldenMaskArray;
    }

    private fun ExpressionCodegen.genInitProperty(prop: SerializableProperty) = getProp(prop)?.let {
        classCodegen.initializeProperty(this, it)
    }
        ?: getParam(prop)?.let {
            this.v.load(0, thisAsmType)
            if (!it.hasDefaultValue()) throw CompilationException(
                "Optional field ${it.name} in primary constructor of serializable " +
                        "$serializableDescriptor must have default value", null, it
            )
            this.gen(it.defaultValue, prop.asmType)
            this.v.putfield(thisAsmType.internalName, prop.descriptor.name.asString(), prop.asmType.descriptor)
        }
        ?: throw IllegalStateException()

    private fun ExpressionCodegen.genInitParam(prop: PropertyDescriptor, param: KtParameter) {
        this.v.load(0, thisAsmType)
        val mapType = classCodegen.typeMapper.mapType(prop.type)
        if (!param.hasDefaultValue()) throw CompilationException(
            "Transient field ${param.name} in primary constructor of serializable " +
                    "$serializableDescriptor must have default value", null, param
        )
        this.gen(param.defaultValue, mapType)
        this.v.putfield(thisAsmType.internalName, prop.name.asString(), mapType.descriptor)

Review comment (suggestion):
```suggestion
        return goldenMaskArray
```

Code after:
            )
        }
        visitLabel(allPresentsLabel)
    }

    private fun InstructionAdapter.stackSerialDescriptor() {
        if (serializableDescriptor.shouldHaveGeneratedSerializer && staticDescriptor) {
            val serializer = serializableDescriptor.classSerializer!!
            StackValue.singleton(serializer, classCodegen.typeMapper).put(kSerializerType, this)
            invokeinterface(kSerializerType.internalName, descriptorGetterName, "()${descType.descriptor}")
        } else {
            generateStaticDescriptorField()

            getstatic(thisAsmType.internalName, initializedDescriptorFieldName, descType.descriptor)
        }
    }

    private fun generateStaticDescriptorField() {
        val flags = Opcodes.ACC_PRIVATE or Opcodes.ACC_FINAL or Opcodes.ACC_SYNTHETIC or Opcodes.ACC_STATIC
        classCodegen.v.newField(
            OtherOrigin(classCodegen.myClass.psiOrParent), flags,
            initializedDescriptorFieldName, descType.descriptor, null, null
        )

        val clInit = classCodegen.createOrGetClInitCodegen()
        with(clInit.v) {
            anew(descImplType)
            dup()
            aconst(serializableDescriptor.serialName())
            aconst(null)
            aconst(properties.serializableProperties.size)
            invokespecial(descImplType.internalName, "<init>", "(Ljava/lang/String;${generatedSerializerType.descriptor}I)V", false)
            for (property in properties.serializableProperties) {
                dup()
                aconst(property.name)
                iconst(if (property.optional) 1 else 0)
                invokevirtual(descImplType.internalName, CallingConventions.addElement, "(Ljava/lang/String;Z)V", false)
            }

            putstatic(thisAsmType.internalName, initializedDescriptorFieldName, descType.descriptor)
        }
    }

    private fun ExpressionCodegen.genInitProperty(prop: SerializableProperty) = getProp(prop)?.let {
        classCodegen.initializeProperty(this, it)
    }
        ?: getParam(prop)?.let {
            this.v.load(0, thisAsmType)
            if (!it.hasDefaultValue()) throw CompilationException(
                "Optional field ${it.name} in primary constructor of serializable " +
                        "$serializableDescriptor must have default value", null, it