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
Prefix for associated constants #232
Comments
Ah yes, that is one of the caveats, no explicit namespacing. It should be relatively simple to add some (like a type prefix as you mention), but we should probably discuss the edge cases and document the specifics, because it's necessarily |
Do you have any concerns (edge cases) in mind?
… On Oct 22, 2018, at 12:01, IGI-111 ***@***.***> wrote:
Ah yes, that is one of the caveats, no explicit namespacing.
It should be relatively simple to add some (like a type prefix as you mention), but we should probably discuss the edge cases and document the specifics, because it's necessarily cbindgen specific behavior.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Mostly collisions. Between namespaces and types, between classic constants and associated variable constants and so on. I'm certainly not opposed to just doing the least surprising behavior by default, i.e.: just adding a type prefix. But we can probably avoid some pains with an optional prefix for typenames for instance. Something like type_prefix = "__" # "" by default That'd make |
Thing is, the current code already produces |
Good point. Searchability is a must. What about this case: #[repr(C)]
struct Foo {}
impl Foo {
const BAR: i32 = 10;
}
const Foo_BAR: f32 = 99.;
const BAR: u32 = 42.; What should we output here? The current output is: #include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#define BAR 10
#define Foo_BAR 99 Interestingly enough it doesn't create an explicit collision. The behavior seems to be that the value declared first is the one outputted. If you change the order of statements, So what should we do here? Keep the current behavior? It certainly produces valid output. |
Verbose mode also indicates the constants generated as INFO which is quite neat. But I think when there is an explicit constant conflict we should WARN. That feels to me like the least surprising behavior: output a valid header with no explicit conflicts but warn the user that they're most likely doing something wrong. |
I believe the probability of a Rust program defining Speaking of signalling, I think a collision should be |
That's correct. If the standard is followed even acronym types should be CamelCase. I guess it still leaves single character types and anyone who doesn't follow the naming convention, but point taken those are super rare cases. Oh and I agree, collisions in this case should be errors. I'll try to follow this up with a PR tomorrow, the changes should be relatively straightforward. |
Awesome, thank you!!!
… On Oct 23, 2018, at 19:19, IGI-111 ***@***.***> wrote:
That's correct. If the standard is followed even acronym types should be CamelCase.
I guess it still leaves single character types and anyone who doesn't follow the naming convention, but point taken those are super rare cases.
Oh and I agree, collisions in this case should be errors.
I'll try to follow this up with a PR tomorrow, the changes should be relatively straightforward.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Fix for mozilla#232 This adds a type prefix for associated constants to avoid namespace collisions. It also adds error invocation in the rare but existing cases where an collisions still happens in the constant namespace.
Fix for mozilla#232 This adds a type prefix for associated constants to avoid namespace collisions. It also adds error invocation in the rare but existing cases where an collisions still happens in the constant namespace.
Fix for mozilla#232 This adds a type prefix for associated constants to avoid namespace collisions. It also adds error invocation in the rare but existing cases where an collisions still happens in the constant namespace.
Fix for #232 This adds a type prefix for associated constants to avoid namespace collisions. It also adds error invocation in the rare but existing cases where an collisions still happens in the constant namespace.
I suppose this ought to be closed now @kvark, I guess the autoclosing didn't work when Github was having hiccups. |
@eqrion when is this going to be published? |
We are looking at the bitflags output of this struct:
The result looks like this:
There is "WGPU" prefix attached (which we specify in the options, but it's only means for types), and instead we'd want the type name to be the prefix, i.e.
The current output is not very usable - it's not desired to have the type prefix affecting associated constants, and the way they are generated now there appears to be conflict between types (i.e. we have similar constants for
BufferUsageFlags
bitflags, and they overlap).cc @grovesNL @eqrion @IGI-111
The text was updated successfully, but these errors were encountered: