streem / pbandk

Kotlin Code Generator and Runtime for Protocol Buffers
MIT License
271 stars 37 forks source link

Very large protobuf messages cause a StackOverflowError on Kotlin/JS #267

Open garyp opened 4 months ago

garyp commented 4 months ago

This can be reproduced by un-excluding the test_compiler_limits.kt file that's currently excluded for Kotlin/JS in https://github.com/streem/pbandk/blob/master/test-types/build.gradle.kts. The compiler will fail with a StackOverflowError and a stack trace similar to:

e: java.lang.StackOverflowError                                                        
        at org.jetbrains.kotlin.ir.backend.js.utils.serialization.JsIrAstSerializer.writeExpression(JsIrAstSerializer.kt:783)
        at org.jetbrains.kotlin.ir.backend.js.utils.serialization.JsIrAstSerializer.access$writeExpression(JsIrAstSerializer.kt:82)
        at org.jetbrains.kotlin.ir.backend.js.utils.serialization.JsIrAstSerializer$writeExpression$visitor$1.visitBinaryExpression(JsIrAstSerializer.kt:478)
        at org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation.accept(JsBinaryOperation.java:47)
        at org.jetbrains.kotlin.ir.backend.js.utils.serialization.JsIrAstSerializer.writeExpression(JsIrAstSerializer.kt:549)
        at org.jetbrains.kotlin.ir.backend.js.utils.serialization.JsIrAstSerializer.access$writeExpression(JsIrAstSerializer.kt:82)
        at org.jetbrains.kotlin.ir.backend.js.utils.serialization.JsIrAstSerializer$writeExpression$visitor$1.visitBinaryExpression(JsIrAstSerializer.kt:478)
        at org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation.accept(JsBinaryOperation.java:47)
        ...

I have not been able to narrow down which specific portion of the generated code is causing the stack overflow. But it seems to be related to the number of fields in MessageWithLotsOfFields.