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

Rollup of 10 pull requests #54051

Merged
merged 32 commits into from
Sep 8, 2018
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
faf80ad
remove base_place
matthewjasper Sep 3, 2018
fb307e5
Rewrite `precompute_borrows_out_of_scope` for fewer hash table lookups.
nnethercote Sep 4, 2018
28745a6
Implement initializer() for FileDesc
fbernier Sep 6, 2018
c34dd37
rustc_resolve: don't record uniform_paths canaries as reexports.
eddyb Sep 6, 2018
9b764c3
crates that provide a `panic_handler` are exempt from `unused_extern_…
japaric Sep 6, 2018
6c4f3f5
update UI test
japaric Sep 6, 2018
8aae6ca
Have rust-lldb look for the rust-enabled lldb
tromey Sep 5, 2018
ef44068
rustbuild: allow configuring llvm version suffix
Keruspe Sep 6, 2018
1242639
change syntax of `newtype_index` to look like a struct decl
nikomatsakis Jul 25, 2018
c46f185
add a comment
nikomatsakis Jul 25, 2018
5aee959
make field always private, add `From` impls
nikomatsakis Jul 25, 2018
6ccf9b8
change from tuple struct to brace struct
nikomatsakis Aug 28, 2018
24ab375
remove all references to `private` from outside the macro
nikomatsakis Aug 28, 2018
c67d518
add various `#[inline]` directives
nikomatsakis Aug 30, 2018
f702bd6
rewrite constants to use NewType::MAX instead of u32::MAX
nikomatsakis Aug 23, 2018
3b6361d
switch to using `NonZeroU32` to represent indices
nikomatsakis Aug 30, 2018
3805ebe
remove use of `from_u32_unchecked`
nikomatsakis Aug 30, 2018
ec0ad09
use a `BTreeSet` for a more stable error message order
nikomatsakis Aug 31, 2018
e5e72f6
switch back to using a plain `u32`, not `NonZeroU32`
nikomatsakis Sep 6, 2018
ab43c1e
add `const_fn` feature
nikomatsakis Sep 6, 2018
de6a611
update books for next release
steveklabnik Sep 6, 2018
b31eaa4
Update `petgraph` dependency to 0.4.13
GabrielMajeri Sep 8, 2018
7569d92
Rollup merge of #53932 - matthewjasper:remove-base-path, r=nikomatsakis
kennytm Sep 8, 2018
dbc9ec9
Rollup merge of #53942 - nnethercote:faster-precompute, r=nikomatsakis
kennytm Sep 8, 2018
5cc51ad
Rollup merge of #53973 - tromey:prefer-rust-enabled-lldb, r=alexcrichton
kennytm Sep 8, 2018
14c21a1
Rollup merge of #53981 - fbernier:patch-1, r=sfackler
kennytm Sep 8, 2018
e2e3608
Rollup merge of #53987 - Keruspe:llvm-suffix, r=alexcrichton
kennytm Sep 8, 2018
407da0a
Rollup merge of #53993 - eddyb:issue-53691, r=petrochenkov
kennytm Sep 8, 2018
1a86a93
Rollup merge of #54007 - japaric:gh53964, r=cramertj
kennytm Sep 8, 2018
0b58d2d
Rollup merge of #54040 - steveklabnik:update-books, r=Mark-Simulacrum
kennytm Sep 8, 2018
b1ef2b8
Rollup merge of #54050 - GabrielMajeri:fix-build-with-nightly, r=alex…
kennytm Sep 8, 2018
51c3879
Rollup merge of #53315 - nikomatsakis:newtype-index, r=Mark-Simulacrum
kennytm Sep 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
@@ -44,7 +44,9 @@ newtype_index! {
}

impl DepNodeIndex {
const INVALID: DepNodeIndex = DepNodeIndex { private: ::std::u32::MAX };
const INVALID: DepNodeIndex = unsafe {
DepNodeIndex::from_u32_unchecked(::std::u32::MAX)
};
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
@@ -1127,14 +1129,16 @@ impl DepNodeColorMap {
match self.values[index] {
COMPRESSED_NONE => None,
COMPRESSED_RED => Some(DepNodeColor::Red),
value => Some(DepNodeColor::Green(DepNodeIndex { private: value - COMPRESSED_FIRST_GREEN })),
value => Some(DepNodeColor::Green(DepNodeIndex::from_u32(
value - COMPRESSED_FIRST_GREEN
)))
}
}

fn insert(&mut self, index: SerializedDepNodeIndex, color: DepNodeColor) {
self.values[index] = match color {
DepNodeColor::Red => COMPRESSED_RED,
DepNodeColor::Green(index) => index.private + COMPRESSED_FIRST_GREEN,
DepNodeColor::Green(index) => index.as_u32() + COMPRESSED_FIRST_GREEN,
}
}
}
16 changes: 2 additions & 14 deletions src/librustc/hir/def_id.rs
Original file line number Diff line number Diff line change
@@ -41,27 +41,15 @@ newtype_index! {
impl CrateNum {
pub fn new(x: usize) -> CrateNum {
assert!(x < (u32::MAX as usize));
CrateNum { private: x as u32 }
}

pub fn from_u32(x: u32) -> CrateNum {
CrateNum { private: x }
}

pub fn as_usize(&self) -> usize {
self.private as usize
}

pub fn as_u32(&self) -> u32 {
u32::from(*self)
CrateNum::from_u32(x as u32)
}

pub fn as_def_id(&self) -> DefId { DefId { krate: *self, index: CRATE_DEF_INDEX } }
}

impl fmt::Display for CrateNum {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(&self.private, f)
fmt::Display::fmt(&self.as_u32(), f)
}
}

