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) {
deserializedModuleFragments.forEach {
ExternalDependenciesGenerator(it.descriptor, symbolTable, irBuiltIns, null).generateUnboundSymbolsAsDependencies(it)
ExternalDependenciesGenerator(it.descriptor, symbolTable, irBuiltIns).generateUnboundSymbolsAsDependencies(it)
}
deserializedModuleFragments.forEach { it.patchDeclarationParents() }
serializeModuleIntoKlib(
@@ -215,7 +215,7 @@ fun compile(
it.descriptor,
context.symbolTable,
context.irBuiltIns,
deserializer
deserializer = deserializer
).generateUnboundSymbolsAsDependencies(it)
}
@@ -14,10 +14,9 @@ import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
object JvmBackendFacade {
fun doGenerateFiles(files: Collection<KtFile>, state: GenerationState, errorHandler: CompilationErrorHandler) {
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)
doGenerateFilesInternal(state, errorHandler, irModuleFragment, psi2irContext)
@@ -36,7 +35,8 @@ object JvmBackendFacade {
ExternalDependenciesGenerator(
irModuleFragment.descriptor,
psi2irContext.symbolTable,
psi2irContext.irBuiltIns
psi2irContext.irBuiltIns,
JvmGeneratorExtensions.externalDeclarationOrigin
).generateUnboundSymbolsAsDependencies(irModuleFragment)
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 })
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>)
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.ir.IrElement
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.SymbolTable
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi2ir.generators.AnnotationGenerator
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.transformations.insertImplicitCasts
import org.jetbrains.kotlin.resolve.BindingContext
@@ -46,13 +47,23 @@ class Psi2IrTranslator(
postprocessingSteps.add(step)
}
fun generateModule(moduleDescriptor: ModuleDescriptor, ktFiles: Collection<KtFile>, bindingContext: BindingContext): IrModuleFragment {
val context = createGeneratorContext(moduleDescriptor, bindingContext)
fun generateModule(
moduleDescriptor: ModuleDescriptor,
ktFiles: Collection<KtFile>,
bindingContext: BindingContext,
generatorExtensions: GeneratorExtensions
): IrModuleFragment {
val context = createGeneratorContext(moduleDescriptor, bindingContext, extensions = generatorExtensions)
return generateModuleFragment(context, ktFiles)
}
fun createGeneratorContext(moduleDescriptor: ModuleDescriptor, bindingContext: BindingContext, symbolTable: SymbolTable = SymbolTable()) =
GeneratorContext(configuration, moduleDescriptor, bindingContext, languageVersionSettings, symbolTable)
fun createGeneratorContext(
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 {
val moduleGenerator = ModuleGenerator(context)
@@ -35,7 +35,8 @@ class GeneratorContext(
val moduleDescriptor: ModuleDescriptor,
val bindingContext: BindingContext,
val languageVersionSettings: LanguageVersionSettings,
val symbolTable: SymbolTable = SymbolTable()
val symbolTable: SymbolTable,
val extensions: GeneratorExtensions
) : IrGeneratorContext() {
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) {
ExternalDependenciesGenerator(
irModule.descriptor, context.symbolTable, context.irBuiltIns, deserializer
irModule.descriptor, context.symbolTable, context.irBuiltIns, context.extensions.externalDeclarationOrigin, deserializer
).generateUnboundSymbolsAsDependencies(irModule, context.bindingContext)
}
@@ -44,8 +44,9 @@ class IrBuiltIns(
val irBuiltInsExternalPackageFragment = IrExternalPackageFragmentImpl(IrExternalPackageFragmentSymbolImpl(packageFragment))
private val symbolTable = outerSymbolTable ?: SymbolTable()
private val stubBuilder =
DeclarationStubGenerator(builtInsModule, symbolTable, IrDeclarationOrigin.IR_BUILTINS_STUB, languageVersionSettings)
private val stubBuilder = DeclarationStubGenerator(
builtInsModule, symbolTable, languageVersionSettings, externalDeclarationOrigin = { IrDeclarationOrigin.IR_BUILTINS_STUB }
)
private fun ClassDescriptor.toIrSymbol() = symbolTable.referenceClass(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.declarations.*
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.lazy.*
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
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.DescriptorUtils
import org.jetbrains.kotlin.resolve.hasBackingField
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.isDynamic
class DeclarationStubGenerator(
moduleDescriptor: ModuleDescriptor,
val symbolTable: SymbolTable,
val origin: IrDeclarationOrigin,
val languageVersionSettings: LanguageVersionSettings,
val deserializer: IrDeserializer? = null
languageVersionSettings: LanguageVersionSettings,
private val externalDeclarationOrigin: ((DeclarationDescriptor) -> IrDeclarationOrigin)? = null,
private val deserializer: IrDeserializer? = null
) {
private val lazyTable = symbolTable.lazyWrapper
internal var unboundSymbolGeneration: Boolean
@@ -87,14 +78,15 @@ class DeclarationStubGenerator(
throw AssertionError("Unexpected member descriptor: $descriptor")
}
private fun computeOrigin(descriptor: DeclarationDescriptor): IrDeclarationOrigin =
externalDeclarationOrigin?.invoke(descriptor) ?: IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB
internal fun generatePropertyStub(
descriptor: PropertyDescriptor,
bindingContext: BindingContext? = null
): IrProperty = symbolTable.referenceProperty(descriptor) {
deserializer?.findDeserializedDeclaration(descriptor) ?:
IrLazyProperty(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor,
this, typeTranslator, bindingContext
deserializer?.findDeserializedDeclaration(descriptor) ?: IrLazyProperty(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(descriptor), descriptor, this, typeTranslator, bindingContext
)
}
@@ -107,7 +99,7 @@ class DeclarationStubGenerator(
val origin =
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE)
IrDeclarationOrigin.FAKE_OVERRIDE
else origin
else computeOrigin(descriptor)
return symbolTable.declareField(
UNDEFINED_OFFSET,
@@ -116,8 +108,8 @@ class DeclarationStubGenerator(
descriptor.original,
descriptor.type.toIrType()
) {
deserializer?.findDeserializedDeclaration(referenced) as? IrField ?:
IrFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, descriptor.type.toIrType())
deserializer?.findDeserializedDeclaration(referenced) as? IrField
?: IrFieldImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, descriptor.type.toIrType())
}.apply {
initializer = descriptor.compileTimeInitializer?.let {
IrExpressionBodyImpl(
@@ -145,17 +137,14 @@ class DeclarationStubGenerator(
val origin =
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE)
IrDeclarationOrigin.FAKE_OVERRIDE
else if (origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB && descriptor is JavaCallableMemberDescriptor)
IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
else
origin
else computeOrigin(descriptor)
return symbolTable.declareSimpleFunction(
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
origin,
descriptor.original
) {
deserializer?.findDeserializedDeclaration(referenced) as? IrSimpleFunction ?:
IrLazyFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
deserializer?.findDeserializedDeclaration(referenced) as? IrSimpleFunction
?: IrLazyFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
}
}
@@ -165,11 +154,12 @@ class DeclarationStubGenerator(
return referenced.owner
}
val origin = computeOrigin(descriptor)
return symbolTable.declareConstructor(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor.original
) {
deserializer?.findDeserializedDeclaration(referenced) as? IrConstructor ?:
IrLazyConstructor(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
deserializer?.findDeserializedDeclaration(referenced) as? IrConstructor
?: IrLazyConstructor(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
}
}
@@ -177,17 +167,17 @@ class DeclarationStubGenerator(
internal fun generateValueParameterStub(descriptor: ValueParameterDescriptor): IrValueParameter {
return IrValueParameterImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(descriptor),
descriptor, descriptor.type.toIrType(), descriptor.varargElementType?.toIrType()
).also { irValueParameter ->
if (descriptor.declaresDefaultValue()) {
irValueParameter.defaultValue =
IrExpressionBodyImpl(
IrErrorExpressionImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, descriptor.type.toIrType(),
"Stub expression for default value of ${descriptor.name}"
)
IrExpressionBodyImpl(
IrErrorExpressionImpl(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, descriptor.type.toIrType(),
"Stub expression for default value of ${descriptor.name}"
)
)
}
}
}
@@ -197,11 +187,12 @@ class DeclarationStubGenerator(
if (referenceClass.isBound) {
return referenceClass.owner
}
val origin = computeOrigin(descriptor)
return symbolTable.declareClass(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor
) {
deserializer?.findDeserializedDeclaration(referenceClass) as? IrClass ?:
IrLazyClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
deserializer?.findDeserializedDeclaration(referenceClass) as? IrClass
?: IrLazyClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
}
}
@@ -210,9 +201,10 @@ class DeclarationStubGenerator(
if (referenced.isBound) {
return referenced.owner
}
val origin = computeOrigin(descriptor)
return symbolTable.declareEnumEntry(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
deserializer?.findDeserializedDeclaration(referenced) as? IrEnumEntry ?:
IrLazyEnumEntryImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
deserializer?.findDeserializedDeclaration(referenced) as? IrEnumEntry
?: IrLazyEnumEntryImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
}
}
@@ -221,12 +213,10 @@ class DeclarationStubGenerator(
if (referenced.isBound) {
return referenced.owner
}
val origin = computeOrigin(descriptor)
return symbolTable.declareGlobalTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
deserializer?.findDeserializedDeclaration(referenced) as? IrTypeParameter ?:
IrLazyTypeParameter(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
it, this, typeTranslator
)
deserializer?.findDeserializedDeclaration(referenced) as? IrTypeParameter
?: IrLazyTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
}
}
@@ -235,11 +225,9 @@ class DeclarationStubGenerator(
if (referenced.isBound) {
return referenced.owner
}
val origin = computeOrigin(descriptor)
return symbolTable.declareScopedTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor) {
IrLazyTypeParameter(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin,
it, this, typeTranslator
)
IrLazyTypeParameter(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, this, typeTranslator)
}
}
}
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
@@ -26,10 +27,11 @@ class ExternalDependenciesGenerator(
moduleDescriptor: ModuleDescriptor,
val symbolTable: SymbolTable,
val irBuiltIns: IrBuiltIns,
externalDeclarationOrigin: ((DeclarationDescriptor) -> IrDeclarationOrigin)? = null,
val deserializer: IrDeserializer? = null
) {
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) {
@@ -71,4 +73,4 @@ class ExternalDependenciesGenerator(
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
FIELD FAKE_OVERRIDE name:value type:kotlin.Int visibility:public flags:
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:
overridden:
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:
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:
+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
FIELD FAKE_OVERRIDE name:field type:kotlin.Int visibility:public flags:
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:
overridden:
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
FIELD FAKE_OVERRIDE name:value type:kotlin.String? visibility:public flags:
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:
overridden:
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:
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:
+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
FIELD FAKE_OVERRIDE name:x type:kotlin.Int visibility:public flags:
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:
overridden:
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 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.KotlinCoreEnvironment
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.psi2ir.Psi2IrConfiguration
import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
import org.jetbrains.kotlin.psi2ir.generators.GeneratorExtensions
import org.jetbrains.kotlin.resolve.AnalyzingUtils
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
import org.jetbrains.kotlin.test.ConfigurationKind
@@ -122,22 +124,27 @@ abstract class AbstractIrGeneratorTestCase : CodegenTestCase() {
moduleDescriptors = emptyList(),
friendModuleDescriptors = emptyList()
),
psi2ir, ktFilesToAnalyze
psi2ir, ktFilesToAnalyze, GeneratorExtensions()
)
fun generateIrModuleWithJvmResolve(
ktFilesToAnalyze: List<KtFile>, environment: KotlinCoreEnvironment, psi2ir: Psi2IrTranslator
): IrModuleFragment =
generateIrModule(JvmResolveUtil.analyze(ktFilesToAnalyze, environment), psi2ir, ktFilesToAnalyze)
generateIrModule(JvmResolveUtil.analyze(ktFilesToAnalyze, environment), psi2ir, ktFilesToAnalyze, JvmGeneratorExtensions)
private fun generateIrModule(
analysisResult: AnalysisResult, psi2ir: Psi2IrTranslator, ktFilesToAnalyze: List<KtFile>
analysisResult: AnalysisResult,
psi2ir: Psi2IrTranslator,
ktFilesToAnalyze: List<KtFile>,
generatorExtensions: GeneratorExtensions
): IrModuleFragment {
if (!psi2ir.configuration.ignoreErrors) {
analysisResult.throwIfError()
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(
irModule.descriptor,
SymbolTable(), // TODO
IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB,
myEnvironment.configuration.languageVersionSettings
)