From ceb3cfbfd55f8b6cd188227af49aa07ba9aff1e3 Mon Sep 17 00:00:00 2001 From: Leonid Startsev Date: Mon, 17 Feb 2020 20:03:39 +0300 Subject: [PATCH] Remove update* calls --- .../backend/ir/SerializerIrGenerator.kt | 9 ++-- .../backend/js/SerializerJsTranslator.kt | 43 ++++--------------- .../backend/jvm/SerializerCodegenImpl.kt | 38 ++++------------ 3 files changed, 23 insertions(+), 67 deletions(-) diff --git a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt index 286b67ac369..d84c7a10a21 100644 --- a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt +++ b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/ir/SerializerIrGenerator.kt @@ -371,18 +371,21 @@ open class SerializerIrGenerator(val irClass: IrClass, final override val compil property.type, genericIndex = property.genericIndex ) + val isSerializable = innerSerial != null // todo: update val decodeFuncToCall = - (if (innerSerial != null) "${CallingConventions.decode}${sti.elementMethodPrefix}Serializable${CallingConventions.elementPostfix}" + (if (isSerializable) "${CallingConventions.decode}${sti.elementMethodPrefix}Serializable${CallingConventions.elementPostfix}" else "${CallingConventions.decode}${sti.elementMethodPrefix}${CallingConventions.elementPostfix}") .let { - inputClass.referenceMethod(it) + inputClass.referenceMethod(it) { it.valueParameters.size == if (isSerializable) 4 else 2 } } val typeArgs = if (decodeFuncToCall.descriptor.typeParameters.isNotEmpty()) listOf(property.type.toIrType()) else listOf() val args = mutableListOf(localSerialDesc.get(), irInt(index)) - if (innerSerial != null) + if (innerSerial != null) { args.add(innerSerial) + args.add(localProps[index].get()) + } // local$i = localInput.decode...(...) +irSetVar( localProps[index].symbol, diff --git a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/js/SerializerJsTranslator.kt b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/js/SerializerJsTranslator.kt index 77ea7ea5363..1f3cb6b8c72 100644 --- a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/js/SerializerJsTranslator.kt +++ b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/js/SerializerJsTranslator.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlinx.serialization.compiler.backend.js @@ -297,30 +286,16 @@ open class SerializerJsTranslator( ) JsInvocation(JsNameRef(readFunc, inputVar), readArgs) } else { - val notSeenTest = propNotSeenTest(bitMasks[bitMaskOff(i)], i) val readFunc = inputClass.getFuncDesc("${CallingConventions.decode}${sti.elementMethodPrefix}Serializable${CallingConventions.elementPostfix}") - .single() + .single { it.valueParameters.size == 4 } .let { context.getNameForDescriptor(it) } - val updateFunc = - inputClass.getFuncDesc("${CallingConventions.update}${sti.elementMethodPrefix}Serializable${CallingConventions.elementPostfix}") - .single() - .let { context.getNameForDescriptor(it) } - JsConditional( - notSeenTest, - JsInvocation( - JsNameRef(readFunc, inputVar), - serialClassDescRef, - JsIntLiteral(i), - innerSerial - ), - JsInvocation( - JsNameRef(updateFunc, inputVar), - serialClassDescRef, - JsIntLiteral(i), - innerSerial, - localProps[i] - ) + JsInvocation( + JsNameRef(readFunc, inputVar), + serialClassDescRef, + JsIntLiteral(i), + innerSerial, + localProps[i] ) } // localPropI = ... diff --git a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/jvm/SerializerCodegenImpl.kt b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/jvm/SerializerCodegenImpl.kt index 91a094c37fb..5f9fb7c6f67 100644 --- a/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/jvm/SerializerCodegenImpl.kt +++ b/plugins/kotlin-serialization/kotlin-serialization-compiler/src/org/jetbrains/kotlinx/serialization/compiler/backend/jvm/SerializerCodegenImpl.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlinx.serialization.compiler.backend.jvm @@ -476,35 +465,24 @@ open class SerializerCodegenImpl( AsmUtil.wrapJavaClassIntoKClass(this) } - fun produceCall(update: Boolean) { + fun produceCall(isUpdatable: Boolean) { invokeinterface( kInputType.internalName, - (if (update) CallingConventions.update else CallingConventions.decode) + sti.elementMethodPrefix + (if (useSerializer) "Serializable" else "") + CallingConventions.elementPostfix, + (CallingConventions.decode) + sti.elementMethodPrefix + (if (useSerializer) "Serializable" else "") + CallingConventions.elementPostfix, "(" + descType.descriptor + "I" + (if (useSerializer) kSerialLoaderType.descriptor else "") + (if (unknownSer) AsmTypes.K_CLASS_TYPE.descriptor else "") - + (if (update) sti.type.descriptor else "") + + (if (isUpdatable) sti.type.descriptor else "") + ")" + (sti.type.descriptor) ) } - if (useSerializer && propertyAddressInBitMask != -1) { - // we can choose either it is read or update - val readLabel = Label() - val endL = Label() - genValidateProperty(index, propertyAddressInBitMask) - ificmpeq(readLabel) + val isUpdatable = useSerializer && propertyAddressInBitMask != -1 + if (isUpdatable) { load(propertyVar, propertyType) StackValue.coerce(propertyType, sti.type, this) - produceCall(true) - goTo(endL) - visitLabel(readLabel) - produceCall(false) - visitLabel(endL) - } else { - // update not supported for primitive types or decodeSequentially - produceCall(false) } + produceCall(isUpdatable) StackValue.coerce(sti.type, propertyType, this) store(propertyVar, propertyType)