Auto merge of #110778 - JohnTitor:rollup-7f51qwk, r=JohnTitor

Rollup of 10 pull requests

Successful merges:

 - #110480 (Add `known-bug` tests for 11 unsound issues)
 - #110539 (Move around `{Idx, IndexVec, IndexSlice}` adjacent code)
 - #110590 (Add some tests around (lack of) object safety of associated types and consts)
 - #110602 (Ignore src/bootstrap formatting commit in .git-blame-ignore-revs)
 - #110667 (pointer-auth-link-with-c: Fix cross compilation.)
 - #110681 (drop few unused crates, gate libc under unix for rustc_codegen_ssa)
 - #110685 (Some cleanups to DataflowConstProp)
 - #110744 (bootstrap: update paths cargo-credential crate)
 - #110750 (Add size asserts for MIR `SourceScopeData` & `VarDebugInfo`)
 - #110760 (rustdoc: Add regression test for #60522)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-04-24 19:09:19 +00:00
commit 521de433f4
196 changed files with 1159 additions and 648 deletions

View File

@ -12,3 +12,5 @@ a06baa56b95674fc626b3c3fd680d6a65357fe60
c34fbfaad38cf5829ef5cfe780dc9d58480adeaa c34fbfaad38cf5829ef5cfe780dc9d58480adeaa
# move tests # move tests
cf2dff2b1e3fa55fa5415d524200070d0d7aacfe cf2dff2b1e3fa55fa5415d524200070d0d7aacfe
# Run rustfmt on bootstrap
b39a1d6f1a30ba29f25d7141038b9a5bf0126e36

View File

