[JS IR BE] Some preparation for IrSerialization
This commit is contained in:
@@ -45,6 +45,7 @@ fun compile(
|
||||
files: List<KtFile>,
|
||||
configuration: CompilerConfiguration,
|
||||
export: List<FqName> = emptyList(),
|
||||
isKlibCompilation: Boolean = false,
|
||||
dependencies: List<CompiledModule> = emptyList(),
|
||||
builtInsModule: CompiledModule? = null,
|
||||
moduleType: ModuleType
|
||||
@@ -82,24 +83,36 @@ fun compile(
|
||||
moduleType
|
||||
)
|
||||
|
||||
// TODO: Split compilation into two steps: kt -> ir, ir -> js
|
||||
val moduleName = configuration[CommonConfigurationKeys.MODULE_NAME]!!
|
||||
when (moduleType) {
|
||||
ModuleType.MAIN -> {
|
||||
val moduleDependencies: List<CompiledModule> =
|
||||
DFS.topologicalOrder(dependencies, CompiledModule::dependencies)
|
||||
.filter { it.moduleType == ModuleType.SECONDARY }
|
||||
|
||||
val fileDependencies = moduleDependencies.flatMap { it.moduleFragment!!.files }
|
||||
if (isKlibCompilation) {
|
||||
// val declarationTable = DeclarationTable(moduleFragment.irBuiltins, DescriptorTable())
|
||||
// val serializedIr = IrModuleSerializer(context, declarationTable/*, onlyForInlines = false*/).serializedIrModule(moduleFragment)
|
||||
// val serializer = KonanSerializationUtil(context, configuration.get(CommonConfigurationKeys.METADATA_VERSION)!!, declarationTable)
|
||||
// val serializedData = serializer.serializeModule(analysisResult.moduleDescriptor, serializedIr)
|
||||
// buildLibrary(serializedData)
|
||||
//
|
||||
TODO("Implemenet IrSerialization")
|
||||
} else {
|
||||
|
||||
moduleFragment.files.addAll(0, fileDependencies)
|
||||
}
|
||||
// TODO: Split compilation into two steps: kt -> ir, ir -> js
|
||||
val moduleName = configuration[CommonConfigurationKeys.MODULE_NAME]!!
|
||||
when (moduleType) {
|
||||
ModuleType.MAIN -> {
|
||||
val moduleDependencies: List<CompiledModule> =
|
||||
DFS.topologicalOrder(dependencies, CompiledModule::dependencies)
|
||||
.filter { it.moduleType == ModuleType.SECONDARY }
|
||||
|
||||
ModuleType.SECONDARY -> {
|
||||
return CompiledModule(moduleName, null, moduleFragment, moduleType, dependencies)
|
||||
}
|
||||
val fileDependencies = moduleDependencies.flatMap { it.moduleFragment!!.files }
|
||||
|
||||
ModuleType.TEST_RUNTIME -> {
|
||||
moduleFragment.files.addAll(0, fileDependencies)
|
||||
}
|
||||
|
||||
ModuleType.SECONDARY -> {
|
||||
return CompiledModule(moduleName, null, moduleFragment, moduleType, dependencies)
|
||||
}
|
||||
|
||||
ModuleType.TEST_RUNTIME -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-15
@@ -14,10 +14,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.builders.Scope
|
||||
import org.jetbrains.kotlin.ir.builders.irCall
|
||||
import org.jetbrains.kotlin.ir.builders.irGet
|
||||
import org.jetbrains.kotlin.ir.builders.irReturn
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
@@ -29,9 +26,7 @@ import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||
import org.jetbrains.kotlin.ir.util.file
|
||||
import org.jetbrains.kotlin.ir.util.getArguments
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
@@ -134,8 +129,6 @@ internal class FunctionInlining(val context: Context): IrElementTransformerWithC
|
||||
return transformedModule
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------//
|
||||
|
||||
override fun visitFunctionNew(declaration: IrFunction, data: Ref<Boolean>): IrStatement {
|
||||
val descriptor = declaration.descriptor
|
||||
|
||||
@@ -160,15 +153,14 @@ internal class FunctionInlining(val context: Context): IrElementTransformerWithC
|
||||
if (callee == null) { // We failed to get the declaration.
|
||||
val message = "Inliner failed to obtain function declaration: " +
|
||||
functionDescriptor.fqNameSafe.toString()
|
||||
callee
|
||||
context.reportWarning(message, currentFile, callSite) // Report warning.
|
||||
return callSite
|
||||
}
|
||||
data.value = data.value or callee.second
|
||||
|
||||
val childIsBad = Ref(inlineFunctions[functionDescriptor] ?: false)
|
||||
callee.first.transformChildren(this, childIsBad)
|
||||
inlineFunctions[functionDescriptor] = childIsBad.value// Process recursive inline.
|
||||
callee.first.transformChildren(this, childIsBad) // Process recursive inline.
|
||||
inlineFunctions[functionDescriptor] = childIsBad.value
|
||||
data.value = data.value or childIsBad.value
|
||||
|
||||
val currentCalleeIsBad = argsAreBad.value or childIsBad.value or callee.second
|
||||
@@ -194,7 +186,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerWithC
|
||||
}
|
||||
|
||||
// TODO: should we keep this at all?
|
||||
private val inlineConstructor = FqName("konan.internal.InlineConstructor")
|
||||
private val inlineConstructor = FqName("kotlin.native.internal.InlineConstructor")
|
||||
private val FunctionDescriptor.isInlineConstructor get() = annotations.hasAnnotation(inlineConstructor)
|
||||
|
||||
//-----------------------------------------------------------------------------//
|
||||
@@ -328,7 +320,8 @@ private class Inliner(val globalSubstituteMap: MutableMap<DeclarationDescriptor,
|
||||
if (functionArgument == null)
|
||||
return super.visitCall(expression)
|
||||
val dispatchDescriptor = dispatchReceiver.descriptor
|
||||
if (dispatchDescriptor is ValueParameterDescriptor && dispatchDescriptor.isNoinline) return super.visitCall(expression)
|
||||
if (dispatchDescriptor is ValueParameterDescriptor &&
|
||||
dispatchDescriptor.isNoinline) return super.visitCall(expression)
|
||||
|
||||
if (functionArgument is IrFunctionReference) {
|
||||
if (!functionArgument.isLambda) return super.visitCall(expression)
|
||||
@@ -378,7 +371,7 @@ private class Inliner(val globalSubstituteMap: MutableMap<DeclarationDescriptor,
|
||||
override fun visitElement(element: IrElement) = element.accept(this, null)
|
||||
}
|
||||
|
||||
private fun isLambdaCall(irCall: IrCall) = irCall.descriptor.isFunctionInvoke && irCall.dispatchReceiver is IrGetValue
|
||||
private fun isLambdaCall(irCall: IrCall) = irCall.descriptor.isFunctionInvoke && irCall.dispatchReceiver is IrGetValue
|
||||
|
||||
private fun createTypeSubstitutor(irCall: IrCall): TypeSubstitutor? {
|
||||
if (irCall.typeArgumentsCount == 0) return null
|
||||
|
||||
@@ -15,6 +15,8 @@ node {
|
||||
val antLauncherJar by configurations.creating
|
||||
val testJsRuntime by configurations.creating
|
||||
|
||||
val generateIrRuntimeKlib by generator("org.jetbrains.kotlin.generators.tests.GenerateIrRuntimeKt")
|
||||
|
||||
dependencies {
|
||||
testRuntime(intellijDep())
|
||||
|
||||
@@ -53,6 +55,7 @@ sourceSets {
|
||||
projectTest {
|
||||
dependsOn(":dist")
|
||||
dependsOn(testJsRuntime)
|
||||
dependsOn(generateIrRuntimeKlib)
|
||||
jvmArgs("-da:jdk.nashorn.internal.runtime.RecompilableScriptFunctionData") // Disable assertion which fails due to a bug in nashorn (KT-23637)
|
||||
workingDir = rootDir
|
||||
if (findProperty("kotlin.compiler.js.ir.tests.skip")?.toString()?.toBoolean() == true) {
|
||||
@@ -66,7 +69,7 @@ projectTest {
|
||||
val prefixForPpropertiesToForward = "fd."
|
||||
for ((key, value) in properties) {
|
||||
if (key.startsWith(prefixForPpropertiesToForward)) {
|
||||
systemProperty(key.substring(prefixForPpropertiesToForward.length), value)
|
||||
systemProperty(key.substring(prefixForPpropertiesToForward.length), value!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* 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.generators.tests
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.openapi.vfs.VirtualFileManager
|
||||
import com.intellij.psi.PsiManager
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.ir.backend.js.compile
|
||||
import org.jetbrains.kotlin.js.test.runtimeSources
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import java.io.File
|
||||
|
||||
fun buildConfiguration(environment: KotlinCoreEnvironment): CompilerConfiguration {
|
||||
val runtimeConfiguration = environment.configuration.copy()
|
||||
runtimeConfiguration.put(CommonConfigurationKeys.MODULE_NAME, "JS_IR_RUNTIME")
|
||||
|
||||
runtimeConfiguration.languageVersionSettings = LanguageVersionSettingsImpl(
|
||||
LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE,
|
||||
specificFeatures = mapOf(
|
||||
LanguageFeature.AllowContractsForCustomFunctions to LanguageFeature.State.ENABLED,
|
||||
LanguageFeature.MultiPlatformProjects to LanguageFeature.State.ENABLED
|
||||
),
|
||||
analysisFlags = mapOf(
|
||||
AnalysisFlags.useExperimental to listOf("kotlin.contracts.ExperimentalContracts", "kotlin.Experimental"),
|
||||
AnalysisFlags.allowResultReturnType to true
|
||||
)
|
||||
)
|
||||
|
||||
return runtimeConfiguration
|
||||
}
|
||||
|
||||
private val stdKlibFile = File("js/js.translator/testData/out/klibs/stdlib.klib")
|
||||
|
||||
fun main() {
|
||||
|
||||
val environment = KotlinCoreEnvironment.createForTests(Disposable { }, CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES)
|
||||
|
||||
fun createPsiFile(fileName: String): KtFile {
|
||||
val psiManager = PsiManager.getInstance(environment.project)
|
||||
val fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL)
|
||||
|
||||
val file = fileSystem.findFileByPath(fileName) ?: error("File not found: $fileName")
|
||||
|
||||
return psiManager.findFile(file) as KtFile
|
||||
}
|
||||
|
||||
val result = compile(
|
||||
environment.project,
|
||||
runtimeSources.map(::createPsiFile),
|
||||
buildConfiguration(environment),
|
||||
null,
|
||||
true,
|
||||
emptyList(),
|
||||
emptyList()
|
||||
)
|
||||
|
||||
TODO("Write library into $stdKlibFile")
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.js.config.JsConfig
|
||||
import org.jetbrains.kotlin.js.facade.MainCallParameters
|
||||
import org.jetbrains.kotlin.js.facade.TranslationUnit
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import java.io.File
|
||||
|
||||
@@ -116,6 +117,7 @@ abstract class BasicIrBoxTest(
|
||||
filesToCompile,
|
||||
config.configuration,
|
||||
listOf(FqName((testPackage?.let { "$it." } ?: "") + testFunction)),
|
||||
false,
|
||||
dependencies,
|
||||
runtimeResult,
|
||||
moduleType = if (isMainModule) ModuleType.MAIN else ModuleType.SECONDARY
|
||||
|
||||
Reference in New Issue
Block a user