diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt index 3e173155058..5549bba6eac 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/AnonymousObjectTransformer.kt @@ -9,7 +9,6 @@ import com.intellij.util.ArrayUtil import org.jetbrains.kotlin.codegen.* import org.jetbrains.kotlin.codegen.coroutines.DEBUG_METADATA_ANNOTATION_ASM_TYPE import org.jetbrains.kotlin.codegen.coroutines.isCoroutineSuperClass -import org.jetbrains.kotlin.codegen.coroutines.isResumeImplMethodName import org.jetbrains.kotlin.codegen.inline.coroutines.CoroutineTransformer import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX import org.jetbrains.kotlin.codegen.serialization.JvmCodegenStringTable @@ -27,6 +26,7 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin.Companion.NO_ORIGIN import org.jetbrains.org.objectweb.asm.* import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter +import org.jetbrains.org.objectweb.asm.commons.Method import org.jetbrains.org.objectweb.asm.tree.* import java.util.* @@ -272,7 +272,7 @@ class AnonymousObjectTransformer( // Since $$forInline functions are not generated if retransformation is the last one (i.e. call site is not inline) // link to the function in OUTERCLASS field becomes invalid. However, since $$forInline function always has no-inline // companion without the suffix, use it. - visitor.visitOuterClass(info.ownerClassName, info.functionName?.removeSuffix(FOR_INLINE_SUFFIX), info.functionDesc) + visitor.visitOuterClass(info.ownerClassName, info.method.name.removeSuffix(FOR_INLINE_SUFFIX), info.method.descriptor) } private fun inlineMethodAndUpdateGlobalResult( @@ -314,11 +314,10 @@ class AnonymousObjectTransformer( SourceMapCopier(sourceMapper, sourceMap), InlineCallSiteInfo( transformationInfo.oldClassName, - sourceNode.name, - if (isConstructor) transformationInfo.newConstructorDescriptor else sourceNode.desc, + Method(sourceNode.name, if (isConstructor) transformationInfo.newConstructorDescriptor else sourceNode.desc), inliningContext.callSiteInfo.isInlineOrInsideInline, - isSuspendFunctionOrLambda(sourceNode), - inliningContext.root.sourceCompilerForInline.inlineCallSiteInfo.lineNumber + inliningContext.callSiteInfo.file, + inliningContext.callSiteInfo.lineNumber ), null ) @@ -328,12 +327,6 @@ class AnonymousObjectTransformer( return result } - private fun isSuspendFunctionOrLambda(sourceNode: MethodNode): Boolean = - (sourceNode.desc.endsWith(";Lkotlin/coroutines/Continuation;)Ljava/lang/Object;") || - sourceNode.desc.endsWith(";Lkotlin/coroutines/experimental/Continuation;)Ljava/lang/Object;")) && - (CoroutineTransformer.findFakeContinuationConstructorClassName(sourceNode) != null || - languageVersionSettings.isResumeImplMethodName(sourceNode.name.removeSuffix(FOR_INLINE_SUFFIX))) - private fun generateConstructorAndFields( classBuilder: ClassBuilder, allCapturedBuilder: ParametersBuilder, diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCallSiteInfo.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCallSiteInfo.kt deleted file mode 100644 index e6b461249d0..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCallSiteInfo.kt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright 2010-2019 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.kotlin.codegen.inline - -class InlineCallSiteInfo( - val ownerClassName: String, - val functionName: String?, - val functionDesc: String?, - val isInlineOrInsideInline: Boolean, - val isSuspend: Boolean, - val lineNumber: Int -) \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ObjectTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ObjectTransformer.kt index fb735ffa313..23057ccc16f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ObjectTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ObjectTransformer.kt @@ -37,7 +37,7 @@ abstract class ObjectTransformer(@JvmField val trans val classBuilder = state.factory.newVisitor( JvmDeclarationOrigin.NO_ORIGIN, Type.getObjectType(transformationInfo.newClassName), - inliningContext.root.sourceCompilerForInline.callsiteFile!! + inliningContext.callSiteInfo.file!! ) return RemappingClassBuilder( diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiSourceCompilerForInline.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiSourceCompilerForInline.kt index 0af8d284abc..d8b0ae84d70 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiSourceCompilerForInline.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/PsiSourceCompilerForInline.kt @@ -60,8 +60,6 @@ class PsiSourceCompilerForInline( override val callElementText: String by lazy { callElement.text } - override val callsiteFile by lazy { callElement.containingFile } - override val inlineCallSiteInfo: InlineCallSiteInfo get() { var context = codegen.getContext() @@ -78,10 +76,9 @@ class PsiSourceCompilerForInline( val signature = codegen.state.typeMapper.mapSignatureSkipGeneric(context.functionDescriptor, context.contextKind) return InlineCallSiteInfo( parentCodegen.className, - signature.asmMethod.name, - signature.asmMethod.descriptor, + signature.asmMethod, context.functionDescriptor.isInlineOrInsideInline(), - context.functionDescriptor.isSuspend, + callElement.containingFile, CodegenUtil.getLineNumberForElement(callElement, false) ?: 0 ) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt index 9509a4c3455..af09f4878eb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt @@ -23,6 +23,14 @@ import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.commons.Method import org.jetbrains.org.objectweb.asm.tree.MethodNode +class InlineCallSiteInfo( + val ownerClassName: String, + val method: Method, + val isInlineOrInsideInline: Boolean, + val file: PsiFile?, + val lineNumber: Int +) + interface SourceCompilerForInline { val state: GenerationState @@ -30,8 +38,6 @@ interface SourceCompilerForInline { val callElementText: String - val callsiteFile: PsiFile? - val inlineCallSiteInfo: InlineCallSiteInfo val sourceMapper: SourceMapper diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/coroutines/CoroutineTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/coroutines/CoroutineTransformer.kt index f25602c2312..7af2f4c35f1 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/coroutines/CoroutineTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/coroutines/CoroutineTransformer.kt @@ -91,8 +91,8 @@ class CoroutineTransformer( obtainClassBuilderForCoroutineState = { classBuilder }, reportSuspensionPointInsideMonitor = { sourceCompilerForInline.reportSuspensionPointInsideMonitor(it) }, // TODO: this linenumbers might not be correct and since they are used only for step-over, check them. - lineNumber = sourceCompilerForInline.inlineCallSiteInfo.lineNumber, - sourceFile = sourceCompilerForInline.callsiteFile?.name ?: "", + lineNumber = inliningContext.callSiteInfo.lineNumber, + sourceFile = inliningContext.callSiteInfo.file?.name ?: "", languageVersionSettings = state.languageVersionSettings, shouldPreserveClassInitialization = state.constructorCallNormalizationMode.shouldPreserveClassInitialization, containingClassInternalName = classBuilder.thisName, @@ -125,8 +125,8 @@ class CoroutineTransformer( createNewMethodFrom(node, name), node.access, name, node.desc, null, null, obtainClassBuilderForCoroutineState = { (inliningContext as RegeneratedClassContext).continuationBuilders[continuationClassName]!! }, reportSuspensionPointInsideMonitor = { sourceCompilerForInline.reportSuspensionPointInsideMonitor(it) }, - lineNumber = sourceCompilerForInline.inlineCallSiteInfo.lineNumber, - sourceFile = sourceCompilerForInline.callsiteFile?.name ?: "", + lineNumber = inliningContext.callSiteInfo.lineNumber, + sourceFile = inliningContext.callSiteInfo.file?.name ?: "", languageVersionSettings = state.languageVersionSettings, shouldPreserveClassInitialization = state.constructorCallNormalizationMode.shouldPreserveClassInitialization, containingClassInternalName = classBuilder.thisName, diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt index 6b99b793fbb..b3641180571 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrInlineCodegen.kt @@ -48,7 +48,7 @@ class IrInlineCodegen( if (info.generateAssertField) { // May be inlining code into ``, in which case it's too late to modify the IR and // `generateAssertFieldIfNeeded` will return a statement for which we need to emit bytecode. - val isClInit = info.callSiteInfo.functionName == "" + val isClInit = info.callSiteInfo.method.name == "" codegen.classCodegen.generateAssertFieldIfNeeded(isClInit)?.accept(codegen, BlockInfo())?.discard() } } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt index 58c5e158020..f9002226898 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/IrSourceCompilerForInline.kt @@ -46,19 +46,15 @@ class IrSourceCompilerForInline( override val callElementText: String get() = ir2string(callElement) - override val callsiteFile: PsiFile? - get() = codegen.irFunction.fileParent.getKtFile() - override val inlineCallSiteInfo: InlineCallSiteInfo get() { val root = generateSequence(codegen) { it.inlinedInto }.last() return InlineCallSiteInfo( root.classCodegen.type.internalName, - root.signature.asmMethod.name, - root.signature.asmMethod.descriptor, + root.signature.asmMethod, root.irFunction.isInlineOrInsideInline(), - root.irFunction.isSuspend, - findElement()?.let { CodegenUtil.getLineNumberForElement(it, false) } ?: 0 + root.irFunction.fileParent.getKtFile(), + callElement.psiElement?.let { CodegenUtil.getLineNumberForElement(it, false) } ?: 0 ) } @@ -141,8 +137,6 @@ class IrSourceCompilerForInline( .at(callElement.symbol.owner as IrDeclaration) .report(SUSPENSION_POINT_INSIDE_MONITOR, stackTraceElement) } - - private fun findElement() = callElement.psiElement as? KtElement } private tailrec fun IrDeclaration.isInlineOrInsideInline(): Boolean {