[dmd-internals] Walking through the template function instantiation

Stefanos Baziotis sdi1600105 at di.uoa.gr
Tue Apr 9 10:00:41 UTC 2019


> Here's where the error is emitted from:
> https://github.com/dlang/dmd/blob/e58579a73438e62a16c0c43dc33ce8d36b520edd/src/dmd/func.d#L>
2788-L2790

Thanks for the help Mike! Didn't see your message till now and so
yesterday, I also stopped here by intuitively doing pretty much the same
steps. So here was my first time in dmd codebase in case any newcomer
finds it helpful:
- The main() function is in mars.d, always good to know. :P
- First, I changed the usage message in usage() function.
- Then, I changed some stuff on the lexer, which is in lexer.d and then on
the parser. Actually, these are 2 things I have wrote many times, so it's
easy for me to understand that code but I think for everyone, the lexer is
the next easiest big thing to experiment with. Also, understanding the
parser (or parts of it), makes you understand the language a little
better.

> expressions --> expressionsem.d --> lowered expressions
> lowered expressions --> e2ir --> intermediate representation

I did not figure that. I guess that expressions -> lowered expressions has
somewhere the 3 semantic passes that you see described in the dmd source
code guide. [1]

Searching for "semantic" in mars.d will get you here [2].
in which semantic analysis is done for every module. Now, from there on
the not-so-fun part starts. :P

Following dSymbolSemantic, will probably lead you here [3] in dsymbolsem.d
which will in turn lead you here [4] which led me here [5]
because of the issue. And... I didn't understand a thing.
So then I said, ok, let's do a "search the whole project" search, to find
the error message that Mike found. Then, disappointed I went to sleep. :P

This error message is when we try to resolve a call, as one would expect,
i.e. when we try to instantiate the function. However, I guess one has to
understand how also the function declaration is analysed and possibly a
bunch of
other things that I don't know. From my perspective, it will take more than
extensive debugging to get a good understanding on the problem. Let me point
that I have not written a very complex semantic analyzer, but I do know
the basics of semantic analysis (and the visitor pattern coming with it) and
still, that was very rough.

Any help is welcome!
Btw, if any newcomer sees this and wants help with things I am somewhat
comfortable (i.e. lexing, parsing), please don't hesitate to ask!

- Stefanos


[1] https://wiki.dlang.org/DMD_Source_Guide#Compilation_cycle
[2] https://github.com/dlang/dmd/blob/master/src/dmd/mars.d#L566
[3] https://github.com/dlang/dmd/blob/master/src/dmd/dsymbolsem.d#L554
[4] https://github.com/dlang/dmd/blob/master/src/dmd/dsymbolsem.d#L632
[5] https://github.com/dlang/dmd/blob/master/src/dmd/dsymbolsem.d#L3062

P.S. I guess using the "Reply" in forum is not the right way to reply. I
was trying to do that
for 15 minutes and I thought I should respond to the mail which I hope,
will get the message posted.




More information about the dmd-internals mailing list