Skip to content
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

GROOVY-7558 Add private field accessors and bridge methods to dynamic… #242

Merged
merged 1 commit into from Jul 2, 2016

Conversation

shils
Copy link
Member

@shils shils commented Jan 16, 2016

… classes with statically compiled inner classes

classNode = oldCN;
}

public void visitDynamicOuterClass(ClassNode node) {
Copy link
Member Author

Choose a reason for hiding this comment

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

adding a public method here is not ideal, though it seems like the alternative would be to create a separate class responsible for adding bridge methods, which would be used by both StaticCompilationVisitor and the phase operation added for dynamic outer classes.

@blackdrag
Copy link
Contributor

So basically you find, you need to generate those bridge methods, and leave it to a later visitor to actually produce that code... The alternative would be to write a visitor that can adds this information and is run from StaticCompilationVisitor, to let the actual adding of those methods be done by the StaticCompilationVisitor later on. But actually the list of inner classes in the classnode is supposed to contain all inner classes at this stage, so I am not sure you even need a full blown visitor for this. What do you think

@shils
Copy link
Member Author

shils commented Jan 21, 2016

If I understand correctly, your suggestion is to have the StaticCompilationVisitor for an inner class or method add bridge methods to its outer class? The issue there is that there may be multiple statically compiled inner classes/methods, each possibly accessing different private members of the outer class, so we would have to try adding bridge methods (to the outer class) for each statically compiled inner node and keep track of which private members we'd already added bridge methods for. This would add some complexity to the implementation, but I think it would be ok. Does that sound like what you had in mind?

@PascalSchumacher
Copy link
Contributor

@blackdrag Any feedback for @shils?

@blackdrag
Copy link
Contributor

Sorry, for not answering earlier. It might be more easy to explain by example... Look at StaticTypeCheckingVisitor.VariableExpressionTypeMemoizer. The memoizer is used in the visitor to track something, even though StaticTypeCheckingVisitor is itself a visitor. The memoizer here does a specific task, by collecting information in the subtrees of the AST, and feeds that to the original visitor. IN your case that would be the information of what bridge methods do need to be added

@shils
Copy link
Member Author

shils commented Feb 25, 2016

@blackdrag That's alright, I've been busier than usual as of late anyway. Thanks for the feedback, I'll take a look.

@shils shils force-pushed the GROOVY-7558 branch 2 times, most recently from 4a22989 to d904d7b Compare March 14, 2016 04:50
@shils
Copy link
Member Author

shils commented May 28, 2016

@blackdrag I'm not sure I understand your comment. Dynamic classes are not visited by any static compilation visitor so the bridge method collecting visitor you suggest would have to be run from some other visitor.. or from a statically compiled inner class. The collecting visitor would also have to perform method selection across all of the statically compiled inner classes (or be run after method selection.)

In any case, I changed the implementation to not add a public method at the cost of possibly misusing phase operations.

@paulk-asert
Copy link
Contributor

+1, the use of a callback in metadata is a little novel but I can't think of a better way right now and I think correctness trumps the added complexity in this case. We can always refactor and simplify if we can think of an improvement.

@shils
Copy link
Member Author

shils commented Jul 2, 2016

Agreed, thanks for reviewing this.

… classes with statically compiled inner classes
@asfgit asfgit merged commit 68d9f3f into apache:master Jul 2, 2016
@shils shils deleted the GROOVY-7558 branch July 2, 2016 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants