From f4fdc66a340210977fa1ec372786786bdf4e712f Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 16 May 2019 11:48:02 +0300 Subject: [PATCH] Introduce experimental FIR compiler #KT-31265 Fixed This commit also includes several FIR2IR fixes which helps FIR compiler to produce normal results --- build.gradle.kts | 3 +- compiler/cli/build.gradle.kts | 4 + .../arguments/CommonCompilerArguments.kt | 6 + .../jetbrains/kotlin/cli/common/arguments.kt | 1 + .../compiler/KotlinToJVMBytecodeCompiler.kt | 174 +++++++++++++++++- .../kotlin/fir/backend/Fir2IrConverter.kt | 14 +- .../kotlin/fir/backend/Fir2IrResult.kt | 12 ++ .../kotlin/fir/backend/Fir2IrVisitor.kt | 9 +- .../fir/descriptors/FirModuleDescriptor.kt | 2 +- .../FirPackageFragmentDescriptor.kt | 4 +- .../descriptors/FirPackageViewDescriptor.kt | 6 +- .../kotlin/fir/AbstractFir2IrTextTest.kt | 4 +- .../kotlin/config/CommonConfigurationKeys.kt | 3 + .../kotlin/backend/jvm/JvmBackendFacade.kt | 21 ++- .../kotlin/backend/jvm/JvmIrCodegenFactory.kt | 13 ++ compiler/testData/cli/js/jsExtraHelp.out | 1 + compiler/testData/cli/jvm/extraHelp.out | 1 + compiler/testData/cli/jvm/firHello.args | 4 + compiler/testData/cli/jvm/firHello.kt | 12 ++ compiler/testData/cli/jvm/firHello.out | 1 + .../classLiteralInAnnotation.fir.txt | 6 +- .../classesWithAnnotations.fir.txt | 12 +- ...edPropertyAccessorsWithAnnotations.fir.txt | 8 +- .../enumEntriesWithAnnotations.fir.txt | 4 +- .../annotations/fieldsWithAnnotations.fir.txt | 4 +- .../annotations/fileAnnotations.fir.txt | 2 +- .../propertiesWithAnnotations.fir.txt | 2 +- ...sorsFromClassHeaderWithAnnotations.fir.txt | 6 +- .../propertyAccessorsWithAnnotations.fir.txt | 6 +- .../provideDelegate/local.fir.txt | 3 +- .../provideDelegate/member.fir.txt | 3 +- .../provideDelegate/memberExtension.fir.txt | 3 +- .../provideDelegate/topLevel.fir.txt | 3 +- .../forWithImplicitReceivers.fir.txt | 3 +- ...icConstructorCallWithTypeArguments.fir.txt | 7 + .../expressions/memberTypeArguments.fir.txt | 3 +- ...pecializedTypeAliasConstructorCall.fir.txt | 1 + .../irText/regressions/coercionInLoop.fir.txt | 3 +- .../typeAliasCtorForGenericClass.fir.txt | 2 + .../javaConstructorWithTypeParameters.fir.txt | 3 +- .../kotlin/cli/CliTestGenerated.java | 5 + .../complexBuildGradleKts/build.gradle.kts | 1 + 42 files changed, 331 insertions(+), 54 deletions(-) create mode 100644 compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrResult.kt create mode 100644 compiler/testData/cli/jvm/firHello.args create mode 100644 compiler/testData/cli/jvm/firHello.kt create mode 100644 compiler/testData/cli/jvm/firHello.out diff --git a/build.gradle.kts b/build.gradle.kts index f30bcad266c..36d7c411cd2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -256,7 +256,8 @@ extra["compilerModules"] = arrayOf( ":compiler:fir:resolve", ":compiler:fir:tree", ":compiler:fir:psi2fir", - ":compiler:fir:fir2ir" + ":compiler:fir:fir2ir", + ":compiler:fir:java" ) val coreLibProjects = listOfNotNull( diff --git a/compiler/cli/build.gradle.kts b/compiler/cli/build.gradle.kts index 5c52b50170f..de66d35fbe0 100644 --- a/compiler/cli/build.gradle.kts +++ b/compiler/cli/build.gradle.kts @@ -20,6 +20,10 @@ dependencies { compile(project(":js:js.translator")) compile(commonDep("org.fusesource.jansi", "jansi")) compile(commonDep("org.jline", "jline")) + compile(project(":compiler:fir:psi2fir")) + compile(project(":compiler:fir:resolve")) + compile(project(":compiler:fir:java")) + compile(project(":compiler:fir:fir2ir")) compile(files("${System.getProperty("java.home")}/../lib/tools.jar")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index e87f878d2e7..176ee9bf9ff 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -286,6 +286,12 @@ abstract class CommonCompilerArguments : CommonToolArguments() { ) var checkStickyPhaseConditions: Boolean by FreezableVar(false) + @Argument( + value = "-Xuse-fir", + description = "Compile using Front-end IR. Warning: this feature is far from being production-ready" + ) + var useFir: Boolean by FreezableVar(false) + open fun configureAnalysisFlags(collector: MessageCollector): MutableMap, Any> { return HashMap, Any>().apply { put(AnalysisFlags.skipMetadataVersionCheck, skipMetadataVersionCheck) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt index 30ac4778613..9e5317fa588 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/arguments.kt @@ -22,6 +22,7 @@ fun CompilerConfiguration.setupCommonArguments( createMetadataVersion: ((IntArray) -> BinaryVersion)? = null ) { put(CommonConfigurationKeys.DISABLE_INLINE, arguments.noInline) + put(CommonConfigurationKeys.USE_FIR, arguments.useFir) putIfNotNull(CLIConfigurationKeys.INTELLIJ_PLUGIN_ROOT, arguments.intellijPluginRoot) put(CommonConfigurationKeys.REPORT_OUTPUT_FILES, arguments.reportOutputFiles) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt index e64101b5162..8aff7af2993 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.kt @@ -16,16 +16,21 @@ package org.jetbrains.kotlin.cli.jvm.compiler +import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.StandardFileSystems import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager +import com.intellij.psi.PsiElementFinder import com.intellij.psi.PsiJavaModule import com.intellij.psi.search.DelegatingGlobalSearchScope import com.intellij.psi.search.GlobalSearchScope +import com.intellij.psi.search.ProjectScope import org.jetbrains.kotlin.analyzer.AnalysisResult +import org.jetbrains.kotlin.analyzer.ModuleInfo import org.jetbrains.kotlin.asJava.FilteredJvmDiagnostics +import org.jetbrains.kotlin.asJava.finder.JavaElementFinder import org.jetbrains.kotlin.backend.common.output.OutputFileCollection import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig @@ -47,15 +52,28 @@ import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.codegen.state.GenerationStateEventCallback import org.jetbrains.kotlin.config.* import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil +import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.backend.Fir2IrConverter +import org.jetbrains.kotlin.fir.builder.RawFirBuilder +import org.jetbrains.kotlin.fir.java.FirJavaModuleBasedSession +import org.jetbrains.kotlin.fir.java.FirLibrarySession +import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider +import org.jetbrains.kotlin.fir.resolve.FirProvider +import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl +import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveTransformer +import org.jetbrains.kotlin.fir.service import org.jetbrains.kotlin.idea.MainFunctionDetector import org.jetbrains.kotlin.javac.JavacWrapper import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager import org.jetbrains.kotlin.modules.Module import org.jetbrains.kotlin.modules.TargetId import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.resolve.TargetPlatform import org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade +import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform import org.jetbrains.kotlin.utils.newLinkedHashMapWithExpectedSize import org.jetbrains.kotlin.utils.tryConstructClassFromStringArgs import java.io.File @@ -102,8 +120,6 @@ object KotlinToJVMBytecodeCompiler { ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() val moduleVisibilityManager = ModuleVisibilityManager.SERVICE.getInstance(environment.project) - - val projectConfiguration = environment.configuration for (module in chunk) { moduleVisibilityManager.addModule(module) } @@ -113,6 +129,11 @@ object KotlinToJVMBytecodeCompiler { moduleVisibilityManager.addFriendPath(path) } + val projectConfiguration = environment.configuration + if (projectConfiguration.getBoolean(CommonConfigurationKeys.USE_FIR)) { + return compileModulesUsingFrontendIR(environment, buildFile, chunk) + } + val targetDescription = "in targets [" + chunk.joinToString { input -> input.getModuleName() + "-" + input.getModuleType() } + "]" val result = repeatAnalysisIfNeeded(analyze(environment, targetDescription), environment, targetDescription) @@ -164,6 +185,15 @@ object KotlinToJVMBytecodeCompiler { outputs[module] = generate(environment, moduleConfiguration, result, ktFiles, module) } + return writeOutputs(environment, projectConfiguration, chunk, outputs) + } + + private fun writeOutputs( + environment: KotlinCoreEnvironment, + projectConfiguration: CompilerConfiguration, + chunk: List, + outputs: Map + ): Boolean { try { for ((_, state) in outputs) { ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() @@ -238,6 +268,143 @@ object KotlinToJVMBytecodeCompiler { configuration.addAll(JVMConfigurationKeys.MODULES, chunk) } + private fun compileModulesUsingFrontendIR(environment: KotlinCoreEnvironment, buildFile: File?, chunk: List): Boolean { + val project = environment.project + Extensions.getArea(project) + .getExtensionPoint(PsiElementFinder.EP_NAME) + .unregisterExtension(JavaElementFinder::class.java) + + val projectConfiguration = environment.configuration + val localFileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL) + val outputs = newLinkedHashMapWithExpectedSize(chunk.size) + for (module in chunk) { + ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() + + val ktFiles = if (chunk.size > 1) { + // filter out source files from other modules + assert(buildFile != null) { "Compiling multiple modules, but build file is null" } + val (moduleSourceDirs, moduleSourceFiles) = + getBuildFilePaths(buildFile, module.getSourceFiles()) + .mapNotNull(localFileSystem::findFileByPath) + .partition(VirtualFile::isDirectory) + + environment.getSourceFiles().filter { file -> + val virtualFile = file.virtualFile + virtualFile in moduleSourceFiles || moduleSourceDirs.any { dir -> + VfsUtilCore.isAncestor(dir, virtualFile, true) + } + } + } else { + environment.getSourceFiles() + } + + if (!checkKotlinPackageUsage(environment, ktFiles)) return false + + val moduleConfiguration = projectConfiguration.copy().apply { + if (buildFile != null) { + fun checkKeyIsNull(key: CompilerConfigurationKey<*>, name: String) { + assert(get(key) == null) { "$name should be null, when buildFile is used" } + } + + checkKeyIsNull(JVMConfigurationKeys.OUTPUT_DIRECTORY, "OUTPUT_DIRECTORY") + checkKeyIsNull(JVMConfigurationKeys.OUTPUT_JAR, "OUTPUT_JAR") + put(JVMConfigurationKeys.OUTPUT_DIRECTORY, File(module.getOutputDirectory())) + } + } + + val scope = GlobalSearchScope.filesScope(project, ktFiles.map { it.virtualFile }) + .uniteWith(TopDownAnalyzerFacadeForJVM.AllJavaSourcesInProjectScope(project)) + val provider = FirProjectSessionProvider(project) + + class FirJvmModuleInfo(override val name: Name) : ModuleInfo { + constructor(moduleName: String) : this(Name.identifier(moduleName)) + + val dependencies: MutableList = mutableListOf() + + override val platform: TargetPlatform? get() = JvmPlatform + + override fun dependencies(): List { + return dependencies + } + } + + val moduleInfo = FirJvmModuleInfo(module.getModuleName()) + val session: FirSession = FirJavaModuleBasedSession(moduleInfo, provider, scope).also { + val dependenciesInfo = FirJvmModuleInfo(Name.special("")) + moduleInfo.dependencies.add(dependenciesInfo) + val librariesScope = ProjectScope.getLibrariesScope(project) + FirLibrarySession.create( + dependenciesInfo, provider, librariesScope, + project, environment.createPackagePartProvider(librariesScope) + ) + + } + val builder = RawFirBuilder(session, stubMode = false) + val resolveTransformer = FirTotalResolveTransformer() + val firFiles = ktFiles.map { + val firFile = builder.buildFirFile(it) + (session.service() as FirProviderImpl).recordFile(firFile) + firFile + }.also { + try { + resolveTransformer.processFiles(it) + } catch (e: Exception) { + throw e + } + } + val (moduleFragment, symbolTable, sourceManager) = + Fir2IrConverter.createModuleFragment(session, firFiles, moduleConfiguration.languageVersionSettings) + val dummyBindingContext = NoScopeRecordCliBindingTrace().bindingContext + + val codegenFactory = JvmIrCodegenFactory(moduleConfiguration.get(CLIConfigurationKeys.PHASE_CONFIG) ?: PhaseConfig(jvmPhases)) + val generationState = GenerationState.Builder( + environment.project, ClassBuilderFactories.BINARIES, + moduleFragment.descriptor, dummyBindingContext, ktFiles, + moduleConfiguration + ).codegenFactory( + codegenFactory + ).withModule( + module + ).onIndependentPartCompilationEnd( + createOutputFilesFlushingCallbackIfPossible(moduleConfiguration) + ).build() + + ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() + + val performanceManager = environment.configuration.get(CLIConfigurationKeys.PERF_MANAGER) + performanceManager?.notifyGenerationStarted() + generationState.beforeCompile() + codegenFactory.generateModule( + generationState, moduleFragment, CompilationErrorHandler.THROW_EXCEPTION, symbolTable, sourceManager + ) + CodegenFactory.doCheckCancelled(generationState) + generationState.factory.done() + performanceManager?.notifyGenerationFinished( + ktFiles.size, + environment.countLinesOfCode(ktFiles), + additionalDescription = "target " + module.getModuleName() + "-" + module.getModuleType() + " " + ) + + ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() + + AnalyzerWithCompilerReport.reportDiagnostics( + FilteredJvmDiagnostics( + generationState.collectedExtraJvmDiagnostics, + dummyBindingContext.diagnostics + ), + environment.messageCollector + ) + + AnalyzerWithCompilerReport.reportBytecodeVersionErrors( + generationState.extraJvmDiagnosticsTrace.bindingContext, environment.messageCollector + ) + + ProgressIndicatorAndCompilationCanceledStatus.checkCanceled() + outputs[module] = generationState + } + return writeOutputs(environment, projectConfiguration, chunk, outputs) + } + private fun getBuildFilePaths(buildFile: File?, sourceFilePaths: List): List = if (buildFile == null) sourceFilePaths else sourceFilePaths.map { path -> @@ -447,7 +614,8 @@ object KotlinToJVMBytecodeCompiler { sourceFiles: List, module: Module? ): GenerationState { - val isIR = configuration.getBoolean(JVMConfigurationKeys.IR) + val isIR = configuration.getBoolean(JVMConfigurationKeys.IR) || + configuration.getBoolean(CommonConfigurationKeys.USE_FIR) val generationState = GenerationState.Builder( environment.project, ClassBuilderFactories.BINARIES, diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt index fc4b4c4728c..da59e8235c5 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt @@ -17,6 +17,8 @@ import org.jetbrains.kotlin.ir.util.ConstantValueGenerator import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.ir.util.TypeTranslator +import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi2ir.PsiSourceManager object Fir2IrConverter { @@ -25,7 +27,7 @@ object Fir2IrConverter { firFiles: List, languageVersionSettings: LanguageVersionSettings, fakeOverrideMode: FakeOverrideMode = FakeOverrideMode.NORMAL - ): IrModuleFragment { + ): Fir2IrResult { val moduleDescriptor = FirModuleDescriptor(session) val symbolTable = SymbolTable() val constantValueGenerator = ConstantValueGenerator(moduleDescriptor, symbolTable) @@ -33,15 +35,19 @@ object Fir2IrConverter { constantValueGenerator.typeTranslator = typeTranslator typeTranslator.constantValueGenerator = constantValueGenerator val builtIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, symbolTable) - val fir2irTransformer = Fir2IrVisitor(session, moduleDescriptor, symbolTable, builtIns, fakeOverrideMode) + val sourceManager = PsiSourceManager() + val fir2irTransformer = Fir2IrVisitor(session, moduleDescriptor, symbolTable, sourceManager, builtIns, fakeOverrideMode) val irFiles = mutableListOf() for (firFile in firFiles) { - irFiles += firFile.accept(fir2irTransformer, null) as IrFile + val irFile = firFile.accept(fir2irTransformer, null) as IrFile + val fileEntry = sourceManager.getOrCreateFileEntry(firFile.psi as KtFile) + sourceManager.putFileEntry(irFile, fileEntry) + irFiles += irFile } val irModuleFragment = IrModuleFragmentImpl(moduleDescriptor, builtIns, irFiles) generateUnboundSymbolsAsDependencies(irModuleFragment, symbolTable, builtIns) - return irModuleFragment + return Fir2IrResult(irModuleFragment, symbolTable, sourceManager) } private fun generateUnboundSymbolsAsDependencies( diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrResult.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrResult.kt new file mode 100644 index 00000000000..6f1ba565835 --- /dev/null +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrResult.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.fir.backend + +import org.jetbrains.kotlin.ir.declarations.IrModuleFragment +import org.jetbrains.kotlin.ir.util.SymbolTable +import org.jetbrains.kotlin.psi2ir.PsiSourceManager + +data class Fir2IrResult(val irModuleFragment: IrModuleFragment, val symbolTable: SymbolTable, val sourceManager: PsiSourceManager) \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 2477d553522..31b913c47d4 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.fir.backend -import com.intellij.psi.PsiFile import org.jetbrains.kotlin.backend.common.descriptors.* import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.fir.* @@ -60,6 +59,7 @@ internal class Fir2IrVisitor( private val session: FirSession, private val moduleDescriptor: FirModuleDescriptor, private val symbolTable: SymbolTable, + private val sourceManager: PsiSourceManager, private val irBuiltIns: IrBuiltIns, private val fakeOverrideMode: FakeOverrideMode ) : FirVisitor() { @@ -140,7 +140,7 @@ internal class Fir2IrVisitor( override fun visitFile(file: FirFile, data: Any?): IrFile { return IrFileImpl( - PsiSourceManager.PsiFileEntry(file.psi as PsiFile), + sourceManager.getOrCreateFileEntry(file.psi as KtFile), moduleDescriptor.findPackageFragmentForFile(file) ).withParent { file.declarations.forEach { @@ -680,7 +680,7 @@ internal class Fir2IrVisitor( private fun IrExpression.applyCallArguments(call: FirCall): IrExpression { return when (this) { - is IrCallImpl -> { + is IrCallWithIndexedArgumentsBase -> { val argumentsCount = call.arguments.size if (argumentsCount <= valueArgumentsCount) { apply { @@ -690,9 +690,10 @@ internal class Fir2IrVisitor( } } } else { + val name = if (this is IrCallImpl) symbol.owner.name else "???" IrErrorCallExpressionImpl( startOffset, endOffset, type, - "Cannot bind $argumentsCount arguments to ${symbol.owner.name} call with $valueArgumentsCount parameters" + "Cannot bind $argumentsCount arguments to $name call with $valueArgumentsCount parameters" ).apply { for (argument in call.arguments) { addArgument(argument.toIrExpression()) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirModuleDescriptor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirModuleDescriptor.kt index 5657318ab68..0b9df85fe18 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirModuleDescriptor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirModuleDescriptor.kt @@ -69,6 +69,6 @@ class FirModuleDescriptor(val session: FirSession) : ModuleDescriptor { } override val annotations: Annotations - get() = TODO("not implemented") + get() = Annotations.EMPTY } \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirPackageFragmentDescriptor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirPackageFragmentDescriptor.kt index a7902bf1e60..a506eabc9e7 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirPackageFragmentDescriptor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirPackageFragmentDescriptor.kt @@ -18,7 +18,7 @@ class FirPackageFragmentDescriptor(override val fqName: FqName, val moduleDescri override fun getMemberScope(): MemberScope { - TODO("not implemented") + return MemberScope.Empty } override fun getOriginal(): DeclarationDescriptorWithSource { @@ -42,6 +42,6 @@ class FirPackageFragmentDescriptor(override val fqName: FqName, val moduleDescri } override val annotations: Annotations - get() = TODO("not implemented") + get() = Annotations.EMPTY } \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirPackageViewDescriptor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirPackageViewDescriptor.kt index ded3ab0cec5..19baea8dd64 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirPackageViewDescriptor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/descriptors/FirPackageViewDescriptor.kt @@ -17,9 +17,11 @@ class FirPackageViewDescriptor(override val fqName: FqName, val moduleDescriptor } override val memberScope: MemberScope - get() = TODO("not implemented") + get() = MemberScope.Empty + override val module: ModuleDescriptor get() = moduleDescriptor + override val fragments: List get() = listOf(FirPackageFragmentDescriptor(fqName, moduleDescriptor)) @@ -40,6 +42,6 @@ class FirPackageViewDescriptor(override val fqName: FqName, val moduleDescriptor } override val annotations: Annotations - get() = TODO("not implemented") + get() = Annotations.EMPTY } \ No newline at end of file diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/AbstractFir2IrTextTest.kt b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/AbstractFir2IrTextTest.kt index 9325fb0ea5c..2d611efa958 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/AbstractFir2IrTextTest.kt +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/fir/AbstractFir2IrTextTest.kt @@ -91,6 +91,8 @@ abstract class AbstractFir2IrTextTest : AbstractIrTextTestCase() { } } - return Fir2IrConverter.createModuleFragment(session, firFiles, myEnvironment.configuration.languageVersionSettings) + return Fir2IrConverter.createModuleFragment( + session, firFiles, myEnvironment.configuration.languageVersionSettings + ).irModuleFragment } } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt b/compiler/frontend/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt index d9f39f7a971..3121125bb96 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/config/CommonConfigurationKeys.kt @@ -41,6 +41,9 @@ object CommonConfigurationKeys { @JvmField val METADATA_VERSION = CompilerConfigurationKey.create("metadata version") + + @JvmField + val USE_FIR = CompilerConfigurationKey.create("front-end IR") } var CompilerConfiguration.languageVersionSettings: LanguageVersionSettings diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt index 06474901361..27d3f6c5c47 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmBackendFacade.kt @@ -10,8 +10,10 @@ import org.jetbrains.kotlin.codegen.CompilationErrorHandler import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator +import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator +import org.jetbrains.kotlin.psi2ir.PsiSourceManager import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext object JvmBackendFacade { @@ -34,15 +36,28 @@ object JvmBackendFacade { irModuleFragment: IrModuleFragment, psi2irContext: GeneratorContext, phaseConfig: PhaseConfig + ) { + doGenerateFilesInternal( + state, errorHandler, irModuleFragment, psi2irContext.symbolTable, psi2irContext.sourceManager, phaseConfig + ) + } + + internal fun doGenerateFilesInternal( + state: GenerationState, + errorHandler: CompilationErrorHandler, + irModuleFragment: IrModuleFragment, + symbolTable: SymbolTable, + sourceManager: PsiSourceManager, + phaseConfig: PhaseConfig ) { val jvmBackendContext = JvmBackendContext( - state, psi2irContext.sourceManager, psi2irContext.irBuiltIns, irModuleFragment, psi2irContext.symbolTable, phaseConfig + state, sourceManager, irModuleFragment.irBuiltins, irModuleFragment, symbolTable, phaseConfig ) //TODO ExternalDependenciesGenerator( irModuleFragment.descriptor, - psi2irContext.symbolTable, - psi2irContext.irBuiltIns, + symbolTable, + irModuleFragment.irBuiltins, JvmGeneratorExtensions.externalDeclarationOrigin ).generateUnboundSymbolsAsDependencies() diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt index deca62106ba..f4a9c42299a 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmIrCodegenFactory.kt @@ -20,9 +20,12 @@ import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig import org.jetbrains.kotlin.codegen.* import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor +import org.jetbrains.kotlin.ir.declarations.IrModuleFragment +import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator +import org.jetbrains.kotlin.psi2ir.PsiSourceManager class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory { @@ -33,6 +36,16 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory JvmBackendFacade.doGenerateFilesInternal(state, errorHandler, irModuleFragment, psi2irContext, phaseConfig) } + fun generateModule( + state: GenerationState, + irModuleFragment: IrModuleFragment, + errorHandler: CompilationErrorHandler, + symbolTable: SymbolTable, + sourceManager: PsiSourceManager + ) { + JvmBackendFacade.doGenerateFilesInternal(state, errorHandler, irModuleFragment, symbolTable, sourceManager, phaseConfig) + } + override fun createPackageCodegen(state: GenerationState, files: Collection, fqName: FqName): PackageCodegen { val impl = PackageCodegenImpl(state, files, fqName) diff --git a/compiler/testData/cli/js/jsExtraHelp.out b/compiler/testData/cli/js/jsExtraHelp.out index eee153dcf30..4fc32bc1bbe 100644 --- a/compiler/testData/cli/js/jsExtraHelp.out +++ b/compiler/testData/cli/js/jsExtraHelp.out @@ -43,6 +43,7 @@ where advanced options include: -Xreport-perf Report detailed performance statistics -Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes) -Xuse-experimental= Enable, but don't propagate usages of experimental API for marker annotation with the given fully qualified name + -Xuse-fir Compile using Front-end IR. Warning: this feature is far from being production-ready -Xverbose-phases Be verbose while performing these backend phases Advanced options are non-standard and may be changed or removed without any notice. diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 658a60a0ed3..d68d1f2aa2b 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -107,6 +107,7 @@ where advanced options include: -Xreport-perf Report detailed performance statistics -Xskip-metadata-version-check Load classes with bad metadata version anyway (incl. pre-release classes) -Xuse-experimental= Enable, but don't propagate usages of experimental API for marker annotation with the given fully qualified name + -Xuse-fir Compile using Front-end IR. Warning: this feature is far from being production-ready -Xverbose-phases Be verbose while performing these backend phases Advanced options are non-standard and may be changed or removed without any notice. diff --git a/compiler/testData/cli/jvm/firHello.args b/compiler/testData/cli/jvm/firHello.args new file mode 100644 index 00000000000..6c3d66c2a85 --- /dev/null +++ b/compiler/testData/cli/jvm/firHello.args @@ -0,0 +1,4 @@ +$TESTDATA_DIR$/firHello.kt +-Xuse-fir +-d +$TEMP_DIR$ diff --git a/compiler/testData/cli/jvm/firHello.kt b/compiler/testData/cli/jvm/firHello.kt new file mode 100644 index 00000000000..f9f883a2ec7 --- /dev/null +++ b/compiler/testData/cli/jvm/firHello.kt @@ -0,0 +1,12 @@ +fun box(): String = "OK" + + +class E(s: String) : Exception(s) { + +} + +fun main(args: Array) { + if (box() == "OK") { + throw E("Hello") + } +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/firHello.out b/compiler/testData/cli/jvm/firHello.out new file mode 100644 index 00000000000..d86bac9de59 --- /dev/null +++ b/compiler/testData/cli/jvm/firHello.out @@ -0,0 +1 @@ +OK diff --git a/compiler/testData/ir/irText/declarations/annotations/classLiteralInAnnotation.fir.txt b/compiler/testData/ir/irText/declarations/annotations/classLiteralInAnnotation.fir.txt index 69f81a9bf19..64a6eac67da 100644 --- a/compiler/testData/ir/irText/declarations/annotations/classLiteralInAnnotation.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/classLiteralInAnnotation.fir.txt @@ -55,7 +55,7 @@ FILE fqName: fileName:/classLiteralInAnnotation.kt BLOCK type=.test2. origin=OBJECT_LITERAL CLASS OBJECT name: modality:FINAL visibility:local superTypes:[kotlin.Any] annotations: - A(klass = ) + A(klass = GET_CLASS type=kotlin.reflect.KClass) $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.test2. CONSTRUCTOR visibility:private <> () returnType:kotlin.Any [primary] BLOCK_BODY @@ -70,7 +70,7 @@ FILE fqName: fileName:/classLiteralInAnnotation.kt BLOCK type=.. origin=OBJECT_LITERAL CLASS OBJECT name: modality:FINAL visibility:local superTypes:[kotlin.Any] annotations: - A(klass = ) + A(klass = GET_CLASS type=kotlin.reflect.KClass) $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.. CONSTRUCTOR visibility:private <> () returnType:kotlin.Any [primary] BLOCK_BODY @@ -84,7 +84,7 @@ FILE fqName: fileName:/classLiteralInAnnotation.kt BLOCK type=.. origin=OBJECT_LITERAL CLASS OBJECT name: modality:FINAL visibility:local superTypes:[kotlin.Any] annotations: - A(klass = ) + A(klass = GET_CLASS type=kotlin.reflect.KClass) $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.. CONSTRUCTOR visibility:private <> () returnType:kotlin.Any [primary] BLOCK_BODY diff --git a/compiler/testData/ir/irText/declarations/annotations/classesWithAnnotations.fir.txt b/compiler/testData/ir/irText/declarations/annotations/classesWithAnnotations.fir.txt index 34e2298ca4b..6fd5d665929 100644 --- a/compiler/testData/ir/irText/declarations/annotations/classesWithAnnotations.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/classesWithAnnotations.fir.txt @@ -29,7 +29,7 @@ FILE fqName: fileName:/classesWithAnnotations.kt $this: VALUE_PARAMETER name: type:kotlin.Any CLASS CLASS name:TestClass modality:FINAL visibility:public superTypes:[kotlin.Any] annotations: - TestAnn(x = ) + TestAnn(x = 'class') $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.TestClass CONSTRUCTOR visibility:public <> () returnType:.TestClass [primary] BLOCK_BODY @@ -50,7 +50,7 @@ FILE fqName: fileName:/classesWithAnnotations.kt $this: VALUE_PARAMETER name: type:kotlin.Any CLASS INTERFACE name:TestInterface modality:ABSTRACT visibility:public superTypes:[kotlin.Any] annotations: - TestAnn(x = ) + TestAnn(x = 'interface') $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.TestInterface FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: @@ -67,7 +67,7 @@ FILE fqName: fileName:/classesWithAnnotations.kt $this: VALUE_PARAMETER name: type:kotlin.Any CLASS OBJECT name:TestObject modality:FINAL visibility:public superTypes:[kotlin.Any] annotations: - TestAnn(x = ) + TestAnn(x = 'object') $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.TestObject CONSTRUCTOR visibility:private <> () returnType:.TestObject [primary] BLOCK_BODY @@ -94,7 +94,7 @@ FILE fqName: fileName:/classesWithAnnotations.kt INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' CLASS OBJECT name:TestCompanion modality:FINAL visibility:public [companion] superTypes:[kotlin.Any] annotations: - TestAnn(x = ) + TestAnn(x = 'companion') $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Host.TestCompanion CONSTRUCTOR visibility:private <> () returnType:.Host.TestCompanion [primary] BLOCK_BODY @@ -128,7 +128,7 @@ FILE fqName: fileName:/classesWithAnnotations.kt $this: VALUE_PARAMETER name: type:kotlin.Any CLASS ENUM_CLASS name:TestEnum modality:FINAL visibility:public superTypes:[kotlin.Enum] annotations: - TestAnn(x = ) + TestAnn(x = 'enum') $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.TestEnum CONSTRUCTOR visibility:private <> () returnType:.TestEnum [primary] BLOCK_BODY @@ -158,7 +158,7 @@ FILE fqName: fileName:/classesWithAnnotations.kt $this: VALUE_PARAMETER name: type:kotlin.Enum CLASS ANNOTATION_CLASS name:TestAnnotation modality:FINAL visibility:public superTypes:[kotlin.Annotation] annotations: - TestAnn(x = ) + TestAnn(x = 'annotation') $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.TestAnnotation CONSTRUCTOR visibility:public <> () returnType:.TestAnnotation [primary] FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean diff --git a/compiler/testData/ir/irText/declarations/annotations/delegatedPropertyAccessorsWithAnnotations.fir.txt b/compiler/testData/ir/irText/declarations/annotations/delegatedPropertyAccessorsWithAnnotations.fir.txt index 1385883918c..d1651a86212 100644 --- a/compiler/testData/ir/irText/declarations/annotations/delegatedPropertyAccessorsWithAnnotations.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/delegatedPropertyAccessorsWithAnnotations.fir.txt @@ -83,7 +83,7 @@ FILE fqName: fileName:/delegatedPropertyAccessorsWithAnnotations.kt $this: VALUE_PARAMETER name: type:kotlin.Any PROPERTY name:test1 visibility:public modality:FINAL [delegated,val] annotations: - A(x = ) + A(x = 'test1.get') FIELD PROPERTY_BACKING_FIELD name:test1 type:IrErrorType visibility:public [final,static] FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType correspondingProperty: PROPERTY name:test1 visibility:public modality:FINAL [delegated,val] @@ -92,9 +92,9 @@ FILE fqName: fileName:/delegatedPropertyAccessorsWithAnnotations.kt GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test1 type:IrErrorType visibility:public [final,static] ' type=IrErrorType origin=null PROPERTY name:test2 visibility:public modality:FINAL [delegated,var] annotations: - A(x = ) - A(x = ) - A(x = ) + A(x = 'test2.get') + A(x = 'test2.set') + A(x = 'test2.set.param') FIELD PROPERTY_BACKING_FIELD name:test2 type:IrErrorType visibility:public [static] FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType correspondingProperty: PROPERTY name:test2 visibility:public modality:FINAL [delegated,var] diff --git a/compiler/testData/ir/irText/declarations/annotations/enumEntriesWithAnnotations.fir.txt b/compiler/testData/ir/irText/declarations/annotations/enumEntriesWithAnnotations.fir.txt index d0955735a12..32e5c53ea62 100644 --- a/compiler/testData/ir/irText/declarations/annotations/enumEntriesWithAnnotations.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/enumEntriesWithAnnotations.fir.txt @@ -35,7 +35,7 @@ FILE fqName: fileName:/enumEntriesWithAnnotations.kt INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ENUM_CLASS name:TestEnum modality:FINAL visibility:public superTypes:[kotlin.Enum]' CLASS ENUM_ENTRY name:ENTRY1 modality:FINAL visibility:public superTypes:[kotlin.Any] annotations: - TestAnn(x = ) + TestAnn(x = 'ENTRY1') $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.TestEnum.ENTRY1 CONSTRUCTOR visibility:public <> () returnType:.TestEnum.ENTRY1 [primary] BLOCK_BODY @@ -56,7 +56,7 @@ FILE fqName: fileName:/enumEntriesWithAnnotations.kt $this: VALUE_PARAMETER name: type:kotlin.Any CLASS ENUM_ENTRY name:ENTRY2 modality:FINAL visibility:public superTypes:[kotlin.Any] annotations: - TestAnn(x = ) + TestAnn(x = 'ENTRY2') $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.TestEnum.ENTRY2 CONSTRUCTOR visibility:public <> () returnType:.TestEnum.ENTRY2 [primary] BLOCK_BODY diff --git a/compiler/testData/ir/irText/declarations/annotations/fieldsWithAnnotations.fir.txt b/compiler/testData/ir/irText/declarations/annotations/fieldsWithAnnotations.fir.txt index d9fd6d73a0c..1852ff783b0 100644 --- a/compiler/testData/ir/irText/declarations/annotations/fieldsWithAnnotations.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/fieldsWithAnnotations.fir.txt @@ -29,7 +29,7 @@ FILE fqName: fileName:/fieldsWithAnnotations.kt $this: VALUE_PARAMETER name: type:kotlin.Any PROPERTY name:testVal visibility:public modality:FINAL [val] annotations: - TestAnn(x = ) + TestAnn(x = 'testVal.field') FIELD PROPERTY_BACKING_FIELD name:testVal type:kotlin.String visibility:public [final,static] EXPRESSION_BODY CONST String type=kotlin.String value="a val" @@ -40,7 +40,7 @@ FILE fqName: fileName:/fieldsWithAnnotations.kt GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:testVal type:kotlin.String visibility:public [final,static] ' type=kotlin.String origin=null PROPERTY name:testVar visibility:public modality:FINAL [var] annotations: - TestAnn(x = ) + TestAnn(x = 'testVar.field') FIELD PROPERTY_BACKING_FIELD name:testVar type:kotlin.String visibility:public [static] EXPRESSION_BODY CONST String type=kotlin.String value="a var" diff --git a/compiler/testData/ir/irText/declarations/annotations/fileAnnotations.fir.txt b/compiler/testData/ir/irText/declarations/annotations/fileAnnotations.fir.txt index bd9fc0aebd7..69e7f44f102 100644 --- a/compiler/testData/ir/irText/declarations/annotations/fileAnnotations.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/fileAnnotations.fir.txt @@ -1,6 +1,6 @@ FILE fqName:test fileName:/fileAnnotations.kt annotations: - A(x = ) + A(x = 'File annotation') CLASS ANNOTATION_CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Annotation] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:test.A CONSTRUCTOR visibility:public <> (x:kotlin.String) returnType:test.A [primary] diff --git a/compiler/testData/ir/irText/declarations/annotations/propertiesWithAnnotations.fir.txt b/compiler/testData/ir/irText/declarations/annotations/propertiesWithAnnotations.fir.txt index 45992652145..5d1583f4a0e 100644 --- a/compiler/testData/ir/irText/declarations/annotations/propertiesWithAnnotations.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/propertiesWithAnnotations.fir.txt @@ -29,7 +29,7 @@ FILE fqName: fileName:/propertiesWithAnnotations.kt $this: VALUE_PARAMETER name: type:kotlin.Any PROPERTY name:testVal visibility:public modality:FINAL [val] annotations: - TestAnn(x = ) + TestAnn(x = 'testVal.property') FIELD PROPERTY_BACKING_FIELD name:testVal type:kotlin.String visibility:public [final,static] EXPRESSION_BODY CONST String type=kotlin.String value="" diff --git a/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsFromClassHeaderWithAnnotations.fir.txt b/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsFromClassHeaderWithAnnotations.fir.txt index a8bfbfc4345..db53e683acb 100644 --- a/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsFromClassHeaderWithAnnotations.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsFromClassHeaderWithAnnotations.fir.txt @@ -37,7 +37,7 @@ FILE fqName: fileName:/propertyAccessorsFromClassHeaderWithAnnotations.kt INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' PROPERTY name:x visibility:public modality:FINAL [val] annotations: - A(x = ) + A(x = 'C.x.get') FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:public [final] EXPRESSION_BODY GET_VAR 'x: kotlin.Int declared in .C.' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER @@ -50,8 +50,8 @@ FILE fqName: fileName:/propertyAccessorsFromClassHeaderWithAnnotations.kt receiver: GET_VAR ': .C declared in .C.' type=.C origin=null PROPERTY name:y visibility:public modality:FINAL [var] annotations: - A(x = ) - A(x = ) + A(x = 'C.y.get') + A(x = 'C.y.set') FIELD PROPERTY_BACKING_FIELD name:y type:kotlin.Int visibility:public EXPRESSION_BODY GET_VAR 'y: kotlin.Int declared in .C.' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER diff --git a/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsWithAnnotations.fir.txt b/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsWithAnnotations.fir.txt index 75ba885eb98..2ccffce29d7 100644 --- a/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsWithAnnotations.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/propertyAccessorsWithAnnotations.fir.txt @@ -45,7 +45,7 @@ FILE fqName: fileName:/propertyAccessorsWithAnnotations.kt BLOCK_BODY PROPERTY name:test3 visibility:public modality:FINAL [val] annotations: - TestAnn(x = ) + TestAnn(x = 'test3.get') FIELD PROPERTY_BACKING_FIELD name:test3 type:kotlin.String visibility:public [final,static] EXPRESSION_BODY CONST String type=kotlin.String value="" @@ -56,8 +56,8 @@ FILE fqName: fileName:/propertyAccessorsWithAnnotations.kt GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test3 type:kotlin.String visibility:public [final,static] ' type=kotlin.String origin=null PROPERTY name:test4 visibility:public modality:FINAL [var] annotations: - TestAnn(x = ) - TestAnn(x = ) + TestAnn(x = 'test4.get') + TestAnn(x = 'test4.set') FIELD PROPERTY_BACKING_FIELD name:test4 type:kotlin.String visibility:public [static] EXPRESSION_BODY CONST String type=kotlin.String value="" diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/local.fir.txt b/compiler/testData/ir/irText/declarations/provideDelegate/local.fir.txt index ad6ea8fb971..5a5d5c42440 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/local.fir.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/local.fir.txt @@ -62,7 +62,8 @@ FILE fqName: fileName:/local.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun provideDelegate (thisRef: kotlin.Any?, property: kotlin.Any?): .Delegate declared in .DelegateProvider' CONSTRUCTOR_CALL 'public constructor (value: kotlin.String) [primary] declared in .Delegate' type=.Delegate origin=null - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + value: CALL 'public final fun (): kotlin.String declared in .DelegateProvider' type=kotlin.String origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/member.fir.txt b/compiler/testData/ir/irText/declarations/provideDelegate/member.fir.txt index 8d41e8c5ef8..64829f52232 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/member.fir.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/member.fir.txt @@ -62,7 +62,8 @@ FILE fqName: fileName:/member.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun provideDelegate (thisRef: kotlin.Any?, property: kotlin.Any?): .Delegate declared in .DelegateProvider' CONSTRUCTOR_CALL 'public constructor (value: kotlin.String) [primary] declared in .Delegate' type=.Delegate origin=null - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + value: CALL 'public final fun (): kotlin.String declared in .DelegateProvider' type=kotlin.String origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt index a11fade9c57..30487b99bf2 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.fir.txt @@ -51,7 +51,8 @@ FILE fqName: fileName:/memberExtension.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun provideDelegate (host: kotlin.Any?, p: kotlin.Any): .Host.StringDelegate declared in .Host' CONSTRUCTOR_CALL 'public constructor (s: kotlin.String) [primary] declared in .Host.StringDelegate' type=.Host.StringDelegate origin=null - PROPERTY name:plusK visibility:public modality:FINAL [delegated,val] + s: ERROR_CALL 'Unresolved reference: this#' type=kotlin.String + PROPERTY name:plusK visibility:public modality:FINAL [delegated,val] FIELD PROPERTY_BACKING_FIELD name:plusK type:IrErrorType visibility:public [final] FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Host) returnType:IrErrorType correspondingProperty: PROPERTY name:plusK visibility:public modality:FINAL [delegated,val] diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/topLevel.fir.txt b/compiler/testData/ir/irText/declarations/provideDelegate/topLevel.fir.txt index b2a768da514..5f14c58d04a 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/topLevel.fir.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/topLevel.fir.txt @@ -62,7 +62,8 @@ FILE fqName: fileName:/topLevel.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun provideDelegate (thisRef: kotlin.Any?, property: kotlin.Any?): .Delegate declared in .DelegateProvider' CONSTRUCTOR_CALL 'public constructor (value: kotlin.String) [primary] declared in .Delegate' type=.Delegate origin=null - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + value: CALL 'public final fun (): kotlin.String declared in .DelegateProvider' type=kotlin.String origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.txt b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.txt index c6f79f5a72e..00407dffda0 100644 --- a/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.txt +++ b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.txt @@ -64,7 +64,8 @@ FILE fqName: fileName:/forWithImplicitReceivers.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun iterator (): .IntCell declared in .IReceiver' CONSTRUCTOR_CALL 'public constructor (value: kotlin.Int) [primary] declared in .IntCell' type=.IntCell origin=null - FUN name:hasNext visibility:public modality:OPEN <> ($this:.IReceiver) returnType:kotlin.Boolean + value: CONST Int type=kotlin.Int value=5 + FUN name:hasNext visibility:public modality:OPEN <> ($this:.IReceiver) returnType:kotlin.Boolean $this: VALUE_PARAMETER name: type:.IReceiver BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun hasNext (): kotlin.Boolean declared in .IReceiver' diff --git a/compiler/testData/ir/irText/expressions/genericConstructorCallWithTypeArguments.fir.txt b/compiler/testData/ir/irText/expressions/genericConstructorCallWithTypeArguments.fir.txt index 133420c2ae3..bc8ccd423c5 100644 --- a/compiler/testData/ir/irText/expressions/genericConstructorCallWithTypeArguments.fir.txt +++ b/compiler/testData/ir/irText/expressions/genericConstructorCallWithTypeArguments.fir.txt @@ -12,6 +12,13 @@ FILE fqName: fileName:/genericConstructorCallWithTypeArguments.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun testArray (n: kotlin.Int, block: kotlin.Function0.testArray>): kotlin.Array.testArray> [inline] declared in ' CONSTRUCTOR_CALL 'public constructor (size: kotlin.Int, init: kotlin.Function1>) declared in kotlin.Array' type=kotlin.Array.testArray> origin=null + size: GET_VAR 'n: kotlin.Int declared in .testArray' type=kotlin.Int origin=null + init: BLOCK type=T of origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:kotlin.Int) returnType:T of + VALUE_PARAMETER name:it index:0 type:kotlin.Int + BLOCK_BODY + ERROR_CALL 'Unresolved reference: #' type=IrErrorType + FUNCTION_REFERENCE 'local final fun (it: kotlin.Int): T of declared in .testArray' type=T of origin=LAMBDA CLASS CLASS name:Box modality:FINAL visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Box TYPE_PARAMETER name:T index:0 variance: superTypes:[] diff --git a/compiler/testData/ir/irText/expressions/memberTypeArguments.fir.txt b/compiler/testData/ir/irText/expressions/memberTypeArguments.fir.txt index 9ac84db6289..e440fc146e6 100644 --- a/compiler/testData/ir/irText/expressions/memberTypeArguments.fir.txt +++ b/compiler/testData/ir/irText/expressions/memberTypeArguments.fir.txt @@ -25,7 +25,8 @@ FILE fqName: fileName:/memberTypeArguments.kt RETURN type=kotlin.Nothing from='public final fun withNewValue (newValue: T of .GenericClass): .GenericClass.GenericClass> declared in .GenericClass' CONSTRUCTOR_CALL 'public constructor (value: T of ) [primary] declared in .GenericClass' type=.GenericClass.GenericClass> origin=null : - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean + value: GET_VAR 'newValue: T of .GenericClass declared in .GenericClass.withNewValue' type=T of .GenericClass origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/expressions/specializedTypeAliasConstructorCall.fir.txt b/compiler/testData/ir/irText/expressions/specializedTypeAliasConstructorCall.fir.txt index 98a758306fc..ec782cb67dc 100644 --- a/compiler/testData/ir/irText/expressions/specializedTypeAliasConstructorCall.fir.txt +++ b/compiler/testData/ir/irText/expressions/specializedTypeAliasConstructorCall.fir.txt @@ -36,3 +36,4 @@ FILE fqName: fileName:/specializedTypeAliasConstructorCall.kt RETURN type=kotlin.Nothing from='public final fun test (): .Cell declared in ' CONSTRUCTOR_CALL 'public constructor (value: T of ) [primary] declared in .Cell' type=.Cell origin=null : + value: CONST Int type=kotlin.Int value=42 diff --git a/compiler/testData/ir/irText/regressions/coercionInLoop.fir.txt b/compiler/testData/ir/irText/regressions/coercionInLoop.fir.txt index 5cc5a61af27..bdd01a241c3 100644 --- a/compiler/testData/ir/irText/regressions/coercionInLoop.fir.txt +++ b/compiler/testData/ir/irText/regressions/coercionInLoop.fir.txt @@ -3,7 +3,8 @@ FILE fqName: fileName:/coercionInLoop.kt BLOCK_BODY VAR name:a type:kotlin.DoubleArray [val] CONSTRUCTOR_CALL 'public constructor (size: kotlin.Int) [primary] declared in kotlin.DoubleArray' type=kotlin.DoubleArray origin=null - VAR name:x type:kotlin.collections.DoubleIterator [val] + size: CONST Int type=kotlin.Int value=5 + VAR name:x type:kotlin.collections.DoubleIterator [val] CALL 'public final fun iterator (): kotlin.collections.DoubleIterator declared in kotlin.DoubleArray' type=kotlin.collections.DoubleIterator origin=null VAR name:i type:kotlin.Int [var] CONST Int type=kotlin.Int value=0 diff --git a/compiler/testData/ir/irText/regressions/typeAliasCtorForGenericClass.fir.txt b/compiler/testData/ir/irText/regressions/typeAliasCtorForGenericClass.fir.txt index d9d923b838f..27ee1e50d70 100644 --- a/compiler/testData/ir/irText/regressions/typeAliasCtorForGenericClass.fir.txt +++ b/compiler/testData/ir/irText/regressions/typeAliasCtorForGenericClass.fir.txt @@ -36,6 +36,8 @@ FILE fqName: fileName:/typeAliasCtorForGenericClass.kt VAR name:b type:.A [val] CONSTRUCTOR_CALL 'public constructor (q: Q of ) [primary] declared in .A' type=.A origin=null : + q: CONST Int type=kotlin.Int value=2 VAR name:b2 type:.A<.A> [val] CONSTRUCTOR_CALL 'public constructor (q: Q of ) [primary] declared in .A' type=.A<.A> origin=null : + q: GET_VAR 'val b: .A [val] declared in .bar' type=.A origin=null diff --git a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.txt b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.txt index 17f144d76a7..ab25014836f 100644 --- a/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.txt +++ b/compiler/testData/ir/irText/stubs/javaConstructorWithTypeParameters.fir.txt @@ -7,7 +7,8 @@ FILE fqName: fileName:/javaConstructorWithTypeParameters.kt BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test2 (): .J1 declared in ' CONSTRUCTOR_CALL 'public constructor (x1: X1 of ?) declared in .J1' type=.J1 origin=null - FUN name:test3 visibility:public modality:FINAL <> (j1:.J1) returnType:IrErrorType + x1: CONST Int type=kotlin.Int value=1 + FUN name:test3 visibility:public modality:FINAL <> (j1:.J1) returnType:IrErrorType VALUE_PARAMETER name:j1 index:0 type:.J1 BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test3 (j1: .J1): IrErrorType declared in ' diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index 48fb946f897..b2448527782 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -256,6 +256,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/fileClassClashMultipleFiles.args"); } + @TestMetadata("firHello.args") + public void testFirHello() throws Exception { + runTest("compiler/testData/cli/jvm/firHello.args"); + } + @TestMetadata("flagAllowingResultAsReturnType.args") public void testFlagAllowingResultAsReturnType() throws Exception { runTest("compiler/testData/cli/jvm/flagAllowingResultAsReturnType.args"); diff --git a/idea/testData/gradle/highlighting/complexBuildGradleKts/build.gradle.kts b/idea/testData/gradle/highlighting/complexBuildGradleKts/build.gradle.kts index 1589efb3200..19ab760884e 100644 --- a/idea/testData/gradle/highlighting/complexBuildGradleKts/build.gradle.kts +++ b/idea/testData/gradle/highlighting/complexBuildGradleKts/build.gradle.kts @@ -118,6 +118,7 @@ extra["compilerModules"] = arrayOf( ":compiler:fir:tree", ":compiler:fir:psi2fir", ":compiler:fir:fir2ir", + ":compiler:fir:java", ":compiler:frontend", ":compiler:frontend.common", ":compiler:frontend.java",