Policy for assumptions about the size of `usize`
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
When in the course of human rusty events, something in core or std depends on the actual width of usize/isize, there are currently (at least) two policies in place:
- Conservatively assume that
usizemay be as narrow as 8 bits.- example:
usize: From<u8> + !From<u16>
- example:
- Liberally assume that
usizeis at least 32 bits wide (as it is on all current officially supported platforms).- example:
Range<u32>: ExactSizeIterator
- example:
Let me know if I missed any other corners of the standard library which make assumptions (identical to one of these or not).
As these policies are in conflict, it seems like one or both of them should be changed. In principle, we can't remove trait implementations from Range<u32> and the like, so we could just declare target_pointer_width-liberalism to be the law of the land. However, this will make it difficult to port Rust to a 16-bit system. In doing such porting, trait implementations like From<u32> for usize and ExactSizeIterator for Range<u32> would need to be gated by a #[cfg]. But, this would make it difficult to port Rust code from, say, a 32-bit target to a 16-bit target, because some code would stop compiling (N.B. this is already potentially the case, because literals given for enum variants are interpreted as isize literals).
So, what should we do?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Start by reviewing the two conflicting usize/isize width policies and their cited examples, then trace other standard-library assumptions about target_pointer_width. Done means reaching and documenting a decided policy for current targets and possible 16-bit ports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100