Skip to content

Kotlin: Simplify kotlinFunctionToJavaEquivalent #10646

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

Merged
merged 11 commits into from
Oct 4, 2022

Conversation

tamasvajk
Copy link
Contributor

@tamasvajk tamasvajk commented Sep 30, 2022

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
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
Copy link
Contributor

@igfoo igfoo left a comment

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
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
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