8 changes: 3 additions & 5 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -131,9 +131,6 @@ pub struct Mir<'tcx> {
cache: cache::Cache,
}

/// where execution begins
pub const START_BLOCK: BasicBlock = BasicBlock { private: 0 };

impl<'tcx> Mir<'tcx> {
pub fn new(
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
@@ -239,7 +236,7 @@ impl<'tcx> Mir<'tcx> {

#[inline]
pub fn local_kind(&self, local: Local) -> LocalKind {
let index = local.private as usize;
let index = local.as_usize();
if index == 0 {
debug_assert!(
self.local_decls[local].mutability == Mutability::Mut,
@@ -855,7 +852,8 @@ pub struct UpvarDecl {

newtype_index! {
pub struct BasicBlock {
DEBUG_FORMAT = "bb{}"
DEBUG_FORMAT = "bb{}",
const START_BLOCK = 0,
}
}

10 changes: 7 additions & 3 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
@@ -1274,7 +1274,9 @@ impl DebruijnIndex {
/// you would need to shift the index for `'a` into 1 new binder.
#[must_use]
pub const fn shifted_in(self, amount: u32) -> DebruijnIndex {
DebruijnIndex { private: self.private + amount }
unsafe {
DebruijnIndex::from_u32_unchecked(self.as_u32() + amount)
}
}

/// Update this index in place by shifting it "in" through
@@ -1287,7 +1289,9 @@ impl DebruijnIndex {
/// `amount` number of new binders.
#[must_use]
pub const fn shifted_out(self, amount: u32) -> DebruijnIndex {
DebruijnIndex { private: self.private - amount }
unsafe {
DebruijnIndex::from_u32_unchecked(self.as_u32() - amount)
}
}

/// Update in place by shifting out from `amount` binders.
@@ -1316,7 +1320,7 @@ impl DebruijnIndex {
/// bound by one of the binders we are shifting out of, that is an
/// error (and should fail an assertion failure).
pub fn shifted_out_to_binder(self, to_binder: DebruijnIndex) -> Self {
self.shifted_out((to_binder.private - INNERMOST.private) as u32)
self.shifted_out(to_binder.as_u32() - INNERMOST.as_u32())
}
}

56 changes: 44 additions & 12 deletions src/librustc_data_structures/indexed_vec.rs
Original file line number Diff line number Diff line change
@@ -102,23 +102,55 @@ macro_rules! newtype_index {
}

impl $type {
#[inline]
$v fn from_usize(value: usize) -> Self {
assert!(value < ($max as usize));
unsafe {
$type::from_u32_unchecked(value as u32)
}
}

#[inline]
$v fn from_u32(value: u32) -> Self {
assert!(value < $max);
unsafe {
$type::from_u32_unchecked(value)
}
}

#[inline]
$v const unsafe fn from_u32_unchecked(value: u32) -> Self {
$type { private: value }
}

/// Extract value of this index as an integer.
#[inline]
$v fn index(self) -> usize {
<Self as Idx>::index(self)
self.as_usize()
}

/// Extract value of this index as a usize.
#[inline]
$v const fn as_u32(self) -> u32 {
self.private
}

/// Extract value of this index as a u32.
#[inline]
$v const fn as_usize(self) -> usize {
self.private as usize
}
}

impl Idx for $type {
#[inline]
fn new(value: usize) -> Self {
assert!(value < ($max) as usize);
$type { private: value as u32 }
Self::from(value)
}

#[inline]
fn index(self) -> usize {
self.private as usize
usize::from(self)
}
}

@@ -153,25 +185,25 @@ macro_rules! newtype_index {

impl From<$type> for u32 {
fn from(v: $type) -> u32 {
v.private
v.as_u32()
}
}

impl From<$type> for usize {
fn from(v: $type) -> usize {
v.private as usize
v.as_usize()
}
}

impl From<usize> for $type {
fn from(v: usize) -> Self {
Self::new(v)
fn from(value: usize) -> Self {
$type::from_usize(value)
}
}

impl From<u32> for $type {
fn from(v: u32) -> Self {
Self::new(v as usize)
fn from(value: u32) -> Self {
$type::from_u32(value)
}
}

@@ -195,7 +227,7 @@ macro_rules! newtype_index {
@debug_format [$debug_format:tt]) => (
impl ::std::fmt::Debug for $type {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(fmt, $debug_format, self.private)
write!(fmt, $debug_format, self.as_u32())
}
}
);
@@ -378,7 +410,7 @@ macro_rules! newtype_index {
const $name:ident = $constant:expr,
$($tokens:tt)*) => (
$(#[doc = $doc])*
pub const $name: $type = $type { private: $constant };
pub const $name: $type = unsafe { $type::from_u32_unchecked($constant) };
newtype_index!(
@derives [$($derives,)*]
@type [$type]