You have created a generator for your language and your users are happily writing their models. At some point, the model grows big and the user decides to split it into two. After doing all the necessary refactoring they finally press Build… and MPS greets them with an error: a broken reference somewhere in the generator.

What has just happened? You have entered the realm of cross-model generation!

Cross-model generation is the term that MPS uses for the situation where you need to generate code from multiple models, each compiled separately. In traditional programming languages this is known as separate compilation.

It turns out that separate compilation, alias cross-model generation, is a totally new can of worms and an unexpected source of headaches for the uninitiated.

What causes the broken references? Generation in MPS works by first transforming the input model into a model in a target language (base language/Java, XML, or some other custom language), perhaps in multiple steps, and then generating text from the last intermediate, transient, model.

Each input model is generated separately, and transient models are not guaranteed to be kept after generation. This is a problem if a transient model generated from model A needs to reference a transient model generated from model B.

On the other hand, if we are only generating a “simple” language that does not deal with references, like XML, JSON, or plaintextgen, then cross-model generation is not going to be a problem.

Now that we know what the problem is, how do we make things work? We’ll look into this in the next email.