@ -3209,7 +3209,6 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"smallvec", "smallvec",
"tempfile",
"tracing", "tracing",
] ]
@ -3303,7 +3302,6 @@ dependencies = [
"rustc_macros", "rustc_macros",
"rustc_serialize", "rustc_serialize",
"smallvec", "smallvec",
"stable_deref_trait",
"stacker", "stacker",
"tempfile", "tempfile",
"thin-vec", "thin-vec",
@ -3516,7 +3514,6 @@ dependencies = [
"rustc_trait_selection", "rustc_trait_selection",
"rustc_type_ir", "rustc_type_ir",
"smallvec", "smallvec",
"thin-vec",
"tracing", "tracing",
] ]
@ -3653,7 +3650,6 @@ dependencies = [
"rustc_trait_selection", "rustc_trait_selection",
"rustc_traits", "rustc_traits",
"rustc_ty_utils", "rustc_ty_utils",
"smallvec",
"tracing", "tracing",
] ]
@ -3761,7 +3757,6 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"rustc_type_ir", "rustc_type_ir",
"smallvec",
"snap", "snap",
"tempfile", "tempfile",
"tracing", "tracing",
@ -3891,7 +3886,6 @@ dependencies = [
"rustc_target", "rustc_target",
"serde", "serde",
"serde_json", "serde_json",
"smallvec",
"tracing", "tracing",
] ]
@ -4010,7 +4004,6 @@ version = "0.0.0"
dependencies = [ dependencies = [
"parking_lot 0.11.2", "parking_lot 0.11.2",
"rustc-rayon-core", "rustc-rayon-core",
"rustc_arena",
"rustc_ast", "rustc_ast",
"rustc_data_structures", "rustc_data_structures",
"rustc_errors", "rustc_errors",
@ -4080,7 +4073,6 @@ dependencies = [
"rustc_fluent_macro", "rustc_fluent_macro",
"rustc_fs_util", "rustc_fs_util",
"rustc_hir", "rustc_hir",
"rustc_index",
"rustc_lint_defs", "rustc_lint_defs",
"rustc_macros", "rustc_macros",
"rustc_serialize", "rustc_serialize",
@ -4149,7 +4141,6 @@ dependencies = [
"rustc_data_structures", "rustc_data_structures",
"rustc_feature", "rustc_feature",
"rustc_fs_util", "rustc_fs_util",
"rustc_index",
"rustc_macros", "rustc_macros",
"rustc_serialize", "rustc_serialize",
"rustc_span", "rustc_span",
@ -4167,7 +4158,6 @@ checksum = "8ba09476327c4b70ccefb6180f046ef588c26a24cf5d269a9feba316eb4f029f"
name = "rustc_trait_selection" name = "rustc_trait_selection"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"itertools",
"rustc_ast", "rustc_ast",
"rustc_attr", "rustc_attr",
"rustc_data_structures", "rustc_data_structures",
@ -4199,7 +4189,6 @@ dependencies = [
"rustc_ast", "rustc_ast",
"rustc_data_structures", "rustc_data_structures",
"rustc_hir", "rustc_hir",
"rustc_index",
"rustc_infer", "rustc_infer",
"rustc_middle", "rustc_middle",
"rustc_span", "rustc_span",

View File

@ -12,7 +12,7 @@ use rustc_data_structures::intern::Interned;
use rustc_data_structures::stable_hasher::Hash64; use rustc_data_structures::stable_hasher::Hash64;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use rustc_data_structures::stable_hasher::StableOrd; use rustc_data_structures::stable_hasher::StableOrd;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use rustc_macros::HashStable_Generic; use rustc_macros::HashStable_Generic;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]

View File

@ -5,7 +5,7 @@ use rustc_hir::def_id::LocalDefId;
use rustc_hir::definitions; use rustc_hir::definitions;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::*; use rustc_hir::*;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;

View File

@ -12,7 +12,7 @@ use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_hir::PredicateOrigin; use rustc_hir::PredicateOrigin;
use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_middle::ty::{ResolverAstLowering, TyCtxt}; use rustc_middle::ty::{ResolverAstLowering, TyCtxt};
use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::source_map::DesugaringKind; use rustc_span::source_map::DesugaringKind;

View File

@ -61,7 +61,7 @@ use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
use rustc_hir::definitions::DefPathData; use rustc_hir::definitions::DefPathData;
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate}; use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_middle::{ use rustc_middle::{
span_bug, span_bug,
ty::{ResolverAstLowering, TyCtxt}, ty::{ResolverAstLowering, TyCtxt},

View File

@ -1,5 +1,5 @@
use rustc_data_structures::graph; use rustc_data_structures::graph;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::mir::ConstraintCategory; use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use rustc_middle::ty::{RegionVid, VarianceDiagInfo};
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;

View File

@ -2,7 +2,7 @@
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use rustc_data_structures::graph::scc::Sccs; use rustc_data_structures::graph::scc::Sccs;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::mir::ConstraintCategory; use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use rustc_middle::ty::{RegionVid, VarianceDiagInfo};
use rustc_span::Span; use rustc_span::Span;

View File

@ -3,7 +3,7 @@
//! This file provides API for compiler consumers. //! This file provides API for compiler consumers.
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_index::vec::IndexSlice; use rustc_index::IndexSlice;
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt}; use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
use rustc_middle::mir::Body; use rustc_middle::mir::Body;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;

View File

@ -3,7 +3,7 @@
use rustc_errors::{Applicability, Diagnostic}; use rustc_errors::{Applicability, Diagnostic};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_index::vec::IndexSlice; use rustc_index::IndexSlice;
use rustc_infer::infer::NllRegionVariableOrigin; use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::{ use rustc_middle::mir::{
Body, CastKind, ConstraintCategory, FakeReadCause, Local, LocalInfo, Location, Operand, Place, Body, CastKind, ConstraintCategory, FakeReadCause, Local, LocalInfo, Location, Operand, Place,

View File

@ -9,7 +9,7 @@ use rustc_errors::{Applicability, Diagnostic};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorKind, Namespace}; use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::GeneratorKind; use rustc_hir::GeneratorKind;
use rustc_index::vec::IndexSlice; use rustc_index::IndexSlice;
use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_infer::infer::LateBoundRegionConversionTime;
use rustc_middle::mir::tcx::PlaceTy; use rustc_middle::mir::tcx::PlaceTy;
use rustc_middle::mir::{ use rustc_middle::mir::{

View File

@ -3,7 +3,7 @@
use crate::region_infer::RegionInferenceContext; use crate::region_infer::RegionInferenceContext;
use crate::Upvar; use crate::Upvar;
use rustc_index::vec::IndexSlice; use rustc_index::IndexSlice;
use rustc_middle::mir::{Body, Local}; use rustc_middle::mir::{Body, Local};
use rustc_middle::ty::{RegionVid, TyCtxt}; use rustc_middle::ty::{RegionVid, TyCtxt};
use rustc_span::source_map::Span; use rustc_span::source_map::Span;

View File

@ -24,7 +24,7 @@ use rustc_fluent_macro::fluent_messages;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_index::bit_set::ChunkedBitSet; use rustc_index::bit_set::ChunkedBitSet;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_infer::infer::{ use rustc_infer::infer::{
DefiningAnchor, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt, DefiningAnchor, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
}; };

View File

@ -1,6 +1,6 @@
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::mir::{BasicBlock, Body, Location}; use rustc_middle::mir::{BasicBlock, Body, Location};
/// Maps between a MIR Location, which identifies a particular /// Maps between a MIR Location, which identifies a particular

View File

@ -2,7 +2,7 @@
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::infer::MemberConstraint; use rustc_middle::infer::MemberConstraint;
use rustc_middle::ty::{self, Ty}; use rustc_middle::ty::{self, Ty};
use rustc_span::Span; use rustc_span::Span;

View File

@ -4,7 +4,7 @@
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_index::vec::IndexSlice; use rustc_index::IndexSlice;
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere}; use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
use rustc_middle::mir::{ use rustc_middle::mir::{
Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, Promoted, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, Promoted,

View File

@ -7,7 +7,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::graph::scc::Sccs; use rustc_data_structures::graph::scc::Sccs;
use rustc_errors::Diagnostic; use rustc_errors::Diagnostic;
use rustc_hir::def_id::CRATE_DEF_ID; use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_infer::infer::outlives::test_type_match; use rustc_infer::infer::outlives::test_type_match;
use rustc_infer::infer::region_constraints::{GenericKind, VarInfos, VerifyBound, VerifyIfEq}; use rustc_infer::infer::region_constraints::{GenericKind, VarInfos, VerifyBound, VerifyIfEq};
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin}; use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin};

View File

@ -4,8 +4,8 @@ use rustc_data_structures::fx::FxIndexSet;
use rustc_index::bit_set::SparseBitMatrix; use rustc_index::bit_set::SparseBitMatrix;
use rustc_index::interval::IntervalSet; use rustc_index::interval::IntervalSet;
use rustc_index::interval::SparseIntervalMatrix; use rustc_index::interval::SparseIntervalMatrix;
use rustc_index::vec::Idx; use rustc_index::Idx;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::mir::{BasicBlock, Body, Location}; use rustc_middle::mir::{BasicBlock, Body, Location};
use rustc_middle::ty::{self, RegionVid}; use rustc_middle::ty::{self, RegionVid};
use std::fmt::Debug; use std::fmt::Debug;

View File

@ -1,7 +1,7 @@
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
use crate::BorrowckInferCtxt; use crate::BorrowckInferCtxt;
use rustc_index::vec::IndexSlice; use rustc_index::IndexSlice;
use rustc_infer::infer::NllRegionVariableOrigin; use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::visit::{MutVisitor, TyContext}; use rustc_middle::mir::visit::{MutVisitor, TyContext};
use rustc_middle::mir::Constant; use rustc_middle::mir::Constant;

View File

@ -1,5 +1,5 @@
use rustc_data_structures::vec_linked_list as vll; use rustc_data_structures::vec_linked_list as vll;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{Body, Local, Location}; use rustc_middle::mir::{Body, Local, Location};

View File

@ -14,7 +14,7 @@ use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_infer::infer::canonical::QueryRegionConstraints; use rustc_infer::infer::canonical::QueryRegionConstraints;
use rustc_infer::infer::outlives::env::RegionBoundPairs; use rustc_infer::infer::outlives::env::RegionBoundPairs;
use rustc_infer::infer::region_constraints::RegionConstraintData; use rustc_infer::infer::region_constraints::RegionConstraintData;

View File

@ -19,7 +19,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::BodyOwnerKind; use rustc_hir::BodyOwnerKind;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_infer::infer::NllRegionVariableOrigin; use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt}; use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt};

View File

@ -9,7 +9,7 @@ use smallvec::{smallvec, SmallVec};
/// this adds an extra parameter pointing to where the return value needs to be stored. /// this adds an extra parameter pointing to where the return value needs to be stored.
pub(super) fn codegen_return_param<'tcx>( pub(super) fn codegen_return_param<'tcx>(
fx: &mut FunctionCx<'_, '_, 'tcx>, fx: &mut FunctionCx<'_, '_, 'tcx>,
ssa_analyzed: &rustc_index::vec::IndexVec<Local, crate::analyze::SsaKind>, ssa_analyzed: &rustc_index::IndexSlice<Local, crate::analyze::SsaKind>,
block_params_iter: &mut impl Iterator<Item = Value>, block_params_iter: &mut impl Iterator<Item = Value>,
) -> CPlace<'tcx> { ) -> CPlace<'tcx> {
let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode { let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode {

View File

@ -2,7 +2,7 @@
use crate::prelude::*; use crate::prelude::*;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::mir::StatementKind::*; use rustc_middle::mir::StatementKind::*;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;

View File

@ -1,7 +1,7 @@
//! Codegen of a single function //! Codegen of a single function
use rustc_ast::InlineAsmOptions; use rustc_ast::InlineAsmOptions;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::adjustment::PointerCast;
use rustc_middle::ty::layout::FnAbiOf; use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;

View File

@ -2,7 +2,7 @@ use cranelift_codegen::isa::TargetFrontendConfig;
use gimli::write::FileId; use gimli::write::FileId;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::ty::layout::{ use rustc_middle::ty::layout::{
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers,
}; };

View File

@ -90,7 +90,7 @@ mod prelude {
pub(crate) use rustc_data_structures::fx::FxHashMap; pub(crate) use rustc_data_structures::fx::FxHashMap;
pub(crate) use rustc_index::vec::Idx; pub(crate) use rustc_index::Idx;
pub(crate) use cranelift_codegen::ir::condcodes::{FloatCC, IntCC}; pub(crate) use cranelift_codegen::ir::condcodes::{FloatCC, IntCC};
pub(crate) use cranelift_codegen::ir::function::Function; pub(crate) use cranelift_codegen::ir::function::Function;

View File

@ -36,6 +36,5 @@ rustc_target = { path = "../rustc_target" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
rustc_ast = { path = "../rustc_ast" } rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
tempfile = "3.2.0"
serde = { version = "1", features = [ "derive" ]} serde = { version = "1", features = [ "derive" ]}
serde_json = "1" serde_json = "1"

View File

@ -12,7 +12,7 @@ use rustc_middle::ty::{self, Instance};
use rustc_session::config::DebugInfo; use rustc_session::config::DebugInfo;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::Idx; use rustc_index::Idx;
/// Produces DIScope DIEs for each MIR Scope which has variables defined in it. /// Produces DIScope DIEs for each MIR Scope which has variables defined in it.
// FIXME(eddyb) almost all of this should be in `rustc_codegen_ssa::mir::debuginfo`. // FIXME(eddyb) almost all of this should be in `rustc_codegen_ssa::mir::debuginfo`.

View File

@ -6,7 +6,7 @@ use rustc_codegen_ssa::{
traits::ConstMethods, traits::ConstMethods,
}; };
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::{ use rustc_middle::{
bug, bug,
ty::{ ty::{

View File

@ -3,7 +3,7 @@ use rustc_codegen_ssa::debuginfo::{
wants_c_like_enum_debuginfo, wants_c_like_enum_debuginfo,
}; };
use rustc_hir::def::CtorKind; use rustc_hir::def::CtorKind;
use rustc_index::vec::IndexSlice; use rustc_index::IndexSlice;
use rustc_middle::{ use rustc_middle::{
bug, bug,
mir::{GeneratorLayout, GeneratorSavedLocal}, mir::{GeneratorLayout, GeneratorSavedLocal},

View File

@ -24,7 +24,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::Hash128; use rustc_data_structures::stable_hasher::Hash128;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_hir::def_id::{DefId, DefIdMap}; use rustc_hir::def_id::{DefId, DefIdMap};
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::subst::SubstsRef;

View File

@ -12,7 +12,6 @@ bitflags = "1.2.1"
cc = "1.0.69" cc = "1.0.69"
itertools = "0.10.1" itertools = "0.10.1"
tracing = "0.1" tracing = "0.1"
libc = "0.2.50"
jobserver = "0.1.22" jobserver = "0.1.22"
tempfile = "3.2" tempfile = "3.2"
thorin-dwp = "0.4" thorin-dwp = "0.4"
@ -43,6 +42,9 @@ rustc_query_system = { path = "../rustc_query_system" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
[target.'cfg(unix)'.dependencies]
libc = "0.2.50"
[dependencies.object] [dependencies.object]
version = "0.30.1" version = "0.30.1"
default-features = false default-features = false

View File

@ -1,6 +1,6 @@
pub use super::ffi::*; pub use super::ffi::*;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::mir::coverage::{ use rustc_middle::mir::coverage::{
CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId, CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId,
InjectedExpressionIndex, MappedExpressionIndex, Op, InjectedExpressionIndex, MappedExpressionIndex, Op,

View File

@ -5,7 +5,7 @@ use super::FunctionCx;
use crate::traits::*; use crate::traits::*;
use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::graph::dominators::Dominators;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::mir::traversal; use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::{self, Location, TerminatorKind}; use rustc_middle::mir::{self, Location, TerminatorKind};

View File

@ -1,5 +1,5 @@
use crate::traits::*; use crate::traits::*;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty; use rustc_middle::ty;

View File

@ -9,7 +9,7 @@ use rustc_target::abi::call::{FnAbi, PassMode};
use std::iter; use std::iter;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use self::debuginfo::{FunctionDebugContext, PerLocalVarDebugInfo}; use self::debuginfo::{FunctionDebugContext, PerLocalVarDebugInfo};
use self::place::PlaceRef; use self::place::PlaceRef;

View File

@ -5,7 +5,7 @@ use std::mem;
use either::{Either, Left, Right}; use either::{Either, Left, Right};
use rustc_hir::{self as hir, def_id::DefId, definitions::DefPathData}; use rustc_hir::{self as hir, def_id::DefId, definitions::DefPathData};
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::mir::interpret::{ErrorHandled, InterpError}; use rustc_middle::mir::interpret::{ErrorHandled, InterpError};
use rustc_middle::ty::layout::{ use rustc_middle::ty::layout::{

View File

@ -5,7 +5,7 @@
use either::{Either, Left, Right}; use either::{Either, Left, Right};
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_index::vec::IndexSlice; use rustc_index::IndexSlice;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty; use rustc_middle::ty;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout}; use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};

View File

@ -21,7 +21,7 @@ use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::{self, List, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, List, TyCtxt, TypeVisitableExt};
use rustc_span::Span; use rustc_span::Span;
use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use std::cell::Cell; use std::cell::Cell;
use std::{cmp, iter, mem}; use std::{cmp, iter, mem};

View File

@ -2,7 +2,7 @@
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_infer::traits::Reveal; use rustc_infer::traits::Reveal;
use rustc_middle::mir::interpret::Scalar; use rustc_middle::mir::interpret::Scalar;
use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor}; use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor};

View File

@ -26,7 +26,6 @@ smallvec = { version = "1.8.1", features = [
"union", "union",
"may_dangle", "may_dangle",
] } ] }
stable_deref_trait = "1.0.0"
stacker = "0.1.15" stacker = "0.1.15"
tempfile = "3.2" tempfile = "3.2"
thin-vec = "0.2.12" thin-vec = "0.2.12"

View File

@ -1,4 +1,4 @@
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use std::{mem, rc::Rc, sync::Arc}; use std::{mem, rc::Rc, sync::Arc};
pub trait IdFunctor: Sized { pub trait IdFunctor: Sized {

View File

@ -10,7 +10,8 @@
//! <https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf> //! <https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf>
use super::ControlFlowGraph; use super::ControlFlowGraph;
use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use std::cmp::Ordering; use std::cmp::Ordering;
#[cfg(test)] #[cfg(test)]

View File

@ -1,6 +1,6 @@
use super::{DirectedGraph, WithNumNodes, WithStartNode, WithSuccessors}; use super::{DirectedGraph, WithNumNodes, WithStartNode, WithSuccessors};
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use std::ops::ControlFlow; use std::ops::ControlFlow;
#[cfg(test)] #[cfg(test)]

View File

@ -1,4 +1,4 @@
use rustc_index::vec::Idx; use rustc_index::Idx;
pub mod dominators; pub mod dominators;
pub mod implementation; pub mod implementation;

View File

@ -8,7 +8,7 @@
use crate::fx::FxHashSet; use crate::fx::FxHashSet;
use crate::graph::vec_graph::VecGraph; use crate::graph::vec_graph::VecGraph;
use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors}; use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors};
use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use std::ops::Range; use std::ops::Range;
#[cfg(test)] #[cfg(test)]

View File

@ -1,5 +1,5 @@
use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors}; use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View File

@ -3,7 +3,7 @@
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use crate::stable_hasher::{HashStable, StableHasher}; use crate::stable_hasher::{HashStable, StableHasher};
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
/// An indexed multi-map that preserves insertion order while permitting both *O*(log *n*) lookup of /// An indexed multi-map that preserves insertion order while permitting both *O*(log *n*) lookup of
/// an item by key and *O*(1) lookup by index. /// an item by key and *O*(1) lookup by index.

View File

@ -1,6 +1,6 @@
use crate::sip128::SipHasher128; use crate::sip128::SipHasher128;
use rustc_index::bit_set; use rustc_index::bit_set::{self, BitSet};
use rustc_index::vec; use rustc_index::{Idx, IndexVec};
use smallvec::SmallVec; use smallvec::SmallVec;
use std::fmt; use std::fmt;
use std::hash::{BuildHasher, Hash, Hasher}; use std::hash::{BuildHasher, Hash, Hasher};
@ -557,7 +557,7 @@ where
} }
} }
impl<I: vec::Idx, T, CTX> HashStable<CTX> for vec::IndexVec<I, T> impl<I: Idx, T, CTX> HashStable<CTX> for IndexVec<I, T>
where where
T: HashStable<CTX>, T: HashStable<CTX>,
{ {
@ -569,13 +569,13 @@ where
} }
} }
impl<I: vec::Idx, CTX> HashStable<CTX> for bit_set::BitSet<I> { impl<I: Idx, CTX> HashStable<CTX> for BitSet<I> {
fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher) { fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher) {
::std::hash::Hash::hash(self, hasher); ::std::hash::Hash::hash(self, hasher);
} }
} }
impl<R: vec::Idx, C: vec::Idx, CTX> HashStable<CTX> for bit_set::BitMatrix<R, C> { impl<R: Idx, C: Idx, CTX> HashStable<CTX> for bit_set::BitMatrix<R, C> {
fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher) { fn hash_stable(&self, _ctx: &mut CTX, hasher: &mut StableHasher) {
::std::hash::Hash::hash(self, hasher); ::std::hash::Hash::hash(self, hasher);
} }

View File

@ -1,6 +1,6 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use rustc_index::vec::Idx; use rustc_index::Idx;
#[derive(Default)] #[derive(Default)]
pub struct AppendOnlyIndexVec<I: Idx, T: Copy> { pub struct AppendOnlyIndexVec<I: Idx, T: Copy> {

View File

@ -1,4 +1,4 @@
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
pub fn iter<Ls>( pub fn iter<Ls>(
first: Option<Ls::LinkIndex>, first: Option<Ls::LinkIndex>,

View File

@ -1,5 +1,5 @@
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::Idx; use rustc_index::Idx;
use std::collections::VecDeque; use std::collections::VecDeque;
/// A work queue is a handy data structure for tracking work left to /// A work queue is a handy data structure for tracking work left to

View File

@ -10,7 +10,7 @@ use crate::def_path_hash_map::DefPathHashMap;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{Hash64, StableHasher}; use rustc_data_structures::stable_hasher::{Hash64, StableHasher};
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use std::fmt::{self, Write}; use std::fmt::{self, Write};

View File

@ -14,7 +14,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::sorted_map::SortedMap;
use rustc_error_messages::MultiSpan; use rustc_error_messages::MultiSpan;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_macros::HashStable_Generic; use rustc_macros::HashStable_Generic;
use rustc_span::hygiene::MacroKind; use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
@ -863,7 +863,7 @@ pub struct OwnerNodes<'tcx> {
impl<'tcx> OwnerNodes<'tcx> { impl<'tcx> OwnerNodes<'tcx> {
pub fn node(&self) -> OwnerNode<'tcx> { pub fn node(&self) -> OwnerNode<'tcx> {
use rustc_index::vec::Idx; use rustc_index::Idx;
let node = self.nodes[ItemLocalId::new(0)].as_ref().unwrap().node; let node = self.nodes[ItemLocalId::new(0)].as_ref().unwrap().node;
let node = node.as_owner().unwrap(); // Indexing must ensure it is an OwnerNode. let node = node.as_owner().unwrap(); // Indexing must ensure it is an OwnerNode.
node node

View File

@ -35,7 +35,7 @@ impl OwnerId {
} }
} }
impl rustc_index::vec::Idx for OwnerId { impl rustc_index::Idx for OwnerId {
#[inline] #[inline]
fn new(idx: usize) -> Self { fn new(idx: usize) -> Self {
OwnerId { def_id: LocalDefId { local_def_index: DefIndex::from_usize(idx) } } OwnerId { def_id: LocalDefId { local_def_index: DefIndex::from_usize(idx) } }
@ -116,10 +116,7 @@ impl HirId {
} }
pub fn index(self) -> (usize, usize) { pub fn index(self) -> (usize, usize) {
( (rustc_index::Idx::index(self.owner.def_id), rustc_index::Idx::index(self.local_id))
rustc_index::vec::Idx::index(self.owner.def_id),
rustc_index::vec::Idx::index(self.local_id),
)
} }
} }

View File

@ -27,5 +27,4 @@ rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_lint_defs = { path = "../rustc_lint_defs" } rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_type_ir = { path = "../rustc_type_ir" } rustc_type_ir = { path = "../rustc_type_ir" }
rustc_feature = { path = "../rustc_feature" } rustc_feature = { path = "../rustc_feature" }
thin-vec = "0.2.12"
tracing = "0.1" tracing = "0.1"

View File

@ -12,7 +12,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{Arm, Block, Expr, Local, Pat, PatKind, Stmt}; use rustc_hir::{Arm, Block, Expr, Local, Pat, PatKind, Stmt};
use rustc_index::vec::Idx; use rustc_index::Idx;
use rustc_middle::middle::region::*; use rustc_middle::middle::region::*;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_span::source_map; use rustc_span::source_map;

View File

@ -3,7 +3,7 @@ use rustc_errors::struct_span_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::traits::specialization_graph::OverlapMode; use rustc_middle::traits::specialization_graph::OverlapMode;
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_span::Symbol; use rustc_span::Symbol;

View File

@ -1,6 +1,6 @@
use std::cmp; use std::cmp;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
rustc_index::newtype_index! { rustc_index::newtype_index! {

View File

@ -21,7 +21,7 @@ use rustc_hir_analysis::astconv::AstConv;
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt; use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
use rustc_hir_analysis::check::potentially_plural_count; use rustc_hir_analysis::check::potentially_plural_count;
use rustc_hir_analysis::structured_errors::StructuredDiagnostic; use rustc_hir_analysis::structured_errors::StructuredDiagnostic;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt}; use rustc_infer::infer::error_reporting::{FailureCode, ObligationCauseExt};
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::infer::TypeTrace; use rustc_infer::infer::TypeTrace;

View File

@ -8,7 +8,7 @@ use hir::{
}; };
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_infer::infer::InferCtxt; use rustc_infer::infer::InferCtxt;
use rustc_middle::{ use rustc_middle::{
hir::map::Map, hir::map::Map,

View File

@ -1,5 +1,5 @@
use super::{DropRangesBuilder, PostOrderId}; use super::{DropRangesBuilder, PostOrderId};
use rustc_index::{bit_set::BitSet, vec::IndexVec}; use rustc_index::{bit_set::BitSet, IndexVec};
use std::collections::BTreeMap; use std::collections::BTreeMap;
impl DropRangesBuilder { impl DropRangesBuilder {

View File

@ -20,7 +20,7 @@ use hir::{Body, HirId, HirIdMap, Node};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::hir::map::Map; use rustc_middle::hir::map::Map;
use rustc_middle::hir::place::{PlaceBase, PlaceWithHirId}; use rustc_middle::hir::place::{PlaceBase, PlaceWithHirId};
use rustc_middle::ty; use rustc_middle::ty;

View File

@ -1,7 +1,7 @@
use hir::HirId; use hir::HirId;
use rustc_errors::struct_span_err; use rustc_errors::struct_span_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_index::vec::Idx; use rustc_index::Idx;
use rustc_middle::ty::layout::{LayoutError, SizeSkeleton}; use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
use rustc_target::abi::{Pointer, VariantIdx}; use rustc_target::abi::{Pointer, VariantIdx};

View File

@ -1,6 +1,3 @@
use crate::vec::{Idx, IndexVec};
use arrayvec::ArrayVec;
use smallvec::{smallvec, SmallVec};
use std::fmt; use std::fmt;
use std::iter; use std::iter;
use std::marker::PhantomData; use std::marker::PhantomData;
@ -9,8 +6,13 @@ use std::ops::{BitAnd, BitAndAssign, BitOrAssign, Bound, Not, Range, RangeBounds
use std::rc::Rc; use std::rc::Rc;
use std::slice; use std::slice;
use arrayvec::ArrayVec;
use smallvec::{smallvec, SmallVec};
use rustc_macros::{Decodable, Encodable}; use rustc_macros::{Decodable, Encodable};
use crate::{Idx, IndexVec};
use Chunk::*; use Chunk::*;
#[cfg(test)] #[cfg(test)]

View File

@ -0,0 +1,45 @@
use std::fmt::Debug;
use std::hash::Hash;
/// Represents some newtyped `usize` wrapper.
///
/// Purpose: avoid mixing indexes for different bitvector domains.
pub trait Idx: Copy + 'static + Eq + PartialEq + Debug + Hash {
fn new(idx: usize) -> Self;
fn index(self) -> usize;
#[inline]
fn increment_by(&mut self, amount: usize) {
*self = self.plus(amount);
}
#[inline]
#[must_use = "Use `increment_by` if you wanted to update the index in-place"]
fn plus(self, amount: usize) -> Self {
Self::new(self.index() + amount)
}
}
impl Idx for usize {
#[inline]
fn new(idx: usize) -> Self {
idx
}
#[inline]
fn index(self) -> usize {
self
}
}
impl Idx for u32 {
#[inline]
fn new(idx: usize) -> Self {
assert!(idx <= u32::MAX as usize);
idx as u32
}
#[inline]
fn index(self) -> usize {
self as usize
}
}

View File

@ -3,10 +3,11 @@ use std::marker::PhantomData;
use std::ops::RangeBounds; use std::ops::RangeBounds;
use std::ops::{Bound, Range}; use std::ops::{Bound, Range};
use crate::vec::Idx;
use crate::vec::IndexVec;
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::idx::Idx;
use crate::vec::IndexVec;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View File

@ -17,7 +17,12 @@
pub mod bit_set; pub mod bit_set;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
pub mod interval; pub mod interval;
pub mod vec;
mod idx;
mod slice;
mod vec;
pub use {idx::Idx, slice::IndexSlice, vec::IndexVec};
#[cfg(feature = "rustc_macros")] #[cfg(feature = "rustc_macros")]
pub use rustc_macros::newtype_index; pub use rustc_macros::newtype_index;

View File

@ -0,0 +1,256 @@
use std::{
fmt,
marker::PhantomData,
ops::{Index, IndexMut},
slice,
};
use crate::{Idx, IndexVec};
/// A view into contiguous `T`s, indexed by `I` rather than by `usize`.
///
/// One common pattern you'll see is code that uses [`IndexVec::from_elem`]
/// to create the storage needed for a particular "universe" (aka the set of all
/// the possible keys that need an associated value) then passes that working
/// area as `&mut IndexSlice<I, T>` to clarify that nothing will be added nor
/// removed during processing (and, as a bonus, to chase fewer pointers).
#[derive(PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct IndexSlice<I: Idx, T> {
_marker: PhantomData<fn(&I)>,
pub raw: [T],
}
impl<I: Idx, T> IndexSlice<I, T> {
#[inline]
pub const fn empty() -> &'static Self {
Self::from_raw(&[])
}
#[inline]
pub const fn from_raw(raw: &[T]) -> &Self {
let ptr: *const [T] = raw;
// SAFETY: `IndexSlice` is `repr(transparent)` over a normal slice
unsafe { &*(ptr as *const Self) }
}
#[inline]
pub fn from_raw_mut(raw: &mut [T]) -> &mut Self {
let ptr: *mut [T] = raw;
// SAFETY: `IndexSlice` is `repr(transparent)` over a normal slice
unsafe { &mut *(ptr as *mut Self) }
}
#[inline]
pub const fn len(&self) -> usize {
self.raw.len()
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.raw.is_empty()
}
/// Gives the next index that will be assigned when `push` is called.
///
/// Manual bounds checks can be done using `idx < slice.next_index()`
/// (as opposed to `idx.index() < slice.len()`).
#[inline]
pub fn next_index(&self) -> I {
I::new(self.len())
}
#[inline]
pub fn iter(&self) -> slice::Iter<'_, T> {
self.raw.iter()
}
#[inline]
pub fn iter_enumerated(
&self,
) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator + '_ {
self.raw.iter().enumerate().map(|(n, t)| (I::new(n), t))
}
#[inline]
pub fn indices(
&self,
) -> impl DoubleEndedIterator<Item = I> + ExactSizeIterator + Clone + 'static {
(0..self.len()).map(|n| I::new(n))
}
#[inline]
pub fn iter_mut(&mut self) -> slice::IterMut<'_, T> {
self.raw.iter_mut()
}
#[inline]
pub fn iter_enumerated_mut(
&mut self,
) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator + '_ {
self.raw.iter_mut().enumerate().map(|(n, t)| (I::new(n), t))
}
#[inline]
pub fn last_index(&self) -> Option<I> {
self.len().checked_sub(1).map(I::new)
}
#[inline]
pub fn swap(&mut self, a: I, b: I) {
self.raw.swap(a.index(), b.index())
}
#[inline]
pub fn get(&self, index: I) -> Option<&T> {
self.raw.get(index.index())
}
#[inline]
pub fn get_mut(&mut self, index: I) -> Option<&mut T> {
self.raw.get_mut(index.index())
}
/// Returns mutable references to two distinct elements, `a` and `b`.
///
/// Panics if `a == b`.
#[inline]
pub fn pick2_mut(&mut self, a: I, b: I) -> (&mut T, &mut T) {
let (ai, bi) = (a.index(), b.index());
assert!(ai != bi);
if ai < bi {
let (c1, c2) = self.raw.split_at_mut(bi);
(&mut c1[ai], &mut c2[0])
} else {
let (c2, c1) = self.pick2_mut(b, a);
(c1, c2)
}
}
/// Returns mutable references to three distinct elements.
///
/// Panics if the elements are not distinct.
#[inline]
pub fn pick3_mut(&mut self, a: I, b: I, c: I) -> (&mut T, &mut T, &mut T) {
let (ai, bi, ci) = (a.index(), b.index(), c.index());
assert!(ai != bi && bi != ci && ci != ai);
let len = self.raw.len();
assert!(ai < len && bi < len && ci < len);
let ptr = self.raw.as_mut_ptr();
unsafe { (&mut *ptr.add(ai), &mut *ptr.add(bi), &mut *ptr.add(ci)) }
}
#[inline]
pub fn binary_search(&self, value: &T) -> Result<I, I>
where
T: Ord,
{
match self.raw.binary_search(value) {
Ok(i) => Ok(Idx::new(i)),
Err(i) => Err(Idx::new(i)),
}
}
}
impl<I: Idx, J: Idx> IndexSlice<I, J> {
/// Invert a bijective mapping, i.e. `invert(map)[y] = x` if `map[x] = y`,
/// assuming the values in `self` are a permutation of `0..self.len()`.
///
/// This is used to go between `memory_index` (source field order to memory order)
/// and `inverse_memory_index` (memory order to source field order).
/// See also `FieldsShape::Arbitrary::memory_index` for more details.
// FIXME(eddyb) build a better abstraction for permutations, if possible.
pub fn invert_bijective_mapping(&self) -> IndexVec<J, I> {
debug_assert_eq!(
self.iter().map(|x| x.index() as u128).sum::<u128>(),
(0..self.len() as u128).sum::<u128>(),
"The values aren't 0..N in input {self:?}",
);
let mut inverse = IndexVec::from_elem_n(Idx::new(0), self.len());
for (i1, &i2) in self.iter_enumerated() {
inverse[i2] = i1;
}
debug_assert_eq!(
inverse.iter().map(|x| x.index() as u128).sum::<u128>(),
(0..inverse.len() as u128).sum::<u128>(),
"The values aren't 0..N in result {self:?}",
);
inverse
}
}
impl<I: Idx, T: fmt::Debug> fmt::Debug for IndexSlice<I, T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.raw, fmt)
}
}
impl<I: Idx, T> Index<I> for IndexSlice<I, T> {
type Output = T;
#[inline]
fn index(&self, index: I) -> &T {
&self.raw[index.index()]
}
}
impl<I: Idx, T> IndexMut<I> for IndexSlice<I, T> {
#[inline]
fn index_mut(&mut self, index: I) -> &mut T {
&mut self.raw[index.index()]
}
}
impl<'a, I: Idx, T> IntoIterator for &'a IndexSlice<I, T> {
type Item = &'a T;
type IntoIter = slice::Iter<'a, T>;
#[inline]
fn into_iter(self) -> slice::Iter<'a, T> {
self.raw.iter()
}
}
impl<'a, I: Idx, T> IntoIterator for &'a mut IndexSlice<I, T> {
type Item = &'a mut T;
type IntoIter = slice::IterMut<'a, T>;
#[inline]
fn into_iter(self) -> slice::IterMut<'a, T> {
self.raw.iter_mut()
}
}
impl<I: Idx, T: Clone> ToOwned for IndexSlice<I, T> {
type Owned = IndexVec<I, T>;
fn to_owned(&self) -> IndexVec<I, T> {
IndexVec::from_raw(self.raw.to_owned())
}
fn clone_into(&self, target: &mut IndexVec<I, T>) {
self.raw.clone_into(&mut target.raw)
}
}
impl<I: Idx, T> Default for &IndexSlice<I, T> {
#[inline]
fn default() -> Self {
IndexSlice::from_raw(Default::default())
}
}
impl<I: Idx, T> Default for &mut IndexSlice<I, T> {
#[inline]
fn default() -> Self {
IndexSlice::from_raw_mut(Default::default())
}
}
// Whether `IndexSlice` is `Send` depends only on the data,
// not the phantom data.
unsafe impl<I: Idx, T> Send for IndexSlice<I, T> where T: Send {}

View File

@ -3,55 +3,13 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::borrow::{Borrow, BorrowMut}; use std::borrow::{Borrow, BorrowMut};
use std::fmt; use std::fmt;
use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ops::{Deref, DerefMut, Index, IndexMut, RangeBounds}; use std::ops::{Deref, DerefMut, RangeBounds};
use std::slice; use std::slice;
use std::vec; use std::vec;
/// Represents some newtyped `usize` wrapper. use crate::{Idx, IndexSlice};
///
/// Purpose: avoid mixing indexes for different bitvector domains.
pub trait Idx: Copy + 'static + Eq + PartialEq + Debug + Hash {
fn new(idx: usize) -> Self;
fn index(self) -> usize;
#[inline]
fn increment_by(&mut self, amount: usize) {
*self = self.plus(amount);
}
#[inline]
#[must_use = "Use `increment_by` if you wanted to update the index in-place"]
fn plus(self, amount: usize) -> Self {
Self::new(self.index() + amount)
}
}
impl Idx for usize {
#[inline]
fn new(idx: usize) -> Self {
idx
}
#[inline]
fn index(self) -> usize {
self
}
}
impl Idx for u32 {
#[inline]
fn new(idx: usize) -> Self {
assert!(idx <= u32::MAX as usize);
idx as u32
}
#[inline]
fn index(self) -> usize {
self as usize
}
}
/// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`. /// An owned contiguous collection of `T`s, indexed by `I` rather than by `usize`.
/// ///
@ -66,68 +24,20 @@ pub struct IndexVec<I: Idx, T> {
_marker: PhantomData<fn(&I)>, _marker: PhantomData<fn(&I)>,
} }
/// A view into contiguous `T`s, indexed by `I` rather than by `usize`.
///
/// One common pattern you'll see is code that uses [`IndexVec::from_elem`]
/// to create the storage needed for a particular "universe" (aka the set of all
/// the possible keys that need an associated value) then passes that working
/// area as `&mut IndexSlice<I, T>` to clarify that nothing will be added nor
/// removed during processing (and, as a bonus, to chase fewer pointers).
#[derive(PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct IndexSlice<I: Idx, T> {
_marker: PhantomData<fn(&I)>,
pub raw: [T],
}
// Whether `IndexVec` is `Send` depends only on the data,
// not the phantom data.
unsafe impl<I: Idx, T> Send for IndexVec<I, T> where T: Send {}
// Whether `IndexSlice` is `Send` depends only on the data,
// not the phantom data.
unsafe impl<I: Idx, T> Send for IndexSlice<I, T> where T: Send {}
#[cfg(feature = "rustc_serialize")]
impl<S: Encoder, I: Idx, T: Encodable<S>> Encodable<S> for IndexVec<I, T> {
fn encode(&self, s: &mut S) {
Encodable::encode(&self.raw, s);
}
}
#[cfg(feature = "rustc_serialize")]
impl<D: Decoder, I: Idx, T: Decodable<D>> Decodable<D> for IndexVec<I, T> {
fn decode(d: &mut D) -> Self {
IndexVec { raw: Decodable::decode(d), _marker: PhantomData }
}
}
impl<I: Idx, T: fmt::Debug> fmt::Debug for IndexVec<I, T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.raw, fmt)
}
}
impl<I: Idx, T: fmt::Debug> fmt::Debug for IndexSlice<I, T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.raw, fmt)
}
}
impl<I: Idx, T> IndexVec<I, T> { impl<I: Idx, T> IndexVec<I, T> {
#[inline] #[inline]
pub fn new() -> Self { pub const fn new() -> Self {
IndexVec { raw: Vec::new(), _marker: PhantomData } IndexVec::from_raw(Vec::new())
} }
#[inline] #[inline]
pub fn from_raw(raw: Vec<T>) -> Self { pub const fn from_raw(raw: Vec<T>) -> Self {
IndexVec { raw, _marker: PhantomData } IndexVec { raw, _marker: PhantomData }
} }
#[inline] #[inline]
pub fn with_capacity(capacity: usize) -> Self { pub fn with_capacity(capacity: usize) -> Self {
IndexVec { raw: Vec::with_capacity(capacity), _marker: PhantomData } IndexVec::from_raw(Vec::with_capacity(capacity))
} }
/// Creates a new vector with a copy of `elem` for each index in `universe`. /// Creates a new vector with a copy of `elem` for each index in `universe`.
@ -146,7 +56,7 @@ impl<I: Idx, T> IndexVec<I, T> {
where where
T: Clone, T: Clone,
{ {
IndexVec { raw: vec![elem; universe.len()], _marker: PhantomData } IndexVec::from_raw(vec![elem; universe.len()])
} }
#[inline] #[inline]
@ -154,7 +64,7 @@ impl<I: Idx, T> IndexVec<I, T> {
where where
T: Clone, T: Clone,
{ {
IndexVec { raw: vec![elem; n], _marker: PhantomData } IndexVec::from_raw(vec![elem; n])
} }
/// Create an `IndexVec` with `n` elements, where the value of each /// Create an `IndexVec` with `n` elements, where the value of each
@ -162,8 +72,7 @@ impl<I: Idx, T> IndexVec<I, T> {
/// be allocated only once, with a capacity of at least `n`.) /// be allocated only once, with a capacity of at least `n`.)
#[inline] #[inline]
pub fn from_fn_n(func: impl FnMut(I) -> T, n: usize) -> Self { pub fn from_fn_n(func: impl FnMut(I) -> T, n: usize) -> Self {
let indices = (0..n).map(I::new); IndexVec::from_raw((0..n).map(I::new).map(func).collect())
Self::from_raw(indices.map(func).collect())
} }
#[inline] #[inline]
@ -178,7 +87,7 @@ impl<I: Idx, T> IndexVec<I, T> {
#[inline] #[inline]
pub fn push(&mut self, d: T) -> I { pub fn push(&mut self, d: T) -> I {
let idx = I::new(self.len()); let idx = self.next_index();
self.raw.push(d); self.raw.push(d);
idx idx
} }
@ -229,7 +138,7 @@ impl<I: Idx, T> IndexVec<I, T> {
} }
pub fn convert_index_type<Ix: Idx>(self) -> IndexVec<Ix, T> { pub fn convert_index_type<Ix: Idx>(self) -> IndexVec<Ix, T> {
IndexVec { raw: self.raw, _marker: PhantomData } IndexVec::from_raw(self.raw)
} }
/// Grows the index vector so that it contains an entry for /// Grows the index vector so that it contains an entry for
@ -248,6 +157,14 @@ impl<I: Idx, T> IndexVec<I, T> {
&mut self[elem] &mut self[elem]
} }
#[inline]
pub fn resize(&mut self, new_len: usize, value: T)
where
T: Clone,
{
self.raw.resize(new_len, value)
}
#[inline] #[inline]
pub fn resize_to_elem(&mut self, elem: I, fill_value: impl FnMut() -> T) { pub fn resize_to_elem(&mut self, elem: I, fill_value: impl FnMut() -> T) {
let min_new_len = elem.index() + 1; let min_new_len = elem.index() + 1;
@ -255,6 +172,30 @@ impl<I: Idx, T> IndexVec<I, T> {
} }
} }
/// `IndexVec` is often used as a map, so it provides some map-like APIs.
impl<I: Idx, T> IndexVec<I, Option<T>> {
#[inline]
pub fn insert(&mut self, index: I, value: T) -> Option<T> {
self.ensure_contains_elem(index, || None).replace(value)
}
#[inline]
pub fn get_or_insert_with(&mut self, index: I, value: impl FnOnce() -> T) -> &mut T {
self.ensure_contains_elem(index, || None).get_or_insert_with(value)
}
#[inline]
pub fn remove(&mut self, index: I) -> Option<T> {
self.get_mut(index)?.take()
}
}
impl<I: Idx, T: fmt::Debug> fmt::Debug for IndexVec<I, T> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.raw, fmt)
}
}
impl<I: Idx, T> Deref for IndexVec<I, T> { impl<I: Idx, T> Deref for IndexVec<I, T> {
type Target = IndexSlice<I, T>; type Target = IndexSlice<I, T>;
@ -283,241 +224,6 @@ impl<I: Idx, T> BorrowMut<IndexSlice<I, T>> for IndexVec<I, T> {
} }
} }
impl<I: Idx, T: Clone> ToOwned for IndexSlice<I, T> {
type Owned = IndexVec<I, T>;
fn to_owned(&self) -> IndexVec<I, T> {
IndexVec::from_raw(self.raw.to_owned())
}
fn clone_into(&self, target: &mut IndexVec<I, T>) {
self.raw.clone_into(&mut target.raw)
}
}
impl<I: Idx, T> IndexSlice<I, T> {
#[inline]
pub fn empty() -> &'static Self {
Default::default()
}
#[inline]
pub fn from_raw(raw: &[T]) -> &Self {
let ptr: *const [T] = raw;
// SAFETY: `IndexSlice` is `repr(transparent)` over a normal slice
unsafe { &*(ptr as *const Self) }
}
#[inline]
pub fn from_raw_mut(raw: &mut [T]) -> &mut Self {
let ptr: *mut [T] = raw;
// SAFETY: `IndexSlice` is `repr(transparent)` over a normal slice
unsafe { &mut *(ptr as *mut Self) }
}
#[inline]
pub fn len(&self) -> usize {
self.raw.len()
}
/// Gives the next index that will be assigned when `push` is called.
///
/// Manual bounds checks can be done using `idx < slice.next_index()`
/// (as opposed to `idx.index() < slice.len()`).
#[inline]
pub fn next_index(&self) -> I {
I::new(self.len())
}
#[inline]
pub fn is_empty(&self) -> bool {
self.raw.is_empty()
}
#[inline]
pub fn iter(&self) -> slice::Iter<'_, T> {
self.raw.iter()
}
#[inline]
pub fn iter_enumerated(
&self,
) -> impl DoubleEndedIterator<Item = (I, &T)> + ExactSizeIterator + '_ {
self.raw.iter().enumerate().map(|(n, t)| (I::new(n), t))
}
#[inline]
pub fn indices(
&self,
) -> impl DoubleEndedIterator<Item = I> + ExactSizeIterator + Clone + 'static {
(0..self.len()).map(|n| I::new(n))
}
#[inline]
pub fn iter_mut(&mut self) -> slice::IterMut<'_, T> {
self.raw.iter_mut()
}
#[inline]
pub fn iter_enumerated_mut(
&mut self,
) -> impl DoubleEndedIterator<Item = (I, &mut T)> + ExactSizeIterator + '_ {
self.raw.iter_mut().enumerate().map(|(n, t)| (I::new(n), t))
}
#[inline]
pub fn last_index(&self) -> Option<I> {
self.len().checked_sub(1).map(I::new)
}
#[inline]
pub fn swap(&mut self, a: I, b: I) {
self.raw.swap(a.index(), b.index())
}
#[inline]
pub fn get(&self, index: I) -> Option<&T> {
self.raw.get(index.index())
}
#[inline]
pub fn get_mut(&mut self, index: I) -> Option<&mut T> {
self.raw.get_mut(index.index())
}
/// Returns mutable references to two distinct elements, `a` and `b`.
///
/// Panics if `a == b`.
#[inline]
pub fn pick2_mut(&mut self, a: I, b: I) -> (&mut T, &mut T) {
let (ai, bi) = (a.index(), b.index());
assert!(ai != bi);
if ai < bi {
let (c1, c2) = self.raw.split_at_mut(bi);
(&mut c1[ai], &mut c2[0])
} else {
let (c2, c1) = self.pick2_mut(b, a);
(c1, c2)
}
}
/// Returns mutable references to three distinct elements.
///
/// Panics if the elements are not distinct.
#[inline]
pub fn pick3_mut(&mut self, a: I, b: I, c: I) -> (&mut T, &mut T, &mut T) {
let (ai, bi, ci) = (a.index(), b.index(), c.index());
assert!(ai != bi && bi != ci && ci != ai);
let len = self.raw.len();
assert!(ai < len && bi < len && ci < len);
let ptr = self.raw.as_mut_ptr();
unsafe { (&mut *ptr.add(ai), &mut *ptr.add(bi), &mut *ptr.add(ci)) }
}
}
impl<I: Idx, J: Idx> IndexSlice<I, J> {
/// Invert a bijective mapping, i.e. `invert(map)[y] = x` if `map[x] = y`,
/// assuming the values in `self` are a permutation of `0..self.len()`.
///
/// This is used to go between `memory_index` (source field order to memory order)
/// and `inverse_memory_index` (memory order to source field order).
/// See also `FieldsShape::Arbitrary::memory_index` for more details.
// FIXME(eddyb) build a better abstraction for permutations, if possible.
pub fn invert_bijective_mapping(&self) -> IndexVec<J, I> {
debug_assert_eq!(
self.iter().map(|x| x.index() as u128).sum::<u128>(),
(0..self.len() as u128).sum::<u128>(),
"The values aren't 0..N in input {self:?}",
);
let mut inverse = IndexVec::from_elem_n(Idx::new(0), self.len());
for (i1, &i2) in self.iter_enumerated() {
inverse[i2] = i1;
}
debug_assert_eq!(
inverse.iter().map(|x| x.index() as u128).sum::<u128>(),
(0..inverse.len() as u128).sum::<u128>(),
"The values aren't 0..N in result {self:?}",
);
inverse
}
}
/// `IndexVec` is often used as a map, so it provides some map-like APIs.
impl<I: Idx, T> IndexVec<I, Option<T>> {
#[inline]
pub fn insert(&mut self, index: I, value: T) -> Option<T> {
self.ensure_contains_elem(index, || None).replace(value)
}
#[inline]
pub fn get_or_insert_with(&mut self, index: I, value: impl FnOnce() -> T) -> &mut T {
self.ensure_contains_elem(index, || None).get_or_insert_with(value)
}
#[inline]
pub fn remove(&mut self, index: I) -> Option<T> {
self.get_mut(index)?.take()
}
}
impl<I: Idx, T: Clone> IndexVec<I, T> {
#[inline]
pub fn resize(&mut self, new_len: usize, value: T) {
self.raw.resize(new_len, value)
}
}
impl<I: Idx, T: Ord> IndexSlice<I, T> {
#[inline]
pub fn binary_search(&self, value: &T) -> Result<I, I> {
match self.raw.binary_search(value) {
Ok(i) => Ok(Idx::new(i)),
Err(i) => Err(Idx::new(i)),
}
}
}
impl<I: Idx, T> Index<I> for IndexSlice<I, T> {
type Output = T;
#[inline]
fn index(&self, index: I) -> &T {
&self.raw[index.index()]
}
}
impl<I: Idx, T> IndexMut<I> for IndexSlice<I, T> {
#[inline]
fn index_mut(&mut self, index: I) -> &mut T {
&mut self.raw[index.index()]
}
}
impl<I: Idx, T> Default for IndexVec<I, T> {
#[inline]
fn default() -> Self {
Self::new()
}
}
impl<I: Idx, T> Default for &IndexSlice<I, T> {
#[inline]
fn default() -> Self {
IndexSlice::from_raw(Default::default())
}
}
impl<I: Idx, T> Default for &mut IndexSlice<I, T> {
#[inline]
fn default() -> Self {
IndexSlice::from_raw_mut(Default::default())
}
}
impl<I: Idx, T> Extend<T> for IndexVec<I, T> { impl<I: Idx, T> Extend<T> for IndexVec<I, T> {
#[inline] #[inline]
fn extend<J: IntoIterator<Item = T>>(&mut self, iter: J) { fn extend<J: IntoIterator<Item = T>>(&mut self, iter: J) {
@ -543,14 +249,7 @@ impl<I: Idx, T> FromIterator<T> for IndexVec<I, T> {
where where
J: IntoIterator<Item = T>, J: IntoIterator<Item = T>,
{ {
IndexVec { raw: FromIterator::from_iter(iter), _marker: PhantomData } IndexVec::from_raw(Vec::from_iter(iter))
}
}
impl<I: Idx, T, const N: usize> From<[T; N]> for IndexVec<I, T> {
#[inline]
fn from(array: [T; N]) -> Self {
IndexVec::from_raw(array.into())
} }
} }
@ -570,7 +269,7 @@ impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T> {
#[inline] #[inline]
fn into_iter(self) -> slice::Iter<'a, T> { fn into_iter(self) -> slice::Iter<'a, T> {
self.raw.iter() self.iter()
} }
} }
@ -580,29 +279,41 @@ impl<'a, I: Idx, T> IntoIterator for &'a mut IndexVec<I, T> {
#[inline] #[inline]
fn into_iter(self) -> slice::IterMut<'a, T> { fn into_iter(self) -> slice::IterMut<'a, T> {
self.raw.iter_mut() self.iter_mut()
} }
} }
impl<'a, I: Idx, T> IntoIterator for &'a IndexSlice<I, T> { impl<I: Idx, T> Default for IndexVec<I, T> {
type Item = &'a T;
type IntoIter = slice::Iter<'a, T>;
#[inline] #[inline]
fn into_iter(self) -> slice::Iter<'a, T> { fn default() -> Self {
self.raw.iter() IndexVec::new()
} }
} }
impl<'a, I: Idx, T> IntoIterator for &'a mut IndexSlice<I, T> { impl<I: Idx, T, const N: usize> From<[T; N]> for IndexVec<I, T> {
type Item = &'a mut T;
type IntoIter = slice::IterMut<'a, T>;
#[inline] #[inline]
fn into_iter(self) -> slice::IterMut<'a, T> { fn from(array: [T; N]) -> Self {
self.raw.iter_mut() IndexVec::from_raw(array.into())
} }
} }
#[cfg(feature = "rustc_serialize")]
impl<S: Encoder, I: Idx, T: Encodable<S>> Encodable<S> for IndexVec<I, T> {
fn encode(&self, s: &mut S) {
Encodable::encode(&self.raw, s);
}
}
#[cfg(feature = "rustc_serialize")]
impl<D: Decoder, I: Idx, T: Decodable<D>> Decodable<D> for IndexVec<I, T> {
fn decode(d: &mut D) -> Self {
IndexVec::from_raw(Vec::<T>::decode(d))
}
}
// Whether `IndexVec` is `Send` depends only on the data,
// not the phantom data.
unsafe impl<I: Idx, T> Send for IndexVec<I, T> where T: Send {}
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;

View File

@ -16,7 +16,7 @@ use rustc_middle::ty::{self, BoundVar, InferConst, List, Ty, TyCtxt, TypeFlags,
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_index::vec::Idx; use rustc_index::Idx;
use smallvec::SmallVec; use smallvec::SmallVec;
impl<'tcx> InferCtxt<'tcx> { impl<'tcx> InferCtxt<'tcx> {

View File

@ -23,7 +23,7 @@
use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind}; use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind};
use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVariableOriginKind}; use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin, TypeVariableOriginKind};
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::GenericArg; use rustc_middle::ty::subst::GenericArg;
use rustc_middle::ty::{self, List, TyCtxt}; use rustc_middle::ty::{self, List, TyCtxt};

View File

@ -19,8 +19,8 @@ use crate::traits::query::{Fallible, NoSolution};
use crate::traits::{Obligation, ObligationCause, PredicateObligation}; use crate::traits::{Obligation, ObligationCause, PredicateObligation};
use crate::traits::{PredicateObligations, TraitEngine, TraitEngineExt}; use crate::traits::{PredicateObligations, TraitEngine, TraitEngineExt};
use rustc_data_structures::captures::Captures; use rustc_data_structures::captures::Captures;
use rustc_index::vec::Idx; use rustc_index::Idx;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::arena::ArenaAllocatable; use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::mir::ConstraintCategory; use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;

View File

@ -13,7 +13,7 @@ use rustc_data_structures::graph::implementation::{
Direction, Graph, NodeIndex, INCOMING, OUTGOING, Direction, Graph, NodeIndex, INCOMING, OUTGOING,
}; };
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::PlaceholderRegion; use rustc_middle::ty::PlaceholderRegion;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};

View File

@ -61,7 +61,7 @@ impl<'tcx> InferCtxt<'tcx> {
}; };
let lexical_region_resolutions = LexicalRegionResolutions { let lexical_region_resolutions = LexicalRegionResolutions {
values: rustc_index::vec::IndexVec::from_elem_n( values: rustc_index::IndexVec::from_elem_n(
crate::infer::lexical_region_resolve::VarValue::Value(self.tcx.lifetimes.re_erased), crate::infer::lexical_region_resolve::VarValue::Value(self.tcx.lifetimes.re_erased),
var_infos.len(), var_infos.len(),
), ),

View File

@ -5,7 +5,7 @@ use rustc_data_structures::{
graph::{scc::Sccs, vec_graph::VecGraph}, graph::{scc::Sccs, vec_graph::VecGraph},
undo_log::UndoLogs, undo_log::UndoLogs,
}; };
use rustc_index::vec::Idx; use rustc_index::Idx;
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::relate::RelateResult; use rustc_middle::ty::relate::RelateResult;

View File

@ -12,7 +12,7 @@ use rustc_data_structures::intern::Interned;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_data_structures::undo_log::UndoLogs; use rustc_data_structures::undo_log::UndoLogs;
use rustc_data_structures::unify as ut; use rustc_data_structures::unify as ut;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::infer::unify_key::{RegionVidKey, UnifiedRegion}; use rustc_middle::infer::unify_key::{RegionVidKey, UnifiedRegion};
use rustc_middle::ty::ReStatic; use rustc_middle::ty::ReStatic;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};

View File

@ -10,7 +10,6 @@ libloading = "0.7.1"
tracing = "0.1" tracing = "0.1"
rustc-rayon-core = { version = "0.5.0", optional = true } rustc-rayon-core = { version = "0.5.0", optional = true }
rustc-rayon = { version = "0.5.0", optional = true } rustc-rayon = { version = "0.5.0", optional = true }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
rustc_ast = { path = "../rustc_ast" } rustc_ast = { path = "../rustc_ast" }
rustc_attr = { path = "../rustc_attr" } rustc_attr = { path = "../rustc_attr" }
rustc_borrowck = { path = "../rustc_borrowck" } rustc_borrowck = { path = "../rustc_borrowck" }

View File

@ -14,7 +14,7 @@ use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::HirId; use rustc_hir::HirId;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::lint::{ use rustc_middle::lint::{
reveal_actual_level, struct_lint_level, LevelAndSource, LintExpectation, LintLevelSource, reveal_actual_level, struct_lint_level, LevelAndSource, LintExpectation, LintLevelSource,

View File

@ -254,7 +254,7 @@ impl Parse for Newtype {
} }
} }
impl rustc_index::vec::Idx for #name { impl rustc_index::Idx for #name {
#[inline] #[inline]
fn new(value: usize) -> Self { fn new(value: usize) -> Self {
Self::from_usize(value) Self::from_usize(value)

View File

@ -11,7 +11,6 @@ libloading = "0.7.1"
odht = { version = "0.3.1", features = ["nightly"] } odht = { version = "0.3.1", features = ["nightly"] }
snap = "1" snap = "1"
tracing = "0.1" tracing = "0.1"
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tempfile = "3.2" tempfile = "3.2"
rustc_middle = { path = "../rustc_middle" } rustc_middle = { path = "../rustc_middle" }
rustc_attr = { path = "../rustc_attr" } rustc_attr = { path = "../rustc_attr" }

View File

@ -12,7 +12,7 @@ use rustc_data_structures::sync::{MappedReadGuard, MappedWriteGuard, ReadGuard,
use rustc_expand::base::SyntaxExtension; use rustc_expand::base::SyntaxExtension;
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, StableCrateIdMap, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, StableCrateIdMap, LOCAL_CRATE};
use rustc_hir::definitions::Definitions; use rustc_hir::definitions::Definitions;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_session::config::{self, CrateType, ExternLocation}; use rustc_session::config::{self, CrateType, ExternLocation};
use rustc_session::cstore::ExternCrateSource; use rustc_session::cstore::ExternCrateSource;

View File

@ -16,7 +16,7 @@ use rustc_hir::def::{CtorKind, DefKind, DocLinkResMap, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash}; use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
use rustc_hir::diagnostic_items::DiagnosticItems; use rustc_hir::diagnostic_items::DiagnosticItems;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use rustc_middle::metadata::ModChild; use rustc_middle::metadata::ModChild;
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState}; use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};

