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

RFC: #[cfg(…)] syntax for size and alignment of FFI types #1354

Closed
wants to merge 3 commits into from

Conversation

Projects
None yet
5 participants
@mzabaluev
Copy link
Contributor

mzabaluev commented Nov 6, 2015

Add syntax for the #[cfg(...)] attribute to support conditional compilation dependent on size and alignment of primitive types used in FFI.

Rendered

@dgrunwald

This comment has been minimized.

Copy link
Contributor

dgrunwald commented Nov 7, 2015

Conditions in conditional compilation should just be Rust expressions, don't create a new mini-language for this purpose.

Instead of adding tons of special cases to #[cfg], we should seriously consider a D-style static if construct.

@mzabaluev

This comment has been minimized.

Copy link
Contributor Author

mzabaluev commented Nov 8, 2015

@dgrunwald: Thanks, I have added your suggestion to the Alternatives section. I'd like to see more design details on that, as it certainly seems a much more extensive change than the one I'm proposing.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Nov 16, 2015

We discussed this RFC in both the compiler and lang subteam meetings, and found a number of drawbacks:

  • Overall, this doesn't seem like the right path for handling enums, as it requires too much careful coding, and we'd prefer to support that as a first-class feature.
  • Without enums, the remaining motivation seems relatively thin, and there don't seem to be a lot of examples arising of where this kind of "sizeof-int-oriented-switch" would be useful (vs the current approach of selecting based on O/S etc).
  • That said, if we were to add this sort of configuration, we'd prefer to generalize cfg in a universal way (i.e., make cfg understand more than boolean equations), rather than adding special-cased support for the sizeof integers etc.

Thoughts?

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Nov 16, 2015

Sorry, I should have added: all that said, I can certainly see why it'd be sometimes be much easier to select based on the size of an integer or something like that, which seems like it might cut across target OS / architectures in a convenient way.

Though I'd be a bit nervous when it comes to struct layout, since I think that can often vary by O/S in small ways, even if the architecture is the same. But perhaps this doesn't matter much in practice.

@DemiMarie

This comment has been minimized.

Copy link

DemiMarie commented Dec 4, 2015

One feature I would like to see is something like D's std.bitmanip.bitfields!, which produces a bitfield with precisely controlled layout (rather than C layout) and does so with convenient syntax. Obviously the syntax will differ, but a similar syntax extension would be useful for things like JIT compilers and assemblers.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Dec 17, 2015

We discussed this again in the compiler team meeting and decided to close this RFC for now, for the reasons cited previously. Thanks very much for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.