moosetechnology / Famix

An abstract representation of source code. Famix is generic and can describe applications in multiple programming languages.
MIT License
13 stars 24 forks source link

`MooseObject>>#removeFromModel` doesn't correctly flush cache #632

Open Gabriel-Darbord opened 1 year ago

Gabriel-Darbord commented 1 year ago

When sending removeFromModel to an entity, I would expect the entity to be completely removed from the model. However:

model := FamixJavaModel new.
entity := FamixJavaClass new.
model add: entity.
model allWithType: entity class. "trigger the cache"

entity removeFromModel.

model includes: entity. "false as expected"
(model allWithType: entity class) includes: entity. "true!!!"

Also, sending mooseModel to the removed entity still answers the model, I feel like this shouldn't be the case.

The issue comes from the removeFromModel method which sends removeEntity: to its model with self as argument. If it used remove: instead, it could be fixed, but this method flushes the whole cache which isn't ideal. On the other hand, removeFromModel ultimately sends updateCacheOnRemovalOf:, which removes the entity from the byType cache of the MooseGroupRuntimeStorage, but this doesn't affect the cache of the model.

NicolasAnquetil commented 1 year ago

Yes that's one of the drawback of having caches. Another point is that if the removed entity is related to other entities (ex: the class owns methods), it will still be present in the other entities after removal (the methods still have the class as parentBehaviouralEntity)

The truth is that Famix models were never designed to evolve. They look more like a snapshot of a situation at one point in time.

In the past Jannick Laval designed Orion for this https://inria.hal.science/file/index/docid/498492/filename/Lava09b-IWST09-incrementalChange.pdf