@@ -15,8 +15,6 @@ import org.jetbrains.kotlin.descriptors.Modality
15
15
import org.jetbrains.kotlin.ir.IrBuiltIns
16
16
import org.jetbrains.kotlin.ir.IrElement
17
17
import org.jetbrains.kotlin.ir.IrStatement
18
- import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
19
- import org.jetbrains.kotlin.ir.builders.declarations.buildFun
20
18
import org.jetbrains.kotlin.ir.declarations.*
21
19
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyDeclarationBase
22
20
import org.jetbrains.kotlin.ir.expressions.*
@@ -35,7 +33,6 @@ import org.jetbrains.kotlin.ir.visitors.IrVisitorVoid
35
33
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
36
34
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
37
35
import org.jetbrains.kotlin.name.FqName
38
- import org.jetbrains.kotlin.name.Name
39
36
import org.jetbrains.kotlin.utils.addIfNotNull
40
37
import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
41
38
import org.jetbrains.kotlin.utils.compact
@@ -520,91 +517,6 @@ internal class PartiallyLinkedIrTreePatcher(
520
517
checkReferencedDeclaration(symbol)
521
518
}
522
519
523
- /* *
524
- * Workaround for CMP-7571. Provides backward compatibility for compose libraries built with k1.
525
- * k1-built libraries may contain cross-module `GetField(...$stable: Int)`,
526
- * but given field became private (when compiled with k2 compose compiler plugin) and also may be uninitialized.
527
- * Such field accesses are transformed to `IrCall(...$stableprop_getter(): Int)` functions (generated by k2 compose compiler plugin)
528
- * TODO drop that workaround in kotlin v2.3: KT-75648
529
- */
530
- override fun visitGetField (expression : IrGetField ): IrExpression {
531
- val COMPOSE_STABLE_FIELD_MARKER = $$" $stable "
532
- val COMPOSE_STABILITY_GETTER_MARKER = $$" $stableprop_getter "
533
-
534
- fun IrGetField.isComposeStableFieldAccess (): Boolean {
535
- // If the field is public, it means it's in a K1-built klib, so we can proceed as before.
536
- // We have a problem only with IrGetField for private fields,
537
- // which are generated by K2 compose compiler plugin.
538
- if (! symbol.isBound || symbol.owner.visibility == DescriptorVisibilities .PUBLIC ) return false
539
- return symbol.owner.name.asString().endsWith(COMPOSE_STABLE_FIELD_MARKER )
540
- }
541
-
542
- fun IrFieldSymbol.generateArtificialStabilityGetter (getterName : String , parent : IrDeclarationContainer , parentField : IrField ): IrSimpleFunction {
543
-
544
- val stabilityField = owner
545
-
546
- // We use stageController to make sure valid unique signatures are generated for k/js and k/wasm
547
- val stabilityGetter = builtIns.irFactory.stageController.restrictTo(parentField) {
548
- builtIns.irFactory.buildFun {
549
- startOffset = UNDEFINED_OFFSET
550
- endOffset = UNDEFINED_OFFSET
551
- name = Name .identifier(getterName)
552
- returnType = stabilityField.type
553
- visibility = DescriptorVisibilities .PUBLIC
554
- origin = PartiallyLinkedDeclarationOrigin .AUXILIARY_GENERATED_DECLARATION
555
- }.also { fn ->
556
- fn.parent = parent
557
- fn.body = builtIns.irFactory.createBlockBody(
558
- UNDEFINED_OFFSET , UNDEFINED_OFFSET ,
559
- listOf (
560
- IrReturnImpl (
561
- UNDEFINED_OFFSET , UNDEFINED_OFFSET ,
562
- builtIns.nothingType,
563
- fn.symbol,
564
- IrGetFieldImpl (UNDEFINED_OFFSET , UNDEFINED_OFFSET , this , stabilityField.type),
565
- ),
566
- ),
567
- )
568
- parent.addChild(fn)
569
- }
570
- }
571
-
572
- return stabilityGetter
573
- }
574
-
575
- fun IrFieldSymbol.findSuitableStabilityGetter (): IrSimpleFunction ? {
576
- val getterFunName = owner.name.asString().removeSuffix(COMPOSE_STABLE_FIELD_MARKER ) + COMPOSE_STABILITY_GETTER_MARKER
577
- val artificialGetterFunName = $$" $$getterFunName$artificial "
578
- return (owner.parent as ? IrDeclarationContainer )?.let { parent ->
579
- parent.findDeclaration<IrSimpleFunction > {
580
- it.name.asString() == getterFunName ||
581
- // try to find already-crafted artificial getter
582
- it.name.asString() == artificialGetterFunName
583
- } ? : generateArtificialStabilityGetter(artificialGetterFunName, parent, owner) // generate one if none found
584
- }
585
-
586
- }
587
-
588
- fun IrGetField.isCrossModuleGetField (): Boolean {
589
- val containingModule = PLModule .determineModuleFor(symbol.owner)
590
- return (containingModule != currentFile.module)
591
- }
592
-
593
- if (expression.isComposeStableFieldAccess() && expression.isCrossModuleGetField()) {
594
- expression.symbol.findSuitableStabilityGetter()?.let {
595
- return super .visitCall(
596
- IrCallImpl .fromSymbolOwner(
597
- expression.startOffset,
598
- expression.endOffset,
599
- expression.type,
600
- it.symbol
601
- )
602
- )
603
- }
604
- }
605
- return super .visitGetField(expression)
606
- }
607
-
608
520
override fun visitClassReference (expression : IrClassReference ) = expression.maybeThrowLinkageError {
609
521
checkReferencedDeclaration(symbol) ? : checkExpressionType(classType)
610
522
}
0 commit comments