Proposal: allow top-level conditional for imports
While it is possible to have separate modules using @if
module foo @if(...);
module foo @if(...);
I think it could be neat to also have this supported with import, so that less code duplication could occur
module foo;
import bar @if(...);
As of now, compiler returns Error: Only '@public' and '@norecurse' are valid attributes here. as expected.
What situation would it solve? When I last tried this I couldn't find a usecase.
for example having something like:
module foo @if(!$feature(XYZ));
import thirdparty;
when I have feature XYZ enabled, the imports still end up getting analyzed even tho the code is unused, and it would be kinda nice if I was able to remove thirdparty from dependencies: [...]
yes, I know it won't end up getting linked, but feels unnecessary to keep it there and store thirdparty.c3l in libs
maybe this way, it could help omit import being analyzed,
I haven't looked into how the compiler performs static analysis and how would this affect further code.
Ordering here is a bit gnarly. That's the main problem with any @if
I have fixed examples like this:
module foo @if($feature(XYZ));
import thirdparty;
So that if a module is disabled, then the error on an import is ignored. This was significantly easier than adding @if to imports. I hope this is sufficient.
Seems to be working fine, this should be sufficient.