Skip to content

Commit 8781366

Browse files
committed
Only extract function annotations for unbound types
Note however this includes extracting annotations for external types, unlike the situation for function bodies.
1 parent 06133e7 commit 8781366

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

java/kotlin-extractor/src/main/kotlin/ExternalDeclExtractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ExternalDeclExtractor(val logger: FileLogger, val invocationTrapFile: Stri
119119

120120
fileExtractor.extractClassSource(irDecl, extractDeclarations = !irDecl.isFileClass, extractStaticInitializer = false, extractPrivateMembers = false, extractFunctionBodies = false)
121121
} else {
122-
fileExtractor.extractDeclaration(irDecl, extractPrivateMembers = false, extractFunctionBodies = false)
122+
fileExtractor.extractDeclaration(irDecl, extractPrivateMembers = false, extractFunctionBodies = false, extractAnnotations = true)
123123
}
124124
}
125125
}

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ open class KotlinFileExtractor(
9191
}
9292

9393
file.declarations.forEach {
94-
extractDeclaration(it, extractPrivateMembers = true, extractFunctionBodies = true)
94+
extractDeclaration(it, extractPrivateMembers = true, extractFunctionBodies = true, extractAnnotations = true)
9595
if (it is IrProperty || it is IrField || it is IrFunction) {
9696
externalClassExtractor.writeStubTrapFile(it, getTrapFileSignature(it))
9797
}
@@ -148,7 +148,7 @@ open class KotlinFileExtractor(
148148
private fun shouldExtractDecl(declaration: IrDeclaration, extractPrivateMembers: Boolean) =
149149
extractPrivateMembers || !isPrivate(declaration)
150150

151-
fun extractDeclaration(declaration: IrDeclaration, extractPrivateMembers: Boolean, extractFunctionBodies: Boolean) {
151+
fun extractDeclaration(declaration: IrDeclaration, extractPrivateMembers: Boolean, extractFunctionBodies: Boolean, extractAnnotations: Boolean) {
152152
with("declaration", declaration) {
153153
if (!shouldExtractDecl(declaration, extractPrivateMembers))
154154
return
@@ -163,7 +163,7 @@ open class KotlinFileExtractor(
163163
is IrFunction -> {
164164
val parentId = useDeclarationParent(declaration.parent, false)?.cast<DbReftype>()
165165
if (parentId != null) {
166-
extractFunction(declaration, parentId, extractBody = extractFunctionBodies, extractMethodAndParameterTypeAccesses = extractFunctionBodies, null, listOf())
166+
extractFunction(declaration, parentId, extractBody = extractFunctionBodies, extractMethodAndParameterTypeAccesses = extractFunctionBodies, extractAnnotations = extractAnnotations, null, listOf())
167167
}
168168
Unit
169169
}
@@ -173,7 +173,7 @@ open class KotlinFileExtractor(
173173
is IrProperty -> {
174174
val parentId = useDeclarationParent(declaration.parent, false)?.cast<DbReftype>()
175175
if (parentId != null) {
176-
extractProperty(declaration, parentId, extractBackingField = true, extractFunctionBodies = extractFunctionBodies, extractPrivateMembers = extractPrivateMembers, null, listOf())
176+
extractProperty(declaration, parentId, extractBackingField = true, extractFunctionBodies = extractFunctionBodies, extractPrivateMembers = extractPrivateMembers, extractAnnotations = extractAnnotations, null, listOf())
177177
}
178178
Unit
179179
}
@@ -406,8 +406,8 @@ open class KotlinFileExtractor(
406406
}
407407
}
408408
when (d) {
409-
is IrFunction -> extractFunction(d, parentId, extractBody = false, extractMethodAndParameterTypeAccesses = false, typeParamSubstitution, argsIncludingOuterClasses)
410-
is IrProperty -> extractProperty(d, parentId, extractBackingField = false, extractFunctionBodies = false, extractPrivateMembers = false, typeParamSubstitution, argsIncludingOuterClasses)
409+
is IrFunction -> extractFunction(d, parentId, extractBody = false, extractMethodAndParameterTypeAccesses = false, extractAnnotations = false, typeParamSubstitution, argsIncludingOuterClasses)
410+
is IrProperty -> extractProperty(d, parentId, extractBackingField = false, extractFunctionBodies = false, extractPrivateMembers = false, extractAnnotations = false, typeParamSubstitution, argsIncludingOuterClasses)
411411
else -> {}
412412
}
413413
}
@@ -604,11 +604,11 @@ open class KotlinFileExtractor(
604604
.filterIsInstance<IrProperty>()
605605
.map {
606606
val getter = it.getter!!
607-
val label = extractFunction(getter, id, extractBody = false, extractMethodAndParameterTypeAccesses = false, null, listOf())
607+
val label = extractFunction(getter, id, extractBody = false, extractMethodAndParameterTypeAccesses = false, extractAnnotations = true, null, listOf())
608608
tw.writeIsAnnotElem(label!!.cast<DbMethod>())
609609
}
610610
} else {
611-
c.declarations.forEach { extractDeclaration(it, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies) }
611+
c.declarations.forEach { extractDeclaration(it, extractPrivateMembers = extractPrivateMembers, extractFunctionBodies = extractFunctionBodies, extractAnnotations = true) }
612612
if (extractStaticInitializer)
613613
extractStaticInitializer(c, { id })
614614
extractJvmStaticProxyMethods(c, id, extractPrivateMembers, extractFunctionBodies)
@@ -665,7 +665,7 @@ open class KotlinFileExtractor(
665665
val proxyFunctionId = tw.getLabelFor<DbMethod>(getFunctionLabel(f, classId, listOf()))
666666
// We extract the function prototype with its ID overridden to belong to `c` not the companion object,
667667
// but suppress outputting the body, which we will replace with a delegating call below.
668-
forceExtractFunction(f, classId, extractBody = false, extractMethodAndParameterTypeAccesses = extractFunctionBodies, typeSubstitution = null, classTypeArgsIncludingOuterClasses = listOf(), extractOrigin = false, OverriddenFunctionAttributes(id = proxyFunctionId))
668+
forceExtractFunction(f, classId, extractBody = false, extractMethodAndParameterTypeAccesses = extractFunctionBodies, extractAnnotations = false, typeSubstitution = null, classTypeArgsIncludingOuterClasses = listOf(), extractOrigin = false, OverriddenFunctionAttributes(id = proxyFunctionId))
669669
addModifiers(proxyFunctionId, "static")
670670
tw.writeCompiler_generated(proxyFunctionId, CompilerGeneratedKinds.JVMSTATIC_PROXY_METHOD.kind)
671671
if (extractFunctionBodies) {
@@ -1010,7 +1010,7 @@ open class KotlinFileExtractor(
10101010
f.realOverrideTarget.let { it != f && (it as? IrSimpleFunction)?.modality != Modality.ABSTRACT && isKotlinDefinedInterface(it.parentClassOrNull) }
10111011

10121012
private fun makeInterfaceForwarder(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, extractMethodAndParameterTypeAccesses: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
1013-
forceExtractFunction(f, parentId, extractBody = false, extractMethodAndParameterTypeAccesses, typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = OverriddenFunctionAttributes(visibility = DescriptorVisibilities.PUBLIC, modality = Modality.OPEN)).also { functionId ->
1013+
forceExtractFunction(f, parentId, extractBody = false, extractMethodAndParameterTypeAccesses, extractAnnotations = false, typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = OverriddenFunctionAttributes(visibility = DescriptorVisibilities.PUBLIC, modality = Modality.OPEN)).also { functionId ->
10141014
tw.writeCompiler_generated(functionId, CompilerGeneratedKinds.INTERFACE_FORWARDER.kind)
10151015
if (extractBody) {
10161016
val realFunctionLocId = tw.getLocation(f)
@@ -1051,7 +1051,7 @@ open class KotlinFileExtractor(
10511051
}
10521052
}
10531053

1054-
private fun extractFunction(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, extractMethodAndParameterTypeAccesses: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
1054+
private fun extractFunction(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, extractMethodAndParameterTypeAccesses: Boolean, extractAnnotations: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) =
10551055
if (isFake(f)) {
10561056
if (needsInterfaceForwarder(f))
10571057
makeInterfaceForwarder(f, parentId, extractBody, extractMethodAndParameterTypeAccesses, typeSubstitution, classTypeArgsIncludingOuterClasses)
@@ -1060,7 +1060,7 @@ open class KotlinFileExtractor(
10601060
} else {
10611061
// Work around an apparent bug causing redeclarations of `fun toString(): String` specifically in interfaces loaded from Java classes show up like fake overrides.
10621062
val overriddenVisibility = if (f.isFakeOverride && isJavaBinaryObjectMethodRedeclaration(f)) OverriddenFunctionAttributes(visibility = DescriptorVisibilities.PUBLIC) else null
1063-
forceExtractFunction(f, parentId, extractBody, extractMethodAndParameterTypeAccesses, typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = overriddenVisibility).also {
1063+
forceExtractFunction(f, parentId, extractBody, extractMethodAndParameterTypeAccesses, extractAnnotations, typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = overriddenVisibility).also {
10641064
// The defaults-forwarder function is a static utility, not a member, so we only need to extract this for the unspecialised instance of this class.
10651065
if (classTypeArgsIncludingOuterClasses.isNullOrEmpty())
10661066
extractDefaultsFunction(f, parentId, extractBody, extractMethodAndParameterTypeAccesses)
@@ -1196,7 +1196,7 @@ open class KotlinFileExtractor(
11961196
parentId
11971197
val sourceDeclId = tw.getLabelFor<DbCallable>(getFunctionLabel(f, sourceParentId, listOf(), overloadParameters))
11981198
val overriddenAttributes = OverriddenFunctionAttributes(id = overloadId, sourceDeclarationId = sourceDeclId, valueParameters = overloadParameters)
1199-
forceExtractFunction(f, parentId, extractBody = false, extractMethodAndParameterTypeAccesses, typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = overriddenAttributes)
1199+
forceExtractFunction(f, parentId, extractBody = false, extractMethodAndParameterTypeAccesses, extractAnnotations = false, typeSubstitution, classTypeArgsIncludingOuterClasses, overriddenAttributes = overriddenAttributes)
12001200
tw.writeCompiler_generated(overloadId, CompilerGeneratedKinds.JVMOVERLOADS_METHOD.kind)
12011201
val realFunctionLocId = tw.getLocation(f)
12021202
if (extractBody) {
@@ -1282,7 +1282,7 @@ open class KotlinFileExtractor(
12821282
logger.warn("Needed a signature for a type that doesn't have one")
12831283
}
12841284

1285-
private fun forceExtractFunction(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, extractMethodAndParameterTypeAccesses: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, extractOrigin: Boolean = true, overriddenAttributes: OverriddenFunctionAttributes? = null): Label<out DbCallable> {
1285+
private fun forceExtractFunction(f: IrFunction, parentId: Label<out DbReftype>, extractBody: Boolean, extractMethodAndParameterTypeAccesses: Boolean, extractAnnotations: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?, extractOrigin: Boolean = true, overriddenAttributes: OverriddenFunctionAttributes? = null): Label<out DbCallable> {
12861286
with("function", f) {
12871287
DeclarationStackAdjuster(f, overriddenAttributes).use {
12881288

@@ -1424,7 +1424,7 @@ open class KotlinFileExtractor(
14241424
return id
14251425
}
14261426

1427-
private fun extractProperty(p: IrProperty, parentId: Label<out DbReftype>, extractBackingField: Boolean, extractFunctionBodies: Boolean, extractPrivateMembers: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) {
1427+
private fun extractProperty(p: IrProperty, parentId: Label<out DbReftype>, extractBackingField: Boolean, extractFunctionBodies: Boolean, extractPrivateMembers: Boolean, extractAnnotations: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?) {
14281428
with("property", p) {
14291429
fun needsInterfaceForwarderQ(f: IrFunction?) = f?.let { needsInterfaceForwarder(f) } ?: false
14301430

@@ -1446,7 +1446,7 @@ open class KotlinFileExtractor(
14461446
logger.warnElement("IrProperty without a getter", p)
14471447
}
14481448
} else if (shouldExtractDecl(getter, extractPrivateMembers)) {
1449-
val getterId = extractFunction(getter, parentId, extractBody = extractFunctionBodies, extractMethodAndParameterTypeAccesses = extractFunctionBodies, typeSubstitution, classTypeArgsIncludingOuterClasses)?.cast<DbMethod>()
1449+
val getterId = extractFunction(getter, parentId, extractBody = extractFunctionBodies, extractMethodAndParameterTypeAccesses = extractFunctionBodies, extractAnnotations = extractAnnotations, typeSubstitution, classTypeArgsIncludingOuterClasses)?.cast<DbMethod>()
14501450
if (getterId != null) {
14511451
tw.writeKtPropertyGetters(id, getterId)
14521452
if (getter.origin == IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR) {
@@ -1463,7 +1463,7 @@ open class KotlinFileExtractor(
14631463
if (!p.isVar) {
14641464
logger.warnElement("!isVar property with a setter", p)
14651465
}
1466-
val setterId = extractFunction(setter, parentId, extractBody = extractFunctionBodies, extractMethodAndParameterTypeAccesses = extractFunctionBodies, typeSubstitution, classTypeArgsIncludingOuterClasses)?.cast<DbMethod>()
1466+
val setterId = extractFunction(setter, parentId, extractBody = extractFunctionBodies, extractMethodAndParameterTypeAccesses = extractFunctionBodies, extractAnnotations = extractAnnotations, typeSubstitution, classTypeArgsIncludingOuterClasses)?.cast<DbMethod>()
14671467
if (setterId != null) {
14681468
tw.writeKtPropertySetters(id, setterId)
14691469
if (setter.origin == IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR) {
@@ -1528,7 +1528,7 @@ open class KotlinFileExtractor(
15281528
}
15291529

15301530
ee.correspondingClass?.let {
1531-
extractDeclaration(it, extractPrivateMembers, extractFunctionBodies)
1531+
extractDeclaration(it, extractPrivateMembers, extractFunctionBodies, extractAnnotations = true)
15321532
}
15331533

15341534
extractAnnotations(ee, id)
@@ -5503,7 +5503,7 @@ open class KotlinFileExtractor(
55035503
// we would need to compose generic type substitutions -- for example, if we're implementing
55045504
// T UnaryOperator<T>.apply(T t) here, we would need to compose substitutions so we can implement
55055505
// the real underlying R Function<T, R>.apply(T t).
5506-
forceExtractFunction(samMember, classId, extractBody = false, extractMethodAndParameterTypeAccesses = true, typeSub, classTypeArgs, overriddenAttributes = OverriddenFunctionAttributes(id = ids.function, sourceLoc = tw.getLocation(e), modality = Modality.FINAL))
5506+
forceExtractFunction(samMember, classId, extractBody = false, extractMethodAndParameterTypeAccesses = true, extractAnnotations = false, typeSub, classTypeArgs, overriddenAttributes = OverriddenFunctionAttributes(id = ids.function, sourceLoc = tw.getLocation(e), modality = Modality.FINAL))
55075507

55085508
addModifiers(ids.function, "override")
55095509
if (st.isSuspendFunctionOrKFunction()) {
@@ -5685,7 +5685,7 @@ open class KotlinFileExtractor(
56855685
val id = extractGeneratedClass(ids, superTypes, tw.getLocation(localFunction), localFunction, localFunction.parent, compilerGeneratedKindOverride = compilerGeneratedKindOverride)
56865686

56875687
// Extract local function as a member
5688-
extractFunction(localFunction, id, extractBody = true, extractMethodAndParameterTypeAccesses = true, null, listOf())
5688+
extractFunction(localFunction, id, extractBody = true, extractMethodAndParameterTypeAccesses = true, extractAnnotations = false, null, listOf())
56895689

56905690
return id
56915691
}

0 commit comments

Comments
 (0)