From 9352d52e7ee896e3fe9efdb51e63f33b7bcc884d Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 18 Apr 2019 18:17:33 +0300 Subject: [PATCH] FIR: load default value from meta-data --- .../deserialization/FirMemberDeserializer.kt | 19 ++++++++++++++----- .../fir/resolve/testData/builtIns/kotlin.txt | 2 +- .../annotations/classMembers/EnumEntry.txt | 2 +- .../annotations/classes/DataClass.txt | 2 +- .../Constructor1WithParamDefaultValue.txt | 2 +- .../Constructor2WithOneParamDefaultValue.txt | 2 +- .../constructor/ConstructorWithTwoDefArgs.txt | 2 +- .../InnerClassConstructorWithDefArgs.txt | 2 +- ...ivateConstructor1WithParamDefaultValue.txt | 2 +- .../dataClass/MixedComponents.txt | 2 +- .../loadCompiledKotlin/dataClass/OneVal.txt | 2 +- .../loadCompiledKotlin/dataClass/TwoVals.txt | 2 +- .../loadCompiledKotlin/dataClass/TwoVars.txt | 2 +- .../enum/EnumWithConstuctor.txt | 2 +- .../fun/nonGeneric/FunDefaultArg.txt | 3 ++- .../typealias/Annotations.txt | 2 +- 16 files changed, 30 insertions(+), 20 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt index 905fc7bcf4c..f58fd53d013 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/deserialization/FirMemberDeserializer.kt @@ -7,23 +7,25 @@ package org.jetbrains.kotlin.fir.deserialization import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.declarations.FirConstructor -import org.jetbrains.kotlin.fir.declarations.FirNamedFunction -import org.jetbrains.kotlin.fir.declarations.FirValueParameter +import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.impl.* import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall +import org.jetbrains.kotlin.fir.expressions.FirExpression +import org.jetbrains.kotlin.fir.expressions.impl.FirExpressionStub import org.jetbrains.kotlin.fir.resolve.transformers.firUnsafe import org.jetbrains.kotlin.fir.symbols.CallableId import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol +import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.types.ConeKotlinType import org.jetbrains.kotlin.fir.types.FirTypeRef +import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl +import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.fir.types.impl.FirResolvedTypeRefImpl import org.jetbrains.kotlin.metadata.ProtoBuf import org.jetbrains.kotlin.metadata.deserialization.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.protobuf.MessageLite import org.jetbrains.kotlin.serialization.deserialization.AnnotatedCallableKind import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags @@ -196,6 +198,13 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { } + private fun defaultValue(flags: Int): FirExpression? { + if (Flags.DECLARES_DEFAULT_VALUE.get(flags)) { + return FirExpressionStub(c.session, null) + } + return null + } + private fun valueParameters( valueParameters: List ): List { @@ -204,7 +213,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) { FirValueParameterImpl( c.session, null, c.nameResolver.getName(proto.name), c.typeDeserializer.type(proto.type(c.typeTable)).toTypeRef(), - null, // TODO: default value + defaultValue(flags), Flags.IS_CROSSINLINE.get(flags), Flags.IS_NOINLINE.get(flags), proto.varargElementType(c.typeTable) != null diff --git a/compiler/fir/resolve/testData/builtIns/kotlin.txt b/compiler/fir/resolve/testData/builtIns/kotlin.txt index 6402b72bc20..4c7bca7aab2 100644 --- a/compiler/fir/resolve/testData/builtIns/kotlin.txt +++ b/compiler/fir/resolve/testData/builtIns/kotlin.txt @@ -292,7 +292,7 @@ public abstract interface Comparable : R|kotlin/Any| { } public final annotation class Deprecated : R|kotlin/Annotation| { - public constructor(message: R|kotlin/String|, replaceWith: R|kotlin/ReplaceWith|, level: R|kotlin/DeprecationLevel|): R|kotlin/Deprecated| + public constructor(message: R|kotlin/String|, replaceWith: R|kotlin/ReplaceWith| = STUB, level: R|kotlin/DeprecationLevel| = STUB): R|kotlin/Deprecated| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/annotations/classMembers/EnumEntry.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/annotations/classMembers/EnumEntry.txt index e14a195c838..47a45308ea6 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/annotations/classMembers/EnumEntry.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/annotations/classMembers/EnumEntry.txt @@ -1,5 +1,5 @@ public final annotation class Anno : R|kotlin/Annotation| { - public constructor(value: R|kotlin/String|, x: R|kotlin/Int|): R|test/Anno| + public constructor(value: R|kotlin/String| = STUB, x: R|kotlin/Int| = STUB): R|test/Anno| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/annotations/classes/DataClass.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/annotations/classes/DataClass.txt index 103534dda9d..12e7fa53126 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/annotations/classes/DataClass.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/annotations/classes/DataClass.txt @@ -1,7 +1,7 @@ public final data class My : R|kotlin/Any| { public final operator fun component1(): R|kotlin/Int| - public final fun copy(x: R|kotlin/Int|): R|test/My| + public final fun copy(x: R|kotlin/Int| = STUB): R|test/My| public open operator fun equals(other: R|kotlin/Any|?): R|kotlin/Boolean| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/Constructor1WithParamDefaultValue.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/Constructor1WithParamDefaultValue.txt index 124ae8c5424..a88db435bbe 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/Constructor1WithParamDefaultValue.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/Constructor1WithParamDefaultValue.txt @@ -1,4 +1,4 @@ public final class ClassWithConstructorWithValueParamWithDefaultValue : R|kotlin/Any| { - public constructor(p: R|kotlin/Int|): R|test/ClassWithConstructorWithValueParamWithDefaultValue| + public constructor(p: R|kotlin/Int| = STUB): R|test/ClassWithConstructorWithValueParamWithDefaultValue| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/Constructor2WithOneParamDefaultValue.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/Constructor2WithOneParamDefaultValue.txt index 71d0b3bcb48..bb78657328e 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/Constructor2WithOneParamDefaultValue.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/Constructor2WithOneParamDefaultValue.txt @@ -1,4 +1,4 @@ public final class TestConstructor : R|kotlin/Any| { - public constructor(p: R|kotlin/Int|, s: R|kotlin/Int|): R|test/TestConstructor| + public constructor(p: R|kotlin/Int| = STUB, s: R|kotlin/Int|): R|test/TestConstructor| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/ConstructorWithTwoDefArgs.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/ConstructorWithTwoDefArgs.txt index 98727ea8919..3948da54193 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/ConstructorWithTwoDefArgs.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/ConstructorWithTwoDefArgs.txt @@ -1,4 +1,4 @@ public final class TestConstructor : R|kotlin/Any| { - public constructor(p: R|kotlin/Int|, d: R|kotlin/Int|): R|test/TestConstructor| + public constructor(p: R|kotlin/Int| = STUB, d: R|kotlin/Int| = STUB): R|test/TestConstructor| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/InnerClassConstructorWithDefArgs.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/InnerClassConstructorWithDefArgs.txt index 3557d89762a..525f16f4dda 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/InnerClassConstructorWithDefArgs.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/InnerClassConstructorWithDefArgs.txt @@ -2,7 +2,7 @@ public final class A : R|kotlin/Any| { public constructor(): R|test/A| public final class TestConstructor : R|kotlin/Any| { - public constructor(p: R|kotlin/Int|): R|test/A.TestConstructor| + public constructor(p: R|kotlin/Int| = STUB): R|test/A.TestConstructor| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/PrivateConstructor1WithParamDefaultValue.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/PrivateConstructor1WithParamDefaultValue.txt index 288ee7b5e2f..19013d51608 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/PrivateConstructor1WithParamDefaultValue.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/constructor/PrivateConstructor1WithParamDefaultValue.txt @@ -1,4 +1,4 @@ public final class TestConstructor : R|kotlin/Any| { - private constructor(p: R|kotlin/Int|): R|test/TestConstructor| + private constructor(p: R|kotlin/Int| = STUB): R|test/TestConstructor| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/MixedComponents.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/MixedComponents.txt index 129d9ca4b5c..34a8422fbe6 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/MixedComponents.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/MixedComponents.txt @@ -3,7 +3,7 @@ public final data class DataClass : R|kotlin/Any| { public final operator fun component2(): R|kotlin/Double| - public final fun copy(x: R|kotlin/String|, z: R|kotlin/Double|): R|test/DataClass| + public final fun copy(x: R|kotlin/String| = STUB, z: R|kotlin/Double| = STUB): R|test/DataClass| public open operator fun equals(other: R|kotlin/Any|?): R|kotlin/Boolean| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/OneVal.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/OneVal.txt index dd0479b55f4..1d46509af8a 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/OneVal.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/OneVal.txt @@ -1,7 +1,7 @@ public final data class DataClass : R|kotlin/Any| { public final operator fun component1(): R|kotlin/String| - public final fun copy(x: R|kotlin/String|): R|test/DataClass| + public final fun copy(x: R|kotlin/String| = STUB): R|test/DataClass| public open operator fun equals(other: R|kotlin/Any|?): R|kotlin/Boolean| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/TwoVals.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/TwoVals.txt index 893e0efb769..4f17f11690f 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/TwoVals.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/TwoVals.txt @@ -3,7 +3,7 @@ public final data class DataClass : R|kotlin/Any| { public final operator fun component2(): R|kotlin/Int| - public final fun copy(x: R|kotlin/String|, y: R|kotlin/Int|): R|test/DataClass| + public final fun copy(x: R|kotlin/String| = STUB, y: R|kotlin/Int| = STUB): R|test/DataClass| public open operator fun equals(other: R|kotlin/Any|?): R|kotlin/Boolean| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/TwoVars.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/TwoVars.txt index 893e0efb769..4f17f11690f 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/TwoVars.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/dataClass/TwoVars.txt @@ -3,7 +3,7 @@ public final data class DataClass : R|kotlin/Any| { public final operator fun component2(): R|kotlin/Int| - public final fun copy(x: R|kotlin/String|, y: R|kotlin/Int|): R|test/DataClass| + public final fun copy(x: R|kotlin/String| = STUB, y: R|kotlin/Int| = STUB): R|test/DataClass| public open operator fun equals(other: R|kotlin/Any|?): R|kotlin/Boolean| diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/enum/EnumWithConstuctor.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/enum/EnumWithConstuctor.txt index 32908d4ab05..e2356cda7e2 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/enum/EnumWithConstuctor.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/enum/EnumWithConstuctor.txt @@ -1,4 +1,4 @@ public final enum class En : R|kotlin/Enum| { - private constructor(b: R|kotlin/Boolean|, i: R|kotlin/Int|): R|test/En| + private constructor(b: R|kotlin/Boolean| = STUB, i: R|kotlin/Int| = STUB): R|test/En| } diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/fun/nonGeneric/FunDefaultArg.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/fun/nonGeneric/FunDefaultArg.txt index c5a227021e1..83ec24a746e 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/fun/nonGeneric/FunDefaultArg.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/fun/nonGeneric/FunDefaultArg.txt @@ -1 +1,2 @@ -public final fun funDefaultArg(p: R|kotlin/Int|, q: R|kotlin/Int|, r: R|kotlin/Int|): R|kotlin/Int| +public final fun funDefaultArg(p: R|kotlin/Int|, q: R|kotlin/Int| = STUB, r: R|kotlin/Int| = STUB): R|kotlin/Int| + diff --git a/compiler/fir/resolve/testData/loadCompiledKotlin/typealias/Annotations.txt b/compiler/fir/resolve/testData/loadCompiledKotlin/typealias/Annotations.txt index c7d1a045874..0ea668b375a 100644 --- a/compiler/fir/resolve/testData/loadCompiledKotlin/typealias/Annotations.txt +++ b/compiler/fir/resolve/testData/loadCompiledKotlin/typealias/Annotations.txt @@ -1,4 +1,4 @@ public final annotation class Ann : R|kotlin/Annotation| { - public constructor(value: R|kotlin/String|): R|test/Ann| + public constructor(value: R|kotlin/String| = STUB): R|test/Ann| }