New generated lambda naming
This commit is contained in:
@@ -103,8 +103,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
@Nullable
|
||||
private final MemberCodegen parentCodegen;
|
||||
|
||||
private NameGenerator inlineNameGenerator;
|
||||
|
||||
/*
|
||||
* When we create a temporary variable to hold some value not to compute it many times
|
||||
* we put it into this map to emit access to that variable instead of evaluating the whole expression
|
||||
@@ -3930,12 +3928,8 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
}
|
||||
|
||||
public NameGenerator getInlineNameGenerator() {
|
||||
if (inlineNameGenerator == null) {
|
||||
CodegenContext context = getContext();
|
||||
String prefix = InlineCodegenUtil.getInlineName(context, typeMapper);
|
||||
|
||||
inlineNameGenerator = new NameGenerator(prefix + "$$inline");
|
||||
}
|
||||
return inlineNameGenerator;
|
||||
NameGenerator nameGenerator = getParentCodegen().getInlineNameGenerator();
|
||||
Name name = context.getContextDescriptor().getName();
|
||||
return nameGenerator.subGenerator((name.isSpecial() ? "$special" : name.asString()) + "$$inlined" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,20 +19,18 @@ package org.jetbrains.jet.codegen;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.asm.InlineCodegenUtil;
|
||||
import org.jetbrains.jet.codegen.asm.NameGenerator;
|
||||
import org.jetbrains.jet.codegen.context.ClassContext;
|
||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||
import org.jetbrains.jet.codegen.context.FieldOwnerContext;
|
||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class MemberCodegen extends ParentCodegenAwareImpl {
|
||||
|
||||
@@ -40,14 +38,13 @@ public class MemberCodegen extends ParentCodegenAwareImpl {
|
||||
|
||||
private final ClassBuilder builder;
|
||||
|
||||
@NotNull
|
||||
private Map<FunctionDescriptor, ClosureCodegen> inlinedClosures = new HashMap<FunctionDescriptor, ClosureCodegen>();
|
||||
private NameGenerator inlineNameGenerator;
|
||||
|
||||
public MemberCodegen(
|
||||
@NotNull GenerationState state,
|
||||
@Nullable MemberCodegen parentCodegen,
|
||||
FieldOwnerContext context,
|
||||
ClassBuilder builder
|
||||
@NotNull FieldOwnerContext context,
|
||||
@Nullable ClassBuilder builder
|
||||
) {
|
||||
super(state, parentCodegen);
|
||||
this.context = context;
|
||||
@@ -138,4 +135,13 @@ public class MemberCodegen extends ParentCodegenAwareImpl {
|
||||
public ClassBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
public NameGenerator getInlineNameGenerator() {
|
||||
if (inlineNameGenerator == null) {
|
||||
String prefix = InlineCodegenUtil.getInlineName(context, typeMapper);
|
||||
|
||||
inlineNameGenerator = new NameGenerator(prefix);
|
||||
}
|
||||
return inlineNameGenerator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,24 +139,24 @@ public class InlineCodegenUtil {
|
||||
if (currentDescriptor instanceof PackageFragmentDescriptor) {
|
||||
file = getContainingFile(codegenContext, typeMapper);
|
||||
|
||||
Type packageFragmentType = null;
|
||||
Type packagePartType;
|
||||
if (file == null) {
|
||||
//in case package fragment clinit
|
||||
if (codegenContext.getParentContext() instanceof PackageContext) {
|
||||
packageFragmentType = ((PackageContext) codegenContext.getParentContext()).getPackagePartType();
|
||||
}
|
||||
assert codegenContext instanceof PackageContext : "Expected package context but " + codegenContext;
|
||||
packagePartType = ((PackageContext) codegenContext).getPackagePartType();
|
||||
} else {
|
||||
packageFragmentType =
|
||||
packagePartType =
|
||||
PackageCodegen.getPackagePartType(PackageClassUtils.getPackageClassFqName(getFqName(currentDescriptor).toSafe()),
|
||||
file.getVirtualFile());
|
||||
}
|
||||
|
||||
if (packageFragmentType == null) {
|
||||
if (packagePartType == null) {
|
||||
DeclarationDescriptor contextDescriptor = codegenContext.getContextDescriptor();
|
||||
//noinspection ConstantConditions
|
||||
throw new RuntimeException("Couldn't find declaration for " + contextDescriptor.getContainingDeclaration().getName() + "." + contextDescriptor.getName() );
|
||||
}
|
||||
|
||||
return packageFragmentType.getInternalName().replace('.', '/');
|
||||
return packagePartType.getInternalName().replace('.', '/');
|
||||
}
|
||||
else if (currentDescriptor instanceof ClassifierDescriptor) {
|
||||
Type type = typeMapper.mapType((ClassifierDescriptor) currentDescriptor);
|
||||
@@ -170,10 +170,9 @@ public class InlineCodegenUtil {
|
||||
}
|
||||
}
|
||||
|
||||
assert currentDescriptor != null : "Wrong descriptor hierarchy " + currentDescriptor;
|
||||
|
||||
String suffix = currentDescriptor.getName().isSpecial() ? "" : currentDescriptor.getName().asString();
|
||||
|
||||
//noinspection ConstantConditions
|
||||
return getInlineName(codegenContext, currentDescriptor.getContainingDeclaration(), typeMapper) + "$" + suffix;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,17 @@
|
||||
|
||||
package org.jetbrains.jet.codegen.asm;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class NameGenerator {
|
||||
|
||||
private final String ownerMethod;
|
||||
|
||||
private int nextIndex = 1;
|
||||
|
||||
private final Map<String, NameGenerator> subGenerators = new HashMap<String, NameGenerator>();
|
||||
|
||||
public NameGenerator(String onwerMethod) {
|
||||
this.ownerMethod = onwerMethod;
|
||||
}
|
||||
@@ -31,6 +36,11 @@ public class NameGenerator {
|
||||
}
|
||||
|
||||
public NameGenerator subGenerator(String inliningMethod) {
|
||||
return new NameGenerator(ownerMethod+ "$" + inliningMethod + nextIndex++);
|
||||
NameGenerator generator = subGenerators.get(inliningMethod);
|
||||
if (generator == null) {
|
||||
generator = new NameGenerator(ownerMethod+ "$" + inliningMethod);
|
||||
subGenerators.put(inliningMethod, generator);
|
||||
}
|
||||
return generator;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user