Skip to content

Commit a0677dd

Browse files
lunakolySpace Team
authored andcommitted
[FIR] Fix typealias abbreviation serialization in FirElementSerializer
See: `ClassifierCommonizationFromSourcesTest.testTypeAliases`.
1 parent bc0d1bc commit a0677dd

File tree

5 files changed

+52
-107
lines changed

5 files changed

+52
-107
lines changed

compiler/fir/fir-serialization/src/org/jetbrains/kotlin/fir/serialization/FirElementSerializer.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ class FirElementSerializer private constructor(
849849

850850
val underlyingType = typeAlias.expandedConeType!!
851851
if (useTypeTable()) {
852-
builder.underlyingTypeId = local.typeId(underlyingType)
852+
builder.underlyingTypeId = local.typeId(underlyingType, abbreviationOnly = true)
853853
} else {
854854
builder.setUnderlyingType(local.typeProto(underlyingType, abbreviationOnly = true))
855855
}
@@ -1030,7 +1030,8 @@ class FirElementSerializer private constructor(
10301030
return typeId(typeRef.coneType, toSuper)
10311031
}
10321032

1033-
fun typeId(type: ConeKotlinType, toSuper: Boolean = false): Int = typeTable[typeProto(type, toSuper)]
1033+
fun typeId(type: ConeKotlinType, toSuper: Boolean = false, abbreviationOnly: Boolean = false): Int =
1034+
typeTable[typeProto(type, toSuper, abbreviationOnly = abbreviationOnly)]
10341035

10351036
private fun typeProto(typeRef: FirTypeRef, toSuper: Boolean = false): ProtoBuf.Type.Builder {
10361037
return typeProto(typeRef.coneType, toSuper, correspondingTypeRef = typeRef)
@@ -1301,7 +1302,7 @@ class FirElementSerializer private constructor(
13011302
}
13021303

13031304
if (useTypeTable()) {
1304-
builder.typeId = typeId(typeProjection.type)
1305+
builder.typeId = typeId(typeProjection.type, abbreviationOnly = abbreviationOnly)
13051306
} else {
13061307
builder.setType(typeProto(typeProjection.type, abbreviationOnly = abbreviationOnly))
13071308
}

compiler/testData/psi/typeAliasExpansion.knm.compiled.stubs.txt

Lines changed: 33 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,16 @@ FILE[kind=File[packageFqName=test]]
5353
MODIFIER_LIST[public]
5454
TYPE_REFERENCE
5555
USER_TYPE
56-
abbreviatedType: test.StringAlias
5756
USER_TYPE
58-
REFERENCE_EXPRESSION[referencedName=kotlin]
59-
REFERENCE_EXPRESSION[referencedName=String]
57+
REFERENCE_EXPRESSION[referencedName=test]
58+
REFERENCE_EXPRESSION[referencedName=StringAlias]
6059
TYPEALIAS[classId=test/NestedFunctionAlias, fqName=test.NestedFunctionAlias, isTopLevel=true, name=NestedFunctionAlias]
6160
MODIFIER_LIST[public]
6261
TYPE_REFERENCE
63-
FUNCTION_TYPE
64-
abbreviatedType: test.FunctionAlias
65-
VALUE_PARAMETER_LIST
66-
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null]
67-
TYPE_REFERENCE
68-
USER_TYPE
69-
USER_TYPE
70-
REFERENCE_EXPRESSION[referencedName=kotlin]
71-
REFERENCE_EXPRESSION[referencedName=String]
72-
TYPE_REFERENCE
73-
USER_TYPE
74-
USER_TYPE
75-
REFERENCE_EXPRESSION[referencedName=kotlin]
76-
REFERENCE_EXPRESSION[referencedName=Int]
62+
USER_TYPE
63+
USER_TYPE
64+
REFERENCE_EXPRESSION[referencedName=test]
65+
REFERENCE_EXPRESSION[referencedName=FunctionAlias]
7766
TYPEALIAS[classId=test/ParameterizedListAlias, fqName=test.ParameterizedListAlias, isTopLevel=true, name=ParameterizedListAlias]
7867
MODIFIER_LIST[public]
7968
TYPE_PARAMETER_LIST
@@ -94,12 +83,9 @@ FILE[kind=File[packageFqName=test]]
9483
MODIFIER_LIST[public]
9584
TYPE_REFERENCE
9685
USER_TYPE
97-
abbreviatedType: test.ParameterizedListAlias<kotlin.String>
9886
USER_TYPE
99-
USER_TYPE
100-
REFERENCE_EXPRESSION[referencedName=kotlin]
101-
REFERENCE_EXPRESSION[referencedName=collections]
102-
REFERENCE_EXPRESSION[referencedName=List]
87+
REFERENCE_EXPRESSION[referencedName=test]
88+
REFERENCE_EXPRESSION[referencedName=ParameterizedListAlias]
10389
TYPE_ARGUMENT_LIST
10490
TYPE_PROJECTION[projectionKind=NONE]
10591
TYPE_REFERENCE
@@ -111,60 +97,46 @@ FILE[kind=File[packageFqName=test]]
11197
MODIFIER_LIST[public]
11298
TYPE_REFERENCE
11399
USER_TYPE
114-
abbreviatedType: test.ParameterizedListAlias<kotlin.String (abbreviatedType: test.StringAlias)>
115100
USER_TYPE
116-
USER_TYPE
117-
REFERENCE_EXPRESSION[referencedName=kotlin]
118-
REFERENCE_EXPRESSION[referencedName=collections]
119-
REFERENCE_EXPRESSION[referencedName=List]
101+
REFERENCE_EXPRESSION[referencedName=test]
102+
REFERENCE_EXPRESSION[referencedName=ParameterizedListAlias]
120103
TYPE_ARGUMENT_LIST
121104
TYPE_PROJECTION[projectionKind=NONE]
122105
TYPE_REFERENCE
123106
USER_TYPE
124-
abbreviatedType: test.StringAlias
125107
USER_TYPE
126-
REFERENCE_EXPRESSION[referencedName=kotlin]
127-
REFERENCE_EXPRESSION[referencedName=String]
108+
REFERENCE_EXPRESSION[referencedName=test]
109+
REFERENCE_EXPRESSION[referencedName=StringAlias]
128110
TYPEALIAS[classId=test/NestedListAliasWithNestedAliasTypeArgument, fqName=test.NestedListAliasWithNestedAliasTypeArgument, isTopLevel=true, name=NestedListAliasWithNestedAliasTypeArgument]
129111
MODIFIER_LIST[public]
130112
TYPE_REFERENCE
131113
USER_TYPE
132-
abbreviatedType: test.ParameterizedListAlias<kotlin.String (abbreviatedType: test.NestedStringAlias)>
133114
USER_TYPE
134-
USER_TYPE
135-
REFERENCE_EXPRESSION[referencedName=kotlin]
136-
REFERENCE_EXPRESSION[referencedName=collections]
137-
REFERENCE_EXPRESSION[referencedName=List]
115+
REFERENCE_EXPRESSION[referencedName=test]
116+
REFERENCE_EXPRESSION[referencedName=ParameterizedListAlias]
138117
TYPE_ARGUMENT_LIST
139118
TYPE_PROJECTION[projectionKind=NONE]
140119
TYPE_REFERENCE
141120
USER_TYPE
142-
abbreviatedType: test.NestedStringAlias
143121
USER_TYPE
144-
REFERENCE_EXPRESSION[referencedName=kotlin]
145-
REFERENCE_EXPRESSION[referencedName=String]
122+
REFERENCE_EXPRESSION[referencedName=test]
123+
REFERENCE_EXPRESSION[referencedName=NestedStringAlias]
146124
TYPEALIAS[classId=test/NestedParameterizedListAlias, fqName=test.NestedParameterizedListAlias, isTopLevel=true, name=NestedParameterizedListAlias]
147125
MODIFIER_LIST[public]
148126
TYPE_PARAMETER_LIST
149127
TYPE_PARAMETER[fqName=null, name=A]
150128
TYPE_REFERENCE
151129
USER_TYPE
152-
abbreviatedType: test.ParameterizedListAlias<kotlin.collections.List<A> (abbreviatedType: test.ParameterizedListAlias<A>)>
153130
USER_TYPE
154-
USER_TYPE
155-
REFERENCE_EXPRESSION[referencedName=kotlin]
156-
REFERENCE_EXPRESSION[referencedName=collections]
157-
REFERENCE_EXPRESSION[referencedName=List]
131+
REFERENCE_EXPRESSION[referencedName=test]
132+
REFERENCE_EXPRESSION[referencedName=ParameterizedListAlias]
158133
TYPE_ARGUMENT_LIST
159134
TYPE_PROJECTION[projectionKind=NONE]
160135
TYPE_REFERENCE
161136
USER_TYPE
162-
abbreviatedType: test.ParameterizedListAlias<A>
163137
USER_TYPE
164-
USER_TYPE
165-
REFERENCE_EXPRESSION[referencedName=kotlin]
166-
REFERENCE_EXPRESSION[referencedName=collections]
167-
REFERENCE_EXPRESSION[referencedName=List]
138+
REFERENCE_EXPRESSION[referencedName=test]
139+
REFERENCE_EXPRESSION[referencedName=ParameterizedListAlias]
168140
TYPE_ARGUMENT_LIST
169141
TYPE_PROJECTION[projectionKind=NONE]
170142
TYPE_REFERENCE
@@ -181,21 +153,18 @@ FILE[kind=File[packageFqName=test]]
181153
TYPEALIAS[classId=test/NestedNullableStringAlias, fqName=test.NestedNullableStringAlias, isTopLevel=true, name=NestedNullableStringAlias]
182154
MODIFIER_LIST[public]
183155
TYPE_REFERENCE
184-
NULLABLE_TYPE
156+
USER_TYPE
185157
USER_TYPE
186-
abbreviatedType: test.NullableStringAlias
187-
USER_TYPE
188-
REFERENCE_EXPRESSION[referencedName=kotlin]
189-
REFERENCE_EXPRESSION[referencedName=String]
158+
REFERENCE_EXPRESSION[referencedName=test]
159+
REFERENCE_EXPRESSION[referencedName=NullableStringAlias]
190160
TYPEALIAS[classId=test/NullableNestedStringAlias, fqName=test.NullableNestedStringAlias, isTopLevel=true, name=NullableNestedStringAlias]
191161
MODIFIER_LIST[public]
192162
TYPE_REFERENCE
193163
NULLABLE_TYPE
194164
USER_TYPE
195-
abbreviatedType: test.StringAlias?
196165
USER_TYPE
197-
REFERENCE_EXPRESSION[referencedName=kotlin]
198-
REFERENCE_EXPRESSION[referencedName=String]
166+
REFERENCE_EXPRESSION[referencedName=test]
167+
REFERENCE_EXPRESSION[referencedName=StringAlias]
199168
TYPEALIAS[classId=test/NullableFunctionAlias, fqName=test.NullableFunctionAlias, isTopLevel=true, name=NullableFunctionAlias]
200169
MODIFIER_LIST[public]
201170
TYPE_REFERENCE
@@ -216,39 +185,18 @@ FILE[kind=File[packageFqName=test]]
216185
TYPEALIAS[classId=test/NestedNullableFunctionAlias, fqName=test.NestedNullableFunctionAlias, isTopLevel=true, name=NestedNullableFunctionAlias]
217186
MODIFIER_LIST[public]
218187
TYPE_REFERENCE
219-
NULLABLE_TYPE
220-
FUNCTION_TYPE
221-
abbreviatedType: test.NullableFunctionAlias
222-
VALUE_PARAMETER_LIST
223-
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null]
224-
TYPE_REFERENCE
225-
USER_TYPE
226-
USER_TYPE
227-
REFERENCE_EXPRESSION[referencedName=kotlin]
228-
REFERENCE_EXPRESSION[referencedName=String]
229-
TYPE_REFERENCE
230-
USER_TYPE
231-
USER_TYPE
232-
REFERENCE_EXPRESSION[referencedName=kotlin]
233-
REFERENCE_EXPRESSION[referencedName=Int]
188+
USER_TYPE
189+
USER_TYPE
190+
REFERENCE_EXPRESSION[referencedName=test]
191+
REFERENCE_EXPRESSION[referencedName=NullableFunctionAlias]
234192
TYPEALIAS[classId=test/NullableNestedFunctionAlias, fqName=test.NullableNestedFunctionAlias, isTopLevel=true, name=NullableNestedFunctionAlias]
235193
MODIFIER_LIST[public]
236194
TYPE_REFERENCE
237195
NULLABLE_TYPE
238-
FUNCTION_TYPE
239-
abbreviatedType: test.FunctionAlias?
240-
VALUE_PARAMETER_LIST
241-
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null]
242-
TYPE_REFERENCE
243-
USER_TYPE
244-
USER_TYPE
245-
REFERENCE_EXPRESSION[referencedName=kotlin]
246-
REFERENCE_EXPRESSION[referencedName=String]
247-
TYPE_REFERENCE
248-
USER_TYPE
249-
USER_TYPE
250-
REFERENCE_EXPRESSION[referencedName=kotlin]
251-
REFERENCE_EXPRESSION[referencedName=Int]
196+
USER_TYPE
197+
USER_TYPE
198+
REFERENCE_EXPRESSION[referencedName=test]
199+
REFERENCE_EXPRESSION[referencedName=FunctionAlias]
252200
CLASS[classId=test/TypeAliasExpansion, fqName=test.TypeAliasExpansion, isClsStubCompiledToJvmDefaultImplementation=false, isInterface=false, isLocal=false, isTopLevel=true, name=TypeAliasExpansion, superNames=[]]
253201
MODIFIER_LIST[public final]
254202
PRIMARY_CONSTRUCTOR[fqName=null, hasBody=false, hasNoExpressionBody=true, isDelegatedCallToThis=false, isExplicitDelegationCall=false, isExtension=false, isTopLevel=false, mayHaveContract=false, name=TypeAliasExpansion]

compiler/testData/psi/typeAliasExpansion.knm.decompiledText.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,31 @@ public typealias EntryAlias = kotlin.collections.Map.Entry<kotlin.String, kotlin
99

1010
public typealias FunctionAlias = (kotlin.String) -> kotlin.Int
1111

12-
public typealias NestedStringAlias = kotlin.String /* from: test.StringAlias */
12+
public typealias NestedStringAlias = test.StringAlias
1313

14-
public typealias NestedFunctionAlias = (kotlin.String) -> kotlin.Int /* from: test.FunctionAlias */
14+
public typealias NestedFunctionAlias = test.FunctionAlias
1515

1616
public typealias ParameterizedListAlias<A> = kotlin.collections.List<A>
1717

18-
public typealias NestedListAliasWithTypeArgument = kotlin.collections.List<kotlin.String> /* from: test.ParameterizedListAlias<kotlin.String> */
18+
public typealias NestedListAliasWithTypeArgument = test.ParameterizedListAlias<kotlin.String>
1919

20-
public typealias NestedListAliasWithAliasTypeArgument = kotlin.collections.List<kotlin.String /* from: test.StringAlias */> /* from: test.ParameterizedListAlias<kotlin.String /* from: test.StringAlias */> */
20+
public typealias NestedListAliasWithAliasTypeArgument = test.ParameterizedListAlias<test.StringAlias>
2121

22-
public typealias NestedListAliasWithNestedAliasTypeArgument = kotlin.collections.List<kotlin.String /* from: test.NestedStringAlias */> /* from: test.ParameterizedListAlias<kotlin.String /* from: test.NestedStringAlias */> */
22+
public typealias NestedListAliasWithNestedAliasTypeArgument = test.ParameterizedListAlias<test.NestedStringAlias>
2323

24-
public typealias NestedParameterizedListAlias<A> = kotlin.collections.List<kotlin.collections.List<A> /* from: test.ParameterizedListAlias<A> */> /* from: test.ParameterizedListAlias<kotlin.collections.List<A> /* from: test.ParameterizedListAlias<A> */> */
24+
public typealias NestedParameterizedListAlias<A> = test.ParameterizedListAlias<test.ParameterizedListAlias<A>>
2525

2626
public typealias NullableStringAlias = kotlin.String?
2727

28-
public typealias NestedNullableStringAlias = kotlin.String? /* from: test.NullableStringAlias */
28+
public typealias NestedNullableStringAlias = test.NullableStringAlias
2929

30-
public typealias NullableNestedStringAlias = kotlin.String? /* from: test.StringAlias? */
30+
public typealias NullableNestedStringAlias = test.StringAlias?
3131

3232
public typealias NullableFunctionAlias = ((kotlin.String) -> kotlin.Int)?
3333