View File

@ -14,7 +14,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, DefPathHash, StableCrateId};
use rustc_hir::definitions::DefKey; use rustc_hir::definitions::DefKey;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_index::bit_set::BitSet; use rustc_index::bit_set::BitSet;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::metadata::ModChild; use rustc_middle::metadata::ModChild;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};

View File

@ -2,7 +2,7 @@ use crate::rmeta::*;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_hir::def::{CtorKind, CtorOf}; use rustc_hir::def::{CtorKind, CtorOf};
use rustc_index::vec::Idx; use rustc_index::Idx;
use rustc_middle::ty::{ParameterizedOverTcx, UnusedGenericParams}; use rustc_middle::ty::{ParameterizedOverTcx, UnusedGenericParams};
use rustc_serialize::opaque::FileEncoder; use rustc_serialize::opaque::FileEncoder;
use rustc_serialize::Encoder as _; use rustc_serialize::Encoder as _;

View File

@ -17,13 +17,13 @@ macro_rules! arena_types {
[decode] mir: rustc_middle::mir::Body<'tcx>, [decode] mir: rustc_middle::mir::Body<'tcx>,
[] steal_promoted: [] steal_promoted:
rustc_data_structures::steal::Steal< rustc_data_structures::steal::Steal<
rustc_index::vec::IndexVec< rustc_index::IndexVec<
rustc_middle::mir::Promoted, rustc_middle::mir::Promoted,
rustc_middle::mir::Body<'tcx> rustc_middle::mir::Body<'tcx>
> >
>, >,
[decode] promoted: [decode] promoted:
rustc_index::vec::IndexVec< rustc_index::IndexVec<
rustc_middle::mir::Promoted, rustc_middle::mir::Promoted,
rustc_middle::mir::Body<'tcx> rustc_middle::mir::Body<'tcx>
>, >,

View File

@ -11,7 +11,7 @@ use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash}; use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::*; use rustc_hir::*;
use rustc_index::vec::Idx; use rustc_index::Idx;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_span::def_id::StableCrateId; use rustc_span::def_id::StableCrateId;
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};

