JVM: remove contextKind from SourceCompilerForInline

Guess what? It's only useful for the old backend's type mapper!
This commit is contained in:
pyos
2021-05-27 21:38:55 +02:00
committed by max-kammerer
parent 1109348b6d
commit 1e953eaf01
5 changed files with 7 additions and 20 deletions
@@ -2956,7 +2956,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
? FictitiousArrayConstructor.create((ConstructorDescriptor) original) : original.getOriginal();
PsiSourceCompilerForInline sourceCompiler = new PsiSourceCompilerForInline(this, callElement, functionDescriptor);
JvmMethodSignature signature = typeMapper.mapSignatureWithGeneric(functionDescriptor, sourceCompiler.getContextKind());
JvmMethodSignature signature = typeMapper.mapSignatureWithGeneric(functionDescriptor, sourceCompiler.getContext().getContextKind());
if (signature.getAsmMethod().getName().contains("-") &&
!state.getConfiguration().getBoolean(JVMConfigurationKeys.USE_OLD_INLINE_CLASSES_MANGLING_SCHEME)
) {
@@ -2964,7 +2964,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
InlineClassesCodegenUtilKt.classFileContainsMethod(functionDescriptor, state, signature.getAsmMethod());
if (classFileContainsMethod != null && !classFileContainsMethod) {
typeMapper.setUseOldManglingRulesForFunctionAcceptingInlineClass(true);
signature = typeMapper.mapSignatureWithGeneric(functionDescriptor, sourceCompiler.getContextKind());
signature = typeMapper.mapSignatureWithGeneric(functionDescriptor, sourceCompiler.getContext().getContextKind());
typeMapper.setUseOldManglingRulesForFunctionAcceptingInlineClass(false);
}
}
@@ -99,7 +99,8 @@ class PsiInlineCodegen(
private val hiddenParameters = mutableListOf<Pair<ParameterInfo, Int>>()
override fun processHiddenParameters() {
if (getMethodAsmFlags(functionDescriptor, sourceCompiler.contextKind, state) and Opcodes.ACC_STATIC == 0) {
val contextKind = (sourceCompiler as PsiSourceCompilerForInline).context.contextKind
if (getMethodAsmFlags(functionDescriptor, contextKind, state) and Opcodes.ACC_STATIC == 0) {
hiddenParameters += invocationParamBuilder.addNextParameter(methodOwner, false, actualDispatchReceiver) to
codegen.frameMap.enterTemp(methodOwner)
}
@@ -46,7 +46,7 @@ class PsiSourceCompilerForInline(
private val additionalInnerClasses = mutableListOf<ClassDescriptor>()
private val context = getContext(
val context = getContext(
functionDescriptor,
functionDescriptor,
codegen.state,
@@ -58,9 +58,6 @@ class PsiSourceCompilerForInline(
override val callsiteFile by lazy { callElement.containingFile }
override val contextKind
get () = context.contextKind
override val inlineCallSiteInfo: InlineCallSiteInfo
get() {
var context = codegen.getContext()
@@ -226,13 +223,13 @@ class PsiSourceCompilerForInline(
private fun mapDefault(): Method {
// This is all available in the `Callable` passed to `PsiInlineCodegen.genCallInner`, but it's not forwarded through the inliner...
var result = state.typeMapper.mapDefaultMethod(functionDescriptor, contextKind)
var result = state.typeMapper.mapDefaultMethod(functionDescriptor, context.contextKind)
if (result.name.contains("-") &&
!state.configuration.getBoolean(JVMConfigurationKeys.USE_OLD_INLINE_CLASSES_MANGLING_SCHEME) &&
classFileContainsMethod(functionDescriptor, state, result) == false
) {
state.typeMapper.useOldManglingRulesForFunctionAcceptingInlineClass = true
result = state.typeMapper.mapDefaultMethod(functionDescriptor, contextKind)
result = state.typeMapper.mapDefaultMethod(functionDescriptor, context.contextKind)
state.typeMapper.useOldManglingRulesForFunctionAcceptingInlineClass = false
}
return result
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.codegen.inline
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.codegen.BaseExpressionCodegen
import org.jetbrains.kotlin.codegen.OwnerKind
import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.config.CommonConfigurationKeys
@@ -34,8 +33,6 @@ interface SourceCompilerForInline {
val callsiteFile: PsiFile?
val contextKind: OwnerKind
val inlineCallSiteInfo: InlineCallSiteInfo
val sourceMapper: SourceMapper
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.backend.common.ir.ir2string
import org.jetbrains.kotlin.backend.jvm.ir.getKtFile
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.hasMangledReturnType
import org.jetbrains.kotlin.codegen.BaseExpressionCodegen
import org.jetbrains.kotlin.codegen.OwnerKind
import org.jetbrains.kotlin.codegen.inline.*
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
@@ -51,13 +50,6 @@ class IrSourceCompilerForInline(
override val callsiteFile: PsiFile?
get() = codegen.irFunction.fileParent.getKtFile()
override val contextKind: OwnerKind
get() = when (val parent = callElement.symbol.owner.parent) {
is IrPackageFragment -> OwnerKind.PACKAGE
is IrClass -> OwnerKind.IMPLEMENTATION
else -> throw AssertionError("Unexpected declaration container: $parent")
}
override val inlineCallSiteInfo: InlineCallSiteInfo
get() {
val root = generateSequence(codegen) { it.inlinedInto }.last()