From dd336a558198670a949711e9bcfc3f5239fb26df Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Mon, 21 Dec 2015 16:56:31 +0300 Subject: [PATCH] ReifiedTypeParameterMappings renamed to TypeParameterMappings, add isReified property --- .../kotlin/codegen/ExpressionCodegen.java | 13 ++++---- .../kotlin/codegen/inline/InlineCodegen.java | 2 +- .../codegen/inline/ReifiedTypeInliner.kt | 33 +++++++++++-------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 532b0c63cdd..e87dfa99392 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -2432,7 +2432,7 @@ public class ExpressionCodegen extends KtVisitor impleme protected CallGenerator getOrCreateCallGenerator( @NotNull CallableDescriptor descriptor, @Nullable KtElement callElement, - @Nullable ReifiedTypeParameterMappings reifiedTypeParameterMappings + @Nullable TypeParameterMappings typeParameterMappings ) { if (callElement == null) return defaultCallGenerator; @@ -2444,7 +2444,7 @@ public class ExpressionCodegen extends KtVisitor impleme if (!isInline) return defaultCallGenerator; SimpleFunctionDescriptor original = DescriptorUtils.unwrapFakeOverride((SimpleFunctionDescriptor) descriptor.getOriginal()); - return new InlineCodegen(this, state, original, callElement, reifiedTypeParameterMappings); + return new InlineCodegen(this, state, original, callElement, typeParameterMappings); } @NotNull @@ -2455,10 +2455,9 @@ public class ExpressionCodegen extends KtVisitor impleme @NotNull private CallGenerator getOrCreateCallGenerator(@NotNull ResolvedCall resolvedCall) { Map typeArguments = resolvedCall.getTypeArguments(); - ReifiedTypeParameterMappings mappings = new ReifiedTypeParameterMappings(); + TypeParameterMappings mappings = new TypeParameterMappings(); for (Map.Entry entry : typeArguments.entrySet()) { TypeParameterDescriptor key = entry.getKey(); - if (!key.isReified()) continue; KotlinType type = entry.getValue(); TypeParameterDescriptor parameterDescriptor = TypeUtils.getTypeParameterDescriptorOrNull(type); @@ -2471,13 +2470,13 @@ public class ExpressionCodegen extends KtVisitor impleme key.getName().getIdentifier(), type, asmType, - signatureWriter.toString() - ); + signatureWriter.toString(), + key.isReified()); } else { mappings.addParameterMappingToNewParameter( key.getName().getIdentifier(), type, - parameterDescriptor.getName().getIdentifier()); + parameterDescriptor.getName().getIdentifier(), key.isReified()); } } return getOrCreateCallGenerator( diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java index 77de62194bb..21a84e21b3c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java @@ -96,7 +96,7 @@ public class InlineCodegen extends CallGenerator { @NotNull GenerationState state, @NotNull SimpleFunctionDescriptor functionDescriptor, @NotNull KtElement callElement, - @Nullable ReifiedTypeParameterMappings typeParameterMappings + @Nullable TypeParameterMappings typeParameterMappings ) { assert InlineUtil.isInline(functionDescriptor) : "InlineCodegen could inline only inline function: " + functionDescriptor; diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt index 377fd7f5652..f77d9e86361 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/ReifiedTypeInliner.kt @@ -33,7 +33,7 @@ import org.jetbrains.org.objectweb.asm.tree.* private class ParameterNameAndNullability(val name: String, val nullable: Boolean) -class ReifiedTypeInliner(private val parametersMapping: ReifiedTypeParameterMappings?) { +class ReifiedTypeInliner(private val parametersMapping: TypeParameterMappings?) { enum class OperationKind { NEW_ARRAY, AS, SAFE_AS, IS, JAVA_CLASS; @@ -68,13 +68,16 @@ class ReifiedTypeInliner(private val parametersMapping: ReifiedTypeParameterMapp private var maxStackSize = 0 + private val hasReifiedParameters = parametersMapping?.hasReifiedParameters() ?: false + /** * @return set of type parameters' identifiers contained in markers that should be reified further * e.g. when we're generating inline function containing reified T * and another function containing reifiable parts is inlined into that function */ fun reifyInstructions(node: MethodNode): ReifiedTypeParametersUsages { - if (parametersMapping == null) return ReifiedTypeParametersUsages() + if (!hasReifiedParameters) return ReifiedTypeParametersUsages() + val instructions = node.instructions maxStackSize = 0 var result = ReifiedTypeParametersUsages() @@ -91,8 +94,10 @@ class ReifiedTypeInliner(private val parametersMapping: ReifiedTypeParameterMapp return result } + fun reifySignature(oldSignature: String): SignatureReificationResult { - if (parametersMapping == null) return SignatureReificationResult(oldSignature, ReifiedTypeParametersUsages()) + if (!hasReifiedParameters) return SignatureReificationResult(oldSignature, ReifiedTypeParametersUsages()) + val signatureRemapper = object : SignatureWriter() { var typeParamsToReify = ReifiedTypeParametersUsages() @@ -117,7 +122,7 @@ class ReifiedTypeInliner(private val parametersMapping: ReifiedTypeParameterMapp } } - private fun getMappingByName(name: String?) = parametersMapping[name!!] + private fun getMappingByName(name: String?) = parametersMapping!![name!!] } SignatureReader(oldSignature).accept(signatureRemapper) @@ -251,24 +256,26 @@ private val MethodInsnNode.operationKind: ReifiedTypeInliner.OperationKind? get( ReifiedTypeInliner.OperationKind.values().getOrNull(it) } -class ReifiedTypeParameterMappings() { - private val mappingsByName = hashMapOf() +class TypeParameterMappings() { + private val mappingsByName = hashMapOf() - fun addParameterMappingToType(name: String, type: KotlinType, asmType: Type, signature: String) { - mappingsByName[name] = ReifiedTypeParameterMapping(name, type, asmType, newName = null, signature = signature) + public fun addParameterMappingToType(name: String, type: KotlinType, asmType: Type, signature: String, isReified: Boolean) { + mappingsByName[name] = TypeParameterMapping(name, type, asmType, newName = null, signature = signature, isReified = isReified) } - fun addParameterMappingToNewParameter(name: String, type: KotlinType, newName: String) { - mappingsByName[name] = ReifiedTypeParameterMapping(name, type = type, asmType = null, newName = newName, signature = null) + public fun addParameterMappingToNewParameter(name: String, type: KotlinType, newName: String, isReified: Boolean) { + mappingsByName[name] = TypeParameterMapping(name, type, asmType = null, newName = newName, signature = null, isReified = isReified) } - operator fun get(name: String): ReifiedTypeParameterMapping? { + operator fun get(name: String): TypeParameterMapping? { return mappingsByName[name] } + + fun hasReifiedParameters() = mappingsByName.values.any { it.isReified } } -class ReifiedTypeParameterMapping( - val name: String, val type: KotlinType, val asmType: Type?, val newName: String?, val signature: String? +class TypeParameterMapping( + val name: String, val type: KotlinType, val asmType: Type?, val newName: String?, val signature: String?, val isReified: Boolean ) class ReifiedTypeParametersUsages {