View File

@ -6,7 +6,7 @@ use rustc_data_structures::graph;
use rustc_data_structures::graph::dominators::{dominators, Dominators}; use rustc_data_structures::graph::dominators::{dominators, Dominators};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::OnceCell; use rustc_data_structures::sync::OnceCell;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use smallvec::SmallVec; use smallvec::SmallVec;

View File

@ -27,7 +27,7 @@ use polonius_engine::Atom;
pub use rustc_ast::Mutability; pub use rustc_ast::Mutability;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::dominators::Dominators; use rustc_data_structures::graph::dominators::Dominators;
use rustc_index::vec::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -3096,9 +3096,11 @@ mod size_asserts {
// tidy-alphabetical-start // tidy-alphabetical-start
static_assert_size!(BasicBlockData<'_>, 144); static_assert_size!(BasicBlockData<'_>, 144);
static_assert_size!(LocalDecl<'_>, 40); static_assert_size!(LocalDecl<'_>, 40);
static_assert_size!(SourceScopeData<'_>, 72);
static_assert_size!(Statement<'_>, 32); static_assert_size!(Statement<'_>, 32);
static_assert_size!(StatementKind<'_>, 16); static_assert_size!(StatementKind<'_>, 16);
static_assert_size!(Terminator<'_>, 112); static_assert_size!(Terminator<'_>, 112);
static_assert_size!(TerminatorKind<'_>, 96); static_assert_size!(TerminatorKind<'_>, 96);
static_assert_size!(VarDebugInfo<'_>, 80);
// tidy-alphabetical-end // tidy-alphabetical-end
} }

View File

@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc_hir::ItemId; use rustc_hir::ItemId;
use rustc_index::vec::Idx; use rustc_index::Idx;
use rustc_query_system::ich::StableHashingContext; use rustc_query_system::ich::StableHashingContext;
use rustc_session::config::OptLevel; use rustc_session::config::OptLevel;
use rustc_span::source_map::Span; use rustc_span::source_map::Span;

View File

@ -1,4 +1,4 @@
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_span::Span; use rustc_span::Span;

View File

@ -10,7 +10,7 @@ use super::spanview::write_mir_fn_spanview;
use either::Either; use either::Either;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_index::vec::Idx; use rustc_index::Idx;
use rustc_middle::mir::interpret::{ use rustc_middle::mir::interpret::{
alloc_range, read_target_uint, AllocBytes, AllocId, Allocation, ConstAllocation, ConstValue, alloc_range, read_target_uint, AllocBytes, AllocId, Allocation, ConstAllocation, ConstValue,
GlobalAlloc, Pointer, Provenance, GlobalAlloc, Pointer, Provenance,

View File

@ -8,7 +8,7 @@ use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_index::bit_set::BitMatrix; use rustc_index::bit_set::BitMatrix;
use rustc_index::vec::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use rustc_span::Span; use rustc_span::Span;
use rustc_target::abi::{FieldIdx, VariantIdx}; use rustc_target::abi::{FieldIdx, VariantIdx};
use smallvec::SmallVec; use smallvec::SmallVec;

View File

@ -16,7 +16,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir}; use rustc_hir::{self as hir};
use rustc_hir::{self, GeneratorKind}; use rustc_hir::{self, GeneratorKind};
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_target::abi::{FieldIdx, VariantIdx}; use rustc_target::abi::{FieldIdx, VariantIdx};
use rustc_ast::Mutability; use rustc_ast::Mutability;

View File

@ -14,7 +14,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::RangeEnd; use rustc_hir::RangeEnd;
use rustc_index::newtype_index; use rustc_index::newtype_index;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_middle::middle::region; use rustc_middle::middle::region;
use rustc_middle::mir::interpret::AllocId; use rustc_middle::mir::interpret::AllocId;
use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, Mutability, UnOp}; use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, Mutability, UnOp};

