-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
cfg() and multiple predicates, logic language, etc #2119
Comments
Somewhat related to #1242 and the ongoing discussion about improvements to attributes. |
#1724 is a related deficiency in |
Agreed that conditional compilation needs to be at least slightly more expressive. We do have to keep in mind that cfg specs are written the general attribute grammar, so adding things like operators needs to make sense for attributes in general. I want to help you get started on this. Let's come up with something minimal that solves some real issues in the existing code base and that modifies the attribute grammar in sensible ways, and keeping in mind the issues and designs discussed in #1242. I know that @graydon and dylukes had some long discussions about ways to overhaul attributes. Regarding |
What if we make |
sounds good to me! |
Glad this topic is reviving a bit. Dylukes and I did discuss this but didn't really finish the conversation, I'm happy to see someone else run with it too. It needs doing. What we boiled things down to was a general sense that:
We didn't implement any of this, but I'd be happy to see any work along these lines. |
Also see https://github.com/mozilla/rust/wiki/Proposal-for-attribute-preprocessing though personally I think it's doing too much and we should be motivated by the actual cases we're running into, which are mostly low-complexity combinations of boolean logic and variable-like reuse of a given test. |
It seems that this was discussed in https://github.com/mozilla/rust/wiki/Meeting-weekly-2013-01-15 but I am not clear which syntax was agreed upon. Can you give an example? |
From IRC: syntax agreed on was to encode
I will try to implement this. |
We discussed a little more in the meeting today and concluded that in the longer-term we'd prefer to solve this by:
The idea being that neither juxtaposed- In the short term, and in a backward-compatible sense, we will land pull req #5410 |
This adopts the syntax from #2119. No more annoying workarounds involving wrapping in mods!
Fixed |
We should revisit graydon's note from 8 months ago: it says we should disallow multiple Otherwise, the current semantics (that multiple |
closing as dupe of #17490 |
Quick over: the
cfg()
attribute can't be used to do multiple-declaration of rust types/fns/mods along multiple-dimensions of consideration (OS, arch) without signifigant hurdle-jumping-through'ing. I spoke with @graydon about this, briefly, on IRC and he was under the impression that commas in a list passed tocfg()
would behave like an&&
, but it seems, from my observation, that they act more like||
.Here's a test case:
Will produce this compiler output:
There are workarounds, of course (As my
new_foo_inst()
impl shows, can acheive similar with nested branches ofos::arch
modules). But I think we can do better.I know this isn't high-priority (as I mentioned, I've already worked around the problem... and I'm not after a turing-completeness for
cfg()
:) , but it would propose changes thecfg()
impl to:,
incfg()
to be||
.&&
as a supported separator, with all that it impliescfg()
using parenthesisAlso, interesting that a single
=
is used for "equals", here. Trying hard to avoid the impulse to not be pedantic about consistency across the language (==
is used for such things in the main grammar).This is totally outside the level of my experience with the language internals so far, and I gather would involve syntax changes. I'm interested in getting my feet wet, gently, with this. Assuming that such a change would be accepted, where would I (or anyone else interested in this work) start?
The text was updated successfully, but these errors were encountered: