-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add shrinker-test examples with never-referenced constructors #2478
Add shrinker-test examples with never-referenced constructors #2478
Conversation
R8 can do some optimizations that assume values of types whose constructors are never referenced are `null`. (A bit confused why the rules here are sufficient to avoid that optimization in the case of a class whose sole constructor has arguments and is unreferenced, since the keep rule only refers to `<init>()` instead of `<init>(...)`. Does R8 have special behavior for `<init>()` where attempting to keep that makes it assume a class is constructable even if it doesn't have a no-args constructor?) Also rename some test classes/names to refer to `NoArgs` instead of `Default` constructors. The examples here care about whether a no-argument constructor is present. While a no-argument constructor (explicitly defined or not) is used by default in some circumstances, the Java documentation consistently uses "default constructor" to refer only to constructors whose implementation is implicitly provided by the complier (all default constructors are no-argument constructors, but not vice versa).
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.
Thanks a lot! The changes look good, just a few small things (see comments below).
R8 can do some optimizations that assume values of types whose constructors are never referenced are
null
I think by accident I triggered this for ProGuard while initially creating the shrinker-tests, respectively I triggered the cryptic NullPointerException
this is causing (with JVM's helpful NullPointerException
messages it says something like 'Cannot throw exception because "null" is null'). Though I am not sure if I still have the code to cause this, and if it would still cause this with the latest gson.pro
file.
A bit confused why the rules here are sufficient to avoid that optimization...
I am not sure either, but I am also not very familiar with the details of R8.
Also rename some test classes/names to refer to
NoArgs
instead ofDefault
constructors
Good point! You are right, the JLS seems to use the term "default constructor" only for the implicit one. I was mixing the terms a bit inconsistently.
shrinker-test/src/main/java/com/example/ClassWithNoArgsConstructor.java
Outdated
Show resolved
Hide resolved
shrinker-test/src/main/java/com/example/NoSerializedNameMain.java
Outdated
Show resolved
Hide resolved
shrinker-test/src/main/java/com/example/NoSerializedNameMain.java
Outdated
Show resolved
Hide resolved
…ctor.java Accept review suggestion Co-authored-by: Marcono1234 <[email protected]>
Accept review suggestion Co-authored-by: Marcono1234 <[email protected]>
shrinker-test/src/main/java/com/example/NoSerializedNameMain.java
Outdated
Show resolved
Hide resolved
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.
Thanks a lot for the changes, they look good to me!
…#2478) * Add shrinker-test examples with never-referenced constructors R8 can do some optimizations that assume values of types whose constructors are never referenced are `null`. (A bit confused why the rules here are sufficient to avoid that optimization in the case of a class whose sole constructor has arguments and is unreferenced, since the keep rule only refers to `<init>()` instead of `<init>(...)`. Does R8 have special behavior for `<init>()` where attempting to keep that makes it assume a class is constructable even if it doesn't have a no-args constructor?) Also rename some test classes/names to refer to `NoArgs` instead of `Default` constructors. The examples here care about whether a no-argument constructor is present. While a no-argument constructor (explicitly defined or not) is used by default in some circumstances, the Java documentation consistently uses "default constructor" to refer only to constructors whose implementation is implicitly provided by the complier (all default constructors are no-argument constructors, but not vice versa). * Update shrinker-test/src/main/java/com/example/ClassWithNoArgsConstructor.java Accept review suggestion Co-authored-by: Marcono1234 <[email protected]> * Update shrinker-test/src/main/java/com/example/NoSerializedNameMain.java Accept review suggestion Co-authored-by: Marcono1234 <[email protected]> * Further adjust test class/method names for consistency * Update shrinker-test/src/main/java/com/example/NoSerializedNameMain.java Co-authored-by: Marcono1234 <[email protected]> --------- Co-authored-by: Marcono1234 <[email protected]>
R8 can do some optimizations that assume values of types whose constructors are never referenced are
null
. (A bit confused why the rules here are sufficient to avoid that optimization in the case of a class whose sole constructor has arguments and is unreferenced, since the keep rule only refers to<init>()
instead of<init>(...)
. Does R8 have special behavior for<init>()
where attempting to keep that makes it assume a class is constructable even if it doesn't have a no-args constructor?)Also rename some test classes/names to refer to
NoArgs
instead ofDefault
constructors. The examples here care about whether a no-argument constructor is present. While a no-argument constructor (explicitly defined or not) is used by default in some circumstances, the Java documentation consistently uses "default constructor" to refer only to constructors whose implementation is implicitly provided by the complier (all default constructors are no-argument constructors, but not vice versa).