gumtree-spoon-ast-diff icon indicating copy to clipboard operation
gumtree-spoon-ast-diff copied to clipboard

Applying actions on ast

Open quentinLeDilavrec opened this issue 5 years ago • 7 comments

Hi,

Is there a standard/convenient way of applying a subset of found actions? I want to apply them on the left spoon ast to evaluate different intermediary version of an evolved code.

Thanks for your help!

quentinLeDilavrec avatar Aug 20 '20 16:08 quentinLeDilavrec

Hi @quentinLeDilavrec

In the current version, that feature is not implemented. It'd be really cool to have it!! Regards Matias

martinezmatias avatar Aug 20 '20 16:08 martinezmatias

Hi @quentinLeDilavrec BTW, it would not be so hard to implement it. As I am quite busy next weeks, if you agree, I can help/guide you to implement it. WDYT? Cheers Matias

martinezmatias avatar Aug 20 '20 16:08 martinezmatias

Part of this is implemented in https://github.com/KTH/spork/

monperrus avatar Aug 20 '20 16:08 monperrus

Thanks @martinezmatias I will make sure to ask you if I have problems with the implementation. Cool @monperrus, I will try it, I was searching for such project, but did not find it ! It would be useful to put a link on http://spoon.gforge.inria.fr/ecosystem.html or fork it from https://github.com/SpoonLabs ;0

For now, I am having difficulties with nested operations, such as updates inside moves, but I did not find explicit rules for this nesting (Update is the only one that can't be nested?).

#67 is also a good start but I think that the example does not work because op.getSrcNode().replace(op. getDstNode()); op does not update the srcNode of its children. But I don't know exactly how to solve it.

Regards, Quentin

quentinLeDilavrec avatar Aug 20 '20 17:08 quentinLeDilavrec

Hi @quentinLeDilavrec

Update is the only one that can't be nested?

Yes. That's right.

op.getSrcNode().replace(op. getDstNode()); op does not update the srcNode of its children.But I don't know exactly how to solve it.

I'll check it.

Regards Matias

martinezmatias avatar Aug 20 '20 19:08 martinezmatias

It would be useful to put a link on http://spoon.gforge.inria.fr/ecosystem.html

Great idea :) Would you make a PR on ecosystem.md?

monperrus avatar Aug 21 '20 07:08 monperrus

It would be useful to put a link on http://spoon.gforge.inria.fr/ecosystem.html

Great idea :) Would you make a PR on ecosystem.md?

Yeah, I will do it.

But even tho it's a great project, I did not find many things that I could reuse from spork :,( It seems that the logic to merge ASTs I buried under a third party merge library and some elements' wrapper to make it work efficiently (no deep equality, and not directly mutating the ast but picking the wrapped pieces that won the merge battle :/).

In my case, my best shot would be to implement a way to just mutate the ast without too much boilerplate, only applying one op at a time and also being able to undo op individually.

  • It would allow me to cycle though the different intermediate state of the code (using a gray code and maybe grouping some op prior to cycling to reduce the combinatorial explosion).
  • And avoid cloning the whole ast.
  • But it makes the handling of things like references and parents a nightmare :b)

Moreover, I cannot consider operations individually, thus I would need to make a wrapper able to update other wrappers to avoid unwanted application of other operations. Wrapping Operations also avoid changing their original behavior. This wrapper should be resistant to applications of its parents operations. It would mutate the ast and other operation with an apply() and unapply() method.

Some examples, given a delete inside a move, a) if we make a swap to apply the move, the delete should become an insert and be immediately applied. then when we decide to apply the delete we can do it easily. b) otherwise if we first apply the delete when we apply the move just need to swap but to then undo the delete we should insert the deleted node in the swapped ast :/.

@martinezmatias It sounds ok? Oo

quentinLeDilavrec avatar Aug 21 '20 09:08 quentinLeDilavrec