Skip to content

Kotlin: Simplify kotlinFunctionToJavaEquivalent#10646

Merged
igfoo merged 11 commits into
github:mainfrom
tamasvajk:kotlin-java-kotlin-function-mapping
Oct 4, 2022
Merged

Kotlin: Simplify kotlinFunctionToJavaEquivalent#10646
igfoo merged 11 commits into
github:mainfrom
tamasvajk:kotlin-java-kotlin-function-mapping

Conversation

@tamasvajk

@tamasvajk tamasvajk commented Sep 30, 2022

Copy link
Copy Markdown
Contributor

This PR

  • removes the approximation from kotlinFunctionToJavaEquivalent and instead looks up only exact member match;
  • removes the list of expectedMissingEquivalents, which was hiding the fact that some of the mappings were missing;
  • extracts missing operator calls: inv, not, and, or, xor, shl, shr and ushr;
  • adds consistency query to report missing mappings
  • fixes kotlinFunctionToJavaEquivalent to ignore nullability;
  • only logs each missing mapping once.

Comment on lines +201 to +205
val syntheticToRealClassMap = HashMap<IrClass, IrClass?>()
val syntheticToRealFunctionMap = HashMap<IrFunction, IrFunction?>()
val syntheticToRealFieldMap = HashMap<IrField, IrField?>()

val deduplicatedWarnings = mutableSetOf<String>()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these be some variants of concurrent maps? Is there any guarantee that we run single threaded? Could KotlinExtractorExtension::generate be invoked by kotlinc from multiple threads?

@tamasvajk tamasvajk marked this pull request as ready for review October 3, 2022 12:58
@tamasvajk tamasvajk requested review from a team as code owners October 3, 2022 12:58
@tamasvajk tamasvajk removed the request for review from a team October 3, 2022 12:58

@igfoo igfoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM.

val msg = "Couldn't find a Java equivalent function to $parentFqName.${f.name.asString()} in ${javaClass.fqNameWhenAvailable?.asString()}"
if (!globalExtensionState.deduplicatedWarnings.contains(msg)) {
logger.warn(msg)
globalExtensionState.deduplicatedWarnings.add(msg)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that https://github.com/github/codeql/blob/main/java/kotlin-extractor/src/main/kotlin/utils/Logger.kt#L117 is already going to limit the number of any kind of warning to (by default) 100, so although this is more specific, I'm not sure that it's worth the extra code here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, let me revert this.

@tamasvajk tamasvajk removed the Java label Oct 4, 2022
@igfoo igfoo merged commit db673c0 into github:main Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants