Skip to content

Commit 37dc766

Browse files
committed
Auto merge of #124831 - nnethercote:rustc_data_structures-cleanups, r=michaelwoerister
`rustc_data_structures` cleanups Some improvements I found while looking through this code. r? `@michaelwoerister`
2 parents ee9a9f8 + 58a06b6 commit 37dc766

File tree

17 files changed

+99
-411
lines changed

17 files changed

+99
-411
lines changed

compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs

+32-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_data_structures::vec_linked_list as vll;
21
use rustc_index::IndexVec;
32
use rustc_middle::mir::visit::{PlaceContext, Visitor};
43
use rustc_middle::mir::{Body, Local, Location};
@@ -37,9 +36,12 @@ pub(crate) struct LocalUseMap {
3736
/// we add for each local variable.
3837
first_drop_at: IndexVec<Local, Option<AppearanceIndex>>,
3938

40-
appearances: IndexVec<AppearanceIndex, Appearance>,
39+
appearances: Appearances,
4140
}
4241

42+
// The `Appearance::next` field effectively embeds a linked list within `Appearances`.
43+
type Appearances = IndexVec<AppearanceIndex, Appearance>;
44+
4345
struct Appearance {
4446
point_index: PointIndex,
4547
next: Option<AppearanceIndex>,
@@ -49,14 +51,34 @@ rustc_index::newtype_index! {
4951
pub struct AppearanceIndex {}
5052
}
5153

52-
impl vll::LinkElem for Appearance {
53-
type LinkIndex = AppearanceIndex;
54+
fn appearances_iter(
55+
first: Option<AppearanceIndex>,
56+
appearances: &Appearances,
57+
) -> impl Iterator<Item = AppearanceIndex> + '_ {
58+
AppearancesIter { appearances, current: first }
59+
}
60+
61+
// Iterates over `Appearances` by following `next` fields.
62+
struct AppearancesIter<'a> {
63+
appearances: &'a Appearances,
64+
current: Option<AppearanceIndex>,
65+
}
5466

