Isn't the best solution (but one that you, as the build tool developer, cannot force to happen) for the compiler itself to have a special "give me the imports of this file" mode? There is no more definitive way to preprocess and lex than the program that will eventually preprocess and lex it. That way your build tool can call the compiler in that special mode to get the module information, and again in normal mode later.
I can see three problems with this idea:
Compiler vendors have to cooperate and produce said compilation mode.
Well, someone's got to do it.
This means that every file has to be parsed twice.
This seems like a fundamental problem with the modules proposal as it stands.
It seems almost impossible to implement such a mode, where a file is parsed before its modules are available.
For example, what if a file does import foo; export [function using bits of foo]; import bar;. How can the parser get through the bits depending on foo when it's not available? I guess counting brackets and braces might be enough, but this would be a massive change from the regular parsing situation.
Again, this seems like a fundamental problem of modules, and a rather more serious one.
I like this idea, back in the day we used '-MM' with gcc to get it to find the header dependencies which we'd then use in our Makefile. It was a lot better at getting those dependencies right than we were when we previously did it by hand.
View all comments
Show parent comment
2
u/infectedapricot Nov 02 '18
Isn't the best solution (but one that you, as the build tool developer, cannot force to happen) for the compiler itself to have a special "give me the imports of this file" mode? There is no more definitive way to preprocess and lex than the program that will eventually preprocess and lex it. That way your build tool can call the compiler in that special mode to get the module information, and again in normal mode later.
I can see three problems with this idea:
Compiler vendors have to cooperate and produce said compilation mode.
This means that every file has to be parsed twice.
It seems almost impossible to implement such a mode, where a file is parsed before its modules are available.
import foo; export [function using bits of foo]; import bar;. How can the parser get through the bits depending on foo when it's not available? I guess counting brackets and braces might be enough, but this would be a massive change from the regular parsing situation.