diff --git a/analysis/low-level-api-fir/build.gradle.kts b/analysis/low-level-api-fir/build.gradle.kts index 65686e6bf7b..d9d79522d21 100644 --- a/analysis/low-level-api-fir/build.gradle.kts +++ b/analysis/low-level-api-fir/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { api(project(":compiler:fir:checkers:checkers.jvm")) api(project(":compiler:fir:checkers:checkers.js")) api(project(":compiler:fir:checkers:checkers.native")) + api(project(":compiler:fir:checkers:checkers.wasm")) api(project(":compiler:fir:java")) api(project(":compiler:backend.common.jvm")) api(project(":analysis:analysis-api-impl-barebone")) diff --git a/build.gradle.kts b/build.gradle.kts index 4b2660c7ca3..cc5ff5a1bd2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -167,6 +167,7 @@ val firCompilerCoreModules = arrayOf( ":compiler:fir:checkers:checkers.jvm", ":compiler:fir:checkers:checkers.js", ":compiler:fir:checkers:checkers.native", + ":compiler:fir:checkers:checkers.wasm", ":compiler:fir:entrypoint", // TODO should not be in core modules but FIR IDE uses DependencyListForCliModule from this module ":compiler:fir:fir2ir:jvm-backend", // TODO should not be in core modules but FIR IDE uses Fir2IrSignatureComposer from this module ":compiler:fir:fir2ir" // TODO should not be in core modules but FIR IDE uses Fir2IrSignatureComposer from this module diff --git a/compiler/cli/build.gradle.kts b/compiler/cli/build.gradle.kts index f40274676ce..763262de4de 100644 --- a/compiler/cli/build.gradle.kts +++ b/compiler/cli/build.gradle.kts @@ -26,6 +26,7 @@ dependencies { api(project(":compiler:fir:checkers:checkers.jvm")) api(project(":compiler:fir:checkers:checkers.js")) api(project(":compiler:fir:checkers:checkers.native")) + api(project(":compiler:fir:checkers:checkers.wasm")) api(project(":compiler:fir:fir-serialization")) api(project(":kotlin-util-io")) diff --git a/compiler/fir/analysis-tests/build.gradle.kts b/compiler/fir/analysis-tests/build.gradle.kts index fe414665989..dd2b68285f1 100644 --- a/compiler/fir/analysis-tests/build.gradle.kts +++ b/compiler/fir/analysis-tests/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { testApi(project(":compiler:fir:checkers:checkers.jvm")) testApi(project(":compiler:fir:checkers:checkers.js")) testApi(project(":compiler:fir:checkers:checkers.native")) + testApi(project(":compiler:fir:checkers:checkers.wasm")) testApi(project(":compiler:fir:fir-serialization")) testApi(project(":compiler:fir:entrypoint")) testApi(project(":compiler:frontend")) diff --git a/compiler/fir/analysis-tests/legacy-fir-tests/build.gradle.kts b/compiler/fir/analysis-tests/legacy-fir-tests/build.gradle.kts index 5b3b131fac9..afcdb1309df 100644 --- a/compiler/fir/analysis-tests/legacy-fir-tests/build.gradle.kts +++ b/compiler/fir/analysis-tests/legacy-fir-tests/build.gradle.kts @@ -21,6 +21,7 @@ dependencies { testApi(project(":compiler:fir:checkers:checkers.jvm")) testApi(project(":compiler:fir:checkers:checkers.js")) testApi(project(":compiler:fir:checkers:checkers.native")) + testApi(project(":compiler:fir:checkers:checkers.wasm")) testApi(project(":compiler:fir:entrypoint")) testApi(project(":compiler:frontend")) diff --git a/compiler/fir/checkers/build.gradle.kts b/compiler/fir/checkers/build.gradle.kts index 0def8b1d5a1..f6c753dea71 100644 --- a/compiler/fir/checkers/build.gradle.kts +++ b/compiler/fir/checkers/build.gradle.kts @@ -38,6 +38,7 @@ val platformGenerationRoots = listOf( "checkers.jvm", "checkers.js", "checkers.native", + "checkers.wasm", ).map { projectDir.resolve(it).resolve("gen") } val generateCheckersComponents by tasks.registering(NoDebugJavaExec::class) { diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt index 48c7a9e24e9..f730da65a53 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/Main.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.DIAGNOSTICS_LIST import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.JS_DIAGNOSTICS_LIST import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.JVM_DIAGNOSTICS_LIST import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.NATIVE_DIAGNOSTICS_LIST +import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.WASM_DIAGNOSTICS_LIST import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.ErrorListDiagnosticListRenderer import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.generateDiagnostics import org.jetbrains.kotlin.fir.declarations.* @@ -101,6 +102,7 @@ fun main(args: Array) { val jvmGenerationPath = File(arguments.getOrElse(1) { "compiler/fir/checkers/checkers.jvm/gen" }) val jsGenerationPath = File(arguments.getOrElse(2) { "compiler/fir/checkers/checkers.js/gen" }) val nativeGenerationPath = File(arguments.getOrElse(3) { "compiler/fir/checkers/checkers.native/gen" }) + val wasmGenerationPath = File(arguments.getOrElse(4) { "compiler/fir/checkers/checkers.wasm/gen" }) val rawFirGenerationPath = File("compiler/fir/raw-fir/raw-fir.common/gen") val packageName = "$basePackage.diagnostics" @@ -109,6 +111,7 @@ fun main(args: Array) { generateDiagnostics(jvmGenerationPath, "$packageName.jvm", JVM_DIAGNOSTICS_LIST, starImportsToAdd = setOf(ErrorListDiagnosticListRenderer.BASE_PACKAGE, ErrorListDiagnosticListRenderer.DIAGNOSTICS_PACKAGE)) generateDiagnostics(jsGenerationPath, "$packageName.js", JS_DIAGNOSTICS_LIST, starImportsToAdd = setOf(ErrorListDiagnosticListRenderer.BASE_PACKAGE, ErrorListDiagnosticListRenderer.DIAGNOSTICS_PACKAGE)) generateDiagnostics(nativeGenerationPath, "$packageName.native", NATIVE_DIAGNOSTICS_LIST, starImportsToAdd = setOf(ErrorListDiagnosticListRenderer.BASE_PACKAGE, ErrorListDiagnosticListRenderer.DIAGNOSTICS_PACKAGE)) + generateDiagnostics(wasmGenerationPath, "$packageName.wasm", WASM_DIAGNOSTICS_LIST, starImportsToAdd = setOf(ErrorListDiagnosticListRenderer.BASE_PACKAGE, ErrorListDiagnosticListRenderer.DIAGNOSTICS_PACKAGE)) generateDiagnostics(rawFirGenerationPath, "org.jetbrains.kotlin.fir.builder", SYNTAX_DIAGNOSTIC_LIST, starImportsToAdd = setOf(ErrorListDiagnosticListRenderer.DIAGNOSTICS_PACKAGE)) generateNonSuppressibleErrorNamesFile(generationPath, packageName) diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirWasmDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirWasmDiagnosticsList.kt new file mode 100644 index 00000000000..5fc24330db8 --- /dev/null +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirWasmDiagnosticsList.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2021 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.checkers.generator.diagnostics + +import org.jetbrains.kotlin.diagnostics.Severity +import org.jetbrains.kotlin.diagnostics.error1 +import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.DiagnosticList +import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.PositioningStrategy +import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.util.PrivateForInline + +@Suppress("ClassName", "unused") +@OptIn(PrivateForInline::class) +object WASM_DIAGNOSTICS_LIST : DiagnosticList("FirWasmErrors") { + val EXTERNALS by object : DiagnosticGroup("Externals") { + val NON_EXTERNAL_TYPE_EXTENDS_EXTERNAL_TYPE by error(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) { + parameter("superType") + } + } +} diff --git a/compiler/fir/checkers/checkers.wasm/build.gradle.kts b/compiler/fir/checkers/checkers.wasm/build.gradle.kts new file mode 100644 index 00000000000..458ef39c8e6 --- /dev/null +++ b/compiler/fir/checkers/checkers.wasm/build.gradle.kts @@ -0,0 +1,38 @@ +import org.jetbrains.kotlin.ideaExt.idea + +plugins { + kotlin("jvm") + id("jps-compatible") +} + +dependencies { + api(project(":compiler:fir:checkers")) + api(project(":core:compiler.common.wasm")) + + /* + * We can't remove this dependency until we use + * diagnostics framework from FE 1.0 + */ + implementation(project(":compiler:frontend")) + implementation(project(":compiler:psi")) + + compileOnly(intellijCore()) +} + +sourceSets { + "main" { + projectDefault() + generatedDir() + } + "test" { none() } +} + +val compileKotlin by tasks +compileKotlin.dependsOn(":compiler:fir:checkers:generateCheckersComponents") + +if (kotlinBuildProperties.isInJpsBuildIdeaSync) { + apply(plugin = "idea") + idea { + this.module.generatedSourceDirs.add(projectDir.resolve("gen")) + } +} diff --git a/compiler/fir/checkers/checkers.wasm/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/wasm/FirWasmErrors.kt b/compiler/fir/checkers/checkers.wasm/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/wasm/FirWasmErrors.kt new file mode 100644 index 00000000000..9a705ec9f9c --- /dev/null +++ b/compiler/fir/checkers/checkers.wasm/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/wasm/FirWasmErrors.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2023 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.analysis.diagnostics.wasm + +import org.jetbrains.kotlin.diagnostics.* +import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies +import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory +import org.jetbrains.kotlin.fir.analysis.diagnostics.* +import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.psi.KtElement + +/* + * This file was generated automatically + * DO NOT MODIFY IT MANUALLY + */ + +object FirWasmErrors { + // Externals + val NON_EXTERNAL_TYPE_EXTENDS_EXTERNAL_TYPE by error1(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT) + + init { + RootDiagnosticRendererFactory.registerFactory(FirWasmErrorsDefaultMessages) + } +} diff --git a/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/diagnostics/wasm/FirWasmErrorsDefaultMessages.kt b/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/diagnostics/wasm/FirWasmErrorsDefaultMessages.kt new file mode 100644 index 00000000000..023eeefc24b --- /dev/null +++ b/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/diagnostics/wasm/FirWasmErrorsDefaultMessages.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2021 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.analysis.diagnostics.wasm + +import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap +import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers +import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors.NON_EXTERNAL_TYPE_EXTENDS_EXTERNAL_TYPE + +@Suppress("unused") +object FirWasmErrorsDefaultMessages : BaseDiagnosticRendererFactory() { + override val MAP = KtDiagnosticFactoryToRendererMap("FIR").also { map -> + map.put(NON_EXTERNAL_TYPE_EXTENDS_EXTERNAL_TYPE, "Non-external type extends external type {0}", FirDiagnosticRenderers.RENDER_TYPE) + } +} diff --git a/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/wasm/checkers/WasmDeclarationCheckers.kt b/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/wasm/checkers/WasmDeclarationCheckers.kt new file mode 100644 index 00000000000..8382d5152b8 --- /dev/null +++ b/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/wasm/checkers/WasmDeclarationCheckers.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2021 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.analysis.wasm.checkers + +import org.jetbrains.kotlin.fir.analysis.checkers.declaration.* +import org.jetbrains.kotlin.fir.analysis.wasm.checkers.declaration.* + +object WasmDeclarationCheckers : DeclarationCheckers() { + override val functionCheckers: Set + get() = setOf( + ) + + override val basicDeclarationCheckers: Set + get() = setOf( + ) + + override val classCheckers: Set + get() = setOf( + FirWasmExternalInheritanceChecker + ) + + override val simpleFunctionCheckers: Set + get() = setOf( + ) +} diff --git a/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/wasm/checkers/WasmExpressionCheckers.kt b/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/wasm/checkers/WasmExpressionCheckers.kt new file mode 100644 index 00000000000..c43f4396871 --- /dev/null +++ b/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/wasm/checkers/WasmExpressionCheckers.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2021 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.analysis.wasm.checkers + +import org.jetbrains.kotlin.fir.analysis.checkers.expression.* + +object WasmExpressionCheckers : ExpressionCheckers() { + override val annotationCallCheckers: Set + get() = setOf( + ) + + override val basicExpressionCheckers: Set + get() = setOf( + ) + + override val functionCallCheckers: Set + get() = setOf( + ) + + override val callCheckers: Set + get() = setOf( + ) +} diff --git a/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/wasm/checkers/declaration/FirWasmExternalInheritanceChecker.kt b/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/wasm/checkers/declaration/FirWasmExternalInheritanceChecker.kt new file mode 100644 index 00000000000..dc504d242b5 --- /dev/null +++ b/compiler/fir/checkers/checkers.wasm/src/org/jetbrains/kotlin/fir/analysis/wasm/checkers/declaration/FirWasmExternalInheritanceChecker.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2023 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.analysis.wasm.checkers.declaration + +import org.jetbrains.kotlin.diagnostics.DiagnosticReporter +import org.jetbrains.kotlin.diagnostics.reportOn +import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext +import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirClassChecker +import org.jetbrains.kotlin.fir.analysis.checkers.toClassLikeSymbol +import org.jetbrains.kotlin.fir.analysis.diagnostics.wasm.FirWasmErrors +import org.jetbrains.kotlin.fir.declarations.utils.isEffectivelyExternal +import org.jetbrains.kotlin.fir.declarations.FirClass +import org.jetbrains.kotlin.fir.types.coneType + +object FirWasmExternalInheritanceChecker : FirClassChecker() { + override fun check(declaration: FirClass, context: CheckerContext, reporter: DiagnosticReporter) { + val session = context.session + if (!declaration.symbol.isEffectivelyExternal(session)) { + for (superTypeRef in declaration.superTypeRefs) { + if (superTypeRef.toClassLikeSymbol(session)?.isEffectivelyExternal(session) == true) { + reporter.reportOn( + declaration.source, + FirWasmErrors.NON_EXTERNAL_TYPE_EXTENDS_EXTERNAL_TYPE, + superTypeRef.coneType, + context + ) + } + } + } + } +} \ No newline at end of file diff --git a/compiler/fir/entrypoint/build.gradle.kts b/compiler/fir/entrypoint/build.gradle.kts index 61890688552..ec3bef1e147 100644 --- a/compiler/fir/entrypoint/build.gradle.kts +++ b/compiler/fir/entrypoint/build.gradle.kts @@ -14,6 +14,7 @@ dependencies { api(project(":compiler:fir:checkers:checkers.jvm")) api(project(":compiler:fir:checkers:checkers.js")) api(project(":compiler:fir:checkers:checkers.native")) + api(project(":compiler:fir:checkers:checkers.wasm")) api(project(":js:js.frontend")) implementation(project(":core:compiler.common.native")) diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CheckersContainers.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CheckersContainers.kt index 603b55f5ab6..6a586fd15fc 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CheckersContainers.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/checkers/CheckersContainers.kt @@ -13,6 +13,8 @@ import org.jetbrains.kotlin.fir.analysis.jvm.checkers.JvmExpressionCheckers import org.jetbrains.kotlin.fir.analysis.jvm.checkers.JvmTypeCheckers import org.jetbrains.kotlin.fir.analysis.native.checkers.NativeDeclarationCheckers import org.jetbrains.kotlin.fir.analysis.native.checkers.NativeExpressionCheckers +import org.jetbrains.kotlin.fir.analysis.wasm.checkers.WasmDeclarationCheckers +import org.jetbrains.kotlin.fir.analysis.wasm.checkers.WasmExpressionCheckers import org.jetbrains.kotlin.fir.session.FirSessionConfigurator fun FirSessionConfigurator.registerCommonCheckers() { @@ -46,5 +48,6 @@ fun FirSessionConfigurator.registerNativeCheckers() { } fun FirSessionConfigurator.registerWasmCheckers() { - // TODO: Implement Wasm checkers (KT-56849) + useCheckers(WasmDeclarationCheckers) + useCheckers(WasmExpressionCheckers) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/wasmTests/jsInterop/inheritance.fir.kt b/compiler/testData/diagnostics/wasmTests/jsInterop/inheritance.fir.kt index a3a07bba5ae..674b8dccf5f 100644 --- a/compiler/testData/diagnostics/wasmTests/jsInterop/inheritance.fir.kt +++ b/compiler/testData/diagnostics/wasmTests/jsInterop/inheritance.fir.kt @@ -10,13 +10,13 @@ external class EC3 : I1, C1 external interface EI1 : I1 -interface I2 : EI1 +interface I2 : EI1 -class C3 : EI1 +class C3 : EI1 -class C4 : EI1, EC1() +class C4 : EI1, EC1() -object O1 : EC1() +object O1 : EC1() -val x1: Any = object : EI1 {} -val x2: Any = object : EC1() {} +val x1: Any = object : EI1 {} +val x2: Any = object : EC1() {} diff --git a/compiler/tests-common/build.gradle.kts b/compiler/tests-common/build.gradle.kts index dfb84a1bb0b..7e4479806dd 100644 --- a/compiler/tests-common/build.gradle.kts +++ b/compiler/tests-common/build.gradle.kts @@ -29,6 +29,7 @@ dependencies { testApi(project(":compiler:fir:checkers:checkers.jvm")) testApi(project(":compiler:fir:checkers:checkers.js")) testApi(project(":compiler:fir:checkers:checkers.native")) + testApi(project(":compiler:fir:checkers:checkers.wasm")) testApi(project(":compiler:fir:java")) testApi(project(":compiler:fir:entrypoint")) testApi(project(":compiler:ir.ir2cfg")) diff --git a/plugins/fir-plugin-prototype/build.gradle.kts b/plugins/fir-plugin-prototype/build.gradle.kts index a29da452560..6bfbcf26138 100644 --- a/plugins/fir-plugin-prototype/build.gradle.kts +++ b/plugins/fir-plugin-prototype/build.gradle.kts @@ -31,6 +31,7 @@ dependencies { testApi(project(":compiler:fir:checkers:checkers.jvm")) testApi(project(":compiler:fir:checkers:checkers.js")) testApi(project(":compiler:fir:checkers:checkers.native")) + testApi(project(":compiler:fir:checkers:checkers.wasm")) testApi(project(":compiler:fir:plugin-utils")) testRuntimeOnly(project(":core:descriptors.runtime")) diff --git a/settings.gradle b/settings.gradle index 1e2f4c615a1..5e3714cb40a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -300,6 +300,7 @@ include ":compiler:fir", ":compiler:fir:checkers:checkers.jvm", ":compiler:fir:checkers:checkers.js", ":compiler:fir:checkers:checkers.native", + ":compiler:fir:checkers:checkers.wasm", ":compiler:fir:checkers:checkers-component-generator", ":compiler:fir:entrypoint", ":compiler:fir:analysis-tests",