'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:
Dmitry Petrov
2016-12-15 12:34:03 +03:00
committed by Stanislav Erokhin
parent a70ac0160d
commit 80bd916f5d
26 changed files with 511 additions and 133 deletions
@@ -488,6 +488,11 @@ open class ProtoCompareGenerated(val oldNameResolver: NameResolver, val newNameR
if (old.abbreviatedTypeId != new.abbreviatedTypeId) return false if (old.abbreviatedTypeId != new.abbreviatedTypeId) return false
} }
if (old.hasFlags() != new.hasFlags()) return false
if (old.hasFlags()) {
if (old.flags != new.flags) return false
}
if (old.getExtensionCount(JvmProtoBuf.typeAnnotation) != new.getExtensionCount(JvmProtoBuf.typeAnnotation)) return false if (old.getExtensionCount(JvmProtoBuf.typeAnnotation) != new.getExtensionCount(JvmProtoBuf.typeAnnotation)) return false
for(i in 0..old.getExtensionCount(JvmProtoBuf.typeAnnotation) - 1) { for(i in 0..old.getExtensionCount(JvmProtoBuf.typeAnnotation) - 1) {
@@ -1361,6 +1366,10 @@ fun ProtoBuf.Type.hashCode(stringIndexes: (Int) -> Int, fqNameIndexes: (Int) ->
hashCode = 31 * hashCode + abbreviatedTypeId hashCode = 31 * hashCode + abbreviatedTypeId
} }
if (hasFlags()) {
hashCode = 31 * hashCode + flags
}
for(i in 0..getExtensionCount(JvmProtoBuf.typeAnnotation) - 1) { for(i in 0..getExtensionCount(JvmProtoBuf.typeAnnotation) - 1) {
hashCode = 31 * hashCode + getExtension(JvmProtoBuf.typeAnnotation, i).hashCode(stringIndexes, fqNameIndexes) hashCode = 31 * hashCode + getExtension(JvmProtoBuf.typeAnnotation, i).hashCode(stringIndexes, fqNameIndexes)
} }
@@ -5509,6 +5509,23 @@ public final class DebugProtoBuf {
* <code>optional int32 abbreviated_type_id = 14;</code> * <code>optional int32 abbreviated_type_id = 14;</code>
*/ */
int getAbbreviatedTypeId(); 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} * Protobuf type {@code org.jetbrains.kotlin.serialization.Type}
@@ -5563,6 +5580,11 @@ public final class DebugProtoBuf {
} }
break; break;
} }
case 8: {
bitField0_ |= 0x00001000;
flags_ = input.readInt32();
break;
}
case 18: { case 18: {
if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
argument_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.DebugProtoBuf.Type.Argument>(); argument_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.DebugProtoBuf.Type.Argument>();
@@ -6812,6 +6834,29 @@ public final class DebugProtoBuf {
return abbreviatedTypeId_; 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() { private void initFields() {
argument_ = java.util.Collections.emptyList(); argument_ = java.util.Collections.emptyList();
nullable_ = false; nullable_ = false;
@@ -6826,6 +6871,7 @@ public final class DebugProtoBuf {
outerTypeId_ = 0; outerTypeId_ = 0;
abbreviatedType_ = org.jetbrains.kotlin.serialization.DebugProtoBuf.Type.getDefaultInstance(); abbreviatedType_ = org.jetbrains.kotlin.serialization.DebugProtoBuf.Type.getDefaultInstance();
abbreviatedTypeId_ = 0; abbreviatedTypeId_ = 0;
flags_ = 0;
} }
private byte memoizedIsInitialized = -1; private byte memoizedIsInitialized = -1;
public final boolean isInitialized() { public final boolean isInitialized() {
@@ -6871,6 +6917,9 @@ public final class DebugProtoBuf {
org.jetbrains.kotlin.protobuf.GeneratedMessage org.jetbrains.kotlin.protobuf.GeneratedMessage
.ExtendableMessage<org.jetbrains.kotlin.serialization.DebugProtoBuf.Type>.ExtensionWriter extensionWriter = .ExtendableMessage<org.jetbrains.kotlin.serialization.DebugProtoBuf.Type>.ExtensionWriter extensionWriter =
newExtensionWriter(); newExtensionWriter();
if (((bitField0_ & 0x00001000) == 0x00001000)) {
output.writeInt32(1, flags_);
}
for (int i = 0; i < argument_.size(); i++) { for (int i = 0; i < argument_.size(); i++) {
output.writeMessage(2, argument_.get(i)); output.writeMessage(2, argument_.get(i));
} }
@@ -6920,6 +6969,10 @@ public final class DebugProtoBuf {
if (size != -1) return size; if (size != -1) return size;
size = 0; size = 0;
if (((bitField0_ & 0x00001000) == 0x00001000)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32Size(1, flags_);
}
for (int i = 0; i < argument_.size(); i++) { for (int i = 0; i < argument_.size(); i++) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeMessageSize(2, argument_.get(i)); .computeMessageSize(2, argument_.get(i));
@@ -7137,6 +7190,8 @@ public final class DebugProtoBuf {
bitField0_ = (bitField0_ & ~0x00000800); bitField0_ = (bitField0_ & ~0x00000800);
abbreviatedTypeId_ = 0; abbreviatedTypeId_ = 0;
bitField0_ = (bitField0_ & ~0x00001000); bitField0_ = (bitField0_ & ~0x00001000);
flags_ = 0;
bitField0_ = (bitField0_ & ~0x00002000);
return this; return this;
} }
@@ -7234,6 +7289,10 @@ public final class DebugProtoBuf {
to_bitField0_ |= 0x00000800; to_bitField0_ |= 0x00000800;
} }
result.abbreviatedTypeId_ = abbreviatedTypeId_; result.abbreviatedTypeId_ = abbreviatedTypeId_;
if (((from_bitField0_ & 0x00002000) == 0x00002000)) {
to_bitField0_ |= 0x00001000;
}
result.flags_ = flags_;
result.bitField0_ = to_bitField0_; result.bitField0_ = to_bitField0_;
onBuilt(); onBuilt();
return result; return result;
@@ -7312,6 +7371,9 @@ public final class DebugProtoBuf {
if (other.hasAbbreviatedTypeId()) { if (other.hasAbbreviatedTypeId()) {
setAbbreviatedTypeId(other.getAbbreviatedTypeId()); setAbbreviatedTypeId(other.getAbbreviatedTypeId());
} }
if (other.hasFlags()) {
setFlags(other.getFlags());
}
this.mergeExtensionFields(other); this.mergeExtensionFields(other);
this.mergeUnknownFields(other.getUnknownFields()); this.mergeUnknownFields(other.getUnknownFields());
return this; return this;
@@ -8316,6 +8378,54 @@ public final class DebugProtoBuf {
return this; 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;
onChanged();
return this;
}
/**
* <code>optional int32 flags = 1;</code>
*
* <pre>
*suspend
* </pre>
*/
public Builder clearFlags() {
bitField0_ = (bitField0_ & ~0x00002000);
flags_ = 0;
onChanged();
return this;
}
// @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.Type) // @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.Type)
} }
@@ -27159,7 +27269,7 @@ public final class DebugProtoBuf {
"\n\004BYTE\020\000\022\010\n\004CHAR\020\001\022\t\n\005SHORT\020\002\022\007\n\003INT\020\003\022\010" + "\n\004BYTE\020\000\022\010\n\004CHAR\020\001\022\t\n\005SHORT\020\002\022\007\n\003INT\020\003\022\010" +
"\n\004LONG\020\004\022\t\n\005FLOAT\020\005\022\n\n\006DOUBLE\020\006\022\013\n\007BOOLE", "\n\004LONG\020\004\022\t\n\005FLOAT\020\005\022\n\n\006DOUBLE\020\006\022\013\n\007BOOLE",
"AN\020\007\022\n\n\006STRING\020\010\022\t\n\005CLASS\020\t\022\010\n\004ENUM\020\n\022\016\n" + "AN\020\007\022\n\n\006STRING\020\010\022\t\n\005CLASS\020\t\022\010\n\004ENUM\020\n\022\016\n" +
"\nANNOTATION\020\013\022\t\n\005ARRAY\020\014\"\212\006\n\004Type\022C\n\010arg" + "\nANNOTATION\020\013\022\t\n\005ARRAY\020\014\"\231\006\n\004Type\022C\n\010arg" +
"ument\030\002 \003(\01321.org.jetbrains.kotlin.seria" + "ument\030\002 \003(\01321.org.jetbrains.kotlin.seria" +
"lization.Type.Argument\022\027\n\010nullable\030\003 \001(\010" + "lization.Type.Argument\022\027\n\010nullable\030\003 \001(\010" +
":\005false\022+\n\035flexible_type_capabilities_id" + ":\005false\022+\n\035flexible_type_capabilities_id" +
@@ -27173,115 +27283,115 @@ public final class DebugProtoBuf {
"ialization.Type\022\025\n\router_type_id\030\013 \001(\005\022B" + "ialization.Type\022\025\n\router_type_id\030\013 \001(\005\022B" +
"\n\020abbreviated_type\030\r \001(\0132(.org.jetbrains" + "\n\020abbreviated_type\030\r \001(\0132(.org.jetbrains" +
".kotlin.serialization.Type\022\033\n\023abbreviate" + ".kotlin.serialization.Type\022\033\n\023abbreviate" +
"d_type_id\030\016 \001(\005\032\334\001\n\010Argument\022U\n\nprojecti" + "d_type_id\030\016 \001(\005\022\r\n\005flags\030\001 \001(\005\032\334\001\n\010Argum" +
"on\030\001 \001(\0162<.org.jetbrains.kotlin.serializ" + "ent\022U\n\nprojection\030\001 \001(\0162<.org.jetbrains." +
"ation.Type.Argument.Projection:\003INV\0226\n\004t" + "kotlin.serialization.Type.Argument.Proje" +
"ype\030\002 \001(\0132(.org.jetbrains.kotlin.seriali" + "ction:\003INV\0226\n\004type\030\002 \001(\0132(.org.jetbrains" +
"zation.Type\022\017\n\007type_id\030\003 \001(\005\"0\n\nProjecti", ".kotlin.serialization.Type\022\017\n\007type_id\030\003 ",
"on\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003INV\020\002\022\010\n\004STAR\020\003*\005" + "\001(\005\"0\n\nProjection\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003IN" +
"\010d\020\310\001\"\236\002\n\rTypeParameter\022\n\n\002id\030\001 \002(\005\022\022\n\004n" + "V\020\002\022\010\n\004STAR\020\003*\005\010d\020\310\001\"\236\002\n\rTypeParameter\022\n" +
"ame\030\002 \002(\005B\004\210\265\030\001\022\026\n\007reified\030\003 \001(\010:\005false\022" + "\n\002id\030\001 \002(\005\022\022\n\004name\030\002 \002(\005B\004\210\265\030\001\022\026\n\007reifie" +
"Q\n\010variance\030\004 \001(\0162:.org.jetbrains.kotlin" + "d\030\003 \001(\010:\005false\022Q\n\010variance\030\004 \001(\0162:.org.j" +
".serialization.TypeParameter.Variance:\003I" + "etbrains.kotlin.serialization.TypeParame" +
"NV\022=\n\013upper_bound\030\005 \003(\0132(.org.jetbrains." + "ter.Variance:\003INV\022=\n\013upper_bound\030\005 \003(\0132(" +
"kotlin.serialization.Type\022\026\n\016upper_bound" + ".org.jetbrains.kotlin.serialization.Type" +
"_id\030\006 \003(\005\"$\n\010Variance\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007" + "\022\026\n\016upper_bound_id\030\006 \003(\005\"$\n\010Variance\022\006\n\002" +
"\n\003INV\020\002*\005\010d\020\350\007\"\236\007\n\005Class\022\020\n\005flags\030\001 \001(\005:" + "IN\020\000\022\007\n\003OUT\020\001\022\007\n\003INV\020\002*\005\010d\020\350\007\"\236\007\n\005Class\022" +
"\0016\022\025\n\007fq_name\030\003 \002(\005B\004\220\265\030\001\022#\n\025companion_o", "\020\n\005flags\030\001 \001(\005:\0016\022\025\n\007fq_name\030\003 \002(\005B\004\220\265\030\001",
"bject_name\030\004 \001(\005B\004\210\265\030\001\022I\n\016type_parameter" + "\022#\n\025companion_object_name\030\004 \001(\005B\004\210\265\030\001\022I\n" +
"\030\005 \003(\01321.org.jetbrains.kotlin.serializat" + "\016type_parameter\030\005 \003(\01321.org.jetbrains.ko" +
"ion.TypeParameter\022;\n\tsupertype\030\006 \003(\0132(.o" + "tlin.serialization.TypeParameter\022;\n\tsupe" +
"rg.jetbrains.kotlin.serialization.Type\022\030" + "rtype\030\006 \003(\0132(.org.jetbrains.kotlin.seria" +
"\n\014supertype_id\030\002 \003(\005B\002\020\001\022!\n\021nested_class" + "lization.Type\022\030\n\014supertype_id\030\002 \003(\005B\002\020\001\022" +
"_name\030\007 \003(\005B\006\020\001\210\265\030\001\022D\n\013constructor\030\010 \003(\013" + "!\n\021nested_class_name\030\007 \003(\005B\006\020\001\210\265\030\001\022D\n\013co" +
"2/.org.jetbrains.kotlin.serialization.Co" + "nstructor\030\010 \003(\0132/.org.jetbrains.kotlin.s" +
"nstructor\022>\n\010function\030\t \003(\0132,.org.jetbra" + "erialization.Constructor\022>\n\010function\030\t \003" +
"ins.kotlin.serialization.Function\022>\n\010pro" + "(\0132,.org.jetbrains.kotlin.serialization." +
"perty\030\n \003(\0132,.org.jetbrains.kotlin.seria", "Function\022>\n\010property\030\n \003(\0132,.org.jetbrai",
"lization.Property\022A\n\ntype_alias\030\013 \003(\0132-." + "ns.kotlin.serialization.Property\022A\n\ntype" +
"org.jetbrains.kotlin.serialization.TypeA" + "_alias\030\013 \003(\0132-.org.jetbrains.kotlin.seri" +
"lias\022A\n\nenum_entry\030\r \003(\0132-.org.jetbrains" + "alization.TypeAlias\022A\n\nenum_entry\030\r \003(\0132" +
".kotlin.serialization.EnumEntry\022A\n\ntype_" + "-.org.jetbrains.kotlin.serialization.Enu" +
"table\030\036 \001(\0132-.org.jetbrains.kotlin.seria" + "mEntry\022A\n\ntype_table\030\036 \001(\0132-.org.jetbrai" +
"lization.TypeTable\022\027\n\017sinceKotlinInfo\030\037 " + "ns.kotlin.serialization.TypeTable\022\027\n\017sin" +
"\001(\005\022Y\n\027since_kotlin_info_table\030 \001(\01328.o" + "ceKotlinInfo\030\037 \001(\005\022Y\n\027since_kotlin_info_" +
"rg.jetbrains.kotlin.serialization.SinceK" + "table\030 \001(\01328.org.jetbrains.kotlin.seria" +
"otlinInfoTable\"x\n\004Kind\022\t\n\005CLASS\020\000\022\r\n\tINT" + "lization.SinceKotlinInfoTable\"x\n\004Kind\022\t\n" +
"ERFACE\020\001\022\016\n\nENUM_CLASS\020\002\022\016\n\nENUM_ENTRY\020\003", "\005CLASS\020\000\022\r\n\tINTERFACE\020\001\022\016\n\nENUM_CLASS\020\002\022",
"\022\024\n\020ANNOTATION_CLASS\020\004\022\n\n\006OBJECT\020\005\022\024\n\020CO" + "\016\n\nENUM_ENTRY\020\003\022\024\n\020ANNOTATION_CLASS\020\004\022\n\n" +
"MPANION_OBJECT\020\006*\005\010d\020\310\001\"\361\002\n\007Package\022>\n\010f" + "\006OBJECT\020\005\022\024\n\020COMPANION_OBJECT\020\006*\005\010d\020\310\001\"\361" +
"unction\030\003 \003(\0132,.org.jetbrains.kotlin.ser" + "\002\n\007Package\022>\n\010function\030\003 \003(\0132,.org.jetbr" +
"ialization.Function\022>\n\010property\030\004 \003(\0132,." + "ains.kotlin.serialization.Function\022>\n\010pr" +
"org.jetbrains.kotlin.serialization.Prope" + "operty\030\004 \003(\0132,.org.jetbrains.kotlin.seri" +
"rty\022A\n\ntype_alias\030\005 \003(\0132-.org.jetbrains." + "alization.Property\022A\n\ntype_alias\030\005 \003(\0132-" +
"kotlin.serialization.TypeAlias\022A\n\ntype_t" + ".org.jetbrains.kotlin.serialization.Type" +
"able\030\036 \001(\0132-.org.jetbrains.kotlin.serial" + "Alias\022A\n\ntype_table\030\036 \001(\0132-.org.jetbrain" +
"ization.TypeTable\022Y\n\027since_kotlin_info_t" + "s.kotlin.serialization.TypeTable\022Y\n\027sinc" +
"able\030 \001(\01328.org.jetbrains.kotlin.serial", "e_kotlin_info_table\030 \001(\01328.org.jetbrain",
"ization.SinceKotlinInfoTable*\005\010d\020\310\001\"_\n\tT" + "s.kotlin.serialization.SinceKotlinInfoTa" +
"ypeTable\0226\n\004type\030\001 \003(\0132(.org.jetbrains.k" + "ble*\005\010d\020\310\001\"_\n\tTypeTable\0226\n\004type\030\001 \003(\0132(." +
"otlin.serialization.Type\022\032\n\016first_nullab" + "org.jetbrains.kotlin.serialization.Type\022" +
"le\030\002 \001(\005:\002-1\"\214\001\n\013Constructor\022\020\n\005flags\030\001 " + "\032\n\016first_nullable\030\002 \001(\005:\002-1\"\214\001\n\013Construc" +
"\001(\005:\0016\022K\n\017value_parameter\030\002 \003(\01322.org.je" + "tor\022\020\n\005flags\030\001 \001(\005:\0016\022K\n\017value_parameter" +
"tbrains.kotlin.serialization.ValueParame" + "\030\002 \003(\01322.org.jetbrains.kotlin.serializat" +
"ter\022\027\n\017sinceKotlinInfo\030\037 \001(\005*\005\010d\020\310\001\"\363\003\n\010" + "ion.ValueParameter\022\027\n\017sinceKotlinInfo\030\037 " +
"Function\022\020\n\005flags\030\t \001(\005:\0016\022\024\n\told_flags\030" + "\001(\005*\005\010d\020\310\001\"\363\003\n\010Function\022\020\n\005flags\030\t \001(\005:\001" +
"\001 \001(\005:\0016\022\022\n\004name\030\002 \002(\005B\004\210\265\030\001\022=\n\013return_t" + "6\022\024\n\told_flags\030\001 \001(\005:\0016\022\022\n\004name\030\002 \002(\005B\004\210" +
"ype\030\003 \001(\0132(.org.jetbrains.kotlin.seriali", "\265\030\001\022=\n\013return_type\030\003 \001(\0132(.org.jetbrains",
"zation.Type\022\026\n\016return_type_id\030\007 \001(\005\022I\n\016t" + ".kotlin.serialization.Type\022\026\n\016return_typ" +
"ype_parameter\030\004 \003(\01321.org.jetbrains.kotl" + "e_id\030\007 \001(\005\022I\n\016type_parameter\030\004 \003(\01321.org" +
"in.serialization.TypeParameter\022?\n\rreceiv" + ".jetbrains.kotlin.serialization.TypePara" +
"er_type\030\005 \001(\0132(.org.jetbrains.kotlin.ser" + "meter\022?\n\rreceiver_type\030\005 \001(\0132(.org.jetbr" +
"ialization.Type\022\030\n\020receiver_type_id\030\010 \001(" + "ains.kotlin.serialization.Type\022\030\n\020receiv" +
"\005\022K\n\017value_parameter\030\006 \003(\01322.org.jetbrai" + "er_type_id\030\010 \001(\005\022K\n\017value_parameter\030\006 \003(" +
"ns.kotlin.serialization.ValueParameter\022A" + "\01322.org.jetbrains.kotlin.serialization.V" +
"\n\ntype_table\030\036 \001(\0132-.org.jetbrains.kotli" + "alueParameter\022A\n\ntype_table\030\036 \001(\0132-.org." +
"n.serialization.TypeTable\022\027\n\017sinceKotlin" + "jetbrains.kotlin.serialization.TypeTable" +
"Info\030\037 \001(\005*\005\010d\020\310\001\"\350\003\n\010Property\022\022\n\005flags\030", "\022\027\n\017sinceKotlinInfo\030\037 \001(\005*\005\010d\020\310\001\"\350\003\n\010Pro",
"\013 \001(\005:\003518\022\027\n\told_flags\030\001 \001(\005:\0042054\022\022\n\004n" + "perty\022\022\n\005flags\030\013 \001(\005:\003518\022\027\n\told_flags\030\001" +
"ame\030\002 \002(\005B\004\210\265\030\001\022=\n\013return_type\030\003 \001(\0132(.o" + " \001(\005:\0042054\022\022\n\004name\030\002 \002(\005B\004\210\265\030\001\022=\n\013return" +
"rg.jetbrains.kotlin.serialization.Type\022\026" + "_type\030\003 \001(\0132(.org.jetbrains.kotlin.seria" +
"\n\016return_type_id\030\t \001(\005\022I\n\016type_parameter" + "lization.Type\022\026\n\016return_type_id\030\t \001(\005\022I\n" +
"\030\004 \003(\01321.org.jetbrains.kotlin.serializat" + "\016type_parameter\030\004 \003(\01321.org.jetbrains.ko" +
"ion.TypeParameter\022?\n\rreceiver_type\030\005 \001(\013" + "tlin.serialization.TypeParameter\022?\n\rrece" +
"2(.org.jetbrains.kotlin.serialization.Ty" + "iver_type\030\005 \001(\0132(.org.jetbrains.kotlin.s" +
"pe\022\030\n\020receiver_type_id\030\n \001(\005\022R\n\026setter_v" + "erialization.Type\022\030\n\020receiver_type_id\030\n " +
"alue_parameter\030\006 \001(\01322.org.jetbrains.kot" + "\001(\005\022R\n\026setter_value_parameter\030\006 \001(\01322.or" +
"lin.serialization.ValueParameter\022\024\n\014gett", "g.jetbrains.kotlin.serialization.ValuePa",
"er_flags\030\007 \001(\005\022\024\n\014setter_flags\030\010 \001(\005\022\027\n\017" + "rameter\022\024\n\014getter_flags\030\007 \001(\005\022\024\n\014setter_" +
"sinceKotlinInfo\030\037 \001(\005*\005\010d\020\310\001\"\355\001\n\016ValuePa" + "flags\030\010 \001(\005\022\027\n\017sinceKotlinInfo\030\037 \001(\005*\005\010d" +
"rameter\022\020\n\005flags\030\001 \001(\005:\0010\022\022\n\004name\030\002 \002(\005B" + "\020\310\001\"\355\001\n\016ValueParameter\022\020\n\005flags\030\001 \001(\005:\0010" +
"\004\210\265\030\001\0226\n\004type\030\003 \001(\0132(.org.jetbrains.kotl" + "\022\022\n\004name\030\002 \002(\005B\004\210\265\030\001\0226\n\004type\030\003 \001(\0132(.org" +
"in.serialization.Type\022\017\n\007type_id\030\005 \001(\005\022E" + ".jetbrains.kotlin.serialization.Type\022\017\n\007" +
"\n\023vararg_element_type\030\004 \001(\0132(.org.jetbra" + "type_id\030\005 \001(\005\022E\n\023vararg_element_type\030\004 \001" +
"ins.kotlin.serialization.Type\022\036\n\026vararg_" + "(\0132(.org.jetbrains.kotlin.serialization." +
"element_type_id\030\006 \001(\005*\005\010d\020\310\001\"\232\003\n\tTypeAli" + "Type\022\036\n\026vararg_element_type_id\030\006 \001(\005*\005\010d" +
"as\022\020\n\005flags\030\001 \001(\005:\0016\022\022\n\004name\030\002 \002(\005B\004\210\265\030\001" + "\020\310\001\"\232\003\n\tTypeAlias\022\020\n\005flags\030\001 \001(\005:\0016\022\022\n\004n" +
"\022I\n\016type_parameter\030\003 \003(\01321.org.jetbrains", "ame\030\002 \002(\005B\004\210\265\030\001\022I\n\016type_parameter\030\003 \003(\0132",
".kotlin.serialization.TypeParameter\022A\n\017u" + "1.org.jetbrains.kotlin.serialization.Typ" +
"nderlying_type\030\004 \001(\0132(.org.jetbrains.kot" + "eParameter\022A\n\017underlying_type\030\004 \001(\0132(.or" +
"lin.serialization.Type\022\032\n\022underlying_typ" + "g.jetbrains.kotlin.serialization.Type\022\032\n" +
"e_id\030\005 \001(\005\022?\n\rexpanded_type\030\006 \001(\0132(.org." + "\022underlying_type_id\030\005 \001(\005\022?\n\rexpanded_ty" +
"jetbrains.kotlin.serialization.Type\022\030\n\020e" + "pe\030\006 \001(\0132(.org.jetbrains.kotlin.serializ" +
"xpanded_type_id\030\007 \001(\005\022B\n\nannotation\030\010 \003(" + "ation.Type\022\030\n\020expanded_type_id\030\007 \001(\005\022B\n\n" +
"\0132..org.jetbrains.kotlin.serialization.A" + "annotation\030\010 \003(\0132..org.jetbrains.kotlin." +
"nnotation\022\027\n\017sinceKotlinInfo\030\037 \001(\005*\005\010d\020\310" + "serialization.Annotation\022\027\n\017sinceKotlinI" +
"\001\"&\n\tEnumEntry\022\022\n\004name\030\001 \001(\005B\004\210\265\030\001*\005\010d\020\310" + "nfo\030\037 \001(\005*\005\010d\020\310\001\"&\n\tEnumEntry\022\022\n\004name\030\001 " +
"\001\"\341\001\n\017SinceKotlinInfo\022\017\n\007version\030\001 \001(\005\022\024", "\001(\005B\004\210\265\030\001*\005\010d\020\310\001\"\341\001\n\017SinceKotlinInfo\022\017\n\007",
"\n\014version_full\030\002 \001(\005\022O\n\005level\030\003 \001(\01629.or" + "version\030\001 \001(\005\022\024\n\014version_full\030\002 \001(\005\022O\n\005l" +
"g.jetbrains.kotlin.serialization.SinceKo" + "evel\030\003 \001(\01629.org.jetbrains.kotlin.serial" +
"tlinInfo.Level:\005ERROR\022\022\n\nerror_code\030\004 \001(" + "ization.SinceKotlinInfo.Level:\005ERROR\022\022\n\n" +
"\005\022\025\n\007message\030\005 \001(\005B\004\230\265\030\001\"+\n\005Level\022\013\n\007WAR" + "error_code\030\004 \001(\005\022\025\n\007message\030\005 \001(\005B\004\230\265\030\001\"" +
"NING\020\000\022\t\n\005ERROR\020\001\022\n\n\006HIDDEN\020\002\"Y\n\024SinceKo" + "+\n\005Level\022\013\n\007WARNING\020\000\022\t\n\005ERROR\020\001\022\n\n\006HIDD" +
"tlinInfoTable\022A\n\004info\030\001 \003(\01323.org.jetbra" + "EN\020\002\"Y\n\024SinceKotlinInfoTable\022A\n\004info\030\001 \003" +
"ins.kotlin.serialization.SinceKotlinInfo" + "(\01323.org.jetbrains.kotlin.serialization." +
"*9\n\010Modality\022\t\n\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABS" + "SinceKotlinInfo*9\n\010Modality\022\t\n\005FINAL\020\000\022\010" +
"TRACT\020\002\022\n\n\006SEALED\020\003*b\n\nVisibility\022\014\n\010INT" + "\n\004OPEN\020\001\022\014\n\010ABSTRACT\020\002\022\n\n\006SEALED\020\003*b\n\nVi" +
"ERNAL\020\000\022\013\n\007PRIVATE\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006P", "sibility\022\014\n\010INTERNAL\020\000\022\013\n\007PRIVATE\020\001\022\r\n\tP",
"UBLIC\020\003\022\023\n\017PRIVATE_TO_THIS\020\004\022\t\n\005LOCAL\020\005*" + "ROTECTED\020\002\022\n\n\006PUBLIC\020\003\022\023\n\017PRIVATE_TO_THI" +
"Q\n\nMemberKind\022\017\n\013DECLARATION\020\000\022\021\n\rFAKE_O" + "S\020\004\022\t\n\005LOCAL\020\005*Q\n\nMemberKind\022\017\n\013DECLARAT" +
"VERRIDE\020\001\022\016\n\nDELEGATION\020\002\022\017\n\013SYNTHESIZED" + "ION\020\000\022\021\n\rFAKE_OVERRIDE\020\001\022\016\n\nDELEGATION\020\002" +
"\020\003B\017B\rDebugProtoBuf" "\022\017\n\013SYNTHESIZED\020\003B\017B\rDebugProtoBuf"
}; };
org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { new org.jetbrains.kotlin.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
@@ -27337,7 +27447,7 @@ public final class DebugProtoBuf {
internal_static_org_jetbrains_kotlin_serialization_Type_fieldAccessorTable = new internal_static_org_jetbrains_kotlin_serialization_Type_fieldAccessorTable = new
org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable( org.jetbrains.kotlin.protobuf.GeneratedMessage.FieldAccessorTable(
internal_static_org_jetbrains_kotlin_serialization_Type_descriptor, internal_static_org_jetbrains_kotlin_serialization_Type_descriptor,
new java.lang.String[] { "Argument", "Nullable", "FlexibleTypeCapabilitiesId", "FlexibleUpperBound", "FlexibleUpperBoundId", "ClassName", "TypeParameter", "TypeParameterName", "TypeAliasName", "OuterType", "OuterTypeId", "AbbreviatedType", "AbbreviatedTypeId", }); new java.lang.String[] { "Argument", "Nullable", "FlexibleTypeCapabilitiesId", "FlexibleUpperBound", "FlexibleUpperBoundId", "ClassName", "TypeParameter", "TypeParameterName", "TypeAliasName", "OuterType", "OuterTypeId", "AbbreviatedType", "AbbreviatedTypeId", "Flags", });
internal_static_org_jetbrains_kotlin_serialization_Type_Argument_descriptor = internal_static_org_jetbrains_kotlin_serialization_Type_Argument_descriptor =
internal_static_org_jetbrains_kotlin_serialization_Type_descriptor.getNestedTypes().get(0); internal_static_org_jetbrains_kotlin_serialization_Type_descriptor.getNestedTypes().get(0);
internal_static_org_jetbrains_kotlin_serialization_Type_Argument_fieldAccessorTable = new internal_static_org_jetbrains_kotlin_serialization_Type_Argument_fieldAccessorTable = new
@@ -17,6 +17,8 @@
package org.jetbrains.kotlin.serialization package org.jetbrains.kotlin.serialization
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor
import org.jetbrains.kotlin.builtins.getFunctionalClassKind
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotated import org.jetbrains.kotlin.descriptors.annotations.Annotated
import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.Name
@@ -25,6 +27,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry import org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry
import org.jetbrains.kotlin.resolve.MemberComparator import org.jetbrains.kotlin.resolve.MemberComparator
import org.jetbrains.kotlin.resolve.constants.NullValue import org.jetbrains.kotlin.resolve.constants.NullValue
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.utils.Interner import org.jetbrains.kotlin.utils.Interner
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
@@ -455,12 +458,25 @@ class DescriptorSerializer private constructor(
} }
private fun fillFromPossiblyInnerType(builder: ProtoBuf.Type.Builder, type: PossiblyInnerType) { private fun fillFromPossiblyInnerType(builder: ProtoBuf.Type.Builder, type: PossiblyInnerType) {
val classifierDescriptor = type.classifierDescriptor val classifierDescriptor: ClassifierDescriptorWithTypeParameters
val isSuspendType: Boolean
val originalClassifierDescriptor = type.classifierDescriptor
if (originalClassifierDescriptor.getFunctionalClassKind() == FunctionClassDescriptor.Kind.SuspendFunction) {
classifierDescriptor = originalClassifierDescriptor.builtIns.getFunction(originalClassifierDescriptor.declaredTypeParameters.size)
isSuspendType = true
}
else {
classifierDescriptor = originalClassifierDescriptor
isSuspendType = false
}
val classifierId = getClassifierId(classifierDescriptor) val classifierId = getClassifierId(classifierDescriptor)
when (classifierDescriptor) { when (classifierDescriptor) {
is ClassDescriptor -> builder.className = classifierId is ClassDescriptor -> builder.className = classifierId
is TypeAliasDescriptor -> builder.typeAliasName = classifierId is TypeAliasDescriptor -> builder.typeAliasName = classifierId
} }
builder.flags = Flags.getTypeFlags(isSuspendType)
for (projection in type.arguments) { for (projection in type.arguments) {
builder.addArgument(typeArgument(projection)) builder.addArgument(typeArgument(projection))
@@ -11,7 +11,7 @@ typealias Test4 = <!WRONG_MODIFIER_TARGET!>suspend<!> Action
typealias Test5 = List<suspend () -> Unit> typealias Test5 = List<suspend () -> Unit>
typealias Test6 = <!WRONG_MODIFIER_TARGET!>suspend<!> List<() -> Unit> typealias Test6 = <!WRONG_MODIFIER_TARGET!>suspend<!> List<() -> Unit>
typealias Test7 = <!WRONG_MODIFIER_TARGET!>suspend<!> SAM typealias Test7 = <!WRONG_MODIFIER_TARGET!>suspend<!> SAM
typealias Test8 = SuspendFunction0<Unit> typealias Test8 = <!WRONG_MODIFIER_TARGET!>suspend<!> <!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
typealias Test9 = suspend (() -> Unit) -> Unit typealias Test9 = suspend (() -> Unit) -> Unit
typealias Test10 = suspend (suspend () -> Unit) -> Unit typealias Test10 = suspend (suspend () -> Unit) -> Unit
typealias Test11 = suspend () -> (suspend () -> Unit) typealias Test11 = suspend () -> (suspend () -> Unit)
@@ -17,5 +17,5 @@ public typealias Test4 = Action
public typealias Test5 = kotlin.collections.List<suspend () -> kotlin.Unit> public typealias Test5 = kotlin.collections.List<suspend () -> kotlin.Unit>
public typealias Test6 = kotlin.collections.List<() -> kotlin.Unit> public typealias Test6 = kotlin.collections.List<() -> kotlin.Unit>
public typealias Test7 = SAM public typealias Test7 = SAM
public typealias Test8 = suspend () -> kotlin.Unit public typealias Test8 = [ERROR : SuspendFunction0<Unit>]<kotlin.Unit>
public typealias Test9 = suspend (() -> kotlin.Unit) -> kotlin.Unit public typealias Test9 = suspend (() -> kotlin.Unit) -> kotlin.Unit
@@ -0,0 +1,3 @@
typealias Test1 = <!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
typealias Test2 = kotlin.<!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
typealias Test3 = kotlin.coroutines.<!UNRESOLVED_REFERENCE!>SuspendFunction0<!><Unit>
@@ -0,0 +1,5 @@
package
public typealias Test1 = [ERROR : SuspendFunction0<Unit>]<kotlin.Unit>
public typealias Test2 = [ERROR : kotlin.SuspendFunction0<Unit>]<kotlin.Unit>
public typealias Test3 = [ERROR : kotlin.coroutines.SuspendFunction0<Unit>]<kotlin.Unit>
@@ -0,0 +1,7 @@
package test
fun test1(): suspend () -> Unit = null!!
fun test2(): suspend (Int, String) -> Int = null!!
fun test3(): suspend Int.(String) -> Int = null!!
fun test4(): List<suspend () -> Unit> = null!!
fun test5(): suspend (suspend () -> Unit) -> Unit = null!!
@@ -0,0 +1,7 @@
package test
public fun test1(): suspend () -> kotlin.Unit
public fun test2(): suspend (kotlin.Int, kotlin.String) -> kotlin.Int
public fun test3(): suspend kotlin.Int.(kotlin.String) -> kotlin.Int
public fun test4(): kotlin.collections.List<suspend () -> kotlin.Unit>
public fun test5(): suspend (suspend () -> kotlin.Unit) -> kotlin.Unit
@@ -4466,6 +4466,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/noInvokeForSuspendFunction.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/noInvokeForSuspendFunction.kt");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("suspendFunctionNIsUnresolved.kt")
public void testSuspendFunctionNIsUnresolved() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/suspendFunctionType/suspendFunctionNIsUnresolved.kt");
doTest(fileName);
}
} }
@TestMetadata("compiler/testData/diagnostics/tests/coroutines/tailCalls") @TestMetadata("compiler/testData/diagnostics/tests/coroutines/tailCalls")
@@ -4805,6 +4805,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestCompiledKotlin(fileName); doTestCompiledKotlin(fileName);
} }
@TestMetadata("SuspendFunction.kt")
public void testSuspendFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/SuspendFunction.kt");
doTestCompiledKotlin(fileName);
}
@TestMetadata("Unit.kt") @TestMetadata("Unit.kt")
public void testUnit() throws Exception { public void testUnit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt");
@@ -3038,6 +3038,12 @@ public class LoadKotlinWithTypeTableTestGenerated extends AbstractLoadKotlinWith
doTest(fileName); doTest(fileName);
} }
@TestMetadata("SuspendFunction.kt")
public void testSuspendFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/SuspendFunction.kt");
doTest(fileName);
}
@TestMetadata("Unit.kt") @TestMetadata("Unit.kt")
public void testUnit() throws Exception { public void testUnit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt");
@@ -3040,6 +3040,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
doTest(fileName); doTest(fileName);
} }
@TestMetadata("SuspendFunction.kt")
public void testSuspendFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/SuspendFunction.kt");
doTest(fileName);
}
@TestMetadata("Unit.kt") @TestMetadata("Unit.kt")
public void testUnit() throws Exception { public void testUnit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt");
@@ -22,6 +22,7 @@ import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory; import org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory;
import org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor;
import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.*; import org.jetbrains.kotlin.descriptors.annotations.*;
import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor; import org.jetbrains.kotlin.descriptors.impl.EmptyPackageFragmentDescriptor;
@@ -38,6 +39,7 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.serialization.deserialization.AdditionalClassPartsProvider; import org.jetbrains.kotlin.serialization.deserialization.AdditionalClassPartsProvider;
import org.jetbrains.kotlin.serialization.deserialization.ClassDescriptorFactory; import org.jetbrains.kotlin.serialization.deserialization.ClassDescriptorFactory;
import org.jetbrains.kotlin.serialization.deserialization.PlatformDependentDeclarationFilter; import org.jetbrains.kotlin.serialization.deserialization.PlatformDependentDeclarationFilter;
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull;
import org.jetbrains.kotlin.storage.NotNullLazyValue; import org.jetbrains.kotlin.storage.NotNullLazyValue;
import org.jetbrains.kotlin.storage.StorageManager; import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.*; import org.jetbrains.kotlin.types.*;
@@ -74,6 +76,8 @@ public abstract class KotlinBuiltIns {
private final NotNullLazyValue<Primitives> primitives; private final NotNullLazyValue<Primitives> primitives;
private final NotNullLazyValue<PackageFragments> packageFragments; private final NotNullLazyValue<PackageFragments> packageFragments;
private final MemoizedFunctionToNotNull<Integer, ClassDescriptor> suspendFunctionClasses;
private final StorageManager storageManager; private final StorageManager storageManager;
public static final FqNames FQ_NAMES = new FqNames(); public static final FqNames FQ_NAMES = new FqNames();
@@ -119,6 +123,18 @@ public abstract class KotlinBuiltIns {
); );
} }
}); });
this.suspendFunctionClasses = storageManager.createMemoizedFunction(new Function1<Integer, ClassDescriptor>() {
@Override
public ClassDescriptor invoke(Integer arity) {
return new FunctionClassDescriptor(
getStorageManager(),
packageFragments.invoke().coroutinePackageFragment,
FunctionClassDescriptor.Kind.SuspendFunction,
arity
);
}
});
} }
protected void createBuiltInsModule() { protected void createBuiltInsModule() {
@@ -531,11 +547,6 @@ public abstract class KotlinBuiltIns {
return "Function" + parameterCount; return "Function" + parameterCount;
} }
@NotNull
public static String getSuspendFunctionName(int parameterCount) {
return "SuspendFunction" + parameterCount;
}
@NotNull @NotNull
public static ClassId getFunctionClassId(int parameterCount) { public static ClassId getFunctionClassId(int parameterCount) {
return new ClassId(BUILT_INS_PACKAGE_FQ_NAME, Name.identifier(getFunctionName(parameterCount))); return new ClassId(BUILT_INS_PACKAGE_FQ_NAME, Name.identifier(getFunctionName(parameterCount)));
@@ -548,7 +559,8 @@ public abstract class KotlinBuiltIns {
@NotNull @NotNull
public ClassDescriptor getSuspendFunction(int parameterCount) { public ClassDescriptor getSuspendFunction(int parameterCount) {
return getBuiltInClassByName(getSuspendFunctionName(parameterCount)); // SuspendFunction$n is not visible through member scope, and is created independently.
return suspendFunctionClasses.invoke(parameterCount);
} }
@NotNull @NotNull
@@ -51,6 +51,9 @@ class BuiltInFictitiousFunctionClassFactory(
@JvmStatic fun getFunctionalClassKind(className: String, packageFqName: FqName) = @JvmStatic fun getFunctionalClassKind(className: String, packageFqName: FqName) =
parseClassName(className, packageFqName)?.kind parseClassName(className, packageFqName)?.kind
@JvmStatic fun getFunctionalClassArity(className: String, packageFqName: FqName) =
parseClassName(className, packageFqName)?.arity
@JvmStatic fun isFunctionClassName(className: String, packageFqName: FqName) = @JvmStatic fun isFunctionClassName(className: String, packageFqName: FqName) =
getFunctionalClassKind(className, packageFqName) == Kind.Function getFunctionalClassKind(className, packageFqName) == Kind.Function
@@ -72,7 +75,7 @@ class BuiltInFictitiousFunctionClassFactory(
override fun shouldCreateClass(packageFqName: FqName, name: Name): Boolean { override fun shouldCreateClass(packageFqName: FqName, name: Name): Boolean {
val string = name.asString() val string = name.asString()
return (string.startsWith("Function") || string.startsWith("KFunction") || string.startsWith("SuspendFunction")) // an optimization return (string.startsWith("Function") || string.startsWith("KFunction")) // an optimization
&& parseClassName(string, packageFqName) != null && parseClassName(string, packageFqName) != null
} }
@@ -85,6 +88,9 @@ class BuiltInFictitiousFunctionClassFactory(
val packageFqName = classId.packageFqName val packageFqName = classId.packageFqName
val (kind, arity) = parseClassName(className, packageFqName) ?: return null val (kind, arity) = parseClassName(className, packageFqName) ?: return null
// SuspendFunction$n can't be created by classId
if (kind == Kind.SuspendFunction) return null
val containingPackageFragment = module.getPackage(packageFqName).fragments.filterIsInstance<BuiltInsPackageFragment>().first() val containingPackageFragment = module.getPackage(packageFqName).fragments.filterIsInstance<BuiltInsPackageFragment>().first()
return FunctionClassDescriptor(storageManager, containingPackageFragment, kind, arity) return FunctionClassDescriptor(storageManager, containingPackageFragment, kind, arity)
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.builtins.functions
import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment
import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME import org.jetbrains.kotlin.builtins.KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.COROUTINES_PACKAGE_FQ_NAME
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.AbstractClassDescriptor import org.jetbrains.kotlin.descriptors.impl.AbstractClassDescriptor
@@ -50,18 +51,12 @@ class FunctionClassDescriptor(
enum class Kind(val packageFqName: FqName, val classNamePrefix: String) { enum class Kind(val packageFqName: FqName, val classNamePrefix: String) {
Function(BUILT_INS_PACKAGE_FQ_NAME, "Function"), Function(BUILT_INS_PACKAGE_FQ_NAME, "Function"),
SuspendFunction(BUILT_INS_PACKAGE_FQ_NAME, "SuspendFunction"), SuspendFunction(COROUTINES_PACKAGE_FQ_NAME, "SuspendFunction"),
KFunction(KOTLIN_REFLECT_FQ_NAME, "KFunction"); KFunction(KOTLIN_REFLECT_FQ_NAME, "KFunction");
fun numberedClassName(arity: Int) = Name.identifier("$classNamePrefix$arity") fun numberedClassName(arity: Int) = Name.identifier("$classNamePrefix$arity")
companion object { companion object {
fun byPackage(fqName: FqName) = when (fqName) {
BUILT_INS_PACKAGE_FQ_NAME -> Function
KOTLIN_REFLECT_FQ_NAME -> KFunction
else -> null
}
fun byClassNamePrefix(packageFqName: FqName, className: String) = fun byClassNamePrefix(packageFqName: FqName, className: String) =
Kind.values().firstOrNull { it.packageFqName == packageFqName && className.startsWith(it.classNamePrefix) } Kind.values().firstOrNull { it.packageFqName == packageFqName && className.startsWith(it.classNamePrefix) }
} }
@@ -138,6 +138,11 @@ message Type {
optional Type abbreviated_type = 13; optional Type abbreviated_type = 13;
optional int32 abbreviated_type_id = 14; optional int32 abbreviated_type_id = 14;
/*
suspend
*/
optional int32 flags = 1;
extensions 100 to 199; extensions 100 to 199;
} }
@@ -20,11 +20,15 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.protobuf.Internal; import org.jetbrains.kotlin.protobuf.Internal;
import org.jetbrains.kotlin.types.KotlinType;
public class Flags { public class Flags {
private 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 BooleanFlagField HAS_ANNOTATIONS = FlagField.booleanFirst();
public static final FlagField<ProtoBuf.Visibility> VISIBILITY = FlagField.after(HAS_ANNOTATIONS, ProtoBuf.Visibility.values()); 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( public static int getClassFlags(
boolean hasAnnotations, boolean hasAnnotations,
Visibility visibility, Visibility visibility,
@@ -4489,6 +4489,23 @@ public final class ProtoBuf {
* <code>optional int32 abbreviated_type_id = 14;</code> * <code>optional int32 abbreviated_type_id = 14;</code>
*/ */
int getAbbreviatedTypeId(); 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} * Protobuf type {@code org.jetbrains.kotlin.serialization.Type}
@@ -4541,6 +4558,11 @@ public final class ProtoBuf {
} }
break; break;
} }
case 8: {
bitField0_ |= 0x00001000;
flags_ = input.readInt32();
break;
}
case 18: { case 18: {
if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
argument_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument>(); argument_ = new java.util.ArrayList<org.jetbrains.kotlin.serialization.ProtoBuf.Type.Argument>();
@@ -5601,6 +5623,29 @@ public final class ProtoBuf {
return abbreviatedTypeId_; 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() { private void initFields() {
argument_ = java.util.Collections.emptyList(); argument_ = java.util.Collections.emptyList();
nullable_ = false; nullable_ = false;
@@ -5615,6 +5660,7 @@ public final class ProtoBuf {
outerTypeId_ = 0; outerTypeId_ = 0;
abbreviatedType_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance(); abbreviatedType_ = org.jetbrains.kotlin.serialization.ProtoBuf.Type.getDefaultInstance();
abbreviatedTypeId_ = 0; abbreviatedTypeId_ = 0;
flags_ = 0;
} }
private byte memoizedIsInitialized = -1; private byte memoizedIsInitialized = -1;
public final boolean isInitialized() { public final boolean isInitialized() {
@@ -5660,6 +5706,9 @@ public final class ProtoBuf {
org.jetbrains.kotlin.protobuf.GeneratedMessageLite org.jetbrains.kotlin.protobuf.GeneratedMessageLite
.ExtendableMessage<org.jetbrains.kotlin.serialization.ProtoBuf.Type>.ExtensionWriter extensionWriter = .ExtendableMessage<org.jetbrains.kotlin.serialization.ProtoBuf.Type>.ExtensionWriter extensionWriter =
newExtensionWriter(); newExtensionWriter();
if (((bitField0_ & 0x00001000) == 0x00001000)) {
output.writeInt32(1, flags_);
}
for (int i = 0; i < argument_.size(); i++) { for (int i = 0; i < argument_.size(); i++) {
output.writeMessage(2, argument_.get(i)); output.writeMessage(2, argument_.get(i));
} }
@@ -5709,6 +5758,10 @@ public final class ProtoBuf {
if (size != -1) return size; if (size != -1) return size;
size = 0; size = 0;
if (((bitField0_ & 0x00001000) == 0x00001000)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32Size(1, flags_);
}
for (int i = 0; i < argument_.size(); i++) { for (int i = 0; i < argument_.size(); i++) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeMessageSize(2, argument_.get(i)); .computeMessageSize(2, argument_.get(i));
@@ -5881,6 +5934,8 @@ public final class ProtoBuf {
bitField0_ = (bitField0_ & ~0x00000800); bitField0_ = (bitField0_ & ~0x00000800);
abbreviatedTypeId_ = 0; abbreviatedTypeId_ = 0;
bitField0_ = (bitField0_ & ~0x00001000); bitField0_ = (bitField0_ & ~0x00001000);
flags_ = 0;
bitField0_ = (bitField0_ & ~0x00002000);
return this; return this;
} }
@@ -5957,6 +6012,10 @@ public final class ProtoBuf {
to_bitField0_ |= 0x00000800; to_bitField0_ |= 0x00000800;
} }
result.abbreviatedTypeId_ = abbreviatedTypeId_; result.abbreviatedTypeId_ = abbreviatedTypeId_;
if (((from_bitField0_ & 0x00002000) == 0x00002000)) {
to_bitField0_ |= 0x00001000;
}
result.flags_ = flags_;
result.bitField0_ = to_bitField0_; result.bitField0_ = to_bitField0_;
return result; return result;
} }
@@ -6009,6 +6068,9 @@ public final class ProtoBuf {
if (other.hasAbbreviatedTypeId()) { if (other.hasAbbreviatedTypeId()) {
setAbbreviatedTypeId(other.getAbbreviatedTypeId()); setAbbreviatedTypeId(other.getAbbreviatedTypeId());
} }
if (other.hasFlags()) {
setFlags(other.getFlags());
}
this.mergeExtensionFields(other); this.mergeExtensionFields(other);
setUnknownFields( setUnknownFields(
getUnknownFields().concat(other.unknownFields)); getUnknownFields().concat(other.unknownFields));
@@ -6731,6 +6793,54 @@ public final class ProtoBuf {
return this; 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) // @@protoc_insertion_point(builder_scope:org.jetbrains.kotlin.serialization.Type)
} }
@@ -16,11 +16,14 @@
package org.jetbrains.kotlin.serialization.deserialization package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
import org.jetbrains.kotlin.descriptors.annotations.Annotations 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.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedTypeParameterDescriptor import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedTypeParameterDescriptor
@@ -105,8 +108,13 @@ class TypeDeserializer(
private fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor = private fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor =
when { when {
proto.hasClassName() -> { proto.hasClassName() -> {
classDescriptors(proto.className)?.typeConstructor if (Flags.SUSPEND_TYPE.get(proto.flags)) {
?: c.components.notFoundClasses.getClass(proto, c.nameResolver, c.typeTable) getSuspendFunctionTypeConstructor(proto)
}
else {
classDescriptors(proto.className)?.typeConstructor
?: c.components.notFoundClasses.getClass(proto, c.nameResolver, c.typeTable)
}
} }
proto.hasTypeParameter() -> proto.hasTypeParameter() ->
typeParameterTypeConstructor(proto.typeParameter) typeParameterTypeConstructor(proto.typeParameter)
@@ -124,6 +132,16 @@ class TypeDeserializer(
else -> ErrorUtils.createErrorTypeConstructor("Unknown type") 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? = private fun typeParameterTypeConstructor(typeParameterId: Int): TypeConstructor? =
typeParameterDescriptors.get(typeParameterId)?.typeConstructor ?: typeParameterDescriptors.get(typeParameterId)?.typeConstructor ?:
parent?.typeParameterTypeConstructor(typeParameterId) parent?.typeParameterTypeConstructor(typeParameterId)
@@ -127,9 +127,8 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
if (!type.hasClassName() && !type.hasTypeAliasName()) return emptySet() if (!type.hasClassName() && !type.hasTypeAliasName()) return emptySet()
val result = hashSetOf<KtModifierKeywordToken>() val result = hashSetOf<KtModifierKeywordToken>()
val classId = c.nameResolver.getClassId(if (type.hasClassName()) type.className else type.typeAliasName)
if (classId.asSingleFqName().toUnsafe().getFunctionalClassKind() == FunctionClassDescriptor.Kind.SuspendFunction) { if (Flags.SUSPEND_TYPE.get(type.flags)) {
result.add(KtTokens.SUSPEND_KEYWORD) result.add(KtTokens.SUSPEND_KEYWORD)
} }
@@ -0,0 +1,15 @@
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package test
public final class TypeModifiers public constructor() {
public final val function: () -> kotlin.Unit /* compiled code */
public final val functionOnSuspendFunction: (suspend () -> kotlin.Unit).() -> kotlin.Unit /* compiled code */
public final val suspendExtFunction: suspend kotlin.Any.() -> kotlin.Unit /* compiled code */
public final val suspendFunction: suspend () -> kotlin.Unit /* compiled code */
}
@@ -0,0 +1,11 @@
package test
class TypeModifiers {
val function: () -> Unit = null!!
val suspendFunction: suspend () -> Unit = null!!
val suspendExtFunction: suspend Any.() -> Unit = null!!
val functionOnSuspendFunction: (suspend () -> Unit).() -> Unit = null!!
}
@@ -150,4 +150,10 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom
doTest(fileName); doTest(fileName);
} }
@TestMetadata("TypeModifiers")
public void testTypeModifiers() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/TypeModifiers/");
doTest(fileName);
}
} }
@@ -156,4 +156,10 @@ public class CommonDecompiledTextTestGenerated extends AbstractCommonDecompiledT
doTest(fileName); doTest(fileName);
} }
@TestMetadata("TypeModifiers")
public void testTypeModifiers() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/TypeModifiers/");
doTest(fileName);
}
} }
@@ -3038,6 +3038,12 @@ public class ResolveByStubTestGenerated extends AbstractResolveByStubTest {
doTest(fileName); doTest(fileName);
} }
@TestMetadata("SuspendFunction.kt")
public void testSuspendFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/SuspendFunction.kt");
doTest(fileName);
}
@TestMetadata("Unit.kt") @TestMetadata("Unit.kt")
public void testUnit() throws Exception { public void testUnit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledKotlin/type/Unit.kt");