Skip to content

Conversation

@shanshin
Copy link
Contributor

  • The warning message about unusual symbols in field type is eliminated.
  • Added correct rules for named companions
  • Changed code for the locating name companion by annotation. Since the list of nested classes is not saved by R8, static fields are analyzed
  • added tests on the rules using R8 in full mode and ProGuard compatibility mode

Fixes #3033

@shanshin shanshin requested a review from sandwwraith July 11, 2025 09:32
serializer(typeOf<SealedInterface>()).descriptor.toString()
)
}
assertSame<KSerializer<*>>(PlainSerializer, serializer(typeOf<PlainWithCustom>()))
Copy link
Member

Choose a reason for hiding this comment

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

Is this change related? I suggest extracting it to separate commit

Also change base branch to dev btw

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not fully related but I think we should add these changes somewhere

}

tasks.compileTestKotlin {
configureCompilation(true)
Copy link
Member

Choose a reason for hiding this comment

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

I think it is better to call function with explicit parameter name: configureCompilation(r8FullMode = true)

return R8CheckerImpl(parseR8Output(mapFile, usageFile))
}

interface R8Checker {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should do interface/Impl split in a 250-lines-long utils file for a small test


sourceSets {
// create the source set for storing sources and using dependency configuration
val common by creating
Copy link
Member

Choose a reason for hiding this comment

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

common name can be misleading because of the strong associations with MPP. Also, test/testCompatible names themselves are quite vague. WDYT of renaming everything to:

  • '(test)Shared'
  • 'testR8Full'
  • 'testPGCompatible'

Or something similar.

Also, you can just reuse regular main sourceset?

}
}
} else {
current.fields.put(name, FieldEntry(name, returnType, obfuscated))
Copy link
Member

Choose a reason for hiding this comment

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

How is it different from fieldRegex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused branch

// process usage.txt
var currentUsageClass: ClassEntry? = null

usageFile.forEachLine { raw ->
Copy link
Member

Choose a reason for hiding this comment

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

If this file contains methods that were removed due to being unused, then it better be named unused.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have the same question :)
But it's common name for this files in Android.

val unusedClass = checker.findClass("kotlinx.serialization.r8.UnusedClass")
assertTrue(unusedClass.isShrunk)

ObfuscatedClass("World").used()
Copy link
Member

Choose a reason for hiding this comment

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

Removing this line causes test to fail, so it's technically a test data. Maybe put this call to some top-level function in Model.kt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we move this call to Model.kt it will be shrinked as only *Tests classes are alwayes kept. So I move it to separate method in R8Tests.

}



Copy link
Member

Choose a reason for hiding this comment

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

unnecessary blank lines

project(":guide").projectDir = file("./guide")

include(":proguard-rules")
project(":proguard-rules").projectDir = file("./rules")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it should be named proguard-rules-test, because rules on their own are just a bunch of .pro files and do not need Gradle module

shanshin added 3 commits July 29, 2025 17:12
- The warning message about unusual symbols in field type is eliminated.
- Added correct rules for named companions
- Changed code for the locating name companion by annotation. Since the list of nested classes is not saved by R8, static fields are analyzed
- added tests on the rules using R8 in full mode and ProGuard compatibility mode

Fixes #3033
@shanshin shanshin requested a review from sandwwraith July 29, 2025 18:58
@shanshin shanshin changed the base branch from master to dev August 4, 2025 14:48
current.methods[signature] = MethodEntry(name, returnType, desc, obfuscated)
} else {
if (existed.obfuscatedName != obfuscated) {
if (obfuscated == name) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add comment explaining the logic of "If method saved its original name in one of the obfuscations, we use original, otherwise we use either of obfuscated"

shanshin and others added 2 commits August 5, 2025 21:02
Co-authored-by: Leonid Startsev <sandwwraith@users.noreply.github.com>
@shanshin shanshin merged commit 51fa6ad into dev Aug 6, 2025
4 checks passed
@shanshin shanshin deleted the r8-proguard branch August 6, 2025 10:35
pdvrieze pushed a commit to pdvrieze/kotlinx.serialization that referenced this pull request Dec 9, 2025
- The warning message about unusual symbols in field type is eliminated.
- Added correct rules for named companions
- Changed code for the locating name companion by annotation. Since the list of nested classes is not saved by R8, static fields are analyzed
- added tests on the rules using R8 in full mode and ProGuard compatibility mode

Fixes Kotlin#3033

Co-authored-by: Leonid Startsev <sandwwraith@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New ProGuard implementation in #2983 causes R8 warning

3 participants