From 372bf17982155b18015a9bb6d3242b7695f2b39c Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 6 May 2014 23:20:12 +0400 Subject: [PATCH] Remove BindingTraceAware, TypeMapperAware, BindingContextAware - delete suspicious caching logic from CodegenBinding.getAsmType(), which makes JetTypeMapper now depend only on BindingContext - inline all of these classes into GenerationStateAware and the latter into JetTypeMapper --- .../codegen/ImplementationBodyCodegen.java | 4 +-- .../codegen/binding/BindingContextAware.java | 33 ------------------- .../codegen/binding/BindingTraceAware.java | 33 ------------------- .../binding/CodegenAnnotatingVisitor.java | 5 ++- .../jet/codegen/binding/CodegenBinding.java | 22 ++++++------- .../codegen/binding/PsiCodegenPredictor.java | 4 +-- .../jet/codegen/context/CodegenContext.java | 5 +-- .../jet/codegen/state/GenerationState.java | 2 +- .../codegen/state/GenerationStateAware.java | 13 +++++--- .../jet/codegen/state/JetTypeMapper.java | 21 +++++++----- .../jet/codegen/state/TypeMapperAware.java | 33 ------------------- 11 files changed, 41 insertions(+), 134 deletions(-) delete mode 100644 compiler/backend/src/org/jetbrains/jet/codegen/binding/BindingContextAware.java delete mode 100644 compiler/backend/src/org/jetbrains/jet/codegen/binding/BindingTraceAware.java delete mode 100644 compiler/backend/src/org/jetbrains/jet/codegen/state/TypeMapperAware.java diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 5255018cd2c..67b2142b1ee 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -245,8 +245,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { boolean isLocalOrAnonymousClass = isObjectLiteral || !(parentDescriptor instanceof PackageFragmentDescriptor || parentDescriptor instanceof ClassDescriptor); - // Do not emit enclosing method in "light-classes mode" since currently we genenerate local light classes as if they're top level - if (isLocalOrAnonymousClass && getState().getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES) { + // Do not emit enclosing method in "light-classes mode" since currently we generate local light classes as if they're top level + if (isLocalOrAnonymousClass && state.getClassBuilderMode() != ClassBuilderMode.LIGHT_CLASSES) { String outerClassName = getOuterClassName(descriptor, typeMapper); FunctionDescriptor function = DescriptorUtils.getParentOfType(descriptor, FunctionDescriptor.class); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/BindingContextAware.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/BindingContextAware.java deleted file mode 100644 index 36560f1a6f9..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/BindingContextAware.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2010-2013 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.jet.codegen.binding; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.resolve.BindingContext; - -public class BindingContextAware { - @NotNull protected final BindingContext bindingContext; - - public BindingContextAware(@NotNull BindingContext context) { - bindingContext = context; - } - - @NotNull - public final BindingContext getBindingContext() { - return bindingContext; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/BindingTraceAware.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/BindingTraceAware.java deleted file mode 100644 index c1efaa61844..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/BindingTraceAware.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2010-2013 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.jet.codegen.binding; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.resolve.BindingTrace; - -public class BindingTraceAware extends BindingContextAware { - @NotNull protected final BindingTrace bindingTrace; - - public BindingTraceAware(@NotNull BindingTrace bindingTrace) { - super(bindingTrace.getBindingContext()); - this.bindingTrace = bindingTrace; - } - - @NotNull public final BindingTrace getBindingTrace() { - return bindingTrace; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java index 67ae06229ad..383718adfb9 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenAnnotatingVisitor.java @@ -172,7 +172,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid { } else { Type asmType = bindingTrace.get(ASM_TYPE, getOuterClassDescriptor()); - assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace, descriptor, asmType); + assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingContext, descriptor, asmType); bindingTrace.record(ASM_TYPE, descriptor, asmType); } } @@ -338,8 +338,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid { @NotNull ClassDescriptor classDescriptor, @NotNull String name ) { - CodegenBinding.recordClosure(bindingTrace, element, classDescriptor, getOuterClassDescriptor(), - Type.getObjectType(name)); + CodegenBinding.recordClosure(bindingTrace, element, classDescriptor, getOuterClassDescriptor(), Type.getObjectType(name)); } @Override diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java index d0a0f1461bd..44a965b651b 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/CodegenBinding.java @@ -171,11 +171,11 @@ public class CodegenBinding { } static void recordClosure( - BindingTrace bindingTrace, + @NotNull BindingTrace bindingTrace, @Nullable JetElement element, - ClassDescriptor classDescriptor, + @NotNull ClassDescriptor classDescriptor, @Nullable ClassDescriptor enclosing, - Type asmType + @NotNull Type asmType ) { JetDelegatorToSuperCall superCall = findSuperCall(bindingTrace.getBindingContext(), element); @@ -193,7 +193,7 @@ public class CodegenBinding { MutableClosure closure = new MutableClosure(superCall, enclosing, enclosingReceiver); - assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace, classDescriptor, asmType); + assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace.getBindingContext(), classDescriptor, asmType); bindingTrace.record(ASM_TYPE, classDescriptor, asmType); bindingTrace.record(CLOSURE, classDescriptor, closure); @@ -284,22 +284,20 @@ public class CodegenBinding { } @NotNull - public static Type getAsmType(@NotNull BindingTrace bindingTrace, @NotNull ClassDescriptor klass) { + public static Type getAsmType(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor klass) { klass = (ClassDescriptor) klass.getOriginal(); - Type alreadyComputedType = bindingTrace.getBindingContext().get(ASM_TYPE, klass); + Type alreadyComputedType = bindingContext.get(ASM_TYPE, klass); if (alreadyComputedType != null) { return alreadyComputedType; } - Type asmType = Type.getObjectType(getAsmTypeImpl(bindingTrace, klass)); - - assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingTrace, klass, asmType); - bindingTrace.record(ASM_TYPE, klass, asmType); + Type asmType = Type.getObjectType(getAsmTypeImpl(bindingContext, klass)); + assert PsiCodegenPredictor.checkPredictedNameFromPsi(bindingContext, klass, asmType); return asmType; } @NotNull - private static String getAsmTypeImpl(@NotNull BindingTrace bindingTrace, @NotNull ClassDescriptor klass) { + private static String getAsmTypeImpl(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor klass) { DeclarationDescriptor container = klass.getContainingDeclaration(); if (container instanceof PackageFragmentDescriptor) { @@ -310,7 +308,7 @@ public class CodegenBinding { assert container instanceof ClassDescriptor : "Unexpected container: " + container + " for " + klass; - String containerInternalName = getAsmType(bindingTrace, (ClassDescriptor) container).getInternalName(); + String containerInternalName = getAsmType(bindingContext, (ClassDescriptor) container).getInternalName(); if (klass.getKind() == ClassKind.OBJECT || klass.getKind() == ClassKind.CLASS_OBJECT) { if (isEnumClass(container)) { return containerInternalName; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/binding/PsiCodegenPredictor.java b/compiler/backend/src/org/jetbrains/jet/codegen/binding/PsiCodegenPredictor.java index bb415082c6b..fd7690d99d7 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/binding/PsiCodegenPredictor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/binding/PsiCodegenPredictor.java @@ -47,9 +47,9 @@ public final class PsiCodegenPredictor { } public static boolean checkPredictedNameFromPsi( - @NotNull BindingTrace bindingTrace, @NotNull DeclarationDescriptor descriptor, @Nullable Type nameFromDescriptors + @NotNull BindingContext bindingContext, @NotNull DeclarationDescriptor descriptor, @Nullable Type nameFromDescriptors ) { - PsiElement element = descriptorToDeclaration(bindingTrace.getBindingContext(), descriptor); + PsiElement element = descriptorToDeclaration(bindingContext, descriptor); if (element instanceof JetDeclaration) { String classNameFromPsi = getPredefinedJvmInternalName((JetDeclaration) element); assert classNameFromPsi == null || Type.getObjectType(classNameFromPsi).equals(nameFromDescriptors) : diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java index 9af831cd3be..5bf5c1b5a18 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/context/CodegenContext.java @@ -304,10 +304,11 @@ public abstract class CodegenContext { lazyOuterExpression = LockBasedStorageManager.NO_LOCKS.createNullableLazyValue(new Function0() { @Override public StackValue invoke() { + BindingContext bindingContext = typeMapper.getBindingContext(); ClassDescriptor enclosingClass = getEnclosingClass(); - return enclosingClass != null && canHaveOuter(typeMapper.getBindingContext(), classDescriptor) + return enclosingClass != null && canHaveOuter(bindingContext, classDescriptor) ? StackValue.field(typeMapper.mapType(enclosingClass), - CodegenBinding.getAsmType(typeMapper.getBindingTrace(), classDescriptor), + CodegenBinding.getAsmType(bindingContext, classDescriptor), CAPTURED_THIS_FIELD, false) : null; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java index c291034c92f..01722da13b9 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationState.java @@ -130,7 +130,7 @@ public class GenerationState { this.bindingTrace = new DelegatingBindingTrace(bindingContext, "trace in GenerationState"); this.bindingContext = bindingTrace.getBindingContext(); - this.typeMapper = new JetTypeMapper(bindingTrace, classBuilderMode); + this.typeMapper = new JetTypeMapper(this.bindingContext, classBuilderMode); this.intrinsics = new IntrinsicMethods(); this.classFileFactory = new ClassFileFactory(this); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationStateAware.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationStateAware.java index 4370991818a..34d163d5781 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationStateAware.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/GenerationStateAware.java @@ -17,16 +17,21 @@ package org.jetbrains.jet.codegen.state; import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.resolve.BindingContext; -public class GenerationStateAware extends TypeMapperAware { - @NotNull protected final GenerationState state; +public class GenerationStateAware { + protected final GenerationState state; + protected final JetTypeMapper typeMapper; + protected final BindingContext bindingContext; public GenerationStateAware(@NotNull GenerationState state) { - super(state.getTypeMapper()); this.state = state; + this.typeMapper = state.getTypeMapper(); + this.bindingContext = state.getBindingContext(); } - @NotNull public GenerationState getState() { + @NotNull + public GenerationState getState() { return state; } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java index 17efbc4007b..b21424be566 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java @@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.codegen.*; -import org.jetbrains.jet.codegen.binding.BindingTraceAware; import org.jetbrains.jet.codegen.binding.CalculatedClosure; import org.jetbrains.jet.codegen.binding.CodegenBinding; import org.jetbrains.jet.codegen.context.CodegenContext; @@ -36,7 +35,6 @@ import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContextUtils; -import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; import org.jetbrains.jet.lang.resolve.java.JvmAbi; @@ -59,13 +57,18 @@ import static org.jetbrains.jet.lang.resolve.BindingContextUtils.isVarCapturedIn import static org.jetbrains.jet.lang.resolve.DescriptorUtils.*; import static org.jetbrains.org.objectweb.asm.Opcodes.*; -public class JetTypeMapper extends BindingTraceAware { - +public class JetTypeMapper { + private final BindingContext bindingContext; private final ClassBuilderMode classBuilderMode; - public JetTypeMapper(BindingTrace bindingTrace, ClassBuilderMode mode) { - super(bindingTrace); - classBuilderMode = mode; + public JetTypeMapper(@NotNull BindingContext bindingContext, @NotNull ClassBuilderMode classBuilderMode) { + this.bindingContext = bindingContext; + this.classBuilderMode = classBuilderMode; + } + + @NotNull + public BindingContext getBindingContext() { + return bindingContext; } private enum JetTypeMapperMode { @@ -267,7 +270,7 @@ public class JetTypeMapper extends BindingTraceAware { } if (descriptor instanceof ClassDescriptor) { - Type asmType = getAsmType(bindingTrace, (ClassDescriptor) descriptor); + Type asmType = getAsmType(bindingContext, (ClassDescriptor) descriptor); writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed); return asmType; } @@ -286,7 +289,7 @@ public class JetTypeMapper extends BindingTraceAware { @NotNull public Type mapTraitImpl(@NotNull ClassDescriptor descriptor) { - return Type.getObjectType(getAsmType(bindingTrace, descriptor).getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX); + return Type.getObjectType(getAsmType(bindingContext, descriptor).getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX); } @NotNull diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/TypeMapperAware.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/TypeMapperAware.java deleted file mode 100644 index 73a5146a3e3..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/TypeMapperAware.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2010-2013 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.jet.codegen.state; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.codegen.binding.BindingTraceAware; - -public class TypeMapperAware extends BindingTraceAware { - @NotNull protected final JetTypeMapper typeMapper; - - public TypeMapperAware(@NotNull JetTypeMapper typeMapper) { - super(typeMapper.getBindingTrace()); - this.typeMapper = typeMapper; - } - - @NotNull public JetTypeMapper getTypeMapper() { - return typeMapper; - } -}