Introduce services to pass data between IC and JS compiler
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.js
|
||||
|
||||
// byte arrays are used to simplify passing to different classloaders
|
||||
interface IncrementalDataProvider {
|
||||
/** gets header metadata (serialized [JsProtoBuf.Header]) from previous compilation */
|
||||
val headerMetadata: ByteArray
|
||||
/** gets non-dirty package parts metadata (serialized [ProtoBuf.PackageFragment]) from previous compilation */
|
||||
val packagePartsMetadata: List<ByteArray>
|
||||
/** gets non-dirty package parts binary trees from previous compilation */
|
||||
val binaryTrees: List<ByteArray>
|
||||
}
|
||||
|
||||
class IncrementalDataProviderImpl(
|
||||
override val headerMetadata: ByteArray,
|
||||
override val packagePartsMetadata: List<ByteArray>,
|
||||
override val binaryTrees: List<ByteArray>
|
||||
) : IncrementalDataProvider
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental.js
|
||||
|
||||
import java.io.File
|
||||
|
||||
interface IncrementalResultsConsumer {
|
||||
/** processes new header metadata (serialized [JsProtoBuf.Header]) */
|
||||
fun processHeader(headerMetadata: ByteArray)
|
||||
/** processes new package part metadata and binary tree for compiled source file */
|
||||
fun processPackagePart(sourceFile: File, packagePartMetadata: ByteArray, binaryAst: ByteArray)
|
||||
}
|
||||
|
||||
class IncrementalResultsConsumerImpl : IncrementalResultsConsumer {
|
||||
lateinit var headerMetadata: ByteArray
|
||||
private set
|
||||
|
||||
private val _packageParts = arrayListOf<PackagePartData>()
|
||||
val packageParts: List<PackagePartData>
|
||||
get() = _packageParts
|
||||
|
||||
override fun processHeader(headerMetadata: ByteArray) {
|
||||
this.headerMetadata = headerMetadata
|
||||
}
|
||||
|
||||
override fun processPackagePart(sourceFile: File, packagePartMetadata: ByteArray, binaryAst: ByteArray) {
|
||||
_packageParts.add(PackagePartData(sourceFile, packagePartMetadata, binaryAst))
|
||||
}
|
||||
|
||||
data class PackagePartData(val sourceFile: File, val proto: ByteArray, val binaryAst: ByteArray)
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
|
||||
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
|
||||
import org.jetbrains.kotlin.serialization.js.PackagesWithHeaderMetadata
|
||||
|
||||
object TopDownAnalyzerFacadeForJS {
|
||||
@JvmStatic
|
||||
@@ -57,8 +58,11 @@ object TopDownAnalyzerFacadeForJS {
|
||||
moduleContext: ModuleContext,
|
||||
config: JsConfig
|
||||
): JsAnalysisResult {
|
||||
val packageFragment = config.configuration[JSConfigurationKeys.FALLBACK_METADATA]?.let {
|
||||
KotlinJavascriptSerializationUtil.readDescriptors(it, moduleContext.storageManager, moduleContext.module,
|
||||
val packageFragment = config.configuration[JSConfigurationKeys.INCREMENTAL_DATA_PROVIDER]?.let {
|
||||
val metadata = PackagesWithHeaderMetadata(it.headerMetadata, it.packagePartsMetadata)
|
||||
KotlinJavascriptSerializationUtil.readDescriptors(metadata,
|
||||
moduleContext.storageManager,
|
||||
moduleContext.module,
|
||||
DeserializationConfiguration.Default)
|
||||
}
|
||||
val analyzerForJs = createTopDownAnalyzerForJs(
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
package org.jetbrains.kotlin.js.config;
|
||||
|
||||
import org.jetbrains.kotlin.config.CompilerConfigurationKey;
|
||||
import org.jetbrains.kotlin.incremental.js.IncrementalDataProvider;
|
||||
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumer;
|
||||
import org.jetbrains.kotlin.serialization.js.ModuleKind;
|
||||
import org.jetbrains.kotlin.serialization.js.PackagesWithHeaderMetadata;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -50,10 +51,11 @@ public class JSConfigurationKeys {
|
||||
public static final CompilerConfigurationKey<Boolean> TYPED_ARRAYS_ENABLED =
|
||||
CompilerConfigurationKey.create("TypedArrays enabled");
|
||||
|
||||
public static final CompilerConfigurationKey<PackagesWithHeaderMetadata> FALLBACK_METADATA =
|
||||
CompilerConfigurationKey.create("fallback metadata");
|
||||
public static final CompilerConfigurationKey<IncrementalDataProvider> INCREMENTAL_DATA_PROVIDER =
|
||||
CompilerConfigurationKey.create("incremental data provider");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> SERIALIZE_FRAGMENTS = CompilerConfigurationKey.create("serialize fragments");
|
||||
public static final CompilerConfigurationKey<IncrementalResultsConsumer> INCREMENTAL_RESULTS_CONSUMER =
|
||||
CompilerConfigurationKey.create("incremental results consumer");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> FRIEND_PATHS_DISABLED =
|
||||
CompilerConfigurationKey.create("disable support for friend paths");
|
||||
|
||||
Reference in New Issue
Block a user