nitlang / nit

Nit language
http://nitlanguage.org
Apache License 2.0
239 stars 65 forks source link

MModule: new method `add_mclassdef` to avoid incoherent cache state. #2777

Closed Louis-Vincent closed 5 years ago

Louis-Vincent commented 5 years ago

Currently, the constructor of MClassDef would directly add itself in the MModule, like so: mmodule.mclassdefs.add(self). However, this could out of date MModule:flatten_mclass_hierarchy. If we want better support for model manipulation after all the semantic phases, we need more logic when adding a new MClassDef in the hierarchy.

Moreover, this allows better protection since MClassDef no longer needs to know mmodule.mclassdefs.

Signed-off-by: Louis-Vincent Boudreault lv.boudreault95@gmail.com

Morriar commented 5 years ago

Following your idea, should we also protect write services on MModule::mclassdefs: https://github.com/nitlang/nit/pull/2777/files#diff-c008a218a118b9a750328dbea9b1e216R176

Maybe declaring it as var mclassdefs: Sequence[MClassDef] = new Array[MClassDef]?

Louis-Vincent commented 5 years ago

@Morriar

Maybe declaring it as var mclassdefs: Sequence[MClassDef] = new Array[MClassDef]?

I'm not sure what you are referring to, but Sequence seems to have add method too.