I don't understand the reasoning why CTFE cannot read files. The compiler can already include arbitrary files compile time with the include macros. What's the difference? I think this limitation is just way too forced and does not really make sense.
Well what if the file changes between two invocations of the compiler, while the source code is unchanged? Now your binary behaves differently. More to the point, the binary now depends on which computer it was compiled on.
And the include! macro adds files to the "source code" of your project, which is different from reading a random file.
You really did not make it clearer:/ I still feel like that there is no real difference and it is just a semi random rule from the past. I'm sure eventually it will be changed because it makes no sense..
Ok, let's simplify. There should be no fundamental reason that you can't invoke include! inside a const context (if the file doesn't exist, then you should get a compile error). However, what you can't do is something like this:
File::open("path_to_file");
This is a dynamic operation that depends on the file-system contents, and the compiler has no way of statically enforcing the result of this.
12
u/sociopath_in_me Jul 19 '18
I don't understand the reasoning why CTFE cannot read files. The compiler can already include arbitrary files compile time with the include macros. What's the difference? I think this limitation is just way too forced and does not really make sense.