Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
introduce "lazy values" concept to fix false positive dependency loops #2174
This is a proposal to solve these issues:
Also, importantly it fixes this hack which is in master branch:
I prototyped this in 3dc8448 and it seemed to be a reasonable solution, but I removed it in d3f2fe2 because it was part of a larger branch (see #2135) and I needed to constrain the scope of the branch.
Here's the fundamental problem:
This activates the hack mentioned above. The problem is that when analyzing the fields of the
Which then has to be evaluated to a
The hack in master branch gives up and assumes pointer sized alignment, which isn't sound reasoning, but just happens to be usually correct by accident.
This proposal would make the above Zig IR resolve into a "lazy value" without having to actually compute
This proposal is potentially also related to #157 - builtin function to tell you the stack size of a function. Zig wouldn't be able to give a numerical value for this, but it would still be a comptime known value, and should still be able to be used in arrays and other contexts. This could be a lazy value - potentially someone could even add a comptime integer to this value, and in code generation zig would be able to emit LLVM with the correct value, even though during normal comptime code execution the actual numerical value would not be available yet.
One question that comes up with this proposal is this example:
Zig's current answer to this question is problematic, which is "if I'm already trying to determine if a struct has zero bits, and the answer to that depends on whether or not it is zero bits, then the answer is no." With lazy values implemented, it would be helpful to have a more precise definition of when a struct has zero bits or not.