New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kotlin: extract annotations #11258
base: main
Are you sure you want to change the base?
Kotlin: extract annotations #11258
Conversation
| logger.warnElement("Expected container class to have a primary constructor", containerClass) | ||
| return null | ||
| } else { | ||
| return IrConstructorCallImpl.fromSymbolOwner(containerClass.defaultType, containerConstructor.symbol).apply { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generating IR makes me nervous. I wonder whether it might be simpler to directly extract the list of annotations, rather than making an IR representation and extracting that?
| @@ -4101,6 +4451,163 @@ open class KotlinFileExtractor( | |||
| extractExpressionExpr(loop.condition, callable, id, 0, id) | |||
| } | |||
|
|
|||
| @Suppress("UNCHECKED_CAST") | |||
| private fun <T : DbExpr> exprIdOrFresh(id: Label<out DbExpr>?) = id as? Label<T> ?: tw.getFreshIdLabel() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can avoid the warning suppression here by using something like id?.cast() ?: tw.getFreshIdLabel()
| tw.writeExprs_stringliteral(id, type.javaResult.id, parent, idx) | ||
| tw.writeExprsKotlinType(id, type.kotlinResult.id) | ||
| extractExprContext(id, locId, enclosingCallable, enclosingStmt) | ||
| tw.writeNamestrings(toQuotedLiteral(v.toString()), v.toString(), id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change results in a lot of changes to expected files. Would it make sense to do this in a separate PR to make the diff cleaner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll do that
| @@ -450,7 +464,406 @@ open class KotlinFileExtractor( | |||
| extractDeclInitializers(c.declarations, false) { Pair(blockId, obinitId) } | |||
| } | |||
|
|
|||
| val jvmStaticFqName = FqName("kotlin.jvm.JvmStatic") | |||
| // Adapted from RepeatedAnnotationLowering.kt | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is already quite large, can we easily move these adapted functions into a separate file?
This gives all annotations and expressions derived from them globally-significant and stable names, enabling the Kotlin and Java extractors to see the same annotation without introducing database conflicts.
Note however this includes extracting annotations for external types, unlike the situation for function bodies.
These are due to changing string literal representation, omitting empty annotations blocks, and changes to how annotation classes are represented in the database.
… ignoring the Metadata annotation
a719a86
to
37e3ecd
Compare
This establishes annotation extraction on a par with the Java extractor (annotations for classes/interfaces, value parameters, fields, callables, and enum entries, but noteworthily not for type parameters or type usages, which require database schema work.) Not annotating type usages particularly means that we don't yet need to worry about nullability annotations.
Wrinkles: