square / square/wire

Boxed OneOfs

Open
#1,448 5 comments 0 reactions 1 assignee View on GitHub

@oldergod is already working on this.

Since Mar 4, 2020.

bug
Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

Let’s implement an alternate form of oneof that doesn’t crash the compiler!

  • Runtime API
  • Kotlin generator
  • Reflection-based adapters
  • Java generator
  • Redacted support
  • Tests & coverage for NameAllocator / name collisions
  • JSON support Kotlin
  • JSON support Java
  • Fix ordering so oneofs are interleaved with non-oneofs in generated code #1997
  • Fix generator to not double readUnknownFields() calls
  • Fix generator to use CONSTANT_CASE for oneof declarations and their keys
  • Confirm we don't have circular deps: https://github.com/square/wire/pull/1856#discussion_r530633011

@damianw’s original report below:

Wire version: 3.1.0

For example, Perfetto's FtraceEvent generates this Kotlin file. Attempting to compile it (with Kotlin 1.3.70) results in:

e: java.lang.IllegalStateException: Backend Internal error: Exception during file facade code generation
File being compiled: file:///.../build/generated/source/wire/perfetto/protos/FtraceEvent.kt
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.codegen.ClassFileFactory$OutputClassFile.asByteArray(ClassFileFactory.java:315)
        at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException(CodegenUtil.kt:247)
        at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:78)
        at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:88)
        at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:67)
        ...
Caused by: java.lang.RuntimeException: Error generating class file perfetto/protos/FtraceEvent$Companion$ADAPTER$1.class (compiled from [/.../build/generated/source/wire/perfetto/protos/FtraceEvent.kt]): Method too large: perfetto/protos/FtraceEvent$Companion$ADAPTER$1.redact (Lperfetto/protos/FtraceEvent;)Lperfetto/protos/FtraceEvent;
        at org.jetbrains.kotlin.codegen.ClassFileFactory$OutputClassFile.asByteArray(ClassFileFactory.java:315)
        at org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAll(outputUtils.kt:32)
        at org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAll(outputUtils.kt:42)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.writeOutput(KotlinToJVMBytecodeCompiler.kt:101)
        ...
Caused by: org.jetbrains.org.objectweb.asm.MethodTooLargeException: Method too large: perfetto/protos/FtraceEvent$Companion$ADAPTER$1.redact (Lperfetto/protos/FtraceEvent;)Lperfetto/protos/FtraceEvent;
        at org.jetbrains.org.objectweb.asm.MethodWriter.computeMethodInfoSize(MethodWriter.java:2089)
        at org.jetbrains.org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:458)
        at org.jetbrains.kotlin.codegen.ClassBuilderFactories$2.asBytes(ClassBuilderFactories.java:118)
        at org.jetbrains.kotlin.codegen.DelegatingClassBuilderFactory.asBytes(DelegatingClassBuilderFactory.kt:36)
        ... 46 more

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.