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

rustc_data_structures cleanups #124831

Merged
merged 7 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 32 additions & 10 deletions compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rustc_data_structures::vec_linked_list as vll;
use rustc_index::IndexVec;
use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{Body, Local, Location};
Expand Down Expand Up @@ -37,9 +36,12 @@ pub(crate) struct LocalUseMap {
/// we add for each local variable.
first_drop_at: IndexVec<Local, Option<AppearanceIndex>>,

appearances: IndexVec<AppearanceIndex, Appearance>,
appearances: Appearances,
}

// The `Appearance::next` field effectively embeds a linked list within `Appearances`.
type Appearances = IndexVec<AppearanceIndex, Appearance>;

struct Appearance {
point_index: PointIndex,
next: Option<AppearanceIndex>,
Expand All @@ -49,14 +51,34 @@ rustc_index::newtype_index! {
pub struct AppearanceIndex {}
}

impl vll::LinkElem for Appearance {
type LinkIndex = AppearanceIndex;
fn appearances_iter(
first: Option<AppearanceIndex>,
appearances: &Appearances,
) -> impl Iterator<Item = AppearanceIndex> + '_ {
AppearancesIter { appearances, current: first }
}

// Iterates over `Appearances` by following `next` fields.
struct AppearancesIter<'a> {
appearances: &'a Appearances,
current: Option<AppearanceIndex>,
}

fn next(elem: &Self) -> Option<AppearanceIndex> {
elem.next
impl<'a> Iterator for AppearancesIter<'a> {
type Item = AppearanceIndex;

fn next(&mut self) -> Option<AppearanceIndex> {
if let Some(c) = self.current {
self.current = self.appearances[c].next;
Some(c)
} else {
None
}
}
}

//-----------------------------------------------------------------------------

impl LocalUseMap {
pub(crate) fn build(
live_locals: &[Local],
Expand Down Expand Up @@ -86,17 +108,17 @@ impl LocalUseMap {
}

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

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

pub(crate) fn drops(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
vll::iter(self.first_drop_at[local], &self.appearances)
appearances_iter(self.first_drop_at[local], &self.appearances)
.map(move |aa| self.appearances[aa].point_index)
}
}
Expand Down Expand Up @@ -146,7 +168,7 @@ impl LocalUseMapBuild<'_> {
fn insert(
elements: &DenseLocationMap,
first_appearance: &mut Option<AppearanceIndex>,
appearances: &mut IndexVec<AppearanceIndex, Appearance>,
appearances: &mut Appearances,
location: Location,
) {
let point_index = elements.point_from_location(location);
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/fingerprint.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::stable_hasher::impl_stable_traits_for_trivial_type;
use crate::stable_hasher::{Hash64, StableHasher, StableHasherResult};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::hash::{Hash, Hasher};
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/flock/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fs::{File, OpenOptions};
use std::io;
use std::os::windows::prelude::*;
use std::path::Path;
use tracing::debug;

use windows::{
Win32::Foundation::{ERROR_INVALID_FUNCTION, HANDLE},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use rustc_index::bit_set::BitSet;
use std::fmt::Debug;
use tracing::debug;

#[cfg(test)]
mod tests;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::graph::implementation::*;
use tracing::debug;

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

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/graph/scc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::graph::vec_graph::VecGraph;
use crate::graph::{DirectedGraph, NumEdges, Successors};
use rustc_index::{Idx, IndexSlice, IndexVec};
use std::ops::Range;
use tracing::{debug, instrument};

#[cfg(test)]
mod tests;
Expand Down
63 changes: 28 additions & 35 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,66 +42,59 @@
#![feature(unwrap_infallible)]
// tidy-alphabetical-end

#[macro_use]
extern crate tracing;

use std::fmt;

pub use atomic_ref::AtomicRef;
pub use ena::snapshot_vec;
pub use ena::undo_log;
pub use ena::unify;
pub use rustc_index::static_assert_size;

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

pub mod aligned;
pub mod base_n;
pub mod binary_search_util;
pub mod captures;
pub mod fingerprint;
pub mod flat_map_in_place;
pub mod flock;
pub mod frozen;
pub mod fx;
pub mod graph;
pub mod intern;
pub mod jobserver;
pub mod macros;
pub mod marker;
pub mod memmap;
pub mod obligation_forest;
pub mod owned_slice;
pub mod packed;
pub mod profiling;
pub mod sharded;
pub mod sip128;
pub mod small_c_str;
pub mod snapshot_map;
pub mod svh;
pub use ena::snapshot_vec;
pub mod memmap;
pub mod sorted_map;
#[macro_use]
pub mod sso;
pub mod stable_hasher;
mod atomic_ref;
pub mod fingerprint;
pub mod marker;
pub mod profiling;
pub mod sharded;
pub mod stack;
pub mod sync;
pub mod tiny_list;
pub mod transitive_relation;
pub mod vec_linked_list;
pub mod work_queue;
pub use atomic_ref::AtomicRef;
pub mod aligned;
pub mod frozen;
mod hashes;
pub mod owned_slice;
pub mod packed;
pub mod sso;
pub mod steal;
pub mod svh;
pub mod sync;
pub mod tagged_ptr;
pub mod temp_dir;
pub mod transitive_relation;
pub mod unhash;
pub mod unord;
pub mod work_queue;

pub use ena::undo_log;
pub use ena::unify;
mod atomic_ref;
mod hashes;

/// This calls the passed function while ensuring it won't be inlined into the caller.
#[inline(never)]
#[cold]
pub fn outline<F: FnOnce() -> R, R>(f: F) -> R {
f()
}

/// Returns a structure that calls `f` when dropped.
pub fn defer<F: FnOnce()>(f: F) -> OnDrop<F> {
Expand Down
37 changes: 0 additions & 37 deletions compiler/rustc_data_structures/src/macros.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@
//! aren't needed anymore.

use crate::fx::{FxHashMap, FxHashSet};

use std::cell::Cell;
use std::collections::hash_map::Entry;
use std::fmt::Debug;
use std::hash;
use std::marker::PhantomData;
use tracing::debug;

mod graphviz;

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_data_structures/src/packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::cmp::Ordering;
use std::fmt;

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

impl Pu128 {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub use measureme::EventId;
use measureme::{EventIdBuilder, Profiler, SerializableString, StringId};
use parking_lot::RwLock;
use smallvec::SmallVec;
use tracing::warn;

bitflags::bitflags! {
#[derive(Clone, Copy)]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_data_structures/src/stable_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ macro_rules! impl_stable_traits_for_trivial_type {
};
}

pub(crate) use impl_stable_traits_for_trivial_type;

impl_stable_traits_for_trivial_type!(i8);
impl_stable_traits_for_trivial_type!(i16);
impl_stable_traits_for_trivial_type!(i32);
Expand Down
80 changes: 0 additions & 80 deletions compiler/rustc_data_structures/src/tiny_list.rs

This file was deleted.

Loading
Loading