-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
[bug] Potential Incorrect behaviour of ActionClassifier when computing roots actions #125
Comments
Actually, one of the problem is when a change (e.g., Insert) also produces that a label of a parent node is updated.
There, the remove of the Literal produces an update of the ConstructorCall (which label is the signature of the executable). |
A different case would be if you have an update of Method's name and an insert on its body: |
Just for context, I'm approaching this from the perspective of applying operations from gumtree-spoon to an AST model (i.e. applying an edit script). I agree with the idea that updates are atomic operations on labels in GumTree. But when this is translated to Spoon, it's not that simple. If I get an update operation from gumtree-spoon, the only information I get is the source node and destination node, but there's no indication of exactly what was updated as the concept of labels doesn't carry over to Spoon. Given only that information, I think it's confusing to not include update operations in root operations, because from an API perspective an update kind of looks like a root operation, if that makes sense. A potential solution there would be to also include the role of the item that was updated. That would give sufficient information to allow for finding the updated "thing". For example, given that we update the name of a method, the update operation contains the source and destination nodes, as well as |
Hi @slarse
Agree. Only CtNamedElements have an equivalent of "label": the
If I am not wrong, the current implement considers all updates as root ops, right?
Just an idea: What about to only consider updates of CtNamedElement? This would simplify the application of partial diffs into the source tree. |
I think I have a case which will be an exemption to this. Consider an update from |
Yes! Which is also confusing, as we then get root operations on elements that are direct descendants of other root operation elements.
That simplicity would be very neat from the use case of applying edit scripts, as @algomaster99 suggest I think we lose some amount of precision there. As for virtual elements, I'm not sure. The fact that modifiers aren't proper nodes is just an eternal bother :( I'll consider this. I think the only way for all of this to make sense is to, as you suggest, dislodge the concept of update operations from root operations. Perhaps the best way to move forward here is that @algomaster99 and I just try to work out a solution that works for applying edit scripts, and then we'll get back to you with some new thoughts. |
I had a go at this problem with what both of you suggested. Might be a good thing to go ahead with if we don't have a lot of roles to care about. Let me elaborate in the steps below.
The problem with this approach is that we will have to analyse many spoon elements for assigning the correct role. On the upside, there may not be a large number of elements that can be updated. Following this approach, we can use the
Still not quite sure how to handle |
@slarse Did you get time to go through the above comment? |
It seems largely reasonable. What I can add is:
As for the update from
? |
It makes sense to me now too. Instead of it making sense, I think I meant it was unnecessary because |
If we follow this approach to update spoon nodes, we shall only be updating the value corresponding to a specific role. We would be skipping the update of the source position of the element since we no longer "replace" elements instead we just updated their so-called labels. I am not sure if that would affect |
@martinezmatias I needed to confirm what is the expected behavior of the classifier in the examples you have proposed above. - int xxxxxx1 = foo001(0) ;
+ int xxxxxx1 = foo002(0,1) Should this have an update operation ( In more general terms, any operation on any children node of an updated node should not be ignored. |
Summary of the problem
The ActionClassifier (probably, IMO) produces an incorrect outputs when Updates operations are the root operations.
Description of the problem:
There are two mains problems.
First, when we have two operations: 1) update on node X and 2) an Insert of Y on X (i.e., Y is a new child of X), the roots operation only shows 1 action: the update.
IMO, That is incorrect: as we discussed in a previous issue (roots of multiple updates), updates should not be grouped (in this case with Insert)
One example is:
Roots is only one: [Update Invocation at X:1 foo001(0) to foo002(0, 1)]
All actions are 2: [Update Invocation at X:1 foo001(0) to foo002(0, 1), Insert Literal at X:1 1]
Second related problem.
In the previous case, the inserted node (literal 1) is a child of the updated node (foo001).
However, if we consider a slightly different example, the ActionClassifier's behaviour is different.
Here, we update the var name instead of the invoked method name (and we always insert a new parameter).
The root operation there are 2:
Update LocalVariable at X:1 int xxxxxx1 = foo001(0) to int xxxxxx2 = foo001(0, 1) , Insert Literal at X:1 1 ]
(in the previous example the roots is only 1).
The difference of behaviour is caused by in this line : the classifier checks if the parent of an action was updated. In this case, the parent of the Insert was not updated (but the grandparent (xxxxxx1) was).
(I found the problem in a real diff, but it's easier to use a fake example to explain the problem)
Solution proposed
Ignore Updates in Root classification. IMH, Updates are atomic ops that only affect one single node.
That would solve the two previous issues.
(basically, the fix removes the term
&& !srcUpdTrees.contains(t.getParent()
from this line and from this one)The text was updated successfully, but these errors were encountered: