diff options
| author | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-09-07 15:28:23 +0200 |
|---|---|---|
| committer | Oliver Schneider <github35764891676564198441@oli-obk.de> | 2018-09-11 11:25:28 +0200 |
| commit | 06a041cbd399dc641cadef2bc22c6e519b01856e (patch) | |
| tree | 877ed7346b700140688c791818a1eb38f6a41d02 | |
| parent | d272e2f6e2e40dadcc68a0f4be5a4145e3d6a006 (diff) | |
| download | rust-06a041cbd399dc641cadef2bc22c6e519b01856e.tar.gz rust-06a041cbd399dc641cadef2bc22c6e519b01856e.zip | |
Forbid the upper indices of `IndexVec` indices to allow for niche optimizations
| -rw-r--r-- | src/librustc/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/region.rs | 6 | ||||
| -rw-r--r-- | src/librustc_data_structures/indexed_vec.rs | 5 | ||||
| -rw-r--r-- | src/librustc_mir/lib.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass-fulldeps/newtype_index.rs | 20 |
5 files changed, 29 insertions, 6 deletions
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index d79281666d6..301fc76f932 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -59,6 +59,8 @@ #![feature(optin_builtin_traits)] #![feature(refcell_replace_swap)] #![feature(rustc_diagnostic_macros)] +#![feature(rustc_attrs)] +#![cfg_attr(stage0, feature(attr_literals))] #![feature(slice_patterns)] #![feature(slice_sort_by_cached_key)] #![feature(specialization)] diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index f6a8f8dc172..a2a056a3590 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -114,7 +114,7 @@ const SCOPE_DATA_NODE: u32 = !0; const SCOPE_DATA_CALLSITE: u32 = !1; const SCOPE_DATA_ARGUMENTS: u32 = !2; const SCOPE_DATA_DESTRUCTION: u32 = !3; -const SCOPE_DATA_REMAINDER_MAX: u32 = !4; +// be sure to add the MAX of FirstStatementIndex if you add more constants here #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)] pub enum ScopeData { @@ -160,9 +160,7 @@ pub struct BlockRemainder { } newtype_index! { - pub struct FirstStatementIndex { - MAX = SCOPE_DATA_REMAINDER_MAX - } + pub struct FirstStatementIndex; } impl_stable_hash_for!(struct ::middle::region::FirstStatementIndex { private }); diff --git a/src/librustc_data_structures/indexed_vec.rs b/src/librustc_data_structures/indexed_vec.rs index 186bc6d43cc..2d1709f2374 100644 --- a/src/librustc_data_structures/indexed_vec.rs +++ b/src/librustc_data_structures/indexed_vec.rs @@ -72,7 +72,7 @@ macro_rules! newtype_index { newtype_index!( // Leave out derives marker so we can use its absence to ensure it comes first @type [$name] - @max [::std::u32::MAX - 1] + @max [0xFFFF_FFFE] @vis [$v] @debug_format ["{}"]); ); @@ -82,7 +82,7 @@ macro_rules! newtype_index { newtype_index!( // Leave out derives marker so we can use its absence to ensure it comes first @type [$name] - @max [::std::u32::MAX - 1] + @max [0xFFFF_FFFE] @vis [$v] @debug_format ["{}"] $($tokens)+); @@ -97,6 +97,7 @@ macro_rules! newtype_index { @vis [$v:vis] @debug_format [$debug_format:tt]) => ( #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)] + #[rustc_layout_scalar_range_end($max)] $v struct $type { private: u32 } diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index d4024981c37..08ee40dbcf4 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -30,6 +30,8 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(exhaustive_patterns)] #![feature(range_contains)] #![feature(rustc_diagnostic_macros)] +#![feature(rustc_attrs)] +#![cfg_attr(stage0, feature(attr_literals))] #![feature(never_type)] #![feature(specialization)] #![feature(try_trait)] diff --git a/src/test/run-pass-fulldeps/newtype_index.rs b/src/test/run-pass-fulldeps/newtype_index.rs new file mode 100644 index 00000000000..d10c51bbe47 --- /dev/null +++ b/src/test/run-pass-fulldeps/newtype_index.rs @@ -0,0 +1,20 @@ +#![feature(rustc_attrs, step_trait, rustc_private)] + +#[macro_use] extern crate rustc_data_structures; +extern crate rustc_serialize; + +use rustc_data_structures::indexed_vec::Idx; + +newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA }); + +use std::mem::size_of; + +fn main() { + assert_eq!(size_of::<MyIdx>(), 4); + assert_eq!(size_of::<Option<MyIdx>>(), 4); + assert_eq!(size_of::<Option<Option<MyIdx>>>(), 4); + assert_eq!(size_of::<Option<Option<Option<MyIdx>>>>(), 4); + assert_eq!(size_of::<Option<Option<Option<Option<MyIdx>>>>>(), 4); + assert_eq!(size_of::<Option<Option<Option<Option<Option<MyIdx>>>>>>(), 4); + assert_eq!(size_of::<Option<Option<Option<Option<Option<Option<MyIdx>>>>>>>(), 8); +} \ No newline at end of file |
