The purpose of a TypeInitializer is to ensure, that the same type is created and registered only once in the type system.
This class is used during the use case, when a type declaration in the AST exists,
for which a corresponding new Typir type needs to be established in the type system ("create new type").
Without checking for duplicates, the same type might be created twice, e.g. in the following scenario:
If the creation of A is delayed, since a type B which is required for some properties of A is not yet created, A will be created not now, but later.
During the "waiting time" for B, another declaration in the AST might be found with the same Typir type A.
(The second declaration might be wrong, but the user expects to get a validation hint, and not Typir to crash, or the current DSL might allow duplicated type declarations.)
Since the first Typir type is not yet in the type systems (since it still waits for B) and therefore remains unknown,
it will be tried to create A a second time, again delayed, since B is still not yet available.
When B is created, A is waiting twice and might be created twice, if no TypeInitializer is used.
Design decision: While this class does not provide some many default implementations,
a common super class (or interface) of all type initializers is useful,
since they all can be used as TypeSelector in an easy way.
The purpose of a TypeInitializer is to ensure, that the same type is created and registered only once in the type system. This class is used during the use case, when a type declaration in the AST exists, for which a corresponding new Typir type needs to be established in the type system ("create new type").
Without checking for duplicates, the same type might be created twice, e.g. in the following scenario: If the creation of A is delayed, since a type B which is required for some properties of A is not yet created, A will be created not now, but later. During the "waiting time" for B, another declaration in the AST might be found with the same Typir type A. (The second declaration might be wrong, but the user expects to get a validation hint, and not Typir to crash, or the current DSL might allow duplicated type declarations.) Since the first Typir type is not yet in the type systems (since it still waits for B) and therefore remains unknown, it will be tried to create A a second time, again delayed, since B is still not yet available. When B is created, A is waiting twice and might be created twice, if no TypeInitializer is used.
Design decision: While this class does not provide some many default implementations, a common super class (or interface) of all type initializers is useful, since they all can be used as TypeSelector in an easy way.