Thread overview
figure out where a particular template function is located
Jun 24, 2020
H. S. Teoh
Jun 24, 2020
Adam D. Ruppe
Jun 24, 2020
kinke
Jun 24, 2020
kinke
June 24, 2020
I have code that instantiates a template:

templ!int("abc");

When I read the source of where I *think* this template should be, I can't find one that would match (I think). I feel like it's being imported elsewhere.

How do I figure out what module (at least) this instantiated template is in? Because of IFTI, I don't know what the template parameters are. Is there a way to figure this out from the call?

I'm looking for a pragma(msg) or such that can give me the fully qualified name/instantiation details of this template.

-Steve
June 24, 2020
On Wed, Jun 24, 2020 at 04:28:24PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:
> I have code that instantiates a template:
> 
> templ!int("abc");
> 
> When I read the source of where I *think* this template should be, I can't find one that would match (I think). I feel like it's being imported elsewhere.
> 
> How do I figure out what module (at least) this instantiated template is in?  Because of IFTI, I don't know what the template parameters are. Is there a way to figure this out from the call?

Use a debugger and step into it? ;-)


> I'm looking for a pragma(msg) or such that can give me the fully qualified name/instantiation details of this template.
[...]

AFAIK there isn't such a thing.


T

-- 
Живёшь только однажды.
June 24, 2020
On Wednesday, 24 June 2020 at 20:28:24 UTC, Steven Schveighoffer wrote:
> Is there a way to figure this out from the call?

The .mangleof the instance might help track it down since it should give you the module name as part of that mangle. Then go in there and start breaking things (or use the __FILE__, __LINE__ default args) to narrow it down.

not a great answer but sould at least get you started.
June 24, 2020
On Wednesday, 24 June 2020 at 20:28:24 UTC, Steven Schveighoffer wrote:
> Is there a way to figure this out from the call?

Another option would be running LDC with -vv for verbose codegen (be warned, lots and lots ouf output); we have fully qualified names in there.
June 24, 2020
On 6/24/20 4:38 PM, Adam D. Ruppe wrote:
> On Wednesday, 24 June 2020 at 20:28:24 UTC, Steven Schveighoffer wrote:
>> Is there a way to figure this out from the call?
> 
> The .mangleof the instance might help track it down since it should give you the module name as part of that mangle. Then go in there and start breaking things (or use the __FILE__, __LINE__ default args) to narrow it down.
> 
> not a great answer but sould at least get you started.

mangleof just gives me the return type mangle:

pragma(msg, foo!int("hi").mangleof); => v (for void)

I have a hard time believing that there's no way to do this! Is there some kind of is-expression that could do this?

Even if I use -vcg-ast it's not going to give me the exact instantiation at the call site (it just shows, e.g. foo("hi"))

I can probably disassemble, and use the mangled name to get back to the real name. But at this point, I'm not going to put in that effort. I just hoped that there was a way to do this in code.

-Steve
June 24, 2020
On Wednesday, 24 June 2020 at 21:05:12 UTC, Steven Schveighoffer wrote:
> I have a hard time believing that there's no way to do this!

This would IMO be the job of the IDE. E.g., Visual D might be able to jump to the template declaration.
June 24, 2020
On 6/24/20 5:40 PM, kinke wrote:
> On Wednesday, 24 June 2020 at 21:05:12 UTC, Steven Schveighoffer wrote:
>> I have a hard time believing that there's no way to do this!
> 
> This would IMO be the job of the IDE. E.g., Visual D might be able to jump to the template declaration.

Something useful in-code might be for instance, using the targeted function as a function pointer. Like, "use the function pointer that would be called with this IFTI call".

But it's not critical for me, I was just trying to locate what code is being called, and I know the compiler knows what it is.

-Steve