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
?: throw AssertionError("File part $file of $facadeFqName: no package fragment")
val partClassFqName = file.getFileClassFqName()
val partInitializerClassFqName = FqName(partClassFqName.asString() + "__Init")
val partType = partClassFqName.toAsmType()
val partInitializerType = partInitializerClassFqName.toAsmType()
val partContext = state.rootContext.intoMultifileClassPart(packageFragment, facadeClassType, partType, partInitializerType, file)
val partType = file.getFileClassFqName().toAsmType()
val partContext = state.rootContext.intoMultifileClassPart(packageFragment, facadeClassType, partType, file)
generateNonPartClassDeclarations(file, partContext)
@@ -370,9 +370,7 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid {
@NotNull
private MutableClosure recordClosure(@NotNull ClassDescriptor classDescriptor, @NotNull String name) {
return CodegenBinding.recordClosure(
bindingTrace, classDescriptor, peekFromStack(classStack), Type.getObjectType(name), fileClassesProvider
);
return CodegenBinding.recordClosure(bindingTrace, classDescriptor, peekFromStack(classStack), Type.getObjectType(name));
}
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.when.WhenByEnumsMapping;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.*;
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, 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();
@@ -150,8 +149,7 @@ public class CodegenBinding {
@NotNull BindingTrace trace,
@NotNull ClassDescriptor classDescriptor,
@Nullable ClassDescriptor enclosing,
@NotNull Type asmType,
@NotNull JvmFileClassesProvider fileClassesManager
@NotNull Type asmType
) {
KtElement element = (KtElement) DescriptorToSourceUtils.descriptorToDeclaration(classDescriptor);
assert element != null : "No source element for " + classDescriptor;
@@ -227,32 +225,6 @@ public class CodegenBinding {
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
public static VariableDescriptor getDelegatedLocalVariableMetadata(
@NotNull VariableDescriptor variableDescriptor,
@@ -248,10 +248,9 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
@NotNull PackageFragmentDescriptor descriptor,
@NotNull Type multifileClassType,
@NotNull Type filePartType,
@NotNull Type filePartInitializerType,
@NotNull KtFile sourceFile
) {
return new MultifileClassPartContext(descriptor, this, multifileClassType, filePartType, filePartInitializerType, sourceFile);
return new MultifileClassPartContext(descriptor, this, multifileClassType, filePartType, sourceFile);
}
@NotNull
@@ -24,19 +24,16 @@ import org.jetbrains.org.objectweb.asm.Type;
public class MultifileClassPartContext extends MultifileClassContextBase implements DelegatingToPartContext, FacadePartWithSourceFile {
private final KtFile sourceFile;
private final Type partInitializerType;
public MultifileClassPartContext(
PackageFragmentDescriptor descriptor,
CodegenContext parent,
Type multifileClassType,
Type filePartType,
Type partInitializerType,
@NotNull KtFile sourceFile
) {
super(descriptor, parent, multifileClassType, filePartType);
this.sourceFile = sourceFile;
this.partInitializerType = partInitializerType;
}
@Nullable
@@ -45,11 +42,6 @@ public class MultifileClassPartContext extends MultifileClassContextBase impleme
return getFilePartType();
}
@NotNull
public Type getPartInitializerType() {
return partInitializerType;
}
@NotNull
@Override
public KtFile getSourceFile() {
@@ -21,7 +21,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
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.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 {
BasicWritableSlice.initSliceDebugNames(JvmSerializationBindings.class);
}
@@ -65,16 +57,8 @@ public final class JvmSerializationBindings {
map.put(slice, key, value);
}
public <K> void put(@NotNull SerializationMappingSetSlice<K> slice, @NotNull K key) {
map.put(slice, key, true);
}
@Nullable
public <K, V> V get(@NotNull SerializationMappingSlice<K, V> slice, @NotNull K 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);
}