[modular] Classes can now be defined and referenced in arbitrary order (without bringing unwanted dependencies) #40507
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
As per the title. Until now, if a class was ever referenced in the modular file BEFORE being redefined in it later on in the file, it could match a class from another modeling file, thus adding wrong dependencies to the generated files.
This PR fixes it, by making sure all classes redefined in modular are removed from the dependency graph of another class if present (they will be added later on with their own dependencies)
So the order of class definition and class reference in modular files can now be arbitrary 🎉(even though to keep clean code, we always want classes to be defined before they are used somewhere, so that someone can read the file "naturally", it is sometimes not practical)
As an example, consider
modular_modernbert_decoderwhich is being modified, where I previously had to use a check on string name instead ofisinstance(class)because the 2 classes are defined afterwards in modular, and would thus bring erroneous dependencies.A few other models had classes at the wrong location due to it, or even some classes that were imported but never used anywhere
This is now all fixed