55-
fn next(elem: &Self) -> Option<AppearanceIndex> {
56-
elem.next
67+
impl<'a> Iterator for AppearancesIter<'a> {
68+
type Item = AppearanceIndex;
69+
70+
fn next(&mut self) -> Option<AppearanceIndex> {
71+
if let Some(c) = self.current {
72+
self.current = self.appearances[c].next;
73+
Some(c)
74+
} else {
75+
None
76+
}
5777
}
5878
}
5979

80+
//-----------------------------------------------------------------------------
81+
6082
impl LocalUseMap {
6183
pub(crate) fn build(
6284
live_locals: &[Local],
@@ -86,17 +108,17 @@ impl LocalUseMap {
86108
}
87109

88110
pub(crate) fn defs(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
89-
vll::iter(self.first_def_at[local], &self.appearances)
111+
appearances_iter(self.first_def_at[local], &self.appearances)
90112
.map(move |aa| self.appearances[aa].point_index)
91113
}
92114

93115
pub(crate) fn uses(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
94-
vll::iter(self.first_use_at[local], &self.appearances)
116+
appearances_iter(self.first_use_at[local], &self.appearances)
95117
.map(move |aa| self.appearances[aa].point_index)
96118
}
97119

98120
pub(crate) fn drops(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
99-
vll::iter(self.first_drop_at[local], &self.appearances)
121+
appearances_iter(self.first_drop_at[local], &self.appearances)
100122
.map(move |aa| self.appearances[aa].point_index)
101123
}
102124
}
@@ -146,7 +168,7 @@ impl LocalUseMapBuild<'_> {
146168
fn insert(
147169
elements: &DenseLocationMap,
148170
first_appearance: &mut Option<AppearanceIndex>,
149-
appearances: &mut IndexVec<AppearanceIndex, Appearance>,
171+
appearances: &mut Appearances,
150172
location: Location,
151173
) {
152174
let point_index = elements.point_from_location(location);

compiler/rustc_data_structures/src/fingerprint.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::stable_hasher::impl_stable_traits_for_trivial_type;
12
use crate::stable_hasher::{Hash64, StableHasher, StableHasherResult};
23
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
34
use std::hash::{Hash, Hasher};

compiler/rustc_data_structures/src/flock/windows.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::fs::{File, OpenOptions};
22
use std::io;
33
use std::os::windows::prelude::*;
44
use std::path::Path;
5+
use tracing::debug;
56

67
use windows::{
78
Win32::Foundation::{ERROR_INVALID_FUNCTION, HANDLE},

compiler/rustc_data_structures/src/graph/implementation/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
2323
use rustc_index::bit_set::BitSet;
2424
use std::fmt::Debug;
25+
use tracing::debug;
2526

2627
#[cfg(test)]
2728
mod tests;

compiler/rustc_data_structures/src/graph/implementation/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::graph::implementation::*;
2+
use tracing::debug;
23

34
type TestGraph = Graph<&'static str, &'static str>;
45

compiler/rustc_data_structures/src/graph/scc/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::graph::vec_graph::VecGraph;
1010
use crate::graph::{DirectedGraph, NumEdges, Successors};
1111
use rustc_index::{Idx, IndexSlice, IndexVec};
1212
use std::ops::Range;
13+
use tracing::{debug, instrument};
1314

1415
#[cfg(test)]
1516
mod tests;

compiler/rustc_data_structures/src/lib.rs

+28-35
Original file line numberDiff line numberDiff line change
@@ -42,66 +42,59 @@
4242
#![feature(unwrap_infallible)]
4343
// tidy-alphabetical-end
4444

45-
#[macro_use]
46-
extern crate tracing;
47-
48-
use std::fmt;
49-
45+
pub use atomic_ref::AtomicRef;
46+
pub use ena::snapshot_vec;
47+
pub use ena::undo_log;
48+
pub use ena::unify;
5049
pub use rustc_index::static_assert_size;
5150

52-
/// This calls the passed function while ensuring it won't be inlined into the caller.
53-
#[inline(never)]
54-
#[cold]
55-
pub fn outline<F: FnOnce() -> R, R>(f: F) -> R {
56-
f()
57-
}
51+
use std::fmt;
5852

53+
pub mod aligned;
5954
pub mod base_n;
6055
pub mod binary_search_util;
6156
pub mod captures;
57+
pub mod fingerprint;
6258
pub mod flat_map_in_place;
6359
pub mod flock;
60+
pub mod frozen;
6461
pub mod fx;
6562
pub mod graph;
6663
pub mod intern;
6764
pub mod jobserver;
68-
pub mod macros;
65+
pub mod marker;
66+
pub mod memmap;
6967
pub mod obligation_forest;
68+
pub mod owned_slice;
69+
pub mod packed;
70+
pub mod profiling;
71+
pub mod sharded;
7072
pub mod sip128;
7173
pub mod small_c_str;
7274
pub mod snapshot_map;
73-
pub mod svh;
74-
pub use ena::snapshot_vec;
75-
pub mod memmap;
7675
pub mod sorted_map;
77-
#[macro_use]
76+
pub mod sso;
7877
pub mod stable_hasher;
79-
mod atomic_ref;
80-
pub mod fingerprint;
81-
pub mod marker;
82-
pub mod profiling;
83-
pub mod sharded;
8478
pub mod stack;
85-
pub mod sync;
86-
pub mod tiny_list;
87-
pub mod transitive_relation;
88-
pub mod vec_linked_list;
89-
pub mod work_queue;
90-
pub use atomic_ref::AtomicRef;
91-
pub mod aligned;
92-
pub mod frozen;
93-
mod hashes;
94-
pub mod owned_slice;
95-
pub mod packed;
96-
pub mod sso;
9779
pub mod steal;
80+
pub mod svh;
81+
pub mod sync;
9882
pub mod tagged_ptr;
9983
pub mod temp_dir;
84+
pub mod transitive_relation;
10085
pub mod unhash;
10186
pub mod unord;
87+
pub mod work_queue;
10288

103-
pub use ena::undo_log;
104-
pub use ena::unify;
89+
mod atomic_ref;
90+
mod hashes;
91+
92+
/// This calls the passed function while ensuring it won't be inlined into the caller.
93+
#[inline(never)]
94+
#[cold]
95+
pub fn outline<F: FnOnce() -> R, R>(f: F) -> R {
96+
f()
97+
}
10598

10699
/// Returns a structure that calls `f` when dropped.
107100
pub fn defer<F: FnOnce()>(f: F) -> OnDrop<F> {

compiler/rustc_data_structures/src/macros.rs

-37
This file was deleted.

compiler/rustc_data_structures/src/obligation_forest/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@
7070
//! aren't needed anymore.
7171
7272
use crate::fx::{FxHashMap, FxHashSet};
73-
7473
use std::cell::Cell;
7574
use std::collections::hash_map::Entry;
7675
use std::fmt::Debug;
7776
use std::hash;
7877
use std::marker::PhantomData;
78+
use tracing::debug;
7979

8080
mod graphviz;
8181

compiler/rustc_data_structures/src/packed.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
33
use std::cmp::Ordering;
44
use std::fmt;
55

6-
#[repr(packed(8))]
6+
/// A packed 128-bit integer. Useful for reducing the size of structures in
7+
/// some cases.
78
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
9+
#[repr(packed(8))]
810
pub struct Pu128(pub u128);
911

1012
impl Pu128 {

compiler/rustc_data_structures/src/profiling.rs

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub use measureme::EventId;
9999
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
100100
use parking_lot::RwLock;
101101
use smallvec::SmallVec;
102+
use tracing::warn;
102103

103104
bitflags::bitflags! {
104105
#[derive(Clone, Copy)]

compiler/rustc_data_structures/src/stable_hasher.rs

+2
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ macro_rules! impl_stable_traits_for_trivial_type {
296296
};
297297
}
298298

299+
pub(crate) use impl_stable_traits_for_trivial_type;
300+
299301
impl_stable_traits_for_trivial_type!(i8);
300302
impl_stable_traits_for_trivial_type!(i16);
301303
impl_stable_traits_for_trivial_type!(i32);

compiler/rustc_data_structures/src/tiny_list.rs

-80
This file was deleted.

0 commit comments

Comments
 (0)