Skip to content

Commit 4eed2fd

Browse files
francescoo22Space Team
authored andcommitted
[IR] Move defaultConstructorMarker to backend.common.ir.Symbols
^KT-80226
1 parent f3b4c82 commit 4eed2fd

File tree

9 files changed

+21
-36
lines changed

9 files changed

+21
-36
lines changed

compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/PreSerializationSymbols.kt

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.ir.types.impl.IrDynamicTypeImpl
2727
import org.jetbrains.kotlin.ir.util.*
2828
import org.jetbrains.kotlin.name.*
2929
import org.jetbrains.kotlin.types.Variance
30-
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly
3130

3231
abstract class BaseSymbolsImpl(protected val irBuiltIns: IrBuiltIns) {
3332
protected val symbolFinder = irBuiltIns.symbolFinder
@@ -108,7 +107,6 @@ interface PreSerializationSymbols {
108107
val throwUninitializedPropertyAccessException: IrSimpleFunctionSymbol
109108
val throwUnsupportedOperationException: IrSimpleFunctionSymbol
110109

111-
val defaultConstructorMarker: IrClassSymbol
112110
val syntheticConstructorMarker: IrClassSymbol
113111
val coroutineContextGetter: IrSimpleFunctionSymbol
114112
val suspendCoroutineUninterceptedOrReturn: IrSimpleFunctionSymbol
@@ -160,7 +158,6 @@ interface PreSerializationKlibSymbols : PreSerializationSymbols {
160158
const val THROW_UNSUPPORTED_OPERATION_NAME = "throwUnsupportedOperationException"
161159
const val GET_COROUTINE_CONTEXT_NAME = "getCoroutineContext"
162160
const val COROUTINE_CONTEXT_NAME = "coroutineContext"
163-
const val DEFAULT_CONSTRUCTOR_MARKET_NAME = "DefaultConstructorMarker"
164161

165162
private val kotlinInternalPackageFqn = FqName.fromSegments(listOf("kotlin", "internal"))
166163
private val String.internalCallableId: CallableId
@@ -189,8 +186,6 @@ interface PreSerializationJsSymbols : PreSerializationWebSymbols {
189186
val jsOutlinedFunctionAnnotationSymbol: IrClassSymbol
190187

191188
open class Impl(irBuiltIns: IrBuiltIns) : PreSerializationJsSymbols, PreSerializationWebSymbols.Impl(irBuiltIns) {
192-
override val defaultConstructorMarker: IrClassSymbol = ClassIds.defaultConstructorMarker.classSymbol()
193-
194189
override val suspendCoroutineUninterceptedOrReturn: IrSimpleFunctionSymbol =
195190
CallableIds.suspendCoroutineUninterceptedOrReturn.functionSymbol()
196191
override val coroutineGetContext: IrSimpleFunctionSymbol = CallableIds.coroutineGetContext.functionSymbol()
@@ -212,7 +207,6 @@ interface PreSerializationJsSymbols : PreSerializationWebSymbols {
212207
private object ClassIds {
213208
private val String.baseJsClassId: ClassId
214209
get() = ClassId(StandardClassIds.BASE_JS_PACKAGE, Name.identifier(this))
215-
val defaultConstructorMarker: ClassId = PreSerializationKlibSymbols.DEFAULT_CONSTRUCTOR_MARKET_NAME.baseJsClassId
216210
val JsOutlinedFunction: ClassId = "JsOutlinedFunction".baseJsClassId
217211
}
218212
}
@@ -221,8 +215,6 @@ interface PreSerializationJsSymbols : PreSerializationWebSymbols {
221215

222216
interface PreSerializationWasmSymbols : PreSerializationWebSymbols {
223217
open class Impl(irBuiltIns: IrBuiltIns) : PreSerializationWasmSymbols, PreSerializationWebSymbols.Impl(irBuiltIns) {
224-
override val defaultConstructorMarker: IrClassSymbol = ClassIds.defaultConstructorMarker.classSymbol()
225-
226218
override val suspendCoroutineUninterceptedOrReturn: IrSimpleFunctionSymbol =
227219
CallableIds.suspendCoroutineUninterceptedOrReturn.functionSymbol()
228220
override val coroutineGetContext: IrSimpleFunctionSymbol = CallableIds.coroutineGetContext.functionSymbol()
@@ -238,12 +230,6 @@ interface PreSerializationWasmSymbols : PreSerializationWebSymbols {
238230
val suspendCoroutineUninterceptedOrReturn: CallableId = COROUTINE_SUSPEND_OR_RETURN_NAME.internalCallableId
239231
val coroutineGetContext: CallableId = PreSerializationKlibSymbols.GET_COROUTINE_CONTEXT_NAME.internalCallableId
240232
}
241-
242-
private object ClassIds {
243-
private val String.internalClassId: ClassId
244-
get() = ClassId(wasmInternalFqName, Name.identifier(this))
245-
val defaultConstructorMarker: ClassId = PreSerializationKlibSymbols.DEFAULT_CONSTRUCTOR_MARKET_NAME.internalClassId
246-
}
247233
}
248234
}
249235
}
@@ -255,7 +241,6 @@ interface PreSerializationNativeSymbols : PreSerializationKlibSymbols {
255241
open class Impl(irBuiltIns: IrBuiltIns) : PreSerializationNativeSymbols, PreSerializationKlibSymbols.Impl(irBuiltIns) {
256242
override val asserts: Iterable<IrSimpleFunctionSymbol> = CallableIds.asserts.functionSymbols()
257243

258-
override val defaultConstructorMarker: IrClassSymbol = ClassIds.defaultConstructorMarker.classSymbol()
259244
override val isAssertionArgumentEvaluationEnabled: IrSimpleFunctionSymbol =
260245
CallableIds.isAssertionArgumentEvaluationEnabled.functionSymbol()
261246

@@ -285,14 +270,6 @@ interface PreSerializationNativeSymbols : PreSerializationKlibSymbols {
285270
val asserts: CallableId = "assert".builtInsCallableId
286271
val isAssertionArgumentEvaluationEnabled: CallableId = "isAssertionArgumentEvaluationEnabled".builtInsCallableId
287272
}
288-
289-
private object ClassIds {
290-
// Internal classes
291-
private val String.internalClassId: ClassId
292-
get() = ClassId(kotlinNativeInternalPackageName, Name.identifier(this))
293-
val defaultConstructorMarker: ClassId =
294-
PreSerializationKlibSymbols.DEFAULT_CONSTRUCTOR_MARKET_NAME.internalClassId
295-
}
296273
}
297274
}
298275
}

compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/ir/Symbols.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ abstract class Symbols(irBuiltIns: IrBuiltIns) : PreSerializationSymbols.Impl(ir
202202

203203
abstract val functionAdapter: IrClassSymbol
204204

205+
abstract val defaultConstructorMarker: IrClassSymbol
206+
205207
open val unsafeCoerceIntrinsic: IrSimpleFunctionSymbol?
206208
get() = null
207209

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
1414
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
1515
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
1616
import org.jetbrains.kotlin.ir.declarations.*
17+
import org.jetbrains.kotlin.ir.expressions.IrConst
1718
import org.jetbrains.kotlin.ir.expressions.IrGetValue
19+
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
1820
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
1921
import org.jetbrains.kotlin.ir.irAttribute
2022
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
@@ -94,6 +96,9 @@ class KlibSyntheticAccessorGenerator(
9496
contributeTopLevelDeclarationSuffix(field)
9597
}
9698

99+
override fun createAccessorMarkerArgument(): IrConst =
100+
IrConstImpl.constNull(UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.symbols.syntheticConstructorMarker.defaultType.makeNullable())
101+
97102
private fun AccessorNameBuilder.contributeTopLevelDeclarationSuffix(declaration: IrDeclaration) {
98103
val parent = declaration.parent
99104
if (parent !is IrPackageFragment) return

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ abstract class SyntheticAccessorGenerator<Context : LoweringContext, ScopeInfo>(
436436
}
437437
newExpression.copyTypeArgumentsFrom(oldExpression)
438438
val newExpressionArguments = if (accessorSymbol is IrConstructorSymbol) {
439-
oldExpression.arguments + createAccessorMarkerArgument(accessorSymbol.owner.parameters.last().origin)
439+
oldExpression.arguments + createAccessorMarkerArgument()
440440
} else {
441441
oldExpression.arguments
442442
}
@@ -475,14 +475,7 @@ abstract class SyntheticAccessorGenerator<Context : LoweringContext, ScopeInfo>(
475475
)
476476
}
477477

478-
fun createAccessorMarkerArgument(origin: IrDeclarationOrigin = IrDeclarationOrigin.DEFAULT_CONSTRUCTOR_MARKER): IrConst {
479-
val symbol = when (origin) {
480-
IrDeclarationOrigin.DEFAULT_CONSTRUCTOR_MARKER -> context.symbols.defaultConstructorMarker
481-
IrDeclarationOrigin.SYNTHETIC_CONSTRUCTOR_MARKER -> context.symbols.syntheticConstructorMarker
482-
else -> error("Unexpected origin '$origin' when creating accessor marker argument.")
483-
}
484-
return IrConstImpl.constNull(UNDEFINED_OFFSET, UNDEFINED_OFFSET, symbol.defaultType.makeNullable())
485-
}
478+
abstract fun createAccessorMarkerArgument(): IrConst
486479

487480
/**
488481
* Produces a call to the synthetic accessor [accessorSymbol] to replace the field _read_ expression [oldExpression].

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsSymbols.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class JsSymbols(
8080

8181
override val functionAdapter = symbolFinder.topLevelClass(BASE_JS_PACKAGE, "FunctionAdapter")
8282

83+
override val defaultConstructorMarker = symbolFinder.topLevelClass(BASE_JS_PACKAGE, "DefaultConstructorMarker")
84+
8385
override fun functionN(n: Int): IrClassSymbol {
8486
return stageController.withInitialIr { super.functionN(n) }
8587
}

compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmSyntheticAccessorGenerator.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
1717
import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
1818
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
1919
import org.jetbrains.kotlin.ir.declarations.*
20+
import org.jetbrains.kotlin.ir.expressions.IrConst
21+
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
2022
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
2123
import org.jetbrains.kotlin.ir.types.defaultType
2224
import org.jetbrains.kotlin.ir.types.makeNullable
@@ -138,6 +140,9 @@ class JvmSyntheticAccessorGenerator(context: JvmBackendContext) :
138140
contributeFieldAccessorSuffix(field, superQualifierSymbol)
139141
}
140142

143+
override fun createAccessorMarkerArgument(): IrConst =
144+
IrConstImpl.constNull(UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.symbols.defaultConstructorMarker.defaultType.makeNullable())
145+
141146
/**
142147
* For both _reading_ and _writing_ field accessors, the suffix that includes some of [field]'s important properties.
143148
*/

compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ir/Ir.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ private object ClassIds {
6969
val kTypeProjectionList = "KTypeProjectionList".internalClassId
7070
val nativePtr = "NativePtr".internalClassId
7171
val functionAdapter = "FunctionAdapter".internalClassId
72+
val defaultConstructorMarker = "DefaultConstructorMarker".internalClassId
7273

7374
// Interop classes
7475
private val String.interopClassId get() = ClassId(InteropFqNames.packageName, Name.identifier(this))
@@ -620,6 +621,8 @@ class KonanSymbols(
620621

621622
override val functionAdapter = ClassIds.functionAdapter.classSymbol()
622623

624+
override val defaultConstructorMarker = ClassIds.defaultConstructorMarker.classSymbol()
625+
623626
val kFunctionImpl = ClassIds.kFunctionImpl.classSymbol()
624627
val kFunctionDescription = ClassIds.kFunctionDescription.classSymbol()
625628
val kFunctionDescriptionCorrect = ClassIds.kFunctionDescriptionCorrect.classSymbol()

compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class WasmSymbols(
131131

132132
override val functionAdapter = getInternalWasmClass("FunctionAdapter")
133133

134+
override val defaultConstructorMarker: IrClassSymbol = getInternalWasmClass("DefaultConstructorMarker")
135+
134136
val wasmUnreachable = getInternalWasmFunction("wasm_unreachable")
135137

136138
val voidClass = getIrClass(FqName("kotlin.wasm.internal.Void"))

compiler/tests-common-new/testFixtures/org/jetbrains/kotlin/test/backend/ir/IrPreSerializationSymbolValidationHandler.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ import kotlin.reflect.KVisibility
2828
abstract class IrPreSerializationSymbolValidationHandler(testServices: TestServices) : AbstractIrHandler(testServices) {
2929
companion object {
3030
private val preSerializationAnnotation = FqName.fromSegments(listOf("kotlin", "internal", "UsedFromCompilerGeneratedCode"))
31-
// TODO drop after KT-80226 is fixed. We should use a new marker here.
32-
// Also `DefaultConstructorMarker` should be moved to the backend symbols.
33-
private val excludeList = listOf("DefaultConstructorMarker")
3431
}
3532

3633
abstract fun getSymbols(irBuiltIns: IrBuiltIns): PreSerializationSymbols
@@ -71,7 +68,6 @@ abstract class IrPreSerializationSymbolValidationHandler(testServices: TestServi
7168
}
7269

7370
private fun validateVisibility(declaration: IrDeclarationWithVisibility, symbolsClass: KClass<out PreSerializationSymbols>) {
74-
if (declaration is IrDeclarationWithName && declaration.name.asString() in excludeList) return
7571
if (declaration.visibility == DescriptorVisibilities.INTERNAL) {
7672
require(declaration.isPublishedApi()) {
7773
"Internal API loaded from ${symbolsClass.qualifiedName} must have '@PublishedApi' annotation: ${declaration.render()}"

0 commit comments

Comments
 (0)