Classes needed for lambda merging in ProGuard#36
Open
heckej wants to merge 40 commits intoGuardsquare:masterfrom
Open
Classes needed for lambda merging in ProGuard#36heckej wants to merge 40 commits intoGuardsquare:masterfrom
heckej wants to merge 40 commits intoGuardsquare:masterfrom
Conversation
…code attribute Summary: Methods can sometimes have empty code attributes, if Dex2Pro skips them due to some failure. Unfortunately, this made the DominatorCalculator crash with an ArrayIndexOutOfBoundsException. This has been fixed by making the analysis skip empty code attributes. Test Plan: New unit test Reviewers: james.hamilton, dennis.titze Reviewed By: dennis.titze Differential Revision: http://phabricator.guardsquare.com/D10236
… targets Summary: When searching for call targets in superinterfaces the call resolver previously didn't enforce that any potential target must be non-abstract. Also, if any other resolution path results in a call to an abstract method, this is now logged as an error to catch bugs earlier. Test Plan: Existing tests Reviewers: james.hamilton, carlo.alberto.pozzoli, dennis.titze Reviewed By: dennis.titze Differential Revision: http://phabricator.guardsquare.com/D10245
Test Plan: existing tests Reviewers: samuel.hopstock Reviewed By: samuel.hopstock Differential Revision: http://phabricator.guardsquare.com/D10254
Summary: Previously an error was logged when the call target turned out to be an abstract method. Unfortunately, things like `myList.iterator().hasNext()` validly target an abstract method, which doesn't warrant an error log message. Keeping the logging in would create tons of log spam. Test Plan: N/A Reviewers: dennis.titze Reviewed By: dennis.titze Differential Revision: http://phabricator.guardsquare.com/D10252
…hen count has changed New classes: ModifiedAllInnerClassesInfoVisitor
src/main/java/proguard/classfile/attribute/visitor/ClassConstantToClassVisitor.java
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,27 @@ | |||
| package proguard.classfile.attribute.visitor; | |||
Contributor
There was a problem hiding this comment.
Can you add the ProGuardCORE header to all the classes?
src/main/java/proguard/classfile/attribute/visitor/ModifiedAllInnerClassesInfoVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/proguard/classfile/visitor/ClassMethodFilter.java
Outdated
Show resolved
Hide resolved
src/main/java/proguard/classfile/visitor/FieldReferenceFinder.java
Outdated
Show resolved
Hide resolved
|
|
||
| @Override | ||
| public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) { | ||
| utf8Constant.setString(utf8Constant.getString().replace(originalType, replacingType)); |
Contributor
There was a problem hiding this comment.
Here we should be using a ConstantPoolEditor to add a new constant. You can use a ConstantPoolShrinker after to remove unused ones.
programMember.u2nameIndex =
new ConstantPoolEditor(programClass).addUtf8Constant(newName);
src/main/java/proguard/classfile/attribute/visitor/InnerClassInfoClassConstantVisitor.java
Outdated
Show resolved
Hide resolved
src/main/java/proguard/classfile/visitor/ClassConstantReferenceUpdater.java
Outdated
Show resolved
Hide resolved
| import proguard.classfile.constant.Constant; | ||
| import proguard.classfile.constant.visitor.ConstantVisitor; | ||
|
|
||
| public class ClassReferenceFinder implements ConstantVisitor |
Contributor
There was a problem hiding this comment.
This might be replacable by the following Filter class which can delegate to another ClassVisitor if the the class is referenced.
It's extracted from proguard.backport.StaticInterfaceMethodConverter.MyReferencedClassFilter in ProGuard.
Usable like the following:
this.programClassPool.classesAccept(
new ClassNameFilter(regularExpression,
new ReferencedClassFilter(
lambdaClass,
enclosingMethodUpdater)));
But I see that currentLambdaClass gets updated, so might not work. Can also be used with a ClassCounter:
ClassCounter counter = new ClassCounter();
programClass.accept(new ReferencedClassFilter(currentLambdaClass, counter))
package proguard.classfile.visitor;
import proguard.classfile.*;
import proguard.classfile.constant.*;
import proguard.classfile.constant.visitor.ConstantVisitor;
import proguard.classfile.visitor.ClassVisitor;
/**
* This ClassVisitor delegates its visits to classes that
* reference a given class via any RefConstant.
*/
public class ReferencedClassFilter
implements ClassVisitor,
ConstantVisitor
{
private final Clazz referencedClass;
private final ClassVisitor classVisitor;
private boolean referenceClassFound;
public ReferencedClassFilter(Clazz referencedClass,
ClassVisitor classVisitor)
{
this.referencedClass = referencedClass;
this.classVisitor = classVisitor;
}
// Implementations for ClassVisitor.
@Override
public void visitAnyClass(Clazz clazz) {}
@Override
public void visitProgramClass(ProgramClass programClass)
{
referenceClassFound = false;
programClass.constantPoolEntriesAccept(this);
if (referenceClassFound)
{
programClass.accept(classVisitor);
}
}
// Implementations for ConstantVisitor.
public void visitAnyConstant(Clazz clazz, Constant constant) {}
public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
{
if (refConstant.referencedClass == referencedClass)
{
referenceClassFound = true;
}
}
}
added 9 commits
June 29, 2022 16:06
Classes involved are: InnerClasssInfoClassConstantVisitor, ClassConstantReferenceUpdater, FieldReferenceFinder, FieldRenamer, MethodCopier, MethodReferenceFinder and PackageGrouper
d0892cc to
5081fbe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This will add visitors that are used to implement lambda merging in ProGuard (see pull request for ProGuard: Implementation of lambda merging for Kotlin lambda classes #257).