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: Keyword unreservations (pure, sizeof, alignof, offsetof) #2421

Merged
merged 10 commits into from
May 27, 2018

Conversation

Centril
Copy link
Contributor

@Centril Centril commented Apr 26, 2018

🖼️ Rendered

⏭ Tracking issue

📝 Summary

We unreserve:

  • pure
  • unsized
  • sizeof
  • alignof
  • offsetof
  • priv

🎵 Note

If you have a particular objection and use case for some keyword this RFC wants to unreserve, please speak up and leave a comment.

@Centril Centril added T-lang Relevant to the language team, which will review and decide on the RFC. I-nominated labels Apr 26, 2018
*"go look at `std::mem::size_of` instead"*. However, we believe it is better
to allow users the freedom to use these keywords instead.

## Rationale for `priv`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @withoutboats - You wanted to keep this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrochenkov Could you elaborate a lil bit on possible use cases you foresee?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering how much activity we have around module proposals, including visibility, I think holding onto this one seems reasonable for now.

Copy link
Contributor Author

@Centril Centril Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aight. As we discussed on the lang team meeting; I'll scratch this one of the list in this round of unreservations. We can always revisit later.

In both 1. and 2., `pure` can be contextual.
We also don't think that the drawbacks are significant for `pure`.

## Rationale for `unsize`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @eddyb - Double checking: This is fine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsized may be useful for custom DST, so I think it's worth holding onto for now

Copy link
Contributor Author

@Centril Centril Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikeyhew Can you elaborate a bit? (possibly with a code example?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use dyn instead of unsize for DST.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikeyhew No specific use case; your comment helps me refine the RFC tho :) But @kennytm's idea seems nice? If this discussion doesn't develop I'll strike unsized in a bit with your motivation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use dyn for dynamic existentials, not dynamic sizes, e.g. you could imagine [T] expanding to dyn<n: usize> [T; n] and dyn Trait to dyn<T: Trait> T.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddyb But what about let vla = [T; dyn size];?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now scratched unsized given @mikeyhew's motivation and that unreserving it violates:

[..] we are sure that we have no intention of using the keyword in the future [..]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Centril That's not a size, that's a length. Dynamic existential shorthands (when each bound type/value name is used only once, in an unambiguous way) could be dyn Trait and [T; dyn usize] (or just dyn, since the type can be inferred or specified elsewhere).

@Centril Centril mentioned this pull request Apr 26, 2018
@nikomatsakis

This comment has been minimized.

@joshtriplett
Copy link
Member

I don't want to keep offsetof as a keyword, but I do want us to have a macro offsetof! (or offset_of!) someday. If anyone is interested in an RFC for that, I'd be happy to work with them.

@eddyb
Copy link
Member

eddyb commented Apr 26, 2018

@joshtriplett I dislike having macros that expand to builtins that cannot be written with other syntax, so I'm curious which approach you're looking for. I guess using an union and taking addresses into it via let $StructName { ref $field_name, .. } = uninit.data; could work without being builtin?

EDIT: I've marked the remaining offsetof discussion as offtopic as per #2421 (comment) - there's a link to an internals post in #2421 (comment) if you wish to continue the discussion there.

@joshtriplett

This comment has been minimized.

@eddyb

This comment has been minimized.

@joshtriplett

This comment has been minimized.

## Rationale for `sizeof`, `alignof`, and `offsetof`

We already have [`std::mem::size_of`](https://doc.rust-lang.org/nightly/std/mem/fn.size_of.html) and similar which
are `const fn`s or can be.
Copy link

@hanna-kruppe hanna-kruppe Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offsetof can't be a const fn, at least not without some sort of static reflection being added to the language – which is a huge feature and AFAIK nothing specific in this direction has ever been proposed. I agree it could be unreserved (and implemented as a macro, as @eddyb showed), but this rationale here only applies to sizeof and alignof, not offsetof.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I would prefer if the macro generated a const fn, so you could use it anywhere a constant value was expected. Most of it will soon become possible, with the exception of the assert, although that's mostly a sanity check and shouldn't be required for soundness.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rkruppe In theory we could know the delta between fields of the same structure (or from the start of the structure to one field) statically at compile time, without needing full static reflection. And many uses of offsetof in C want it in a compile-time-constant context..

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joshtriplett What you describe sounds more like a special keyword than a const fn! I don't see a nice, generic (i.e., which enables more than just const fn offsetof) extension to current Rust that allows one to write const fn offsetof in a library. Well, nothing that's smaller/simpler than the beginnings of a reflection system. Once you start introducing things like "reifying a field into a value and passing it to a function" (which seems necessary to even define the interface of const fn offsetof, let alone its implementation) you're already in reflection land.

(I agree that offset calculations need to work in constant contexts, but as @eddyb said, the macro is perfectly compatible with that!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rkruppe This is true; I'll clarify.

@eddyb

This comment has been minimized.

@joshtriplett

This comment has been minimized.

@eddyb

This comment has been minimized.

@Centril
Copy link
Contributor Author

Centril commented Apr 26, 2018

Update: I've removed priv from the list of unreservations and moved it to the "future work" section.

@Centril

This comment has been minimized.

@Centril Centril changed the title RFC: Keyword unreservations (pure, unsize, sizeof, alignof, offsetof, priv) RFC: Keyword unreservations (pure, sizeof, alignof, offsetof) Apr 30, 2018
@Amanieu

This comment has been minimized.

@eddyb

This comment has been minimized.

@Centril
Copy link
Contributor Author

Centril commented May 2, 2018

I made a topic for it: https://internals.rust-lang.org/t/discussion-on-offset-of/7440

Just to double check: Everyone is fine with unreserving offsetof?
Please mark this comment with 👍 if yes, or 👎 if not, and then explain why (if 👎).

@joshtriplett
Copy link
Member

Based on discussion in the lang team meeting, we're ready to unreserve the remaining keywords in this RFC.

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented May 3, 2018

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. labels May 3, 2018
@rfcbot
Copy link
Collaborator

rfcbot commented May 17, 2018

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. and removed proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. labels May 17, 2018
text/0000-unreservations-2018.md Outdated Show resolved Hide resolved
@rfcbot
Copy link
Collaborator

rfcbot commented May 27, 2018

The final comment period, with a disposition to merge, as per the review above, is now complete.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this RFC. and removed final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. labels May 27, 2018
@Centril Centril merged commit 7a2ce51 into rust-lang:master May 27, 2018
@Centril
Copy link
Contributor Author

Centril commented May 27, 2018

Huzzah! This RFC is merged!

Tracking issue: rust-lang/rust#51115

@Centril Centril deleted the rfc/unreservations-2018 branch May 27, 2018 22:33
@Centril Centril added A-syntax Syntax related proposals & ideas A-keyword Proposals relating to keywords. labels Nov 23, 2018
nwtnni added a commit to nwtnni/rust.vim that referenced this pull request Jun 5, 2019
nwtnni added a commit to nwtnni/rust.vim that referenced this pull request Jun 5, 2019
da-x pushed a commit to rust-lang/rust.vim that referenced this pull request Jun 6, 2019
@scottmcm scottmcm mentioned this pull request Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-keyword Proposals relating to keywords. A-syntax Syntax related proposals & ideas disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.