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

change newtype_index! to use Nonzero #45842

Closed
nikomatsakis opened this issue Nov 7, 2017 · 2 comments
Closed

change newtype_index! to use Nonzero #45842

nikomatsakis opened this issue Nov 7, 2017 · 2 comments
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

So now that @spastorino and @Nashenas88 have converted so much of the compiler to use newtype_index!, I was thinking that we could change the implementation of all these index types from struct Foo(u32) to struct Foo(Nonzero<u32>). This would require adding (and subtracting) 1 internally to convert from the actual index into its internal representation, but it would have the bonus that we could Option<I> for some index type I would still be a single u32-sized value.

This is somewhat hindered by the fact that at least one of these "newtype'd index" types has a public field. We should see if we can change that.

(And , of course, what I really want is something like Nonmax that uses u32::MAX as the sentinel value, since that is not a useful index.)

cc @arielb1, with whom I was discussing this general theme before. Think this could be a good idea? I'm not sure how much people really use Option<I>.

@nikomatsakis nikomatsakis added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 7, 2017
@spastorino
Copy link
Member

Hey @nikomatsakis @arielb1, I can make this change but please confirm that we really want to do it before I ahead and provide a PR 😄.

@cuviper
Copy link
Member

cuviper commented Sep 1, 2020

(And , of course, what I really want is something like Nonmax that uses u32::MAX as the sentinel value, since that is not a useful index.)

I believe this has been implemented since #54032, commit 06a041c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants