Skip to content
Open
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
54 changes: 27 additions & 27 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::range::{RangeFrom, RangeInclusive, RangeToInclusive};
use std::{cmp, iter};

use rustc_hashes::Hash64;
use rustc_index::Idx;
use rustc_index::bit_set::BitMatrix;
use rustc_index::{Idx, StableIdx};
use tracing::{debug, trace};

use crate::{
Expand Down Expand Up @@ -88,8 +88,8 @@ rustc_index::newtype_index! {
// for non-ZST uninhabited data (mostly partial initialization).
fn absent<'a, FieldIdx, VariantIdx, F>(fields: &IndexSlice<FieldIdx, F>) -> bool
where
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug,
{
let uninhabited = fields.iter().any(|f| f.is_uninhabited());
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
Self { cx }
}

pub fn array_like<FieldIdx: Idx, VariantIdx: Idx, F>(
pub fn array_like<FieldIdx: StableIdx, VariantIdx: Idx, F>(
&self,
element: &LayoutData<FieldIdx, VariantIdx>,
count_if_sized: Option<u64>, // None for slices
Expand Down Expand Up @@ -208,8 +208,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
number_of_vectors: NumScalableVectors,
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F>
where
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: AsRef<LayoutData<FieldIdx, VariantIdx>> + fmt::Debug,
{
vector_type_layout(
Expand All @@ -227,8 +227,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
repr_packed: bool,
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F>
where
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: AsRef<LayoutData<FieldIdx, VariantIdx>> + fmt::Debug,
{
let kind = if repr_packed { SimdVectorKind::PackedFixed } else { SimdVectorKind::Fixed };
Expand All @@ -242,9 +242,9 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
pub fn coroutine<
'a,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
VariantIdx: Idx,
FieldIdx: Idx,
LocalIdx: Idx,
VariantIdx: StableIdx,
FieldIdx: StableIdx,
LocalIdx: StableIdx,
>(
&self,
local_layouts: &IndexSlice<LocalIdx, F>,
Expand All @@ -265,8 +265,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {

pub fn univariant<
'a,
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
>(
&self,
Expand Down Expand Up @@ -340,8 +340,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {

pub fn layout_of_struct_or_enum<
'a,
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
>(
&self,
Expand Down Expand Up @@ -394,8 +394,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {

pub fn layout_of_union<
'a,
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
>(
&self,
Expand Down Expand Up @@ -522,8 +522,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
/// single-variant enums are just structs, if you think about it
fn layout_of_struct<
'a,
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
>(
&self,
Expand Down Expand Up @@ -575,8 +575,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {

fn layout_of_enum<
'a,
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
>(
&self,
Expand Down Expand Up @@ -1080,8 +1080,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {

fn univariant_biased<
'a,
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
>(
&self,
Expand Down Expand Up @@ -1426,8 +1426,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {

fn format_field_niches<
'a,
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug,
>(
&self,
Expand Down Expand Up @@ -1472,8 +1472,8 @@ fn vector_type_layout<FieldIdx, VariantIdx, F>(
count: u64,
) -> LayoutCalculatorResult<FieldIdx, VariantIdx, F>
where
FieldIdx: Idx,
VariantIdx: Idx,
FieldIdx: StableIdx,
VariantIdx: StableIdx,
F: AsRef<LayoutData<FieldIdx, VariantIdx>> + fmt::Debug,
{
let elt = element.as_ref();
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_abi/src/layout/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use std::iter;

use rustc_index::bit_set::{BitMatrix, DenseBitSet};
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_index::{IndexSlice, IndexVec, StableIdx};
use tracing::{debug, trace};

use crate::{
Expand All @@ -39,7 +39,11 @@ enum SavedLocalEligibility<VariantIdx, FieldIdx> {
}

/// Compute the eligibility and assignment of each local.
fn coroutine_saved_local_eligibility<VariantIdx: Idx, FieldIdx: Idx, LocalIdx: Idx>(
fn coroutine_saved_local_eligibility<
VariantIdx: StableIdx,
FieldIdx: StableIdx,
LocalIdx: StableIdx,
>(
nb_locals: usize,
variant_fields: &IndexSlice<VariantIdx, IndexVec<FieldIdx, LocalIdx>>,
storage_conflicts: &BitMatrix<LocalIdx, LocalIdx>,
Expand Down Expand Up @@ -139,9 +143,9 @@ fn coroutine_saved_local_eligibility<VariantIdx: Idx, FieldIdx: Idx, LocalIdx: I
pub(super) fn layout<
'a,
F: core::ops::Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + core::fmt::Debug + Copy,
VariantIdx: Idx,
FieldIdx: Idx,
LocalIdx: Idx,
VariantIdx: StableIdx,
FieldIdx: StableIdx,
LocalIdx: StableIdx,
>(
calc: &super::LayoutCalculator<impl HasDataLayout>,
local_layouts: &IndexSlice<LocalIdx, F>,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ fn index_ast<'tcx>(
let index = indexer.index;
let resolver = Arc::new(resolver);
return tcx.arena.alloc_index_slice_from_iter::<LocalDefId, _, _>(
index.into_iter().map(|owner| Steal::new((Arc::clone(&resolver), owner))),
// Using `unstable_into_iter` is fine here, since `index` was assigned deterministically here
index.unstable_into_iter().map(|owner| Steal::new((Arc::clone(&resolver), owner))),
);

struct Indexer<'s, 'hir> {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
}

rustc_index::newtype_index! {
#[orderable]
#[debug_format = "OutlivesConstraintIndex({})"]
pub(crate) struct OutlivesConstraintIndex {}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/graph/dominators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//! Thomas Lengauer and Robert Endre Tarjan.
//! <https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf>

use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_index::{Idx, IndexSlice, IndexVec, StableIdx};

use super::ControlFlowGraph;

Expand Down Expand Up @@ -414,7 +414,7 @@ struct Time {
finish: u32,
}

fn compute_access_time<N: Idx>(
fn compute_access_time<N: StableIdx>(
start_node: N,
immediate_dominators: &IndexSlice<N, Option<N>>,
) -> IndexVec<N, Time> {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_data_structures/src/graph/linked_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use std::fmt::Debug;

use rustc_index::bit_set::DenseBitSet;
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_index::{Idx, IndexSlice, IndexVec, StableIdx};
use tracing::debug;

#[cfg(test)]
Expand Down Expand Up @@ -100,6 +100,8 @@ impl Idx for NodeIndex {
}
}

impl StableIdx for NodeIndex {}

impl<N: Debug, E: Debug> LinkedGraph<N, E> {
pub fn new() -> Self {
Self { nodes: IndexVec::new(), edges: Vec::new() }
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_data_structures/src/graph/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_index::Idx;
use rustc_index::{Idx, StableIdx};

pub mod dominators;
pub mod iterate;
Expand All @@ -12,7 +12,7 @@ pub mod vec_graph;
mod tests;

pub trait DirectedGraph {
type Node: Idx;
type Node: StableIdx;

/// Returns the total number of nodes in this graph.
///
Expand Down
24 changes: 12 additions & 12 deletions compiler/rustc_data_structures/src/graph/scc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::fmt::Debug;
use std::marker::PhantomData;
use std::ops::Range;

use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_index::{IndexSlice, IndexVec, StableIdx};
use tracing::{debug, instrument, trace};

use crate::fx::FxHashSet;
Expand Down Expand Up @@ -42,18 +42,18 @@ pub trait Annotation: Debug + Copy {
}

/// An accumulator for annotations.
pub trait Annotations<N: Idx> {
pub trait Annotations<N: StableIdx> {
type Ann: Annotation;
type SccIdx: Idx + Ord;
type SccIdx: StableIdx + Ord;

fn new(&self, element: N) -> Self::Ann;
fn annotate_scc(&mut self, scc: Self::SccIdx, annotation: Self::Ann);
}

/// The nil annotation accumulator, which does nothing.
struct NoAnnotations<S: Idx + Ord>(PhantomData<S>);
struct NoAnnotations<S: StableIdx + Ord>(PhantomData<S>);

impl<N: Idx, S: Idx + Ord> Annotations<N> for NoAnnotations<S> {
impl<N: StableIdx, S: StableIdx + Ord> Annotations<N> for NoAnnotations<S> {
type SccIdx = S;
type Ann = ();
fn new(&self, _element: N) {}
Expand All @@ -70,7 +70,7 @@ impl Annotation for () {
/// the index type for the graph nodes and `S` is the index type for
/// the SCCs. We can map from each node to the SCC that it
/// participates in, and we also have the successors of each SCC.
pub struct Sccs<N: Idx, S: Idx> {
pub struct Sccs<N: StableIdx, S: StableIdx> {
/// For each node, what is the SCC index of the SCC to which it
/// belongs.
scc_indices: IndexVec<N, S>,
Expand All @@ -92,7 +92,7 @@ struct SccDetails {
// is difficult when it's publicly inspectable.
//
// Obey the law of Demeter!
struct SccData<S: Idx> {
struct SccData<S: StableIdx> {
/// Maps SCC indices to their metadata, including
/// offsets into `all_successors`.
scc_details: IndexVec<S, SccDetails>,
Expand All @@ -103,7 +103,7 @@ struct SccData<S: Idx> {
all_successors: Vec<S>,
}

impl<N: Idx, S: Idx + Ord> Sccs<N, S> {
impl<N: StableIdx, S: StableIdx + Ord> Sccs<N, S> {
/// Compute SCCs without annotations.
pub fn new(graph: &impl Successors<Node = N>) -> Self {
Self::new_with_annotation(graph, &mut NoAnnotations(PhantomData::<S>))
Expand Down Expand Up @@ -159,27 +159,27 @@ impl<N: Idx, S: Idx + Ord> Sccs<N, S> {
}
}

impl<N: Idx, S: Idx + Ord> DirectedGraph for Sccs<N, S> {
impl<N: StableIdx, S: StableIdx + Ord> DirectedGraph for Sccs<N, S> {
type Node = S;

fn num_nodes(&self) -> usize {
self.num_sccs()
}
}

impl<N: Idx, S: Idx + Ord> NumEdges for Sccs<N, S> {
impl<N: StableIdx, S: StableIdx + Ord> NumEdges for Sccs<N, S> {
fn num_edges(&self) -> usize {
self.scc_data.all_successors.len()
}
}

impl<N: Idx, S: Idx + Ord> Successors for Sccs<N, S> {
impl<N: StableIdx, S: StableIdx + Ord> Successors for Sccs<N, S> {
fn successors(&self, node: S) -> impl Iterator<Item = Self::Node> {
self.successors(node).iter().cloned()
}
}

impl<S: Idx> SccData<S> {
impl<S: StableIdx> SccData<S> {
/// Number of SCCs,
fn len(&self) -> usize {
self.scc_details.len()
Expand Down
Loading
Loading