View File

@ -10,7 +10,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_query_system::ich::StableHashingContext; use rustc_query_system::ich::StableHashingContext;
use rustc_session::DataTypeKind; use rustc_session::DataTypeKind;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;

View File

@ -50,7 +50,7 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::{ use rustc_hir::{
Constness, ExprKind, HirId, ImplItemKind, ItemKind, Node, TraitCandidate, TraitItemKind, Constness, ExprKind, HirId, ImplItemKind, ItemKind, Node, TraitCandidate, TraitItemKind,
}; };
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_query_system::dep_graph::DepNodeIndex; use rustc_query_system::dep_graph::DepNodeIndex;
use rustc_query_system::ich::StableHashingContext; use rustc_query_system::ich::StableHashingContext;

View File

@ -5,7 +5,7 @@ use crate::ty::{self, ReprOptions, Ty, TyCtxt, TypeVisitableExt};
use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic}; use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_session::config::OptLevel; use rustc_session::config::OptLevel;
use rustc_span::symbol::{sym, Symbol}; use rustc_span::symbol::{sym, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};

View File

@ -41,7 +41,7 @@ use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res}; use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap}; use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
use rustc_hir::Node; use rustc_hir::Node;
use rustc_index::vec::IndexVec; use rustc_index::IndexVec;
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_query_system::ich::StableHashingContext; use rustc_query_system::ich::StableHashingContext;
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};

Some files were not shown because too many files have changed in this diff Show More