'SuspendFunction$n' should not be visible in member scopes (should be unresolved).
'SuspendFunction$n' class descriptors are created on demand by KotlinBuiltIns (and cached). On serialization, types constructed with 'SuspendFunction$n' are written as 'Function$n' with extra flag (SUSPEND_TYPE). On deserialization, corresponding 'SuspendFunction$n' classes are used.
This commit is contained in:
committed by
Stanislav Erokhin
parent
a70ac0160d
commit
80bd916f5d
@@ -138,6 +138,11 @@ message Type {
|
||||
optional Type abbreviated_type = 13;
|
||||
optional int32 abbreviated_type_id = 14;
|
||||
|
||||
/*
|
||||
suspend
|
||||
*/
|
||||
optional int32 flags = 1;
|
||||
|
||||
extensions 100 to 199;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.protobuf.Internal;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
|
||||
public class Flags {
|
||||
private Flags() {}
|
||||
|
||||
// Common
|
||||
// Types
|
||||
public static final BooleanFlagField SUSPEND_TYPE = FlagField.booleanFirst();
|
||||
|
||||
// Common for declarations
|
||||
|
||||
public static final BooleanFlagField HAS_ANNOTATIONS = FlagField.booleanFirst();
|
||||
public static final FlagField<ProtoBuf.Visibility> VISIBILITY = FlagField.after(HAS_ANNOTATIONS, ProtoBuf.Visibility.values());
|
||||
@@ -78,6 +82,10 @@ public class Flags {
|
||||
|
||||
// ---
|
||||
|
||||
public static int getTypeFlags(boolean isSuspend) {
|
||||
return SUSPEND_TYPE.toFlags(isSuspend);
|
||||
}
|
||||
|
||||
public static int getClassFlags(
|
||||
boolean hasAnnotations,
|
||||
Visibility visibility,
|
||||
|
||||
@@ -4489,6 +4489,23 @@ public final class ProtoBuf {
|
||||
* <code>optional int32 abbreviated_type_id = 14;</code>
|
||||
*/
|
||||
int getAbbreviatedTypeId();
|
||||
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*suspend
|
||||
* </pre>
|
||||
*/
|
||||
boolean hasFlags();
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*suspend
|
||||
* </pre>
|
||||
*/
|
||||
int getFlags();
|
||||
}
|
||||
/**
|
||||
* Protobuf type {@code org.jetbrains.kotlin.serialization.Type}
|
||||
@@ -4541,6 +4558,11 @@ public final class ProtoBuf {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8: {
|
||||
bitField0_ |= 0x00001000;
|
||||
flags_ = input.readInt32();
|
||||
break;
|
||||
}
|
||||
case 18: {
|
||||
if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
|
||||
argument_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument>();
|
||||
@@ -5601,6 +5623,29 @@ public final class ProtoBuf {
|
||||
return abbreviatedTypeId_;
|
||||
}
|
||||
|
||||
public static final int FLAGS_FIELD_NUMBER = 1;
|
||||
private int flags_;
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*suspend
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasFlags() {
|
||||
return ((bitField0_ & 0x00001000) == 0x00001000);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*suspend
|
||||
* </pre>
|
||||
*/
|
||||
public int getFlags() {
|
||||
return flags_;
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
argument_ = java.util.Collections.emptyList();
|
||||
nullable_ = false;
|
||||
@@ -5615,6 +5660,7 @@ public final class ProtoBuf {
|
||||
outerTypeId_ = 0;
|
||||
abbreviatedType_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance();
|
||||
abbreviatedTypeId_ = 0;
|
||||
flags_ = 0;
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
@@ -5660,6 +5706,9 @@ public final class ProtoBuf {
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
.ExtendableMessage<org.jetbrains.kotlin.serialization.ProtoBuf.Type>.ExtensionWriter extensionWriter =
|
||||
newExtensionWriter();
|
||||
if (((bitField0_ & 0x00001000) == 0x00001000)) {
|
||||
output.writeInt32(1, flags_);
|
||||
}
|
||||
for (int i = 0; i < argument_.size(); i++) {
|
||||
output.writeMessage(2, argument_.get(i));
|
||||
}
|
||||
@@ -5709,6 +5758,10 @@ public final class ProtoBuf {
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
if (((bitField0_ & 0x00001000) == 0x00001000)) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeInt32Size(1, flags_);
|
||||
}
|
||||
for (int i = 0; i < argument_.size(); i++) {
|
||||
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
|
||||
.computeMessageSize(2, argument_.get(i));
|
||||
@@ -5881,6 +5934,8 @@ public final class ProtoBuf {
|
||||
bitField0_ = (bitField0_ & ~0x00000800);
|
||||
abbreviatedTypeId_ = 0;
|
||||
bitField0_ = (bitField0_ & ~0x00001000);
|
||||
flags_ = 0;
|
||||
bitField0_ = (bitField0_ & ~0x00002000);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -5957,6 +6012,10 @@ public final class ProtoBuf {
|
||||
to_bitField0_ |= 0x00000800;
|
||||
}
|
||||
result.abbreviatedTypeId_ = abbreviatedTypeId_;
|
||||
if (((from_bitField0_ & 0x00002000) == 0x00002000)) {
|
||||
to_bitField0_ |= 0x00001000;
|
||||
}
|
||||
result.flags_ = flags_;
|
||||
result.bitField0_ = to_bitField0_;
|
||||
return result;
|
||||
}
|
||||
@@ -6009,6 +6068,9 @@ public final class ProtoBuf {
|
||||
if (other.hasAbbreviatedTypeId()) {
|
||||
setAbbreviatedTypeId(other.getAbbreviatedTypeId());
|
||||
}
|
||||
if (other.hasFlags()) {
|
||||
setFlags(other.getFlags());
|
||||
}
|
||||
this.mergeExtensionFields(other);
|
||||
setUnknownFields(
|
||||
getUnknownFields().concat(other.unknownFields));
|
||||
@@ -6731,6 +6793,54 @@ public final class ProtoBuf {
|
||||
return this;
|
||||
}
|
||||
|
||||
private int flags_ ;
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*suspend
|
||||
* </pre>
|
||||
*/
|
||||
public boolean hasFlags() {
|
||||
return ((bitField0_ & 0x00002000) == 0x00002000);
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*suspend
|
||||
* </pre>
|
||||
*/
|
||||
public int getFlags() {
|
||||
return flags_;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*suspend
|
||||
* </pre>
|
||||
*/
|
||||
public Builder setFlags(int value) {
|
||||
bitField0_ |= 0x00002000;
|
||||
flags_ = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* <code>optional int32 flags = 1;</code>
|
||||
*
|
||||
* <pre>
|
||||
*suspend
|
||||
* </pre>
|
||||
*/
|
||||
public Builder clearFlags() {
|
||||
bitField0_ = (bitField0_ & ~0x00002000);
|
||||
flags_ = 0;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.Type)
|
||||
}
|
||||
|
||||
|
||||
+20
-2
@@ -16,11 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.serialization.Flags
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedTypeParameterDescriptor
|
||||
@@ -105,8 +108,13 @@ class TypeDeserializer(
|
||||
private fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor =
|
||||
when {
|
||||
proto.hasClassName() -> {
|
||||
classDescriptors(proto.className)?.typeConstructor
|
||||
?: c.components.notFoundClasses.getClass(proto, c.nameResolver, c.typeTable)
|
||||
if (Flags.SUSPEND_TYPE.get(proto.flags)) {
|
||||
getSuspendFunctionTypeConstructor(proto)
|
||||
}
|
||||
else {
|
||||
classDescriptors(proto.className)?.typeConstructor
|
||||
?: c.components.notFoundClasses.getClass(proto, c.nameResolver, c.typeTable)
|
||||
}
|
||||
}
|
||||
proto.hasTypeParameter() ->
|
||||
typeParameterTypeConstructor(proto.typeParameter)
|
||||
@@ -124,6 +132,16 @@ class TypeDeserializer(
|
||||
else -> ErrorUtils.createErrorTypeConstructor("Unknown type")
|
||||
}
|
||||
|
||||
private fun getSuspendFunctionTypeConstructor(proto: ProtoBuf.Type): TypeConstructor {
|
||||
val classId = c.nameResolver.getClassId(proto.className)
|
||||
val arity = BuiltInFictitiousFunctionClassFactory.getFunctionalClassArity(classId.shortClassName.asString(), classId.packageFqName)
|
||||
|
||||
return if (arity != null)
|
||||
c.containingDeclaration.builtIns.getSuspendFunction(arity - 1).typeConstructor
|
||||
else
|
||||
ErrorUtils.createErrorTypeConstructor("Class is not a FunctionN ${classId.asString()}")
|
||||
}
|
||||
|
||||
private fun typeParameterTypeConstructor(typeParameterId: Int): TypeConstructor? =
|
||||
typeParameterDescriptors.get(typeParameterId)?.typeConstructor ?:
|
||||
parent?.typeParameterTypeConstructor(typeParameterId)
|
||||
|
||||
Reference in New Issue
Block a user