Remove dependency of module 'backend' on 'backend.jvm' and 'ir.tree'

This breaks the circular dependency between 'backend' and 'backend.jvm'
This commit is contained in:
Alexander Udalov
2017-06-03 15:45:06 +03:00
parent cf04157ec8
commit e6001f57fa
21 changed files with 98 additions and 53 deletions
-2
View File
@@ -12,7 +12,5 @@
<orderEntry type="module" module-name="serialization" />
<orderEntry type="module" module-name="backend-common" exported="" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="backend.jvm" />
<orderEntry type="module" module-name="ir.tree" />
</component>
</module>
@@ -0,0 +1,36 @@
/*
* 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
import org.jetbrains.kotlin.codegen.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
enum class OwnerKind {
PACKAGE,
IMPLEMENTATION,
DEFAULT_IMPLS;
companion object {
fun getMemberOwnerKind(descriptor: DeclarationDescriptor): OwnerKind = when (descriptor) {
is FileClassDescriptor, is PackageFragmentDescriptor -> OwnerKind.PACKAGE
is ClassDescriptor -> OwnerKind.IMPLEMENTATION
else -> throw AssertionError("Unexpected declaration container: $this")
}
}
}
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2017 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.descriptors
import org.jetbrains.kotlin.descriptors.ClassDescriptor
interface FileClassDescriptor : ClassDescriptor
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.codegen.inline
import org.jetbrains.kotlin.backend.jvm.codegen.getMemberOwnerKind
import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.codegen.OwnerKind
import org.jetbrains.kotlin.codegen.inline.InlineCodegenUtil.DEFAULT_LAMBDA_FAKE_CALL
@@ -48,12 +47,9 @@ private data class Condition(
fun extractDefaultLambdaOffsetAndDescriptor(jvmSignature: JvmMethodSignature, functionDescriptor: FunctionDescriptor): Map<Int, ValueParameterDescriptor> {
val valueParameters = jvmSignature.valueParameters
val containingDeclaration = functionDescriptor.containingDeclaration
val kind = containingDeclaration.getMemberOwnerKind().let {
if (DescriptorUtils.isInterface(containingDeclaration)) {
OwnerKind.DEFAULT_IMPLS
}
else it
}
val kind =
if (DescriptorUtils.isInterface(containingDeclaration)) OwnerKind.DEFAULT_IMPLS
else OwnerKind.getMemberOwnerKind(containingDeclaration)
val parameterOffsets = parameterOffsets(AsmUtil.isStaticMethod(kind, functionDescriptor), valueParameters)
val valueParameterOffset = valueParameters.takeWhile { it.kind != JvmMethodParameterKind.VALUE }.size
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.codegen.state
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.ModificationTracker
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
import org.jetbrains.kotlin.codegen.*
import org.jetbrains.kotlin.codegen.`when`.MappingsClassesForWhenByEnum
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
@@ -56,6 +55,7 @@ class GenerationState @JvmOverloads constructor(
val files: List<KtFile>,
val configuration: CompilerConfiguration,
val generateDeclaredClassFilter: GenerateClassFilter = GenerationState.GenerateClassFilter.GENERATE_ALL,
val codegenFactory: CodegenFactory = DefaultCodegenFactory,
// For incremental compilation
val targetId: TargetId? = null,
moduleName: String? = configuration.get(CommonConfigurationKeys.MODULE_NAME),
@@ -64,7 +64,6 @@ class GenerationState @JvmOverloads constructor(
// TODO: get rid of it with the proper module infrastructure
val outDirectory: File? = null,
private val onIndependentPartCompilationEnd: GenerationStateEventCallback = GenerationStateEventCallback.DO_NOTHING,
val codegenFactory: CodegenFactory = if (configuration.getBoolean(JVMConfigurationKeys.IR)) JvmIrCodegenFactory else DefaultCodegenFactory,
wantsDiagnostics: Boolean = true
) {
abstract class GenerateClassFilter {
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.codegen.signature.AsmTypeFactory;
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter;
import org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.IrBuiltinsPackageFragmentDescriptor;
import org.jetbrains.kotlin.descriptors.impl.LocalVariableAccessorDescriptor;
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor;
@@ -42,7 +43,6 @@ import org.jetbrains.kotlin.fileClasses.FileClasses;
import org.jetbrains.kotlin.fileClasses.JvmFileClassInfo;
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider;
import org.jetbrains.kotlin.ir.descriptors.IrBuiltinsPackageFragmentDescriptor;
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature;
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature.SpecialSignatureInfo;
import org.jetbrains.kotlin.load.java.JvmAbi;
@@ -236,6 +236,7 @@ public class KotlinTypeMapper {
if (facadeFqName != null) return facadeFqName;
}
// TODO: drop this usage and move IrBuiltinsPackageFragmentDescriptor to IR modules; it shouldn't be used here
if (descriptor.getContainingDeclaration() instanceof IrBuiltinsPackageFragmentDescriptor) {
return descriptor.getContainingDeclaration().getName().asString();
}
+1
View File
@@ -24,5 +24,6 @@
<orderEntry type="module" module-name="frontend.script" />
<orderEntry type="module" module-name="javac-wrapper" />
<orderEntry type="module" module-name="js.dce" />
<orderEntry type="module" module-name="backend.jvm" />
</component>
</module>
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.asJava.FilteredJvmDiagnostics
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection
import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.ExitCode
import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage
@@ -39,10 +40,7 @@ import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAll
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
import org.jetbrains.kotlin.cli.jvm.config.*
import org.jetbrains.kotlin.codegen.ClassBuilderFactories
import org.jetbrains.kotlin.codegen.CompilationErrorHandler
import org.jetbrains.kotlin.codegen.GeneratedClassLoader
import org.jetbrains.kotlin.codegen.KotlinCodegenFacade
import org.jetbrains.kotlin.codegen.*
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.codegen.state.GenerationStateEventCallback
import org.jetbrains.kotlin.config.CommonConfigurationKeys
@@ -438,6 +436,7 @@ object KotlinToJVMBytecodeCompiler {
sourceFiles,
configuration,
GenerationState.GenerateClassFilter.GENERATE_ALL,
if (configuration.getBoolean(JVMConfigurationKeys.IR)) JvmIrCodegenFactory else DefaultCodegenFactory,
module?.let(::TargetId),
module?.let(Module::getModuleName),
module?.let { File(it.getOutputDirectory()) },
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2017 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.
@@ -14,12 +14,6 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.codegen;
package org.jetbrains.kotlin.descriptors
public enum OwnerKind {
PACKAGE,
IMPLEMENTATION,
DEFAULT_IMPLS
}
interface IrBuiltinsPackageFragmentDescriptor : PackageFragmentDescriptor
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDescriptorWithExtraFlags
import org.jetbrains.kotlin.backend.jvm.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.codegen.*
import org.jetbrains.kotlin.codegen.MemberCodegen.badDescriptor
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
@@ -244,7 +243,7 @@ private fun MemberDescriptor.calcModalityFlag(): Int {
return flags
}
val MemberDescriptor.effectiveModality: Modality
private val MemberDescriptor.effectiveModality: Modality
get() {
if (this is ClassDescriptor && kind == ClassKind.ENUM_CLASS) {
if (JvmCodegenUtil.hasAbstractMembers(this)) {
@@ -260,21 +259,11 @@ val MemberDescriptor.effectiveModality: Modality
return modality
}
val DeclarationDescriptorWithSource.psiElement: PsiElement?
private val DeclarationDescriptorWithSource.psiElement: PsiElement?
get() = (source as? PsiSourceElement)?.psi
val IrField.OtherOrigin: JvmDeclarationOrigin
private val IrField.OtherOrigin: JvmDeclarationOrigin
get() = OtherOrigin(descriptor.psiElement, this.descriptor)
val IrFunction.OtherOrigin: JvmDeclarationOrigin
internal val IrFunction.OtherOrigin: JvmDeclarationOrigin
get() = OtherOrigin(descriptor.psiElement, this.descriptor)
fun DeclarationDescriptor.getMemberOwnerKind(): OwnerKind = when (this) {
is FileClassDescriptor,
is PackageFragmentDescriptor ->
OwnerKind.PACKAGE
is ClassDescriptor ->
OwnerKind.IMPLEMENTATION
else ->
throw AssertionError("Unexpected declaration container: $this")
}
@@ -53,7 +53,8 @@ class FunctionCodegen(val irFunction: IrFunction, val classCodegen: ClassCodegen
private fun doGenerate() {
val signature = classCodegen.typeMapper.mapSignatureWithGeneric(descriptor, OwnerKind.IMPLEMENTATION)
val isStatic = isStaticMethod(classCodegen.descriptor.getMemberOwnerKind(), descriptor) || DescriptorUtils.isStaticDeclaration(descriptor)
val isStatic = isStaticMethod(OwnerKind.getMemberOwnerKind(classCodegen.descriptor), descriptor) ||
DescriptorUtils.isStaticDeclaration(descriptor)
val frameMap = createFrameMapWithReceivers(classCodegen.state, descriptor, signature, isStatic)
@@ -16,13 +16,12 @@
package org.jetbrains.kotlin.backend.jvm.descriptors
import org.jetbrains.kotlin.codegen.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType
interface FileClassDescriptor : ClassDescriptor
class FileClassDescriptorImpl(
name: Name,
containingDeclaration: PackageFragmentDescriptor,
@@ -39,4 +38,4 @@ class FileClassDescriptorImpl(
}
override fun isExternal() = false
}
}
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.backend.jvm.descriptors
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.codegen.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl
@@ -17,13 +17,12 @@
package org.jetbrains.kotlin.backend.jvm.lower
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.backend.common.ClassLoweringPass
import org.jetbrains.kotlin.backend.common.bridges.Bridge
import org.jetbrains.kotlin.backend.common.bridges.findInterfaceImplementation
import org.jetbrains.kotlin.backend.common.bridges.generateBridgesForFunctionDescriptor
import org.jetbrains.kotlin.backend.common.ClassLoweringPass
import org.jetbrains.kotlin.backend.jvm.JvmLoweredStatementOrigin
import org.jetbrains.kotlin.backend.jvm.descriptors.DefaultImplsClassDescriptor
import org.jetbrains.kotlin.backend.jvm.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmFunctionDescriptorImpl
import org.jetbrains.kotlin.codegen.AsmUtil.getVisibilityAccessFlag
import org.jetbrains.kotlin.codegen.AsmUtil.isAbstractMethod
@@ -33,6 +32,7 @@ import org.jetbrains.kotlin.codegen.FunctionCodegen.isThereOverriddenInKotlinCla
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
import org.jetbrains.kotlin.codegen.JvmCodegenUtil.getDirectMember
import org.jetbrains.kotlin.codegen.OwnerKind
import org.jetbrains.kotlin.codegen.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.descriptors.*
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.backend.jvm.lower
import org.jetbrains.kotlin.backend.common.FileLoweringPass
import org.jetbrains.kotlin.backend.jvm.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.codegen.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrClass
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.backend.jvm.lower
import org.jetbrains.kotlin.backend.common.FileLoweringPass
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
import org.jetbrains.kotlin.backend.jvm.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.backend.jvm.intrinsics.receiverAndArgs
import org.jetbrains.kotlin.codegen.AccessorForCallableDescriptor
import org.jetbrains.kotlin.codegen.AccessorForPropertyDescriptor
@@ -26,6 +25,7 @@ import org.jetbrains.kotlin.codegen.JvmCodegenUtil
import org.jetbrains.kotlin.codegen.OwnerKind
import org.jetbrains.kotlin.codegen.context.ClassContext
import org.jetbrains.kotlin.codegen.context.CodegenContext
import org.jetbrains.kotlin.codegen.descriptors.FileClassDescriptor
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.descriptors.*
@@ -16,14 +16,16 @@
package org.jetbrains.kotlin.ir.descriptors
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorVisitor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.IrBuiltinsPackageFragmentDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.scopes.MemberScope
interface IrBuiltinsPackageFragmentDescriptor : PackageFragmentDescriptor
class IrBuiltinsPackageFragmentDescriptorImpl(
val containingModule: ModuleDescriptor,
override val fqName: FqName
@@ -17,11 +17,13 @@
package org.jetbrains.kotlin.codegen
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.descriptors.PackagePartProvider
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.AnalyzingUtils
@@ -64,7 +66,8 @@ object GenerationUtils {
val state = GenerationState(
files.first().project, classBuilderFactory, analysisResult.moduleDescriptor, analysisResult.bindingContext,
files, configuration
files, configuration,
codegenFactory = if (configuration.getBoolean(JVMConfigurationKeys.IR)) JvmIrCodegenFactory else DefaultCodegenFactory
)
if (analysisResult.shouldGenerateCode) {
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION)
+1
View File
@@ -30,5 +30,6 @@
<orderEntry type="library" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" name="intellij-core" level="project" />
<orderEntry type="library" name="idea-full" level="project" />
<orderEntry type="module" module-name="backend.jvm" />
</component>
</module>
+1
View File
@@ -67,5 +67,6 @@
<orderEntry type="library" name="kotlinx-coroutines-core" level="project" />
<orderEntry type="module" module-name="frontend.script" />
<orderEntry type="module" module-name="idea-maven" />
<orderEntry type="module" module-name="backend.jvm" />
</component>
</module>
@@ -37,8 +37,10 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.java.decompiler.IdeaLogger;
import org.jetbrains.kotlin.backend.common.output.OutputFile;
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection;
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory;
import org.jetbrains.kotlin.codegen.ClassBuilderFactories;
import org.jetbrains.kotlin.codegen.CompilationErrorHandler;
import org.jetbrains.kotlin.codegen.DefaultCodegenFactory;
import org.jetbrains.kotlin.codegen.KotlinCodegenFacade;
import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.config.*;
@@ -325,7 +327,8 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
GenerationState state = new GenerationState(
ktFile.getProject(), ClassBuilderFactories.TEST, resolutionFacade.getModuleDescriptor(), bindingContext, toProcess,
configuration, generateClassFilter
configuration, generateClassFilter,
configuration.getBoolean(JVMConfigurationKeys.IR) ? JvmIrCodegenFactory.INSTANCE : DefaultCodegenFactory.INSTANCE
);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);