Do not use IR_EXTERNAL_JAVA_DECLARATION_STUB in DeclarationStubGenerator

This code is common across backends and it should not depend on
JVM-specific behavior. Introduce GeneratorExtensions to reverse the
dependency here
This commit is contained in:
Alexander Udalov
2019-03-01 15:22:36 +01:00
parent f29012a78f
commit aaa2bad719
17 changed files with 115 additions and 74 deletions
@@ -172,7 +172,7 @@ fun compile(
val context = if (compileMode.generateKlib) { val context = if (compileMode.generateKlib) {
deserializedModuleFragments.forEach { deserializedModuleFragments.forEach {
ExternalDependenciesGenerator(it.descriptor, symbolTable, irBuiltIns, null).generateUnboundSymbolsAsDependencies(it) ExternalDependenciesGenerator(it.descriptor, symbolTable, irBuiltIns).generateUnboundSymbolsAsDependencies(it)
} }
deserializedModuleFragments.forEach { it.patchDeclarationParents() } deserializedModuleFragments.forEach { it.patchDeclarationParents() }
serializeModuleIntoKlib( serializeModuleIntoKlib(
@@ -215,7 +215,7 @@ fun compile(
it.descriptor, it.descriptor,
context.symbolTable, context.symbolTable,
context.irBuiltIns, context.irBuiltIns,
deserializer deserializer = deserializer
).generateUnboundSymbolsAsDependencies(it) ).generateUnboundSymbolsAsDependencies(it)
} }
@@ -14,10 +14,9 @@ import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
object JvmBackendFacade { object JvmBackendFacade {
fun doGenerateFiles(files: Collection<KtFile>, state: GenerationState, errorHandler: CompilationErrorHandler) { fun doGenerateFiles(files: Collection<KtFile>, state: GenerationState, errorHandler: CompilationErrorHandler) {
val psi2ir = Psi2IrTranslator(state.languageVersionSettings) val psi2ir = Psi2IrTranslator(state.languageVersionSettings)
val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext) val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext, extensions = JvmGeneratorExtensions)
val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files) val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files)
doGenerateFilesInternal(state, errorHandler, irModuleFragment, psi2irContext) doGenerateFilesInternal(state, errorHandler, irModuleFragment, psi2irContext)
@@ -36,7 +35,8 @@ object JvmBackendFacade {
ExternalDependenciesGenerator( ExternalDependenciesGenerator(
irModuleFragment.descriptor, irModuleFragment.descriptor,
psi2irContext.symbolTable, psi2irContext.symbolTable,
psi2irContext.irBuiltIns psi2irContext.irBuiltIns,
JvmGeneratorExtensions.externalDeclarationOrigin
).generateUnboundSymbolsAsDependencies(irModuleFragment) ).generateUnboundSymbolsAsDependencies(irModuleFragment)
val jvmBackend = JvmBackend(jvmBackendContext) val jvmBackend = JvmBackend(jvmBackendContext)
@@ -0,0 +1,20 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.backend.jvm
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions
object JvmGeneratorExtensions : GeneratorExtensions() {
override val externalDeclarationOrigin: ((DeclarationDescriptor) -> IrDeclarationOrigin)? = { descriptor ->
if (descriptor is JavaCallableMemberDescriptor)
IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
else
IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB
}
}
@@ -31,7 +31,7 @@ object JvmIrCodegenFactory : CodegenFactory {
assert(!files.any { it == null }) assert(!files.any { it == null })
val psi2ir = Psi2IrTranslator(state.languageVersionSettings) val psi2ir = Psi2IrTranslator(state.languageVersionSettings)
val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext) val psi2irContext = psi2ir.createGeneratorContext(state.module, state.bindingContext, extensions = JvmGeneratorExtensions)
val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files as Collection<KtFile>) val irModuleFragment = psi2ir.generateModuleFragment(psi2irContext, files as Collection<KtFile>)
JvmBackendFacade.doGenerateFilesInternal(state, errorHandler, irModuleFragment, psi2irContext) JvmBackendFacade.doGenerateFilesInternal(state, errorHandler, irModuleFragment, psi2irContext)
} }
@@ -20,13 +20,14 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.util.IrDeserializer import org.jetbrains.kotlin.ir.util.IrDeserializer
import org.jetbrains.kotlin.ir.util.SymbolTable
import org.jetbrains.kotlin.ir.util.patchDeclarationParents import org.jetbrains.kotlin.ir.util.patchDeclarationParents
import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi2ir.generators.AnnotationGenerator import org.jetbrains.kotlin.psi2ir.generators.AnnotationGenerator
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions
import org.jetbrains.kotlin.psi2ir.generators.ModuleGenerator import org.jetbrains.kotlin.psi2ir.generators.ModuleGenerator
import org.jetbrains.kotlin.psi2ir.transformations.insertImplicitCasts import org.jetbrains.kotlin.psi2ir.transformations.insertImplicitCasts
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
@@ -46,13 +47,23 @@ class Psi2IrTranslator(
postprocessingSteps.add(step) postprocessingSteps.add(step)
} }
fun generateModule(moduleDescriptor: ModuleDescriptor, ktFiles: Collection<KtFile>, bindingContext: BindingContext): IrModuleFragment { fun generateModule(
val context = createGeneratorContext(moduleDescriptor, bindingContext) moduleDescriptor: ModuleDescriptor,
ktFiles: Collection<KtFile>,
bindingContext: BindingContext,
generatorExtensions: GeneratorExtensions
): IrModuleFragment {
val context = createGeneratorContext(moduleDescriptor, bindingContext, extensions = generatorExtensions)
return generateModuleFragment(context, ktFiles) return generateModuleFragment(context, ktFiles)
} }
fun createGeneratorContext(moduleDescriptor: ModuleDescriptor, bindingContext: BindingContext, symbolTable: SymbolTable = SymbolTable()) = fun createGeneratorContext(
GeneratorContext(configuration, moduleDescriptor, bindingContext, languageVersionSettings, symbolTable) moduleDescriptor: ModuleDescriptor,
bindingContext: BindingContext,
symbolTable: SymbolTable = SymbolTable(),
extensions: GeneratorExtensions = GeneratorExtensions()
): GeneratorContext =
GeneratorContext(configuration, moduleDescriptor, bindingContext, languageVersionSettings, symbolTable, extensions)
fun generateModuleFragment(context: GeneratorContext, ktFiles: Collection<KtFile>, deserializer: IrDeserializer? = null): IrModuleFragment { fun generateModuleFragment(context: GeneratorContext, ktFiles: Collection<KtFile>, deserializer: IrDeserializer? = null): IrModuleFragment {
val moduleGenerator = ModuleGenerator(context) val moduleGenerator = ModuleGenerator(context)
@@ -35,7 +35,8 @@ class GeneratorContext(
val moduleDescriptor: ModuleDescriptor, val moduleDescriptor: ModuleDescriptor,
val bindingContext: BindingContext, val bindingContext: BindingContext,
val languageVersionSettings: LanguageVersionSettings, val languageVersionSettings: LanguageVersionSettings,
val symbolTable: SymbolTable = SymbolTable() val symbolTable: SymbolTable,
val extensions: GeneratorExtensions
) : IrGeneratorContext() { ) : IrGeneratorContext() {
val constantValueGenerator: ConstantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) val constantValueGenerator: ConstantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable)
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
open class GeneratorExtensions {
open val externalDeclarationOrigin: ((DeclarationDescriptor) -> IrDeclarationOrigin)?
get() = null
}
@@ -44,7 +44,7 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment, deserializer: IrDeserializer? = null) { fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment, deserializer: IrDeserializer? = null) {
ExternalDependenciesGenerator( ExternalDependenciesGenerator(
irModule.descriptor, context.symbolTable, context.irBuiltIns, deserializer irModule.descriptor, context.symbolTable, context.irBuiltIns, context.extensions.externalDeclarationOrigin, deserializer
).generateUnboundSymbolsAsDependencies(irModule, context.bindingContext) ).generateUnboundSymbolsAsDependencies(irModule, context.bindingContext)
} }
@@ -44,8 +44,9 @@ class IrBuiltIns(
val irBuiltInsExternalPackageFragment = IrExternalPackageFragmentImpl(IrExternalPackageFragmentSymbolImpl(packageFragment)) val irBuiltInsExternalPackageFragment = IrExternalPackageFragmentImpl(IrExternalPackageFragmentSymbolImpl(packageFragment))
private val symbolTable = outerSymbolTable ?: SymbolTable() private val symbolTable = outerSymbolTable ?: SymbolTable()
private val stubBuilder = private val stubBuilder = DeclarationStubGenerator(
DeclarationStubGenerator(builtInsModule, symbolTable, IrDeclarationOrigin.IR_BUILTINS_STUB, languageVersionSettings) builtInsModule, symbolTable, languageVersionSettings, externalDeclarationOrigin = { IrDeclarationOrigin.IR_BUILTINS_STUB }
)
private fun ClassDescriptor.toIrSymbol() = symbolTable.referenceClass(this) private fun ClassDescriptor.toIrSymbol() = symbolTable.referenceClass(this)
private fun KotlinType.toIrType() = typeTranslator.translateType(this) private fun KotlinType.toIrType() = typeTranslator.translateType(this)
@@ -21,30 +21,21 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
import org.jetbrains.kotlin.ir.declarations.lazy.* import org.jetbrains.kotlin.ir.declarations.lazy.*
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
import org.jetbrains.kotlin.ir.types.impl.IrDynamicTypeImpl
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor
import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.hasBackingField
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.isDynamic
class DeclarationStubGenerator( class DeclarationStubGenerator(
moduleDescriptor: ModuleDescriptor, moduleDescriptor: ModuleDescriptor,
val symbolTable: SymbolTable, val symbolTable: SymbolTable,
val origin: IrDeclarationOrigin, languageVersionSettings: LanguageVersionSettings,
val languageVersionSettings: LanguageVersionSettings, private val externalDeclarationOrigin: ((DeclarationDescriptor) -> IrDeclarationOrigin)? = null,
val deserializer: IrDeserializer? = null private val deserializer: IrDeserializer? = null
) { ) {
private val lazyTable = symbolTable.lazyWrapper private val lazyTable = symbolTable.lazyWrapper
internal var unboundSymbolGeneration: Boolean internal var unboundSymbolGeneration: Boolean
@@ -87,14 +78,15 @@ class DeclarationStubGenerator(
throw AssertionError("Unexpected member descriptor: $descriptor") throw AssertionError("Unexpected member descriptor: $descriptor")
} }
private fun computeOrigin(descriptor: DeclarationDescriptor): IrDeclarationOrigin =
externalDeclarationOrigin?.invoke(descriptor) ?: IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB
internal fun generatePropertyStub( internal fun generatePropertyStub(
descriptor: PropertyDescriptor, descriptor: PropertyDescriptor,
bindingContext: BindingContext? = null bindingContext: BindingContext? = null
): IrProperty = symbolTable.referenceProperty(descriptor) { ): IrProperty = symbolTable.referenceProperty(descriptor) {
deserializer?.findDeserializedDeclaration(descriptor) ?: deserializer?.findDeserializedDeclaration(descriptor) ?: IrLazyProperty(
IrLazyProperty( UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(descriptor), descriptor, this, typeTranslator, bindingContext
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor,
this, typeTranslator, bindingContext
) )
} }
@@ -107,7 +99,7 @@ class DeclarationStubGenerator(
val origin = val origin =
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE)
IrDeclarationOrigin.FAKE_OVERRIDE IrDeclarationOrigin.FAKE_OVERRIDE
else origin else computeOrigin(descriptor)
return symbolTable.declareField( return symbolTable.declareField(
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
@@ -116,8 +108,8 @@ class DeclarationStubGenerator(
descriptor.original, descriptor.original,
descriptor.type.toIrType() descriptor.type.toIrType()
) { ) {
deserializer?.findDeserializedDeclaration(referenced) as? IrField ?: deserializer?.findDeserializedDeclaration(referenced) as? IrField
IrFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, descriptor.type.toIrType()) ?: IrFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, descriptor.type.toIrType())
}.apply { }.apply {
initializer = descriptor.compileTimeInitializer?.let { initializer = descriptor.compileTimeInitializer?.let {
IrExpressionBodyImpl( IrExpressionBodyImpl(
@@ -145,17 +137,14 @@ class DeclarationStubGenerator(
val origin = val origin =
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE)
IrDeclarationOrigin.FAKE_OVERRIDE IrDeclarationOrigin.FAKE_OVERRIDE
else if (origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB && descriptor is JavaCallableMemberDescriptor) else computeOrigin(descriptor)
IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
else
origin
return symbolTable.declareSimpleFunction( return symbolTable.declareSimpleFunction(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, UNDEFINED_OFFSET, UNDEFINED_OFFSET,
origin, origin,
descriptor.original descriptor.original
) { ) {
deserializer?.findDeserializedDeclaration(referenced) as? IrSimpleFunction ?: deserializer?.findDeserializedDeclaration(referenced) as? IrSimpleFunction
IrLazyFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator) ?: IrLazyFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
} }
} }
@@ -165,11 +154,12 @@ class DeclarationStubGenerator(
return referenced.owner return referenced.owner
} }
val origin = computeOrigin(descriptor)
return symbolTable.declareConstructor( return symbolTable.declareConstructor(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original
) { ) {
deserializer?.findDeserializedDeclaration(referenced) as? IrConstructor ?: deserializer?.findDeserializedDeclaration(referenced) as? IrConstructor
IrLazyConstructor(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator) ?: IrLazyConstructor(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
} }
} }
@@ -177,17 +167,17 @@ class DeclarationStubGenerator(
internal fun generateValueParameterStub(descriptor: ValueParameterDescriptor): IrValueParameter { internal fun generateValueParameterStub(descriptor: ValueParameterDescriptor): IrValueParameter {
return IrValueParameterImpl( return IrValueParameterImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(descriptor),
descriptor, descriptor.type.toIrType(), descriptor.varargElementType?.toIrType() descriptor, descriptor.type.toIrType(), descriptor.varargElementType?.toIrType()
).also { irValueParameter -> ).also { irValueParameter ->
if (descriptor.declaresDefaultValue()) { if (descriptor.declaresDefaultValue()) {
irValueParameter.defaultValue = irValueParameter.defaultValue =
IrExpressionBodyImpl( IrExpressionBodyImpl(
IrErrorExpressionImpl( IrErrorExpressionImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, descriptor.type.toIrType(), UNDEFINED_OFFSET, UNDEFINED_OFFSET, descriptor.type.toIrType(),
"Stub expression for default value of ${descriptor.name}" "Stub expression for default value of ${descriptor.name}"
)
) )
)
} }
} }
} }
@@ -197,11 +187,12 @@ class DeclarationStubGenerator(
if (referenceClass.isBound) { if (referenceClass.isBound) {
return referenceClass.owner return referenceClass.owner
} }
val origin = computeOrigin(descriptor)
return symbolTable.declareClass( return symbolTable.declareClass(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor
) { ) {
deserializer?.findDeserializedDeclaration(referenceClass) as? IrClass ?: deserializer?.findDeserializedDeclaration(referenceClass) as? IrClass
IrLazyClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator) ?: IrLazyClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
} }
} }
@@ -210,9 +201,10 @@ class DeclarationStubGenerator(
if (referenced.isBound) { if (referenced.isBound) {
return referenced.owner return referenced.owner
} }
val origin = computeOrigin(descriptor)
return symbolTable.declareEnumEntry(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) { return symbolTable.declareEnumEntry(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
deserializer?.findDeserializedDeclaration(referenced) as? IrEnumEntry ?: deserializer?.findDeserializedDeclaration(referenced) as? IrEnumEntry
IrLazyEnumEntryImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator) ?: IrLazyEnumEntryImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
} }
} }
@@ -221,12 +213,10 @@ class DeclarationStubGenerator(
if (referenced.isBound) { if (referenced.isBound) {
return referenced.owner return referenced.owner
} }
val origin = computeOrigin(descriptor)
return symbolTable.declareGlobalTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) { return symbolTable.declareGlobalTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
deserializer?.findDeserializedDeclaration(referenced) as? IrTypeParameter ?: deserializer?.findDeserializedDeclaration(referenced) as? IrTypeParameter
IrLazyTypeParameter( ?: IrLazyTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
it, this, typeTranslator
)
} }
} }
@@ -235,11 +225,9 @@ class DeclarationStubGenerator(
if (referenced.isBound) { if (referenced.isBound) {
return referenced.owner return referenced.owner
} }
val origin = computeOrigin(descriptor)
return symbolTable.declareScopedTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) { return symbolTable.declareScopedTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
IrLazyTypeParameter( IrLazyTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
it, this, typeTranslator
)
} }
} }
} }
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.ir.util package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
@@ -26,10 +27,11 @@ class ExternalDependenciesGenerator(
moduleDescriptor: ModuleDescriptor, moduleDescriptor: ModuleDescriptor,
val symbolTable: SymbolTable, val symbolTable: SymbolTable,
val irBuiltIns: IrBuiltIns, val irBuiltIns: IrBuiltIns,
externalDeclarationOrigin: ((DeclarationDescriptor) -> IrDeclarationOrigin)? = null,
val deserializer: IrDeserializer? = null val deserializer: IrDeserializer? = null
) { ) {
private val stubGenerator = DeclarationStubGenerator( private val stubGenerator = DeclarationStubGenerator(
moduleDescriptor, symbolTable, IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB, irBuiltIns.languageVersionSettings, deserializer moduleDescriptor, symbolTable, irBuiltIns.languageVersionSettings, externalDeclarationOrigin, deserializer
) )
fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment, bindingContext: BindingContext? = null) { fun generateUnboundSymbolsAsDependencies(irModule: IrModuleFragment, bindingContext: BindingContext? = null) {
@@ -71,4 +73,4 @@ class ExternalDependenciesGenerator(
assert(symbolTable.unboundTypeParameters.isEmpty()) assert(symbolTable.unboundTypeParameters.isEmpty())
} }
} }
} }
@@ -26,7 +26,7 @@ FILE fqName:<root> fileName:/Derived.kt
PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL flags:var PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL flags:var
FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public flags: FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public flags:
overridden: overridden:
FIELD IR_EXTERNAL_DECLARATION_STUB name:value type:kotlin.Int visibility:public flags: FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.Int visibility:public flags:
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags:
overridden: overridden:
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags:
@@ -40,4 +40,3 @@ FILE fqName:<root> fileName:/Derived.kt
overridden: overridden:
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags:
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags: $this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:
+1 -1
View File
@@ -144,7 +144,7 @@ FILE fqName:<root> fileName:/kt16904.kt
PROPERTY FAKE_OVERRIDE name:field visibility:public modality:FINAL flags:var PROPERTY FAKE_OVERRIDE name:field visibility:public modality:FINAL flags:var
FIELD FAKE_OVERRIDE name:field type:kotlin.Int visibility:public flags: FIELD FAKE_OVERRIDE name:field type:kotlin.Int visibility:public flags:
overridden: overridden:
FIELD IR_EXTERNAL_DECLARATION_STUB name:field type:kotlin.Int visibility:public flags: FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:field type:kotlin.Int visibility:public flags:
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags:
overridden: overridden:
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags:
@@ -23,7 +23,7 @@ FILE fqName:<root> fileName:/Derived.kt
PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL flags:var PROPERTY FAKE_OVERRIDE name:value visibility:public modality:FINAL flags:var
FIELD FAKE_OVERRIDE name:value type:kotlin.String? visibility:public flags: FIELD FAKE_OVERRIDE name:value type:kotlin.String? visibility:public flags:
overridden: overridden:
FIELD IR_EXTERNAL_DECLARATION_STUB name:value type:kotlin.String? visibility:public flags: FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:value type:kotlin.String? visibility:public flags:
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags:
overridden: overridden:
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags: FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean flags:
@@ -37,4 +37,3 @@ FILE fqName:<root> fileName:/Derived.kt
overridden: overridden:
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags: FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String flags:
$this: VALUE_PARAMETER name:<this> type:kotlin.Any flags: $this: VALUE_PARAMETER name:<this> type:kotlin.Any flags:
+1 -1
View File
@@ -20,7 +20,7 @@ FILE fqName:<root> fileName:/javaInnerClass.kt
PROPERTY FAKE_OVERRIDE name:x visibility:public modality:FINAL flags:var PROPERTY FAKE_OVERRIDE name:x visibility:public modality:FINAL flags:var
FIELD FAKE_OVERRIDE name:x type:kotlin.Int visibility:public flags: FIELD FAKE_OVERRIDE name:x type:kotlin.Int visibility:public flags:
overridden: overridden:
FIELD IR_EXTERNAL_DECLARATION_STUB name:x type:kotlin.Int visibility:public flags: FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:x type:kotlin.Int visibility:public flags:
FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:J) returnType:kotlin.Unit flags: FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:J) returnType:kotlin.Unit flags:
overridden: overridden:
FUN IR_EXTERNAL_JAVA_DECLARATION_STUB name:bar visibility:public modality:OPEN <> ($this:J) returnType:kotlin.Unit flags: FUN IR_EXTERNAL_JAVA_DECLARATION_STUB name:bar visibility:public modality:OPEN <> ($this:J) returnType:kotlin.Unit flags:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.analyzer.AnalysisResult import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.backend.jvm.JvmGeneratorExtensions
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.codegen.CodegenTestCase import org.jetbrains.kotlin.codegen.CodegenTestCase
@@ -28,6 +29,7 @@ import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration
import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions
import org.jetbrains.kotlin.resolve.AnalyzingUtils import org.jetbrains.kotlin.resolve.AnalyzingUtils
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
import org.jetbrains.kotlin.test.ConfigurationKind import org.jetbrains.kotlin.test.ConfigurationKind
@@ -122,22 +124,27 @@ abstract class AbstractIrGeneratorTestCase : CodegenTestCase() {
moduleDescriptors = emptyList(), moduleDescriptors = emptyList(),
friendModuleDescriptors = emptyList() friendModuleDescriptors = emptyList()
), ),
psi2ir, ktFilesToAnalyze psi2ir, ktFilesToAnalyze, GeneratorExtensions()
) )
fun generateIrModuleWithJvmResolve( fun generateIrModuleWithJvmResolve(
ktFilesToAnalyze: List<KtFile>, environment: KotlinCoreEnvironment, psi2ir: Psi2IrTranslator ktFilesToAnalyze: List<KtFile>, environment: KotlinCoreEnvironment, psi2ir: Psi2IrTranslator
): IrModuleFragment = ): IrModuleFragment =
generateIrModule(JvmResolveUtil.analyze(ktFilesToAnalyze, environment), psi2ir, ktFilesToAnalyze) generateIrModule(JvmResolveUtil.analyze(ktFilesToAnalyze, environment), psi2ir, ktFilesToAnalyze, JvmGeneratorExtensions)
private fun generateIrModule( private fun generateIrModule(
analysisResult: AnalysisResult, psi2ir: Psi2IrTranslator, ktFilesToAnalyze: List<KtFile> analysisResult: AnalysisResult,
psi2ir: Psi2IrTranslator,
ktFilesToAnalyze: List<KtFile>,
generatorExtensions: GeneratorExtensions
): IrModuleFragment { ): IrModuleFragment {
if (!psi2ir.configuration.ignoreErrors) { if (!psi2ir.configuration.ignoreErrors) {
analysisResult.throwIfError() analysisResult.throwIfError()
AnalyzingUtils.throwExceptionOnErrors(analysisResult.bindingContext) AnalyzingUtils.throwExceptionOnErrors(analysisResult.bindingContext)
} }
return psi2ir.generateModule(analysisResult.moduleDescriptor, ktFilesToAnalyze, analysisResult.bindingContext) return psi2ir.generateModule(
analysisResult.moduleDescriptor, ktFilesToAnalyze, analysisResult.bindingContext, generatorExtensions
)
} }
} }
} }
@@ -56,7 +56,6 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() {
val stubGenerator = DeclarationStubGenerator( val stubGenerator = DeclarationStubGenerator(
irModule.descriptor, irModule.descriptor,
SymbolTable(), // TODO SymbolTable(), // TODO
IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
myEnvironment.configuration.languageVersionSettings myEnvironment.configuration.languageVersionSettings
) )