-
-
Notifications
You must be signed in to change notification settings - Fork 133
fix: detect usage of more kinds of import, e.g. of inner classes. #1505
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
Conversation
// normalize class names to only contain '.' characters (in case of inner classes) | ||
.associate { it.className.replace('$', '.') to it.constantFields.toSortedSet() } |
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.
the fix part 1
Job Summary for GradleTest :: gradle |
Ah darn, this is too aggressive a change and will result in false positives. |
Notes to self: First, when enabling asm debug logging, I see this:
which clearly shows a field that would look roughly like this in source: This analysis is on the producer side; specifically it's looking at the compiled class files coming from a project dependency. I don't know if it would be any different if analyzing a jar from an external dependency, but presumably not (or something is very wrong). This code is compiled with javac from the core Gradle plugins. As an aside, I'm seeing that output twice, for both Second, I see this on the consumer side:
for the Kotlin source: fun useConstant() {
println(Inner.CONSTANT)
} Due to constant inlining, I don't think I'll be able to see any reference to New observation. I added public static final String CONSTANT = "magic";
public static final int INT_CONST = 9;
public static final float FLOAT_CONST = 4.2f; and the Kotlin source: fun useConstant() {
println(Inner.CONSTANT)
println(Inner.INT_CONST)
println(Inner.FLOAT_CONST)
} Here's the consumer bytecode:
there's a missing
What is Kotlin doing when loading an Ok, more info. If I add logging for the visitLineNumber() function, I see this:
So I suppose kotlinc is just doing some performance-related things for ints that it isn't doing for Strings or floats. The line numbers correspond 1:1 with the line numbers in the source code. It's possible I could use that. Why can't kotlinc just produce a class file with a constant pool like a normal compiler? |
f9b02e4
to
caa6d8f
Compare
Job Summary for GradleTest :: gradle |
Job Summary for GradleTest :: gradle |
Job Summary for GradleTest :: gradle |
Sigh there are definitely false positives with this approach. Why do so many libraries define empty string constants, some even with the same name? Fucking Kotlin. |
src/main/kotlin/com/autonomousapps/model/internal/intermediates/consumer/InferredLdcConstant.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/com/autonomousapps/model/internal/intermediates/producer/ExplodedJar.kt
Show resolved
Hide resolved
src/main/kotlin/com/autonomousapps/model/internal/intermediates/producer/LdcConstant.kt
Outdated
Show resolved
Hide resolved
is ConstantCapability -> usesConstant = usesConstant(dependencyCoordinates, capability, context) | ||
is ConstantCapability -> { | ||
// TODO | ||
usesConstant = usesConstantByBytecode(dependencyCoordinates, capability, context) | ||
usesConstant = usesConstant || usesConstantByImport(dependencyCoordinates, capability, context) | ||
} | ||
|
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.
TODO
The problem is... solved... thanks to a pair of aggressive heuristics that partially cancel each other out, resulting in a successful test suite. Woohoo. |
ecfcc2b
to
34b9dbe
Compare
…asses. This involves a pair of heuristics, one for source parsing (looking at import statements), and another from bytecode analysis (looking at the ldc instruction) and from that inferring usage of inlined constants. Resolves #1504"
502a871
to
4d448ef
Compare
Resolves #1504