Skip to content

Commit 517495c

Browse files
francescoo22Space Cloud
authored and
Space Cloud
committed
[IR] Remove copyWithOffsets methods
^KT-75196 Fixed
1 parent 9668d75 commit 517495c

File tree

5 files changed

+38
-47
lines changed

5 files changed

+38
-47
lines changed

compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/UpgradeCallableReferences.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,11 @@ open class UpgradeCallableReferences(
188188
val argument = expression.argument
189189
if (argument !is IrRichFunctionReference) return expression
190190
return argument.apply {
191+
startOffset = expression.startOffset
192+
endOffset = expression.endOffset
191193
type = expression.typeOperand
192194
overriddenFunctionSymbol = selectSAMOverriddenFunction(expression.typeOperand)
193-
}.copyWithOffsets(expression.startOffset, expression.endOffset)
195+
}
194196
}
195197
return super.visitTypeOperator(expression, data)
196198
}

compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/JvmOptimizationLowering.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,20 @@ internal class JvmOptimizationLowering(val context: JvmBackendContext) : FileLow
412412
// initializer with the constant initializer.
413413
val variable = expression.symbol.owner
414414
return when (val replacement = getInlineableValueForTemporaryVal(variable)) {
415-
is IrConst ->
416-
replacement.copyWithOffsets(expression.startOffset, expression.endOffset)
417-
is IrGetValue ->
418-
replacement.copyWithOffsets(expression.startOffset, expression.endOffset)
415+
is IrConst -> IrConstImpl(
416+
expression.startOffset,
417+
expression.endOffset,
418+
replacement.type,
419+
replacement.kind,
420+
replacement.value
421+
)
422+
is IrGetValue -> IrGetValueImpl(
423+
expression.startOffset,
424+
expression.endOffset,
425+
replacement.type,
426+
replacement.symbol,
427+
replacement.origin
428+
)
419429
else ->
420430
expression
421431
}

compiler/ir/ir.inline/src/org/jetbrains/kotlin/ir/inline/FunctionInlining.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,12 @@ private class CallInlining(
241241

242242
argument.transformChildrenVoid(this) // Default argument can contain subjects for substitution.
243243

244-
val ret =
245-
if (argument is IrGetValue && argument in elementsWithLocationToPatch)
246-
argument.copyWithOffsets(newExpression.startOffset, newExpression.endOffset)
247-
else
248-
argument.deepCopyWithSymbols()
249-
250-
return ret.doImplicitCastIfNeededTo(newExpression.type)
244+
return argument.deepCopyWithSymbols().apply {
245+
if (argument is IrGetValue && argument in elementsWithLocationToPatch) {
246+
startOffset = newExpression.startOffset
247+
endOffset = newExpression.endOffset
248+
}
249+
}.doImplicitCastIfNeededTo(newExpression.type)
251250
}
252251

253252
override fun visitCall(expression: IrCall): IrExpression {
@@ -371,10 +370,11 @@ private class CallInlining(
371370
val argument = when {
372371
parameter !in unboundArgsSet -> {
373372
val arg = boundFunctionParametersMap[parameter]!!
374-
if (arg is IrGetValue && arg in elementsWithLocationToPatch) {
375-
arg.copyWithOffsets(irCall.startOffset, irCall.endOffset)
376-
} else {
377-
arg.deepCopyWithSymbols()
373+
arg.deepCopyWithSymbols().apply {
374+
if (arg is IrGetValue && arg in elementsWithLocationToPatch) {
375+
startOffset = irCall.startOffset
376+
endOffset = irCall.endOffset
377+
}
378378
}
379379
}
380380
unboundIndex == valueParameters.size && parameter.defaultValue != null -> {

compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,32 +1488,6 @@ fun IrBlockImpl.inlineStatement(statement: IrStatement) {
14881488
}
14891489
}
14901490

1491-
// TODO: KT-75196: please make `startOffset` and `endOffset` mutable, and remove this method
1492-
fun IrConst.copyWithOffsets(startOffset: Int, endOffset: Int) =
1493-
IrConstImpl(startOffset, endOffset, type, kind, value)
1494-
1495-
// TODO: KT-75196: please make `startOffset` and `endOffset` mutable, and remove this method
1496-
fun IrGetValue.copyWithOffsets(newStartOffset: Int, newEndOffset: Int): IrGetValue =
1497-
IrGetValueImpl(newStartOffset, newEndOffset, type, symbol, origin)
1498-
1499-
// TODO: KT-75196: please make `startOffset` and `endOffset` mutable, and remove this method
1500-
fun IrRichFunctionReference.copyWithOffsets(newStartOffset: Int, newEndOffset: Int): IrRichFunctionReference =
1501-
IrRichFunctionReferenceImpl(
1502-
newStartOffset, newEndOffset,
1503-
type,
1504-
reflectionTargetSymbol,
1505-
overriddenFunctionSymbol,
1506-
invokeFunction,
1507-
origin,
1508-
hasUnitConversion,
1509-
hasSuspendConversion,
1510-
hasVarargConversion,
1511-
isRestrictedSuspension
1512-
).apply {
1513-
copyAttributes(this@copyWithOffsets)
1514-
boundValues.addAll(this@copyWithOffsets.boundValues)
1515-
}
1516-
15171491
fun IrModuleFragment.addFile(file: IrFile) {
15181492
files.add(file)
15191493
file.module = this

plugins/compose/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/LiveLiteralTransformer.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,25 +370,30 @@ open class LiveLiteralTransformer(
370370
// If live literals are enabled, don't do anything
371371
if (!liveLiteralsEnabled) return expression
372372

373+
val originalStartOffset = expression.startOffset
374+
val originalEndOffset = expression.endOffset
373375
// create the getter function on the live literals class
374376
val getter = irLiveLiteralGetter(
375377
key = key,
376378
// Move the start/endOffsets to the call of the getter since we don't
377379
// want to step into <clinit> in the debugger.
378-
literalValue = expression.copyWithOffsets(UNDEFINED_OFFSET, UNDEFINED_OFFSET),
380+
literalValue = expression.apply {
381+
startOffset = UNDEFINED_OFFSET
382+
endOffset = UNDEFINED_OFFSET
383+
},
379384
literalType = expression.type,
380-
startOffset = expression.startOffset
385+
startOffset = originalStartOffset
381386
)
382387

383388
// return a call to the getter in place of the constant
384389
return IrCallImpl(
385-
expression.startOffset,
386-
expression.endOffset,
390+
originalStartOffset,
391+
originalEndOffset,
387392
expression.type,
388393
getter.symbol,
389394
getter.symbol.owner.typeParameters.size
390395
).apply {
391-
dispatchReceiver = irGetLiveLiteralsClass(expression.startOffset, expression.endOffset)
396+
dispatchReceiver = irGetLiveLiteralsClass(originalStartOffset, originalEndOffset)
392397
}
393398
}
394399

0 commit comments

Comments
 (0)