Remove unused and obsolete code in JVM backend

This commit is contained in:
Alexander Udalov
2017-06-08 22:02:55 +03:00
parent 728de91140
commit 9344f7f42f
7 changed files with 10 additions and 102 deletions
@@ -205,11 +205,8 @@ class MultifileClassCodegenImpl(
val packageFragment = this.packageFragment val packageFragment = this.packageFragment
?: throw AssertionError("File part $file of $facadeFqName: no package fragment") ?: throw AssertionError("File part $file of $facadeFqName: no package fragment")
val partClassFqName = file.getFileClassFqName() val partType = file.getFileClassFqName().toAsmType()
val partInitializerClassFqName = FqName(partClassFqName.asString() + "__Init") val partContext = state.rootContext.intoMultifileClassPart(packageFragment, facadeClassType, partType, file)
val partType = partClassFqName.toAsmType()
val partInitializerType = partInitializerClassFqName.toAsmType()
val partContext = state.rootContext.intoMultifileClassPart(packageFragment, facadeClassType, partType, partInitializerType, file)
generateNonPartClassDeclarations(file, partContext) generateNonPartClassDeclarations(file, partContext)
@@ -370,9 +370,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
@NotNull @NotNull
private MutableClosure recordClosure(@NotNull ClassDescriptor classDescriptor, @NotNull String name) { private MutableClosure recordClosure(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
return CodegenBinding.recordClosure( return CodegenBinding.recordClosure(bindingTrace, classDescriptor, peekFromStack(classStack), Type.getObjectType(name));
bindingTrace, classDescriptor, peekFromStack(classStack), Type.getObjectType(name), fileClassesProvider
);
} }
private void recordLocalVariablePropertyMetadata(LocalVariableDescriptor variableDescriptor) { private void recordLocalVariablePropertyMetadata(LocalVariableDescriptor variableDescriptor) {
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.codegen.SamType;
import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.codegen.when.WhenByEnumsMapping; import org.jetbrains.kotlin.codegen.when.WhenByEnumsMapping;
import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider;
import org.jetbrains.kotlin.name.FqName; import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt; import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
@@ -49,7 +48,7 @@ public class CodegenBinding {
public static final WritableSlice<ClassDescriptor, Boolean> ENUM_ENTRY_CLASS_NEED_SUBCLASS = Slices.createSimpleSetSlice(); public static final WritableSlice<ClassDescriptor, Boolean> ENUM_ENTRY_CLASS_NEED_SUBCLASS = Slices.createSimpleSetSlice();
public static final WritableSlice<ClassDescriptor, Collection<ClassDescriptor>> INNER_CLASSES = Slices.createSimpleSlice(); private static final WritableSlice<ClassDescriptor, Collection<ClassDescriptor>> INNER_CLASSES = Slices.createSimpleSlice();
public static final WritableSlice<KtExpression, SamType> SAM_VALUE = Slices.createSimpleSlice(); public static final WritableSlice<KtExpression, SamType> SAM_VALUE = Slices.createSimpleSlice();
@@ -150,8 +149,7 @@ public class CodegenBinding {
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull ClassDescriptor classDescriptor, @NotNull ClassDescriptor classDescriptor,
@Nullable ClassDescriptor enclosing, @Nullable ClassDescriptor enclosing,
@NotNull Type asmType, @NotNull Type asmType
@NotNull JvmFileClassesProvider fileClassesManager
) { ) {
KtElement element = (KtElement) DescriptorToSourceUtils.descriptorToDeclaration(classDescriptor); KtElement element = (KtElement) DescriptorToSourceUtils.descriptorToDeclaration(classDescriptor);
assert element != null : "No source element for " + classDescriptor; assert element != null : "No source element for " + classDescriptor;
@@ -227,32 +225,6 @@ public class CodegenBinding {
return type; return type;
} }
@NotNull
public static Collection<ClassDescriptor> getAllInnerClasses(
@NotNull BindingContext bindingContext, @NotNull ClassDescriptor outermostClass
) {
Collection<ClassDescriptor> innerClasses = bindingContext.get(INNER_CLASSES, outermostClass);
if (innerClasses == null || innerClasses.isEmpty()) return Collections.emptySet();
Set<ClassDescriptor> allInnerClasses = new HashSet<>();
Deque<ClassDescriptor> stack = new ArrayDeque<>(innerClasses);
do {
ClassDescriptor currentClass = stack.pop();
if (allInnerClasses.add(currentClass)) {
Collection<ClassDescriptor> nextClasses = bindingContext.get(INNER_CLASSES, currentClass);
if (nextClasses != null) {
for (ClassDescriptor nextClass : nextClasses) {
stack.push(nextClass);
}
}
}
}
while (!stack.isEmpty());
return allInnerClasses;
}
@NotNull @NotNull
public static VariableDescriptor getDelegatedLocalVariableMetadata( public static VariableDescriptor getDelegatedLocalVariableMetadata(
@NotNull VariableDescriptor variableDescriptor, @NotNull VariableDescriptor variableDescriptor,
@@ -248,10 +248,9 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
@NotNull PackageFragmentDescriptor descriptor, @NotNull PackageFragmentDescriptor descriptor,
@NotNull Type multifileClassType, @NotNull Type multifileClassType,
@NotNull Type filePartType, @NotNull Type filePartType,
@NotNull Type filePartInitializerType,
@NotNull KtFile sourceFile @NotNull KtFile sourceFile
) { ) {
return new MultifileClassPartContext(descriptor, this, multifileClassType, filePartType, filePartInitializerType, sourceFile); return new MultifileClassPartContext(descriptor, this, multifileClassType, filePartType, sourceFile);
} }
@NotNull @NotNull
@@ -24,19 +24,16 @@ import org.jetbrains.org.objectweb.asm.Type;
public class MultifileClassPartContext extends MultifileClassContextBase implements DelegatingToPartContext, FacadePartWithSourceFile { public class MultifileClassPartContext extends MultifileClassContextBase implements DelegatingToPartContext, FacadePartWithSourceFile {
private final KtFile sourceFile; private final KtFile sourceFile;
private final Type partInitializerType;
public MultifileClassPartContext( public MultifileClassPartContext(
PackageFragmentDescriptor descriptor, PackageFragmentDescriptor descriptor,
CodegenContext parent, CodegenContext parent,
Type multifileClassType, Type multifileClassType,
Type filePartType, Type filePartType,
Type partInitializerType,
@NotNull KtFile sourceFile @NotNull KtFile sourceFile
) { ) {
super(descriptor, parent, multifileClassType, filePartType); super(descriptor, parent, multifileClassType, filePartType);
this.sourceFile = sourceFile; this.sourceFile = sourceFile;
this.partInitializerType = partInitializerType;
} }
@Nullable @Nullable
@@ -45,11 +42,6 @@ public class MultifileClassPartContext extends MultifileClassContextBase impleme
return getFilePartType(); return getFilePartType();
} }
@NotNull
public Type getPartInitializerType() {
return partInitializerType;
}
@NotNull @NotNull
@Override @Override
public KtFile getSourceFile() { public KtFile getSourceFile() {
@@ -21,7 +21,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor; import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
import org.jetbrains.kotlin.descriptors.PropertyDescriptor; import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
import org.jetbrains.kotlin.util.slicedMap.*; import org.jetbrains.kotlin.util.slicedMap.BasicWritableSlice;
import org.jetbrains.kotlin.util.slicedMap.MutableSlicedMap;
import org.jetbrains.kotlin.util.slicedMap.SlicedMapImpl;
import org.jetbrains.kotlin.util.slicedMap.Slices;
import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.Method; import org.jetbrains.org.objectweb.asm.commons.Method;
@@ -44,17 +47,6 @@ public final class JvmSerializationBindings {
} }
} }
private static final class SerializationMappingSetSlice<K> extends SetSlice<K> {
public SerializationMappingSetSlice() {
super(Slices.ONLY_REWRITE_TO_EQUAL, false);
}
@NotNull
public static <K> SerializationMappingSetSlice<K> create() {
return new SerializationMappingSetSlice<>();
}
}
static { static {
BasicWritableSlice.initSliceDebugNames(JvmSerializationBindings.class); BasicWritableSlice.initSliceDebugNames(JvmSerializationBindings.class);
} }
@@ -65,16 +57,8 @@ public final class JvmSerializationBindings {
map.put(slice, key, value); map.put(slice, key, value);
} }
public <K> void put(@NotNull SerializationMappingSetSlice<K> slice, @NotNull K key) {
map.put(slice, key, true);
}
@Nullable @Nullable
public <K, V> V get(@NotNull SerializationMappingSlice<K, V> slice, @NotNull K key) { public <K, V> V get(@NotNull SerializationMappingSlice<K, V> slice, @NotNull K key) {
return map.get(slice, key); return map.get(slice, key);
} }
public <K> boolean get(@NotNull SerializationMappingSetSlice<K> slice, @NotNull K key) {
return Boolean.TRUE.equals(map.get(slice, key));
}
} }
@@ -1,34 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.codegen.state;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Collection;
public interface Progress {
Progress DEAF = (sourceFiles, outputFile) -> {
};
/**
* @param sourceFiles a (possibly empty) collection of source files {@code outputFile} was generated from
* @param outputFile an output file
*/
void reportOutput(@NotNull Collection<File> sourceFiles, @Nullable File outputFile);
}