Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute necessity of having refAllDecls everywhere? #10

Open
mifopen opened this issue Nov 15, 2023 · 2 comments
Open

Absolute necessity of having refAllDecls everywhere? #10

mifopen opened this issue Nov 15, 2023 · 2 comments

Comments

@mifopen
Copy link

mifopen commented Nov 15, 2023

I see tests that call 'refAllDecls' in almost every library. What's the purpose of those? If it is so necessary to have and maintain those, why it's not embedded into compiler?

@greenfork
Copy link

Zig uses "lazy loading" of code which means that if the code is not used, it is not compiled. This helps with compilation speed and the size of binaries because the code that is not used is not in the final binary.

In tests however we often want to check that at least the syntax and types are correct, and a bunch of other things in addition to that. refAllDecls references all declarations in a module effectively saying Zig to "use" them, so they are loaded and checked. I don't know whether they exist in the final binary with that, but for the test you probably don't mind it anyway. If you don't do refAllDecls, you may have code that is in fact incorrect and Zig compiler will yell at you once you try to use it, even though previously there was no problem when you worked with other code.

@Guigui220D
Copy link

There is also refAllDeclsRecursive which allows you to put the call in less places but yeeah @greenfork gives you the reason ^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants