Skip to content

Generate pub const for most of anonymous enums #84

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

Closed
upsuper opened this issue Oct 14, 2016 · 3 comments
Closed

Generate pub const for most of anonymous enums #84

upsuper opened this issue Oct 14, 2016 · 3 comments

Comments

@upsuper
Copy link
Contributor

upsuper commented Oct 14, 2016

Anonymous enums usually serve as a container of scoped constants without linkage. It is more useful to have a pub const for each of its members, rather than an enum with some unique name.

Discussed this with @Manishearth on IRC, and he prefers having enum because that fits matching better. However, in majority of cases, you cannot get a variable with its type being an anonymous enum, which means you need a manual conversion anyway. And that manual conversion requires the knowledge of the name of the enum in binding, which is volatile.

There is one case, though, you can get a variable with an anonymous enum type, that someone writes enum { XXX } var, in which case @Manishearth's argument makes lots of sense. So I suggest that for all other cases, we generate pub consts rather than enums.

@emilio
Copy link
Contributor

emilio commented Oct 14, 2016

We do this for top-level anonymous enums IIRC (see the NODE_ flags in stylo). I agree it makes sense to expand this behavior and shouldn't be too hard.

@upsuper
Copy link
Contributor Author

upsuper commented Oct 14, 2016

I guess it is not hard to generate consts, but it might be hard to determine whether an anonymous enum is used like enum { XXX } var;. If that's the case, we can probably generate both enums and consts.

@upsuper
Copy link
Contributor Author

upsuper commented Oct 14, 2016

FWIW, I want this because in servo/servo#13674, we use a static const from Gecko side, which leads to linking failure on Windows. And I want to either convert that static const to a macro or an enum constant. It seems to me the latter is better because it is scoped.

If we can have this enhancement implemented soonish, I would use enum constants for that, otherwise, I'll change it to a macro.

bors-servo pushed a commit that referenced this issue Oct 19, 2016
codegen: Generate constants names for unnamed enums in classes.

Fixes #84.

cc @upsuper, sorry for not doing it before, I totally forgot about it.

r? @fitzgen or @nox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants