Revert "[FIR2IR] Set proper offsets for generated data class members"

This reverts commit b33798d65a.

Reverted because of KT-58215


Co-authored-by: Aleksandr Korepanov <Alexander.Korepanov@jetbrains.com>


Merge-request: KT-MR-14328
Merged-by: Anton Bannykh <Anton.Bannykh@jetbrains.com>
This commit is contained in:
Alexander Korepanov
2024-02-13 09:52:09 +00:00
committed by Space Team
parent 64083d6d5c
commit 4e62400f6f
6 changed files with 73 additions and 35 deletions
@@ -78,10 +78,6 @@ fun AbstractKtSourceElement?.startOffsetSkippingComments(): Int? {
} }
} }
internal inline fun <T : IrElement> FirElement.convertWithOffsets(defaultOffset: Int, f: (startOffset: Int, endOffset: Int) -> T): T {
return source.convertWithOffsets(defaultOffset, f)
}
internal inline fun <T : IrElement> FirElement.convertWithOffsets(f: (startOffset: Int, endOffset: Int) -> T): T { internal inline fun <T : IrElement> FirElement.convertWithOffsets(f: (startOffset: Int, endOffset: Int) -> T): T {
return source.convertWithOffsets(f) return source.convertWithOffsets(f)
} }
@@ -93,19 +89,15 @@ internal fun <T : IrElement> FirPropertyAccessor?.convertWithOffsets(
} }
internal inline fun <T : IrElement> KtSourceElement?.convertWithOffsets(f: (startOffset: Int, endOffset: Int) -> T): T { internal inline fun <T : IrElement> KtSourceElement?.convertWithOffsets(f: (startOffset: Int, endOffset: Int) -> T): T {
return convertWithOffsets(UNDEFINED_OFFSET, f)
}
internal inline fun <T : IrElement> KtSourceElement?.convertWithOffsets(defaultOffset: Int, f: (startOffset: Int, endOffset: Int) -> T): T {
val startOffset: Int val startOffset: Int
val endOffset: Int val endOffset: Int
if (isCompiledElement(psi) || this?.kind == KtFakeSourceElementKind.DataClassGeneratedMembers) { if (isCompiledElement(psi) || this?.kind == KtFakeSourceElementKind.DataClassGeneratedMembers) {
startOffset = defaultOffset startOffset = UNDEFINED_OFFSET
endOffset = defaultOffset endOffset = UNDEFINED_OFFSET
} else { } else {
startOffset = this?.startOffsetSkippingComments() ?: this?.startOffset ?: defaultOffset startOffset = this?.startOffsetSkippingComments() ?: this?.startOffset ?: UNDEFINED_OFFSET
endOffset = this?.endOffset ?: defaultOffset endOffset = this?.endOffset ?: UNDEFINED_OFFSET
} }
return f(startOffset, endOffset) return f(startOffset, endOffset)
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.fir.scopes.getProperties
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.builders.IrGeneratorContextBase import org.jetbrains.kotlin.ir.builders.IrGeneratorContextBase
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
@@ -192,8 +193,8 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
irFunction.declareThisReceiverParameter( irFunction.declareThisReceiverParameter(
irClass.defaultType, irClass.defaultType,
IrDeclarationOrigin.DEFINED, IrDeclarationOrigin.DEFINED,
SYNTHETIC_OFFSET, UNDEFINED_OFFSET,
SYNTHETIC_OFFSET UNDEFINED_OFFSET
) )
fun generateHeaders(): List<FirDeclaration> { fun generateHeaders(): List<FirDeclaration> {
@@ -312,8 +313,8 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
val signature = if (klass.symbol.classId.isLocal) null else components.signatureComposer.composeSignature(syntheticCounterpart) val signature = if (klass.symbol.classId.isLocal) null else components.signatureComposer.composeSignature(syntheticCounterpart)
val symbol = components.declarationStorage.createFunctionSymbol(signature) val symbol = components.declarationStorage.createFunctionSymbol(signature)
return components.irFactory.createSimpleFunction( return components.irFactory.createSimpleFunction(
startOffset = SYNTHETIC_OFFSET, startOffset = UNDEFINED_OFFSET,
endOffset = SYNTHETIC_OFFSET, endOffset = UNDEFINED_OFFSET,
origin = origin, origin = origin,
name = name, name = name,
visibility = DescriptorVisibilities.PUBLIC, visibility = DescriptorVisibilities.PUBLIC,
@@ -350,8 +351,8 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
private fun createSyntheticIrParameter(irFunction: IrFunction, name: Name, type: IrType, index: Int = 0): IrValueParameter = private fun createSyntheticIrParameter(irFunction: IrFunction, name: Name, type: IrType, index: Int = 0): IrValueParameter =
components.irFactory.createValueParameter( components.irFactory.createValueParameter(
startOffset = SYNTHETIC_OFFSET, startOffset = UNDEFINED_OFFSET,
endOffset = SYNTHETIC_OFFSET, endOffset = UNDEFINED_OFFSET,
origin = IrDeclarationOrigin.DEFINED, origin = IrDeclarationOrigin.DEFINED,
name = name, name = name,
type = type, type = type,
@@ -110,16 +110,11 @@ class Fir2IrCallableDeclarationsGenerator(val components: Fir2IrComponents) : Fi
@Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472 @Suppress("USELESS_CAST") // K2 warning suppression, TODO: KT-62472
if (isLambda) ((function as FirAnonymousFunction).typeRef as? FirResolvedTypeRef)?.type?.isSuspendOrKSuspendFunctionType(session) == true if (isLambda) ((function as FirAnonymousFunction).typeRef as? FirResolvedTypeRef)?.type?.isSuspendOrKSuspendFunctionType(session) == true
else function.isSuspend else function.isSuspend
val defaultOffset = when { val created = function.convertWithOffsets { startOffset, endOffset ->
function.origin == FirDeclarationOrigin.Synthetic.DataClassMember -> SYNTHETIC_OFFSET
updatedOrigin == IrDeclarationOrigin.DELEGATED_MEMBER -> SYNTHETIC_OFFSET
else -> UNDEFINED_OFFSET
}
val created = function.convertWithOffsets(defaultOffset) { startOffset, endOffset ->
classifierStorage.preCacheTypeParameters(function, symbol) classifierStorage.preCacheTypeParameters(function, symbol)
irFactory.createSimpleFunction( irFactory.createSimpleFunction(
startOffset = startOffset, startOffset = if (updatedOrigin == IrDeclarationOrigin.DELEGATED_MEMBER) SYNTHETIC_OFFSET else startOffset,
endOffset = endOffset, endOffset = if (updatedOrigin == IrDeclarationOrigin.DELEGATED_MEMBER) SYNTHETIC_OFFSET else endOffset,
origin = updatedOrigin, origin = updatedOrigin,
name = name, name = name,
visibility = components.visibilityConverter.convertToDescriptorVisibility(visibility), visibility = components.visibilityConverter.convertToDescriptorVisibility(visibility),
+58 -1
View File
@@ -61,7 +61,7 @@ fun box() {
// test.kt:25 box // test.kt:25 box
// test.kt:26 box // test.kt:26 box
// EXPECTATIONS JS_IR // EXPECTATIONS ClassicFrontend JS_IR
// test.kt:14 box // test.kt:14 box
// test.kt:4 <init> // test.kt:4 <init>
// test.kt:4 <init> // test.kt:4 <init>
@@ -118,6 +118,63 @@ fun box() {
// test.kt:6 <init> // test.kt:6 <init>
// test.kt:26 box // test.kt:26 box
// EXPECTATIONS FIR JS_IR // TODO: There is an inconsistency in names between K1 and K2. This should be fixed in KT-64435.
// test.kt:14 box
// test.kt:4 <init>
// test.kt:4 <init>
// test.kt:4 <init>
// test.kt:15 box
// test.kt:4 <init>
// test.kt:4 <init>
// test.kt:4 <init>
// test.kt:15 box
// test.kt:1 protoOf.equals
// test.kt:1 protoOf.equals
// test.kt:1 protoOf.equals
// test.kt:1 protoOf.equals
// test.kt:1 protoOf.equals
// test.kt:1 protoOf.equals
// test.kt:16 box
// test.kt:1 protoOf.hashCode
// test.kt:1 protoOf.hashCode
// test.kt:17 box
// test.kt:1 protoOf.toString
// test.kt:18 box
// test.kt:1 protoOf.component1_7eebsc_k$
// test.kt:18 box
// test.kt:1 protoOf.component2_7eebsb_k$
// test.kt:19 box
// test.kt:1 protoOf.copy$default_8mg6yi_k$
// test.kt:1 protoOf.copy$default_8mg6yi_k$
// test.kt:1 protoOf.copy_xhhsuv_k$
// test.kt:4 <init>
// test.kt:4 <init>
// test.kt:4 <init>
// test.kt:20 box
// test.kt:6 <init>
// test.kt:6 <init>
// test.kt:6 <init>
// test.kt:21 box
// test.kt:6 <init>
// test.kt:6 <init>
// test.kt:6 <init>
// test.kt:21 box
// test.kt:8 equals
// test.kt:22 box
// test.kt:9 hashCode
// test.kt:23 box
// test.kt:7 toString
// test.kt:24 box
// test.kt:1 protoOf.component1_7eebsc_k$
// test.kt:24 box
// test.kt:1 protoOf.component2_7eebsb_k$
// test.kt:25 box
// test.kt:10 copy
// test.kt:6 <init>
// test.kt:6 <init>
// test.kt:6 <init>
// test.kt:26 box
// EXPECTATIONS WASM // EXPECTATIONS WASM
// test.kt:14 $box (12, 14, 17, 17, 17, 17, 12) // test.kt:14 $box (12, 14, 17, 17, 17, 17, 12)
// String.kt:141 $kotlin.stringLiteral (17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17) // String.kt:141 $kotlin.stringLiteral (17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17, 17, 28, 17)
-7
View File
@@ -23,13 +23,6 @@ fun box() {
// test.kt:14 <init> // test.kt:14 <init>
// test.kt:17 box // test.kt:17 box
// test.kt:18 box // test.kt:18 box
// EXPECTATIONS FIR JVM_IR
// test.kt:14 f
// test.kt:10 f
// test.kt:11 f
// test.kt:14 f
// test.kt:19 box
// EXPECTATIONS ClassicFrontend JVM_IR
// test.kt:11 f // test.kt:11 f
// test.kt:-1 f // test.kt:-1 f
// test.kt:19 box // test.kt:19 box
+1 -1
View File
@@ -4,4 +4,4 @@ data class A(
) )
// LINES(ClassicFrontend JS_IR): 1 2 3 1 2 2 3 3 2 2 2 3 3 3 1 1 1 1 1 1 1 2 3 1 1 1 1 2 3 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 // LINES(ClassicFrontend JS_IR): 1 2 3 1 2 2 3 3 2 2 2 3 3 3 1 1 1 1 1 1 1 2 3 1 1 1 1 2 3 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
// LINES(FIR JS_IR): 1 2 3 1 2 2 3 3 2 2 2 3 3 3 1 1 1 1 1 1 1 1 1 1 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 // LINES(FIR JS_IR): 1 2 3 1 2 2 3 3 2 2 2 3 3 3 1 1 1 1 1 1 1 1 1 1 1 * 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1