From 28673da64ce50103abffe49ff74922c3baa248ab Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Mon, 1 Jul 2019 08:34:30 +0200 Subject: [PATCH 1/6] Guarantee that isize/usize are at least 16-bit wide --- reference/src/layout/scalars.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/reference/src/layout/scalars.md b/reference/src/layout/scalars.md index 7b647cbc..0ea3bfde 100644 --- a/reference/src/layout/scalars.md +++ b/reference/src/layout/scalars.md @@ -35,7 +35,8 @@ of `char` is _implementation-defined_. The `isize` and `usize` types are pointer-sized signed and unsigned integers. They have the same layout as the [pointer types] for which the pointee is -`Sized`, and are layout compatible with C's `uintptr_t` and `intptr_t` types. +`Sized`, and are layout compatible with C's `uintptr_t` and `intptr_t` types, +and are therefore at least 16-bit wide. > **Note**: Rust's `usize` and C's `unsigned` types are **not** equivalent. C's > `unsigned` is at least as large as a short, allowed to have padding bits, etc. @@ -59,6 +60,19 @@ They have the same layout as the [pointer types] for which the pointee is > These limits have not gone through the RFC process and are not guaranteed to > hold. +
Rationale + +C99 [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4) "Limits of +integer types capable of holding object pointers" provides the following minimum +range of values that the pointer-holding integer types must support: + +* `intptr_t`: `[INTPTR_MIN, INTPTR_MAX] = [-(2^15 - 1), 2^15 - 1]` +* `uintptr_t`: `[0, UINTPTR_MAX] = [0, 2^16 - 1]` + +That is, `isize`/`usize` are at least 16-bit wide. + +
+ [pointer types]: ./pointers.md ## Fixed-width integer types From 8128316eb74b26b13e13ce087b642dd13bb36727 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Mon, 1 Jul 2019 08:36:49 +0200 Subject: [PATCH 2/6] Document that libcore relies on this guarantee --- reference/src/layout/scalars.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/reference/src/layout/scalars.md b/reference/src/layout/scalars.md index 0ea3bfde..71980c9d 100644 --- a/reference/src/layout/scalars.md +++ b/reference/src/layout/scalars.md @@ -69,7 +69,11 @@ range of values that the pointer-holding integer types must support: * `intptr_t`: `[INTPTR_MIN, INTPTR_MAX] = [-(2^15 - 1), 2^15 - 1]` * `uintptr_t`: `[0, UINTPTR_MAX] = [0, 2^16 - 1]` -That is, `isize`/`usize` are at least 16-bit wide. +That is, `isize`/`usize` are at least 16-bit wide. `libcore` relies on +this guarantee and unconditionally provides: + +* `impl From for isize`, +* `impl From for usize`. From 3b1353f3120ce291b2fc208886bc1a1c7018b5e5 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Mon, 1 Jul 2019 08:59:17 +0200 Subject: [PATCH 3/6] Document current behavior and don't guarantee 16-bit wide isize/usize --- reference/src/layout/scalars.md | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/reference/src/layout/scalars.md b/reference/src/layout/scalars.md index 71980c9d..ff8429f0 100644 --- a/reference/src/layout/scalars.md +++ b/reference/src/layout/scalars.md @@ -35,8 +35,14 @@ of `char` is _implementation-defined_. The `isize` and `usize` types are pointer-sized signed and unsigned integers. They have the same layout as the [pointer types] for which the pointee is -`Sized`, and are layout compatible with C's `uintptr_t` and `intptr_t` types, -and are therefore at least 16-bit wide. +`Sized`, and are layout compatible with C's `uintptr_t` and `intptr_t` types. + +> **Note**: on all platforms that we currently support, `usize`/`isize` are at +> least 16-bit wide. C99 +> [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4) requires +> `uintptr_t` and `intptr_t` to be at least 16-bit wide. `libcore` relies on +> this to unconditionally provide impls of `From`/`From` for +> `isize`/`usize`. > **Note**: Rust's `usize` and C's `unsigned` types are **not** equivalent. C's > `unsigned` is at least as large as a short, allowed to have padding bits, etc. @@ -60,23 +66,6 @@ and are therefore at least 16-bit wide. > These limits have not gone through the RFC process and are not guaranteed to > hold. -
Rationale - -C99 [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4) "Limits of -integer types capable of holding object pointers" provides the following minimum -range of values that the pointer-holding integer types must support: - -* `intptr_t`: `[INTPTR_MIN, INTPTR_MAX] = [-(2^15 - 1), 2^15 - 1]` -* `uintptr_t`: `[0, UINTPTR_MAX] = [0, 2^16 - 1]` - -That is, `isize`/`usize` are at least 16-bit wide. `libcore` relies on -this guarantee and unconditionally provides: - -* `impl From for isize`, -* `impl From for usize`. - -
- [pointer types]: ./pointers.md ## Fixed-width integer types From 5fc5e71789c8c4586ddfe953a50a45bf14268ea2 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Mon, 1 Jul 2019 09:06:44 +0200 Subject: [PATCH 4/6] Reword --- reference/src/layout/scalars.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/reference/src/layout/scalars.md b/reference/src/layout/scalars.md index ff8429f0..78f11571 100644 --- a/reference/src/layout/scalars.md +++ b/reference/src/layout/scalars.md @@ -37,11 +37,11 @@ The `isize` and `usize` types are pointer-sized signed and unsigned integers. They have the same layout as the [pointer types] for which the pointee is `Sized`, and are layout compatible with C's `uintptr_t` and `intptr_t` types. -> **Note**: on all platforms that we currently support, `usize`/`isize` are at -> least 16-bit wide. C99 -> [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4) requires -> `uintptr_t` and `intptr_t` to be at least 16-bit wide. `libcore` relies on -> this to unconditionally provide impls of `From`/`From` for +> **Note**: C99 [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4) +> requires `uintptr_t` and `intptr_t` to be at least 16-bit wide. That is, on +> all platforms that we currently support, which have a C platform, +> `isize`/`usize` are at least 16-bit wide. `libcore` relies on this guarantee +> to unconditionally provide impls of `From`/`From` for > `isize`/`usize`. > **Note**: Rust's `usize` and C's `unsigned` types are **not** equivalent. C's From 66a8182c68351cea7b1e4ea612d05ffc4c3fcfc0 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 2 Jul 2019 11:09:19 +0200 Subject: [PATCH 5/6] Do not say that libcore relies on usize>=16bit --- reference/src/layout/scalars.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/reference/src/layout/scalars.md b/reference/src/layout/scalars.md index 78f11571..7f79f409 100644 --- a/reference/src/layout/scalars.md +++ b/reference/src/layout/scalars.md @@ -40,9 +40,8 @@ They have the same layout as the [pointer types] for which the pointee is > **Note**: C99 [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4) > requires `uintptr_t` and `intptr_t` to be at least 16-bit wide. That is, on > all platforms that we currently support, which have a C platform, -> `isize`/`usize` are at least 16-bit wide. `libcore` relies on this guarantee -> to unconditionally provide impls of `From`/`From` for -> `isize`/`usize`. +> `isize`/`usize` are at least 16-bit wide. Currently, `libcore` unconditionally +> provides impls of `From`/`From` for `isize`/`usize`. > **Note**: Rust's `usize` and C's `unsigned` types are **not** equivalent. C's > `unsigned` is at least as large as a short, allowed to have padding bits, etc. From d8d7edbe16bb77c0e2cad2f212eae9cd9271b6cd Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Tue, 23 Jul 2019 16:57:20 +0200 Subject: [PATCH 6/6] Clarify that all platforms we support have a C platform --- reference/src/layout/scalars.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/reference/src/layout/scalars.md b/reference/src/layout/scalars.md index 7f79f409..a5b4e7d9 100644 --- a/reference/src/layout/scalars.md +++ b/reference/src/layout/scalars.md @@ -38,10 +38,9 @@ They have the same layout as the [pointer types] for which the pointee is `Sized`, and are layout compatible with C's `uintptr_t` and `intptr_t` types. > **Note**: C99 [7.18.2.4](https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4) -> requires `uintptr_t` and `intptr_t` to be at least 16-bit wide. That is, on -> all platforms that we currently support, which have a C platform, -> `isize`/`usize` are at least 16-bit wide. Currently, `libcore` unconditionally -> provides impls of `From`/`From` for `isize`/`usize`. +> requires `uintptr_t` and `intptr_t` to be at least 16-bit wide. All +> platforms we currently support have a C platform, and as a consequence, +> `isize`/`usize` are at least 16-bit wide for all of them. > **Note**: Rust's `usize` and C's `unsigned` types are **not** equivalent. C's > `unsigned` is at least as large as a short, allowed to have padding bits, etc.