digitalmars.D.internals - Finding the module that caused a template instanciation
- Benjamin Thaut (24/24) Dec 18 2017 For my dll work I need some pointers from someone who has a
- Walter Bright (7/15) Dec 26 2017 The model used internally by the compiler is "as if" it was instantiated...
For my dll work I need some pointers from someone who has a deeper understanding of how the template implementation inside dmd works. Here is the problem Given a template instance I need to know which module caused this template to be instanciated. I don't need the module the template was declared in but instead the module that triggered the instanciation. This also has to work in cases where the compiler re-uses existing template instances. In a re-use case I need the module that caused instaciation of the re-used instance. Example: module a; struct SomeTemplate(T){ ... } module b; SomeTemplate!int g_var; When looking at template instace caused by the g_var declaration I need to know that it was instanciated because the module "b" requested it. Looking at the data structures conntected to templates and the template instance I got the impression that this information is currently not stored in the compiler internal data structures. In case this actually is not stored yet, what would be the best place to add it? Kind Regards Benjamin Thaut
Dec 18 2017
On 12/18/2017 4:33 AM, Benjamin Thaut wrote:For my dll work I need some pointers from someone who has a deeper understanding of how the template implementation inside dmd works. Here is the problem Given a template instance I need to know which module caused this template to be instanciated. I don't need the module the template was declared in but instead the module that triggered the instanciation. This also has to work in cases where the compiler re-uses existing template instances. In a re-use case I need the module that caused instaciation of the re-used instance.The model used internally by the compiler is "as if" it was instantiated every time it was used, and then duplicates are discarded by the linker. The compiler does an optimization internally by looking to see if it was already instantiated, and just pointing to that instead of instantiating it again. I suspect the problem you're having is a dependency on who instantiated it that shouldn't be a dependency.
Dec 26 2017