Keep typeRemapper in inlining context instead of hashMap for transformed types
This commit is contained in:
+3
-9
@@ -27,10 +27,7 @@ import org.jetbrains.kotlin.codegen.state.GenerationState;
|
|||||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||||
import org.jetbrains.org.objectweb.asm.*;
|
import org.jetbrains.org.objectweb.asm.*;
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode;
|
import org.jetbrains.org.objectweb.asm.tree.*;
|
||||||
import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode;
|
|
||||||
import org.jetbrains.org.objectweb.asm.tree.MethodNode;
|
|
||||||
import org.jetbrains.org.objectweb.asm.tree.VarInsnNode;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -65,8 +62,6 @@ public class AnonymousObjectTransformer {
|
|||||||
|
|
||||||
private final Map<String, List<String>> fieldNames = new HashMap<String, List<String>>();
|
private final Map<String, List<String>> fieldNames = new HashMap<String, List<String>>();
|
||||||
|
|
||||||
private final TypeRemapper typeRemapper;
|
|
||||||
|
|
||||||
public AnonymousObjectTransformer(
|
public AnonymousObjectTransformer(
|
||||||
@NotNull String objectInternalName,
|
@NotNull String objectInternalName,
|
||||||
@NotNull InliningContext inliningContext,
|
@NotNull InliningContext inliningContext,
|
||||||
@@ -81,7 +76,6 @@ public class AnonymousObjectTransformer {
|
|||||||
this.newLambdaType = newLambdaType;
|
this.newLambdaType = newLambdaType;
|
||||||
|
|
||||||
reader = InlineCodegenUtil.buildClassReaderByInternalName(state, objectInternalName);
|
reader = InlineCodegenUtil.buildClassReaderByInternalName(state, objectInternalName);
|
||||||
typeRemapper = new TypeRemapper(inliningContext.typeMapping);
|
|
||||||
transformationResult = InlineResult.create();
|
transformationResult = InlineResult.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +186,7 @@ public class AnonymousObjectTransformer {
|
|||||||
String oldFunReturnType = returnType.getInternalName();
|
String oldFunReturnType = returnType.getInternalName();
|
||||||
String newFunReturnType = funResult.getChangedTypes().get(oldFunReturnType);
|
String newFunReturnType = funResult.getChangedTypes().get(oldFunReturnType);
|
||||||
if (newFunReturnType != null) {
|
if (newFunReturnType != null) {
|
||||||
typeRemapper.addAdditionalMappings(oldFunReturnType, newFunReturnType);
|
inliningContext.typeRemapper.addAdditionalMappings(oldFunReturnType, newFunReturnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deferringMethods.add(deferringVisitor);
|
deferringMethods.add(deferringVisitor);
|
||||||
@@ -344,7 +338,7 @@ public class AnonymousObjectTransformer {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private ClassBuilder createClassBuilder() {
|
private ClassBuilder createClassBuilder() {
|
||||||
ClassBuilder classBuilder = state.getFactory().newVisitor(NO_ORIGIN, newLambdaType, inliningContext.getRoot().callElement.getContainingFile());
|
ClassBuilder classBuilder = state.getFactory().newVisitor(NO_ORIGIN, newLambdaType, inliningContext.getRoot().callElement.getContainingFile());
|
||||||
return new RemappingClassBuilder(classBuilder, typeRemapper);
|
return new RemappingClassBuilder(classBuilder, inliningContext.typeRemapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class InliningContext {
|
|||||||
|
|
||||||
public final NameGenerator nameGenerator;
|
public final NameGenerator nameGenerator;
|
||||||
|
|
||||||
public final Map<String, String> typeMapping;
|
public final TypeRemapper typeRemapper;
|
||||||
|
|
||||||
public final ReifiedTypeInliner reifedTypeInliner;
|
public final ReifiedTypeInliner reifedTypeInliner;
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class InliningContext {
|
|||||||
@NotNull Map<Integer, LambdaInfo> map,
|
@NotNull Map<Integer, LambdaInfo> map,
|
||||||
@NotNull GenerationState state,
|
@NotNull GenerationState state,
|
||||||
@NotNull NameGenerator nameGenerator,
|
@NotNull NameGenerator nameGenerator,
|
||||||
@NotNull Map<String, String> typeMapping,
|
@NotNull TypeRemapper typeRemapper,
|
||||||
@NotNull ReifiedTypeInliner reifedTypeInliner,
|
@NotNull ReifiedTypeInliner reifedTypeInliner,
|
||||||
boolean isInliningLambda,
|
boolean isInliningLambda,
|
||||||
boolean classRegeneration
|
boolean classRegeneration
|
||||||
@@ -57,7 +57,7 @@ public class InliningContext {
|
|||||||
expressionMap = map;
|
expressionMap = map;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.nameGenerator = nameGenerator;
|
this.nameGenerator = nameGenerator;
|
||||||
this.typeMapping = typeMapping;
|
this.typeRemapper = typeRemapper;
|
||||||
this.reifedTypeInliner = reifedTypeInliner;
|
this.reifedTypeInliner = reifedTypeInliner;
|
||||||
this.isInliningLambda = isInliningLambda;
|
this.isInliningLambda = isInliningLambda;
|
||||||
this.classRegeneration = classRegeneration;
|
this.classRegeneration = classRegeneration;
|
||||||
@@ -78,13 +78,12 @@ public class InliningContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public InliningContext subInlineWithClassRegeneration(@NotNull NameGenerator generator,
|
public InliningContext subInlineWithClassRegeneration(@NotNull NameGenerator generator,
|
||||||
@NotNull Map<String, String> additionalTypeMappings,
|
@NotNull Map<String, String> newTypeMappings,
|
||||||
@NotNull AnonymousObjectGeneration anonymousObjectGeneration
|
@NotNull AnonymousObjectGeneration anonymousObjectGeneration
|
||||||
) {
|
) {
|
||||||
Map<String, String> newTypeMappings = new HashMap<String, String>(typeMapping);
|
|
||||||
newTypeMappings.putAll(additionalTypeMappings);
|
|
||||||
return new RegeneratedClassContext(this, expressionMap, state, generator,
|
return new RegeneratedClassContext(this, expressionMap, state, generator,
|
||||||
newTypeMappings, reifedTypeInliner, isInliningLambda, anonymousObjectGeneration);
|
new TypeRemapper(typeRemapper, newTypeMappings),
|
||||||
|
reifedTypeInliner, isInliningLambda, anonymousObjectGeneration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InliningContext subInline(NameGenerator generator, Map<String, String> additionalTypeMappings, boolean isInliningLambda) {
|
public InliningContext subInline(NameGenerator generator, Map<String, String> additionalTypeMappings, boolean isInliningLambda) {
|
||||||
@@ -97,10 +96,8 @@ public class InliningContext {
|
|||||||
boolean isInliningLambda,
|
boolean isInliningLambda,
|
||||||
boolean isRegeneration
|
boolean isRegeneration
|
||||||
) {
|
) {
|
||||||
Map<String, String> newTypeMappings = new HashMap<String, String>(typeMapping);
|
|
||||||
newTypeMappings.putAll(additionalTypeMappings);
|
|
||||||
return new InliningContext(this, expressionMap, state, generator,
|
return new InliningContext(this, expressionMap, state, generator,
|
||||||
newTypeMappings, reifedTypeInliner, isInliningLambda, isRegeneration);
|
new TypeRemapper(typeRemapper, additionalTypeMappings), reifedTypeInliner, isInliningLambda, isRegeneration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRoot() {
|
public boolean isRoot() {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class MethodInliner {
|
|||||||
public MethodInliner(
|
public MethodInliner(
|
||||||
@NotNull MethodNode node,
|
@NotNull MethodNode node,
|
||||||
@NotNull Parameters parameters,
|
@NotNull Parameters parameters,
|
||||||
@NotNull InliningContext parent,
|
@NotNull InliningContext inliningContext,
|
||||||
@NotNull FieldRemapper nodeRemapper,
|
@NotNull FieldRemapper nodeRemapper,
|
||||||
boolean isSameModule,
|
boolean isSameModule,
|
||||||
@NotNull String errorPrefix,
|
@NotNull String errorPrefix,
|
||||||
@@ -86,12 +86,12 @@ public class MethodInliner {
|
|||||||
) {
|
) {
|
||||||
this.node = node;
|
this.node = node;
|
||||||
this.parameters = parameters;
|
this.parameters = parameters;
|
||||||
this.inliningContext = parent;
|
this.inliningContext = inliningContext;
|
||||||
this.nodeRemapper = nodeRemapper;
|
this.nodeRemapper = nodeRemapper;
|
||||||
this.isSameModule = isSameModule;
|
this.isSameModule = isSameModule;
|
||||||
this.errorPrefix = errorPrefix;
|
this.errorPrefix = errorPrefix;
|
||||||
this.sourceMapper = sourceMapper;
|
this.sourceMapper = sourceMapper;
|
||||||
this.typeMapper = parent.state.getTypeMapper();
|
this.typeMapper = inliningContext.state.getTypeMapper();
|
||||||
this.result = InlineResult.create();
|
this.result = InlineResult.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +153,9 @@ public class MethodInliner {
|
|||||||
|
|
||||||
final Iterator<AnonymousObjectGeneration> iterator = anonymousObjectGenerations.iterator();
|
final Iterator<AnonymousObjectGeneration> iterator = anonymousObjectGenerations.iterator();
|
||||||
|
|
||||||
|
final TypeRemapper remapper = TypeRemapper.createFrom(currentTypeMapping);
|
||||||
RemappingMethodAdapter remappingMethodAdapter = new RemappingMethodAdapter(resultNode.access, resultNode.desc, resultNode,
|
RemappingMethodAdapter remappingMethodAdapter = new RemappingMethodAdapter(resultNode.access, resultNode.desc, resultNode,
|
||||||
new TypeRemapper(currentTypeMapping));
|
remapper);
|
||||||
|
|
||||||
final int markerShift = InlineCodegenUtil.calcMarkerShift(parameters, node);
|
final int markerShift = InlineCodegenUtil.calcMarkerShift(parameters, node);
|
||||||
InlineAdapter lambdaInliner = new InlineAdapter(remappingMethodAdapter, parameters.getArgsSizeOnStack(), sourceMapper) {
|
InlineAdapter lambdaInliner = new InlineAdapter(remappingMethodAdapter, parameters.getArgsSizeOnStack(), sourceMapper) {
|
||||||
@@ -167,7 +168,7 @@ public class MethodInliner {
|
|||||||
//TODO: need poping of type but what to do with local funs???
|
//TODO: need poping of type but what to do with local funs???
|
||||||
String oldClassName = anonymousObjectGen.getOwnerInternalName();
|
String oldClassName = anonymousObjectGen.getOwnerInternalName();
|
||||||
String newClassName = inliningContext.nameGenerator.genLambdaClassName();
|
String newClassName = inliningContext.nameGenerator.genLambdaClassName();
|
||||||
currentTypeMapping.put(oldClassName, newClassName);
|
remapper.addMapping(oldClassName, newClassName);
|
||||||
AnonymousObjectTransformer transformer =
|
AnonymousObjectTransformer transformer =
|
||||||
new AnonymousObjectTransformer(oldClassName,
|
new AnonymousObjectTransformer(oldClassName,
|
||||||
inliningContext
|
inliningContext
|
||||||
@@ -551,7 +552,7 @@ public class MethodInliner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAlreadyRegenerated(@NotNull String owner) {
|
private boolean isAlreadyRegenerated(@NotNull String owner) {
|
||||||
return inliningContext.typeMapping.containsKey(owner);
|
return inliningContext.typeRemapper.hasNoAdditionalMapping(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
+2
-2
@@ -30,12 +30,12 @@ public class RegeneratedClassContext extends InliningContext {
|
|||||||
@NotNull Map<Integer, LambdaInfo> map,
|
@NotNull Map<Integer, LambdaInfo> map,
|
||||||
@NotNull GenerationState state,
|
@NotNull GenerationState state,
|
||||||
@NotNull NameGenerator nameGenerator,
|
@NotNull NameGenerator nameGenerator,
|
||||||
@NotNull Map<String, String> typeMapping,
|
@NotNull TypeRemapper typeRemapper,
|
||||||
@NotNull ReifiedTypeInliner reifiedTypeInliner,
|
@NotNull ReifiedTypeInliner reifiedTypeInliner,
|
||||||
boolean isInliningLambda,
|
boolean isInliningLambda,
|
||||||
@NotNull AnonymousObjectGeneration anonymousObjectGeneration
|
@NotNull AnonymousObjectGeneration anonymousObjectGeneration
|
||||||
) {
|
) {
|
||||||
super(parent, map, state, nameGenerator, typeMapping, reifiedTypeInliner, isInliningLambda, true);
|
super(parent, map, state, nameGenerator, typeRemapper, reifiedTypeInliner, isInliningLambda, true);
|
||||||
this.anonymousObjectGeneration = anonymousObjectGeneration;
|
this.anonymousObjectGeneration = anonymousObjectGeneration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.codegen.context.CodegenContext;
|
|||||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||||
import org.jetbrains.kotlin.psi.KtElement;
|
import org.jetbrains.kotlin.psi.KtElement;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class RootInliningContext extends InliningContext {
|
public class RootInliningContext extends InliningContext {
|
||||||
@@ -38,7 +37,7 @@ public class RootInliningContext extends InliningContext {
|
|||||||
@NotNull String classNameToInline,
|
@NotNull String classNameToInline,
|
||||||
@NotNull ReifiedTypeInliner inliner
|
@NotNull ReifiedTypeInliner inliner
|
||||||
) {
|
) {
|
||||||
super(null, map, state, nameGenerator, Collections.<String, String>emptyMap(), inliner, false, false);
|
super(null, map, state, nameGenerator, TypeRemapper.createEmpty(), inliner, false, false);
|
||||||
this.callElement = callElement;
|
this.callElement = callElement;
|
||||||
this.startContext = startContext;
|
this.startContext = startContext;
|
||||||
this.classNameToInline = classNameToInline;
|
this.classNameToInline = classNameToInline;
|
||||||
|
|||||||
@@ -23,14 +23,43 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class TypeRemapper extends Remapper {
|
public class TypeRemapper extends Remapper {
|
||||||
|
//typeMapping field could be changed outside through method processing
|
||||||
private final Map<String, String> typeMapping;
|
private final Map<String, String> typeMapping;
|
||||||
|
|
||||||
private Map<String, String> additionalMappings;
|
private Map<String, String> additionalMappings;
|
||||||
|
|
||||||
//typeMapping could be changed outside through method processing
|
//typeMapping field could be changed outside through method processing
|
||||||
public TypeRemapper(@NotNull Map<String, String> typeMapping) {
|
private TypeRemapper(@NotNull Map<String, String> typeMapping) {
|
||||||
this.typeMapping = typeMapping;
|
this.typeMapping = typeMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TypeRemapper(@NotNull TypeRemapper remapper, @NotNull Map<String, String> newTypeMappings) {
|
||||||
|
this(createNewAndMerge(remapper, newTypeMappings));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TypeRemapper createEmpty() {
|
||||||
|
return new TypeRemapper(new HashMap<String, String>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TypeRemapper createFrom(Map<String, String> mappings) {
|
||||||
|
return new TypeRemapper(mappings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static Map<String, String> createNewAndMerge(@NotNull TypeRemapper remapper, @NotNull Map<String, String> additionalTypeMappings) {
|
||||||
|
Map<String, String> map = new HashMap<String, String>(remapper.typeMapping);
|
||||||
|
map.putAll(additionalTypeMappings);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addMapping(String type, String newType) {
|
||||||
|
typeMapping.put(type, newType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasNoAdditionalMapping(String type) {
|
||||||
|
return typeMapping.containsKey(type);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String map(String type) {
|
public String map(String type) {
|
||||||
String newType = typeMapping.get(type);
|
String newType = typeMapping.get(type);
|
||||||
|
|||||||
Reference in New Issue
Block a user