getOptionalAnnotationClassList() {
+ if (optionalAnnotationClassBuilder_ == null) {
+ return java.util.Collections.unmodifiableList(optionalAnnotationClass_);
+ } else {
+ return optionalAnnotationClassBuilder_.getMessageList();
+ }
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public int getOptionalAnnotationClassCount() {
+ if (optionalAnnotationClassBuilder_ == null) {
+ return optionalAnnotationClass_.size();
+ } else {
+ return optionalAnnotationClassBuilder_.getCount();
+ }
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public org.jetbrains.kotlin.metadata.DebugProtoBuf.Class getOptionalAnnotationClass(int index) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ return optionalAnnotationClass_.get(index);
+ } else {
+ return optionalAnnotationClassBuilder_.getMessage(index);
+ }
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public Builder setOptionalAnnotationClass(
+ int index, org.jetbrains.kotlin.metadata.DebugProtoBuf.Class value) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensureOptionalAnnotationClassIsMutable();
+ optionalAnnotationClass_.set(index, value);
+ onChanged();
+ } else {
+ optionalAnnotationClassBuilder_.setMessage(index, value);
+ }
+ return this;
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public Builder setOptionalAnnotationClass(
+ int index, org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.Builder builderForValue) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ ensureOptionalAnnotationClassIsMutable();
+ optionalAnnotationClass_.set(index, builderForValue.build());
+ onChanged();
+ } else {
+ optionalAnnotationClassBuilder_.setMessage(index, builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public Builder addOptionalAnnotationClass(org.jetbrains.kotlin.metadata.DebugProtoBuf.Class value) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensureOptionalAnnotationClassIsMutable();
+ optionalAnnotationClass_.add(value);
+ onChanged();
+ } else {
+ optionalAnnotationClassBuilder_.addMessage(value);
+ }
+ return this;
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public Builder addOptionalAnnotationClass(
+ int index, org.jetbrains.kotlin.metadata.DebugProtoBuf.Class value) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ if (value == null) {
+ throw new NullPointerException();
+ }
+ ensureOptionalAnnotationClassIsMutable();
+ optionalAnnotationClass_.add(index, value);
+ onChanged();
+ } else {
+ optionalAnnotationClassBuilder_.addMessage(index, value);
+ }
+ return this;
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public Builder addOptionalAnnotationClass(
+ org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.Builder builderForValue) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ ensureOptionalAnnotationClassIsMutable();
+ optionalAnnotationClass_.add(builderForValue.build());
+ onChanged();
+ } else {
+ optionalAnnotationClassBuilder_.addMessage(builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public Builder addOptionalAnnotationClass(
+ int index, org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.Builder builderForValue) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ ensureOptionalAnnotationClassIsMutable();
+ optionalAnnotationClass_.add(index, builderForValue.build());
+ onChanged();
+ } else {
+ optionalAnnotationClassBuilder_.addMessage(index, builderForValue.build());
+ }
+ return this;
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public Builder addAllOptionalAnnotationClass(
+ java.lang.Iterable extends org.jetbrains.kotlin.metadata.DebugProtoBuf.Class> values) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ ensureOptionalAnnotationClassIsMutable();
+ org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
+ values, optionalAnnotationClass_);
+ onChanged();
+ } else {
+ optionalAnnotationClassBuilder_.addAllMessages(values);
+ }
+ return this;
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public Builder clearOptionalAnnotationClass() {
+ if (optionalAnnotationClassBuilder_ == null) {
+ optionalAnnotationClass_ = java.util.Collections.emptyList();
+ bitField0_ = (bitField0_ & ~0x00000040);
+ onChanged();
+ } else {
+ optionalAnnotationClassBuilder_.clear();
+ }
+ return this;
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public Builder removeOptionalAnnotationClass(int index) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ ensureOptionalAnnotationClassIsMutable();
+ optionalAnnotationClass_.remove(index);
+ onChanged();
+ } else {
+ optionalAnnotationClassBuilder_.remove(index);
+ }
+ return this;
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.Builder getOptionalAnnotationClassBuilder(
+ int index) {
+ return getOptionalAnnotationClassFieldBuilder().getBuilder(index);
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public org.jetbrains.kotlin.metadata.DebugProtoBuf.ClassOrBuilder getOptionalAnnotationClassOrBuilder(
+ int index) {
+ if (optionalAnnotationClassBuilder_ == null) {
+ return optionalAnnotationClass_.get(index); } else {
+ return optionalAnnotationClassBuilder_.getMessageOrBuilder(index);
+ }
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public java.util.List extends org.jetbrains.kotlin.metadata.DebugProtoBuf.ClassOrBuilder>
+ getOptionalAnnotationClassOrBuilderList() {
+ if (optionalAnnotationClassBuilder_ != null) {
+ return optionalAnnotationClassBuilder_.getMessageOrBuilderList();
+ } else {
+ return java.util.Collections.unmodifiableList(optionalAnnotationClass_);
+ }
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.Builder addOptionalAnnotationClassBuilder() {
+ return getOptionalAnnotationClassFieldBuilder().addBuilder(
+ org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.getDefaultInstance());
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.Builder addOptionalAnnotationClassBuilder(
+ int index) {
+ return getOptionalAnnotationClassFieldBuilder().addBuilder(
+ index, org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.getDefaultInstance());
+ }
+ /**
+ * repeated .org.jetbrains.kotlin.metadata.Class optional_annotation_class = 16;
+ *
+ *
+ * @OptionalExpectation-annotated annotation classes in this module. This list is only used in the compiler frontend when compiling
+ * a second-tier multiplatform module against a multiplatform module which uses optional annotations, not actualized on the JVM.
+ * This is not needed in the IDE because optional annotations can only be used in common modules, where the IDE plugin resolves
+ * it to the corresponding class with the resolution capabilities of common modules.
+ *
+ */
+ public java.util.List
+ getOptionalAnnotationClassBuilderList() {
+ return getOptionalAnnotationClassFieldBuilder().getBuilderList();
+ }
+ private org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
+ org.jetbrains.kotlin.metadata.DebugProtoBuf.Class, org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.Builder, org.jetbrains.kotlin.metadata.DebugProtoBuf.ClassOrBuilder>
+ getOptionalAnnotationClassFieldBuilder() {
+ if (optionalAnnotationClassBuilder_ == null) {
+ optionalAnnotationClassBuilder_ = new org.jetbrains.kotlin.protobuf.RepeatedFieldBuilder<
+ org.jetbrains.kotlin.metadata.DebugProtoBuf.Class, org.jetbrains.kotlin.metadata.DebugProtoBuf.Class.Builder, org.jetbrains.kotlin.metadata.DebugProtoBuf.ClassOrBuilder>(
+ optionalAnnotationClass_,
+ ((bitField0_ & 0x00000040) == 0x00000040),
+ getParentForChildren(),
+ isClean());
+ optionalAnnotationClass_ = null;
+ }
+ return optionalAnnotationClassBuilder_;
+ }
+
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.metadata.jvm.Module)
}
@@ -4644,7 +5212,7 @@ public final class DebugJvmModuleProtoBuf {
"\n,core/metadata.jvm/src/jvm_module.debug" +
".proto\022!org.jetbrains.kotlin.metadata.jv" +
"m\032&core/metadata/src/metadata.debug.prot" +
- "o\"\205\003\n\006Module\022F\n\rpackage_parts\030\001 \003(\0132/.or" +
+ "o\"\316\003\n\006Module\022F\n\rpackage_parts\030\001 \003(\0132/.or" +
"g.jetbrains.kotlin.metadata.jvm.PackageP" +
"arts\022G\n\016metadata_parts\030\002 \003(\0132/.org.jetbr" +
"ains.kotlin.metadata.jvm.PackageParts\022\030\n" +
@@ -4653,16 +5221,18 @@ public final class DebugJvmModuleProtoBuf {
"ringTable\022O\n\024qualified_name_table\030\005 \001(\0132",
"1.org.jetbrains.kotlin.metadata.Qualifie" +
"dNameTable\022=\n\nannotation\030\006 \003(\0132).org.jet" +
- "brains.kotlin.metadata.Annotation\"\276\002\n\014Pa" +
- "ckageParts\022\027\n\017package_fq_name\030\001 \002(\t\022\030\n\020s" +
- "hort_class_name\030\002 \003(\t\022*\n\036multifile_facad" +
- "e_short_name_id\030\003 \003(\005B\002\020\001\022#\n\033multifile_f" +
- "acade_short_name\030\004 \003(\t\022.\n&class_with_jvm" +
- "_package_name_short_name\030\005 \003(\t\022F\n:class_" +
- "with_jvm_package_name_multifile_facade_s" +
- "hort_name_id\030\007 \003(\005B\002\020\001\0222\n&class_with_jvm",
- "_package_name_package_id\030\006 \003(\005B\002\020\001B\030B\026De" +
- "bugJvmModuleProtoBuf"
+ "brains.kotlin.metadata.Annotation\022G\n\031opt" +
+ "ional_annotation_class\030\020 \003(\0132$.org.jetbr" +
+ "ains.kotlin.metadata.Class\"\276\002\n\014PackagePa" +
+ "rts\022\027\n\017package_fq_name\030\001 \002(\t\022\030\n\020short_cl" +
+ "ass_name\030\002 \003(\t\022*\n\036multifile_facade_short" +
+ "_name_id\030\003 \003(\005B\002\020\001\022#\n\033multifile_facade_s" +
+ "hort_name\030\004 \003(\t\022.\n&class_with_jvm_packag" +
+ "e_name_short_name\030\005 \003(\t\022F\n:class_with_jv",
+ "m_package_name_multifile_facade_short_na" +
+ "me_id\030\007 \003(\005B\002\020\001\0222\n&class_with_jvm_packag" +
+ "e_name_package_id\030\006 \003(\005B\002\020\001B\030B\026DebugJvmM" +
+ "oduleProtoBuf"
};
org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -4682,7 +5252,7 @@ public final class DebugJvmModuleProtoBuf {
internal_static_org_jetbrains_kotlin_metadata_jvm_Module_fieldAccessorTable = new
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_org_jetbrains_kotlin_metadata_jvm_Module_descriptor,
- new java.lang.String[] { "PackageParts", "MetadataParts", "JvmPackageName", "StringTable", "QualifiedNameTable", "Annotation", });
+ new java.lang.String[] { "PackageParts", "MetadataParts", "JvmPackageName", "StringTable", "QualifiedNameTable", "Annotation", "OptionalAnnotationClass", });
internal_static_org_jetbrains_kotlin_metadata_jvm_PackageParts_descriptor =
getDescriptor().getMessageTypes().get(1);
internal_static_org_jetbrains_kotlin_metadata_jvm_PackageParts_fieldAccessorTable = new
diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java
index 09efebcd8d1..31d971ff096 100644
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.InlineClassDescriptorResolver;
import org.jetbrains.kotlin.resolve.InlineClassesUtilsKt;
-import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker;
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver;
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
import org.jetbrains.kotlin.resolve.jvm.*;
@@ -433,9 +432,6 @@ public class AsmUtil {
if (descriptor instanceof SyntheticClassDescriptorForLambda) {
return getVisibilityAccessFlagForAnonymous(descriptor);
}
- if (ExpectedActualDeclarationChecker.isOptionalAnnotationClass(descriptor)) {
- return NO_FLAG_PACKAGE_PRIVATE;
- }
if (descriptor.getKind() == ClassKind.ENUM_ENTRY) {
return NO_FLAG_PACKAGE_PRIVATE;
}
diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java
index 9090acb75f2..87620c140b1 100644
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.metadata.jvm.JvmModuleProtoBuf;
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping;
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMappingKt;
import org.jetbrains.kotlin.metadata.jvm.deserialization.PackageParts;
+import org.jetbrains.kotlin.metadata.serialization.StringTable;
import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.KtFile;
@@ -129,15 +130,18 @@ public class ClassFileFactory implements OutputFileCollection {
JvmModuleProtoBuf.Module.Builder builder = JvmModuleProtoBuf.Module.newBuilder();
String outputFilePath = getMappingFileName(state.getModuleName());
- for (PackageParts part : ClassFileUtilsKt.addCompiledPartsAndSort(packagePartRegistry.getParts().values(), state)) {
- part.addTo(builder);
- }
+ StringTableImpl stringTable = new StringTableImpl();
+ ClassFileUtilsKt.addDataFromCompiledModule(builder, packagePartRegistry, stringTable, state);
List experimental = state.getLanguageVersionSettings().getFlag(AnalysisFlags.getExperimental());
if (!experimental.isEmpty()) {
- writeExperimentalMarkers(state.getModule(), builder, experimental);
+ writeExperimentalMarkers(state.getModule(), builder, experimental, stringTable);
}
+ Pair tables = stringTable.buildProto();
+ builder.setStringTable(tables.getFirst());
+ builder.setQualifiedNameTable(tables.getSecond());
+
JvmModuleProtoBuf.Module moduleProto = builder.build();
generators.put(outputFilePath, new OutAndSourceFileList(CollectionsKt.toList(sourceFiles)) {
@@ -160,9 +164,9 @@ public class ClassFileFactory implements OutputFileCollection {
private static void writeExperimentalMarkers(
@NotNull ModuleDescriptor module,
@NotNull JvmModuleProtoBuf.Module.Builder builder,
- @NotNull List experimental
+ @NotNull List experimental,
+ @NotNull StringTable stringTable
) {
- StringTableImpl stringTable = new StringTableImpl();
for (String fqName : experimental) {
ClassDescriptor descriptor =
DescriptorUtilKt.resolveClassByFqName(module, new FqName(fqName), NoLookupLocation.FOR_ALREADY_TRACKED);
@@ -175,9 +179,6 @@ public class ClassFileFactory implements OutputFileCollection {
}
}
}
- Pair tables = stringTable.buildProto();
- builder.setStringTable(tables.getFirst());
- builder.setQualifiedNameTable(tables.getSecond());
}
@NotNull
diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PackageCodegenImpl.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PackageCodegenImpl.java
index 4f63e424beb..e0d2b6466ef 100644
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PackageCodegenImpl.java
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PackageCodegenImpl.java
@@ -90,8 +90,12 @@ public class PackageCodegenImpl implements PackageCodegen {
for (KtDeclaration declaration : file.getDeclarations()) {
if (declaration instanceof KtClassOrObject) {
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, declaration);
- if (PsiUtilsKt.hasExpectModifier(declaration) &&
- (descriptor == null || !ExpectedActualDeclarationChecker.shouldGenerateExpectClass(descriptor))) {
+ if (PsiUtilsKt.hasExpectModifier(declaration)) {
+ if (descriptor != null && ExpectedActualDeclarationChecker.shouldGenerateExpectClass(descriptor)) {
+ assert ExpectedActualDeclarationChecker.isOptionalAnnotationClass(descriptor) :
+ "Expect class should be generated only if it's an optional annotation: " + descriptor;
+ state.getFactory().getPackagePartRegistry().getOptionalAnnotations().add(descriptor);
+ }
continue;
}
diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PackagePartRegistry.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/PackagePartRegistry.kt
index 1f35fd45266..29a526e91a6 100644
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PackagePartRegistry.kt
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PackagePartRegistry.kt
@@ -16,11 +16,13 @@
package org.jetbrains.kotlin.codegen
+import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.metadata.jvm.deserialization.PackageParts
import org.jetbrains.kotlin.name.FqName
class PackagePartRegistry {
val parts = mutableMapOf()
+ val optionalAnnotations = mutableListOf()
fun addPart(packageFqName: FqName, partInternalName: String, facadeInternalName: String?) {
parts.computeIfAbsent(packageFqName) { PackageParts(it.asString()) }.addPart(partInternalName, facadeInternalName)
diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/classFileUtils.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/classFileUtils.kt
index ead6ba6a55a..8d1b64ca375 100644
--- a/compiler/backend/src/org/jetbrains/kotlin/codegen/classFileUtils.kt
+++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/classFileUtils.kt
@@ -18,10 +18,19 @@ package org.jetbrains.kotlin.codegen
import org.jetbrains.kotlin.backend.common.output.OutputFile
import org.jetbrains.kotlin.codegen.state.GenerationState
+import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
import org.jetbrains.kotlin.load.kotlin.loadModuleMapping
+import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
+import org.jetbrains.kotlin.metadata.jvm.JvmModuleProtoBuf
+import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping
import org.jetbrains.kotlin.metadata.jvm.deserialization.PackageParts
+import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
+import org.jetbrains.kotlin.serialization.DescriptorSerializer
+import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
+import org.jetbrains.kotlin.serialization.StringTableImpl
+import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
fun ClassFileFactory.getClassFiles(): Iterable {
return asList().filterClassFiles()
@@ -31,27 +40,64 @@ fun List.filterClassFiles(): List {
return filter { it.relativePath.endsWith(".class") }
}
-fun Iterable.addCompiledPartsAndSort(state: GenerationState): List =
- addCompiledParts(state).sortedBy { it.packageFqName }
-
-private fun Iterable.addCompiledParts(state: GenerationState): List {
- val incrementalCache = state.incrementalCacheForThisTarget ?: return this.toList()
- val moduleMappingData = incrementalCache.getModuleMappingData() ?: return this.toList()
-
- val mapping = ModuleMapping.loadModuleMapping(moduleMappingData, "", state.deserializationConfiguration) { version ->
- throw IllegalStateException("Version of the generated module cannot be incompatible: $version")
+fun JvmModuleProtoBuf.Module.Builder.addDataFromCompiledModule(
+ registry: PackagePartRegistry, stringTable: StringTableImpl, state: GenerationState
+) {
+ for (part in registry.parts.values.addCompiledPartsAndSort(state)) {
+ part.addTo(this)
}
- incrementalCache.getObsoletePackageParts().forEach { internalName ->
+ // Take all optional annotation classes from sources, as well as look up all previously compiled optional annotation classes
+ // by FQ name in the current module. The latter is needed because in incremental compilation scenario, the already compiled
+ // classes will not be available via sources.
+ val optionalAnnotationClassDescriptors =
+ registry.optionalAnnotations.toSet() +
+ state.loadCompiledModule()?.moduleData?.run {
+ optionalAnnotations.mapNotNull { proto ->
+ state.module.findClassAcrossModuleDependencies(
+ ClassId.fromString(nameResolver.getQualifiedClassName(proto.fqName))
+ )
+ }
+ }.orEmpty()
+
+ val serializer = DescriptorSerializer.createTopLevel(JvmOptionalAnnotationSerializerExtension(stringTable))
+ for (descriptor in optionalAnnotationClassDescriptors) {
+ addOptionalAnnotationClass(serializer.classProto(descriptor))
+ }
+}
+
+class JvmOptionalAnnotationSerializerExtension(
+ override val stringTable: StringTableImpl
+) : KotlinSerializerExtensionBase(BuiltInSerializerProtocol) {
+ override val metadataVersion: BinaryVersion
+ get() = JvmMetadataVersion.INSTANCE
+
+ override fun shouldUseTypeTable(): Boolean = true
+}
+
+private fun Iterable.addCompiledPartsAndSort(state: GenerationState): List =
+ addCompiledParts(state).sortedBy { it.packageFqName }
+
+private fun Iterable.addCompiledParts(state: GenerationState): List {
+ val mapping = state.loadCompiledModule() ?: return this.toList()
+
+ state.incrementalCacheForThisTarget?.getObsoletePackageParts()?.forEach { internalName ->
val qualifier = JvmClassName.byInternalName(internalName).packageFqName.asString()
mapping.findPackageParts(qualifier)?.removePart(internalName)
}
return (this + mapping.packageFqName2Parts.values)
- .groupBy { it.packageFqName }
- .map { (packageFqName, allOldPackageParts) ->
- PackageParts(packageFqName).apply {
- allOldPackageParts.forEach { packageParts -> this += packageParts }
- }
+ .groupBy { it.packageFqName }
+ .map { (packageFqName, allOldPackageParts) ->
+ PackageParts(packageFqName).apply {
+ allOldPackageParts.forEach { packageParts -> this += packageParts }
}
+ }
+}
+
+private fun GenerationState.loadCompiledModule(): ModuleMapping? {
+ val moduleMappingData = incrementalCacheForThisTarget?.getModuleMappingData() ?: return null
+ return ModuleMapping.loadModuleMapping(moduleMappingData, "", deserializationConfiguration) { version ->
+ throw IllegalStateException("Version of the generated module cannot be incompatible: $version")
+ }
}
diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/TopDownAnalyzerFacadeForJVM.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/TopDownAnalyzerFacadeForJVM.kt
index 6e04c6da1d1..70e1a890e26 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/TopDownAnalyzerFacadeForJVM.kt
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/TopDownAnalyzerFacadeForJVM.kt
@@ -51,6 +51,7 @@ import org.jetbrains.kotlin.konan.properties.propertyList
import org.jetbrains.kotlin.konan.util.KlibMetadataFactories
import org.jetbrains.kotlin.library.KLIB_PROPERTY_DEPENDS
import org.jetbrains.kotlin.library.KotlinLibrary
+import org.jetbrains.kotlin.library.metadata.NullFlexibleTypeDeserializer
import org.jetbrains.kotlin.load.java.JavaClassesTracker
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver
import org.jetbrains.kotlin.load.java.structure.JavaClass
@@ -68,10 +69,10 @@ import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisHandlerExtension
import org.jetbrains.kotlin.resolve.jvm.extensions.PackageFragmentProviderExtension
+import org.jetbrains.kotlin.resolve.jvm.multiplatform.OptionalAnnotationPackageFragmentProvider
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
-import org.jetbrains.kotlin.library.metadata.NullFlexibleTypeDeserializer
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.storage.StorageManager
import java.util.*
@@ -195,7 +196,8 @@ object TopDownAnalyzerFacadeForJVM {
CompositePackageFragmentProvider(
listOf(
moduleClassResolver.compiledCodeResolver.packageFragmentProvider,
- dependenciesContainer.get()
+ dependenciesContainer.get(),
+ dependenciesContainer.get()
)
)
)
@@ -252,7 +254,10 @@ object TopDownAnalyzerFacadeForJVM {
)
module.initialize(
CompositePackageFragmentProvider(
- listOf(container.get().packageFragmentProvider) + additionalProviders
+ listOf(
+ container.get().packageFragmentProvider,
+ container.get()
+ ) + additionalProviders
)
)
diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt
index 4a1956b8e01..bef3b2dcd29 100644
--- a/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt
+++ b/compiler/frontend.java/src/org/jetbrains/kotlin/frontend/java/di/injection.kt
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.platform.TargetPlatform
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
import org.jetbrains.kotlin.resolve.jvm.JvmDiagnosticComponents
+import org.jetbrains.kotlin.resolve.jvm.multiplatform.OptionalAnnotationPackageFragmentProvider
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatformAnalyzerServices
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
@@ -121,6 +122,7 @@ fun StorageComponentContainer.configureJavaSpecificComponents(
useInstance((moduleContext.module.builtIns as JvmBuiltIns).settings)
useImpl()
}
+ useImpl()
useInstance(javaClassTracker ?: JavaClassesTracker.Default)
useInstance(
diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackagePartProvider.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackagePartProvider.kt
index 6eb6ba6675f..4e439270dd0 100644
--- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackagePartProvider.kt
+++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackagePartProvider.kt
@@ -16,18 +16,20 @@
package org.jetbrains.kotlin.load.kotlin.incremental
+import org.jetbrains.kotlin.load.kotlin.JvmPackagePartProviderBase
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.load.kotlin.loadModuleMapping
import org.jetbrains.kotlin.metadata.jvm.deserialization.ModuleMapping
import org.jetbrains.kotlin.name.ClassId
+import org.jetbrains.kotlin.serialization.deserialization.ClassData
import org.jetbrains.kotlin.serialization.deserialization.DeserializationConfiguration
import org.jetbrains.kotlin.storage.StorageManager
class IncrementalPackagePartProvider(
- private val parent: PackagePartProvider,
- incrementalCaches: List,
- storageManager: StorageManager
+ private val parent: PackagePartProvider,
+ incrementalCaches: List,
+ storageManager: StorageManager
) : PackagePartProvider {
lateinit var deserializationConfiguration: DeserializationConfiguration
@@ -48,4 +50,8 @@ class IncrementalPackagePartProvider(
override fun getAnnotationsOnBinaryModule(moduleName: String): List {
return parent.getAnnotationsOnBinaryModule(moduleName)
}
+
+ override fun getAllOptionalAnnotationClasses(): List =
+ moduleMappings().flatMap((JvmPackagePartProviderBase)::getAllOptionalAnnotationClasses) +
+ parent.getAllOptionalAnnotationClasses()
}
diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/multiplatform/OptionalAnnotationPackageFragmentProvider.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/multiplatform/OptionalAnnotationPackageFragmentProvider.kt
new file mode 100644
index 00000000000..788bfbdca58
--- /dev/null
+++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/multiplatform/OptionalAnnotationPackageFragmentProvider.kt
@@ -0,0 +1,118 @@
+/*
+ * 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.resolve.jvm.multiplatform
+
+import org.jetbrains.kotlin.config.LanguageVersionSettings
+import org.jetbrains.kotlin.descriptors.*
+import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
+import org.jetbrains.kotlin.incremental.components.LookupLocation
+import org.jetbrains.kotlin.incremental.components.LookupTracker
+import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
+import org.jetbrains.kotlin.name.ClassId
+import org.jetbrains.kotlin.name.FqName
+import org.jetbrains.kotlin.name.Name
+import org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration
+import org.jetbrains.kotlin.resolve.sam.SamConversionResolver
+import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
+import org.jetbrains.kotlin.resolve.scopes.MemberScope
+import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl
+import org.jetbrains.kotlin.serialization.deserialization.*
+import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
+import org.jetbrains.kotlin.storage.NotNullLazyValue
+import org.jetbrains.kotlin.storage.StorageManager
+import org.jetbrains.kotlin.storage.getValue
+import org.jetbrains.kotlin.utils.Printer
+
+class OptionalAnnotationPackageFragmentProvider(
+ module: ModuleDescriptor,
+ storageManager: StorageManager,
+ notFoundClasses: NotFoundClasses,
+ languageVersionSettings: LanguageVersionSettings,
+ packagePartProvider: PackagePartProvider,
+) : PackageFragmentProvider {
+ val packages: Map by storageManager.createLazyValue p@{
+ // We call getAllOptionalAnnotationClasses under lazy value only because IncrementalPackagePartProvider requires
+ // deserializationConfiguration to be injected.
+ val optionalAnnotationClasses = packagePartProvider.getAllOptionalAnnotationClasses()
+ if (optionalAnnotationClasses.isEmpty()) return@p emptyMap()
+
+ mutableMapOf().also { packages ->
+ // We use BuiltInSerializerProtocol when serializing optional annotation classes (see
+ // JvmOptionalAnnotationSerializerExtension). Use it in deserialization as well, to be able to load annotations on
+ // optional annotation classes and their members (in particular, the `@OptionalExpectation` annotation).
+ val serializerProtocol = BuiltInSerializerProtocol
+
+ val classDataFinder = OptionalAnnotationClassDataFinder(optionalAnnotationClasses)
+ val components = storageManager.createLazyValue {
+ DeserializationComponents(
+ storageManager, module, CompilerDeserializationConfiguration(languageVersionSettings),
+ classDataFinder,
+ AnnotationAndConstantLoaderImpl(module, notFoundClasses, serializerProtocol),
+ this,
+ LocalClassifierTypeSettings.Default,
+ ErrorReporter.DO_NOTHING,
+ LookupTracker.DO_NOTHING,
+ FlexibleTypeDeserializer.ThrowException,
+ emptyList(),
+ notFoundClasses,
+ ContractDeserializer.DEFAULT,
+ extensionRegistryLite = serializerProtocol.extensionRegistry,
+ samConversionResolver = SamConversionResolver.Empty
+ )
+ }
+
+ for ((packageFqName, classes) in classDataFinder.classIdToData.entries.groupBy { it.key.packageFqName }) {
+ val classNames = classes.mapNotNull { (classId) ->
+ classId.shortClassName.takeUnless { classId.isNestedClass }
+ }.toSet()
+ // TODO: make this lazy value more granular, e.g. a memoized function ClassId -> ClassDescriptor
+ val classDescriptors = storageManager.createLazyValue {
+ classes.mapNotNull { (classId, classData) ->
+ components().classDeserializer.deserializeClass(classId, classData)
+ }.associateBy(ClassDescriptor::getName)
+ }
+ packages[packageFqName] = PackageFragmentForOptionalAnnotations(module, packageFqName, classNames, classDescriptors)
+ }
+ }
+ }
+
+ override fun getPackageFragments(fqName: FqName): List =
+ packages[fqName]?.let(::listOf).orEmpty()
+
+ override fun getSubPackagesOf(fqName: FqName, nameFilter: (Name) -> Boolean): Collection =
+ emptyList()
+}
+
+private class OptionalAnnotationClassDataFinder(classes: List) : ClassDataFinder {
+ val classIdToData = classes.associateBy { (nameResolver, klass) -> nameResolver.getClassId(klass.fqName) }
+
+ override fun findClassData(classId: ClassId): ClassData? = classIdToData[classId]
+}
+
+private class PackageFragmentForOptionalAnnotations(
+ module: ModuleDescriptor,
+ fqName: FqName,
+ classNames: Set,
+ classDescriptors: NotNullLazyValue