34-
public typealias NestedNullableFunctionAlias = ((kotlin.String) -> kotlin.Int)? /* from: test.NullableFunctionAlias */
34+
public typealias NestedNullableFunctionAlias = test.NullableFunctionAlias
3535

36-
public typealias NullableNestedFunctionAlias = ((kotlin.String) -> kotlin.Int)? /* from: test.FunctionAlias? */
36+
public typealias NullableNestedFunctionAlias = test.FunctionAlias?
3737

3838
public final class TypeAliasExpansion public constructor() {
3939
public final val functionAlias: (kotlin.String) -> kotlin.Int /* from: test.FunctionAlias */ /* compiled code */

compiler/testData/psi/typeAliases.knm.compiled.stubs.txt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,10 @@
281281
VALUE_PARAMETER_LIST
282282
VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null]
283283
TYPE_REFERENCE
284-
FUNCTION_TYPE
285-
abbreviatedType: dependency.A
286-
VALUE_PARAMETER_LIST
287-
TYPE_REFERENCE
288-
USER_TYPE
289-
USER_TYPE
290-
REFERENCE_EXPRESSION[referencedName=kotlin]
291-
REFERENCE_EXPRESSION[referencedName=Unit]
284+
USER_TYPE
285+
USER_TYPE
286+
REFERENCE_EXPRESSION[referencedName=dependency]
287+
REFERENCE_EXPRESSION[referencedName=A]
292288
TYPE_REFERENCE
293289
USER_TYPE
294290
USER_TYPE

compiler/testData/psi/typeAliases.knm.decompiledText.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
public final class OrderA public constructor() {
4242
}
4343

44-
public typealias B = (() -> kotlin.Unit /* from: dependency.A */) -> kotlin.Unit
44+
public typealias B = (dependency.A) -> kotlin.Unit
4545

4646
@test.Ann private typealias Parametrized<E, F> = kotlin.collections.Map<E, F>
4747
}

0 commit comments

Comments
 (0)