mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
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:
commit
521de433f4
@ -12,3 +12,5 @@ a06baa56b95674fc626b3c3fd680d6a65357fe60
|
||||
c34fbfaad38cf5829ef5cfe780dc9d58480adeaa
|
||||
# move tests
|
||||
cf2dff2b1e3fa55fa5415d524200070d0d7aacfe
|
||||
# Run rustfmt on bootstrap
|
||||
b39a1d6f1a30ba29f25d7141038b9a5bf0126e36
|
||||
|
11
Cargo.lock
11
Cargo.lock
@ -3209,7 +3209,6 @@ dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"tempfile",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
@ -3303,7 +3302,6 @@ dependencies = [
|
||||
"rustc_macros",
|
||||
"rustc_serialize",
|
||||
"smallvec",
|
||||
"stable_deref_trait",
|
||||
"stacker",
|
||||
"tempfile",
|
||||
"thin-vec",
|
||||
@ -3516,7 +3514,6 @@ dependencies = [
|
||||
"rustc_trait_selection",
|
||||
"rustc_type_ir",
|
||||
"smallvec",
|
||||
"thin-vec",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
@ -3653,7 +3650,6 @@ dependencies = [
|
||||
"rustc_trait_selection",
|
||||
"rustc_traits",
|
||||
"rustc_ty_utils",
|
||||
"smallvec",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
@ -3761,7 +3757,6 @@ dependencies = [
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
"rustc_type_ir",
|
||||
"smallvec",
|
||||
"snap",
|
||||
"tempfile",
|
||||
"tracing",
|
||||
@ -3891,7 +3886,6 @@ dependencies = [
|
||||
"rustc_target",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
@ -4010,7 +4004,6 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"parking_lot 0.11.2",
|
||||
"rustc-rayon-core",
|
||||
"rustc_arena",
|
||||
"rustc_ast",
|
||||
"rustc_data_structures",
|
||||
"rustc_errors",
|
||||
@ -4080,7 +4073,6 @@ dependencies = [
|
||||
"rustc_fluent_macro",
|
||||
"rustc_fs_util",
|
||||
"rustc_hir",
|
||||
"rustc_index",
|
||||
"rustc_lint_defs",
|
||||
"rustc_macros",
|
||||
"rustc_serialize",
|
||||
@ -4149,7 +4141,6 @@ dependencies = [
|
||||
"rustc_data_structures",
|
||||
"rustc_feature",
|
||||
"rustc_fs_util",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_serialize",
|
||||
"rustc_span",
|
||||
@ -4167,7 +4158,6 @@ checksum = "8ba09476327c4b70ccefb6180f046ef588c26a24cf5d269a9feba316eb4f029f"
|
||||
name = "rustc_trait_selection"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"rustc_ast",
|
||||
"rustc_attr",
|
||||
"rustc_data_structures",
|
||||
@ -4199,7 +4189,6 @@ dependencies = [
|
||||
"rustc_ast",
|
||||
"rustc_data_structures",
|
||||
"rustc_hir",
|
||||
"rustc_index",
|
||||
"rustc_infer",
|
||||
"rustc_middle",
|
||||
"rustc_span",
|
||||
|
@ -12,7 +12,7 @@ use rustc_data_structures::intern::Interned;
|
||||
use rustc_data_structures::stable_hasher::Hash64;
|
||||
#[cfg(feature = "nightly")]
|
||||
use rustc_data_structures::stable_hasher::StableOrd;
|
||||
use rustc_index::vec::{IndexSlice, IndexVec};
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
#[cfg(feature = "nightly")]
|
||||
use rustc_macros::HashStable_Generic;
|
||||
#[cfg(feature = "nightly")]
|
||||
|
@ -5,7 +5,7 @@ use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::definitions;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::*;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::source_map::SourceMap;
|
||||
|
@ -12,7 +12,7 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID};
|
||||
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_span::edit_distance::find_best_match_for_name;
|
||||
use rustc_span::source_map::DesugaringKind;
|
||||
|
@ -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::definitions::DefPathData;
|
||||
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
|
||||
use rustc_index::vec::{Idx, IndexSlice, IndexVec};
|
||||
use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||
use rustc_middle::{
|
||||
span_bug,
|
||||
ty::{ResolverAstLowering, TyCtxt},
|
||||
|
@ -1,5 +1,5 @@
|
||||
use rustc_data_structures::graph;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::ty::{RegionVid, VarianceDiagInfo};
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
@ -2,7 +2,7 @@
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
||||
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::ty::{RegionVid, VarianceDiagInfo};
|
||||
use rustc_span::Span;
|
||||
|
@ -3,7 +3,7 @@
|
||||
//! This file provides API for compiler consumers.
|
||||
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_index::IndexSlice;
|
||||
use rustc_infer::infer::{DefiningAnchor, TyCtxtInferExt};
|
||||
use rustc_middle::mir::Body;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
@ -3,7 +3,7 @@
|
||||
use rustc_errors::{Applicability, Diagnostic};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_index::IndexSlice;
|
||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||
use rustc_middle::mir::{
|
||||
Body, CastKind, ConstraintCategory, FakeReadCause, Local, LocalInfo, Location, Operand, Place,
|
||||
|
@ -9,7 +9,7 @@ use rustc_errors::{Applicability, Diagnostic};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, Namespace};
|
||||
use rustc_hir::GeneratorKind;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_index::IndexSlice;
|
||||
use rustc_infer::infer::LateBoundRegionConversionTime;
|
||||
use rustc_middle::mir::tcx::PlaceTy;
|
||||
use rustc_middle::mir::{
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
use crate::region_infer::RegionInferenceContext;
|
||||
use crate::Upvar;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_index::IndexSlice;
|
||||
use rustc_middle::mir::{Body, Local};
|
||||
use rustc_middle::ty::{RegionVid, TyCtxt};
|
||||
use rustc_span::source_map::Span;
|
||||
|
@ -24,7 +24,7 @@ use rustc_fluent_macro::fluent_messages;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_index::bit_set::ChunkedBitSet;
|
||||
use rustc_index::vec::{IndexSlice, IndexVec};
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_infer::infer::{
|
||||
DefiningAnchor, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt,
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::mir::{BasicBlock, Body, Location};
|
||||
|
||||
/// Maps between a MIR Location, which identifies a particular
|
||||
|
@ -2,7 +2,7 @@
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
use rustc_data_structures::captures::Captures;
|
||||
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::ty::{self, Ty};
|
||||
use rustc_span::Span;
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
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::{
|
||||
Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, Promoted,
|
||||
|
@ -7,7 +7,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::graph::scc::Sccs;
|
||||
use rustc_errors::Diagnostic;
|
||||
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::region_constraints::{GenericKind, VarInfos, VerifyBound, VerifyIfEq};
|
||||
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin};
|
||||
|
@ -4,8 +4,8 @@ use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_index::bit_set::SparseBitMatrix;
|
||||
use rustc_index::interval::IntervalSet;
|
||||
use rustc_index::interval::SparseIntervalMatrix;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::Idx;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::mir::{BasicBlock, Body, Location};
|
||||
use rustc_middle::ty::{self, RegionVid};
|
||||
use std::fmt::Debug;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
use crate::BorrowckInferCtxt;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_index::IndexSlice;
|
||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||
use rustc_middle::mir::visit::{MutVisitor, TyContext};
|
||||
use rustc_middle::mir::Constant;
|
||||
|
@ -1,5 +1,5 @@
|
||||
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::{Body, Local, Location};
|
||||
|
||||
|
@ -14,7 +14,7 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
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::outlives::env::RegionBoundPairs;
|
||||
use rustc_infer::infer::region_constraints::RegionConstraintData;
|
||||
|
@ -19,7 +19,7 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::BodyOwnerKind;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt};
|
||||
|
@ -9,7 +9,7 @@ use smallvec::{smallvec, SmallVec};
|
||||
/// this adds an extra parameter pointing to where the return value needs to be stored.
|
||||
pub(super) fn codegen_return_param<'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>,
|
||||
) -> CPlace<'tcx> {
|
||||
let (ret_place, ret_param): (_, SmallVec<[_; 2]>) = match fx.fn_abi.as_ref().unwrap().ret.mode {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::mir::StatementKind::*;
|
||||
use rustc_middle::ty::Ty;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Codegen of a single function
|
||||
|
||||
use rustc_ast::InlineAsmOptions;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::ty::adjustment::PointerCast;
|
||||
use rustc_middle::ty::layout::FnAbiOf;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
|
@ -2,7 +2,7 @@ use cranelift_codegen::isa::TargetFrontendConfig;
|
||||
use gimli::write::FileId;
|
||||
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::ty::layout::{
|
||||
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers,
|
||||
};
|
||||
|
@ -90,7 +90,7 @@ mod prelude {
|
||||
|
||||
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::function::Function;
|
||||
|
@ -36,6 +36,5 @@ rustc_target = { path = "../rustc_target" }
|
||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
rustc_ast = { path = "../rustc_ast" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
tempfile = "3.2.0"
|
||||
serde = { version = "1", features = [ "derive" ]}
|
||||
serde_json = "1"
|
||||
|
@ -12,7 +12,7 @@ use rustc_middle::ty::{self, Instance};
|
||||
use rustc_session::config::DebugInfo;
|
||||
|
||||
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.
|
||||
// FIXME(eddyb) almost all of this should be in `rustc_codegen_ssa::mir::debuginfo`.
|
||||
|
@ -6,7 +6,7 @@ use rustc_codegen_ssa::{
|
||||
traits::ConstMethods,
|
||||
};
|
||||
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::{
|
||||
bug,
|
||||
ty::{
|
||||
|
@ -3,7 +3,7 @@ use rustc_codegen_ssa::debuginfo::{
|
||||
wants_c_like_enum_debuginfo,
|
||||
};
|
||||
use rustc_hir::def::CtorKind;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_index::IndexSlice;
|
||||
use rustc_middle::{
|
||||
bug,
|
||||
mir::{GeneratorLayout, GeneratorSavedLocal},
|
||||
|
@ -24,7 +24,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::Hash128;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_hir::def_id::{DefId, DefIdMap};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
|
@ -12,7 +12,6 @@ bitflags = "1.2.1"
|
||||
cc = "1.0.69"
|
||||
itertools = "0.10.1"
|
||||
tracing = "0.1"
|
||||
libc = "0.2.50"
|
||||
jobserver = "0.1.22"
|
||||
tempfile = "3.2"
|
||||
thorin-dwp = "0.4"
|
||||
@ -43,6 +42,9 @@ rustc_query_system = { path = "../rustc_query_system" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_session = { path = "../rustc_session" }
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
libc = "0.2.50"
|
||||
|
||||
[dependencies.object]
|
||||
version = "0.30.1"
|
||||
default-features = false
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub use super::ffi::*;
|
||||
|
||||
use rustc_index::vec::{IndexSlice, IndexVec};
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_middle::mir::coverage::{
|
||||
CodeRegion, CounterValueReference, ExpressionOperandId, InjectedExpressionId,
|
||||
InjectedExpressionIndex, MappedExpressionIndex, Op,
|
||||
|
@ -5,7 +5,7 @@ use super::FunctionCx;
|
||||
use crate::traits::*;
|
||||
use rustc_data_structures::graph::dominators::Dominators;
|
||||
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::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::{self, Location, TerminatorKind};
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::traits::*;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::ty;
|
||||
|
@ -9,7 +9,7 @@ use rustc_target::abi::call::{FnAbi, PassMode};
|
||||
use std::iter;
|
||||
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
|
||||
use self::debuginfo::{FunctionDebugContext, PerLocalVarDebugInfo};
|
||||
use self::place::PlaceRef;
|
||||
|
@ -5,7 +5,7 @@ use std::mem;
|
||||
use either::{Either, Left, Right};
|
||||
|
||||
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::interpret::{ErrorHandled, InterpError};
|
||||
use rustc_middle::ty::layout::{
|
||||
|
@ -5,7 +5,7 @@
|
||||
use either::{Either, Left, Right};
|
||||
|
||||
use rustc_ast::Mutability;
|
||||
use rustc_index::vec::IndexSlice;
|
||||
use rustc_index::IndexSlice;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
|
||||
|
@ -21,7 +21,7 @@ use rustc_middle::ty::subst::InternalSubsts;
|
||||
use rustc_middle::ty::{self, List, TyCtxt, TypeVisitableExt};
|
||||
use rustc_span::Span;
|
||||
|
||||
use rustc_index::vec::{Idx, IndexSlice, IndexVec};
|
||||
use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::{cmp, iter, mem};
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_infer::traits::Reveal;
|
||||
use rustc_middle::mir::interpret::Scalar;
|
||||
use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor};
|
||||
|
@ -26,7 +26,6 @@ smallvec = { version = "1.8.1", features = [
|
||||
"union",
|
||||
"may_dangle",
|
||||
] }
|
||||
stable_deref_trait = "1.0.0"
|
||||
stacker = "0.1.15"
|
||||
tempfile = "3.2"
|
||||
thin-vec = "0.2.12"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use std::{mem, rc::Rc, sync::Arc};
|
||||
|
||||
pub trait IdFunctor: Sized {
|
||||
|
@ -10,7 +10,8 @@
|
||||
//! <https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf>
|
||||
|
||||
use super::ControlFlowGraph;
|
||||
use rustc_index::vec::{Idx, IndexSlice, IndexVec};
|
||||
use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use super::{DirectedGraph, WithNumNodes, WithStartNode, WithSuccessors};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::{IndexSlice, IndexVec};
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::Idx;
|
||||
|
||||
pub mod dominators;
|
||||
pub mod implementation;
|
||||
|
@ -8,7 +8,7 @@
|
||||
use crate::fx::FxHashSet;
|
||||
use crate::graph::vec_graph::VecGraph;
|
||||
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;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors};
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
@ -3,7 +3,7 @@
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
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 item by key and *O*(1) lookup by index.
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::sip128::SipHasher128;
|
||||
use rustc_index::bit_set;
|
||||
use rustc_index::vec;
|
||||
use rustc_index::bit_set::{self, BitSet};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use smallvec::SmallVec;
|
||||
use std::fmt;
|
||||
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
|
||||
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) {
|
||||
::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) {
|
||||
::std::hash::Hash::hash(self, hasher);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::Idx;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AppendOnlyIndexVec<I: Idx, T: Copy> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
|
||||
pub fn iter<Ls>(
|
||||
first: Option<Ls::LinkIndex>,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::Idx;
|
||||
use std::collections::VecDeque;
|
||||
|
||||
/// A work queue is a handy data structure for tracking work left to
|
||||
|
@ -10,7 +10,7 @@ use crate::def_path_hash_map::DefPathHashMap;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
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 std::fmt::{self, Write};
|
||||
|
@ -14,7 +14,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_error_messages::MultiSpan;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::source_map::Spanned;
|
||||
@ -863,7 +863,7 @@ pub struct OwnerNodes<'tcx> {
|
||||
|
||||
impl<'tcx> OwnerNodes<'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 = node.as_owner().unwrap(); // Indexing must ensure it is an OwnerNode.
|
||||
node
|
||||
|
@ -35,7 +35,7 @@ impl OwnerId {
|
||||
}
|
||||
}
|
||||
|
||||
impl rustc_index::vec::Idx for OwnerId {
|
||||
impl rustc_index::Idx for OwnerId {
|
||||
#[inline]
|
||||
fn new(idx: usize) -> Self {
|
||||
OwnerId { def_id: LocalDefId { local_def_index: DefIndex::from_usize(idx) } }
|
||||
@ -116,10 +116,7 @@ impl HirId {
|
||||
}
|
||||
|
||||
pub fn index(self) -> (usize, usize) {
|
||||
(
|
||||
rustc_index::vec::Idx::index(self.owner.def_id),
|
||||
rustc_index::vec::Idx::index(self.local_id),
|
||||
)
|
||||
(rustc_index::Idx::index(self.owner.def_id), rustc_index::Idx::index(self.local_id))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,5 +27,4 @@ rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
rustc_lint_defs = { path = "../rustc_lint_defs" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
rustc_feature = { path = "../rustc_feature" }
|
||||
thin-vec = "0.2.12"
|
||||
tracing = "0.1"
|
||||
|
@ -12,7 +12,7 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
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::ty::TyCtxt;
|
||||
use rustc_span::source_map;
|
||||
|
@ -3,7 +3,7 @@ use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
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::ty::{self, TyCtxt};
|
||||
use rustc_span::Symbol;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::cmp;
|
||||
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
|
@ -21,7 +21,7 @@ use rustc_hir_analysis::astconv::AstConv;
|
||||
use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt;
|
||||
use rustc_hir_analysis::check::potentially_plural_count;
|
||||
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::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc_infer::infer::TypeTrace;
|
||||
|
@ -8,7 +8,7 @@ use hir::{
|
||||
};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_hir as hir;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_infer::infer::InferCtxt;
|
||||
use rustc_middle::{
|
||||
hir::map::Map,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use super::{DropRangesBuilder, PostOrderId};
|
||||
use rustc_index::{bit_set::BitSet, vec::IndexVec};
|
||||
use rustc_index::{bit_set::BitSet, IndexVec};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
impl DropRangesBuilder {
|
||||
|
@ -20,7 +20,7 @@ use hir::{Body, HirId, HirIdMap, Node};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_hir as hir;
|
||||
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::place::{PlaceBase, PlaceWithHirId};
|
||||
use rustc_middle::ty;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use hir::HirId;
|
||||
use rustc_errors::struct_span_err;
|
||||
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::{self, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_target::abi::{Pointer, VariantIdx};
|
||||
|
@ -1,6 +1,3 @@
|
||||
use crate::vec::{Idx, IndexVec};
|
||||
use arrayvec::ArrayVec;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
use std::marker::PhantomData;
|
||||
@ -9,8 +6,13 @@ use std::ops::{BitAnd, BitAndAssign, BitOrAssign, Bound, Not, Range, RangeBounds
|
||||
use std::rc::Rc;
|
||||
use std::slice;
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
use rustc_macros::{Decodable, Encodable};
|
||||
|
||||
use crate::{Idx, IndexVec};
|
||||
|
||||
use Chunk::*;
|
||||
|
||||
#[cfg(test)]
|
||||
|
45
compiler/rustc_index/src/idx.rs
Normal file
45
compiler/rustc_index/src/idx.rs
Normal 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
|
||||
}
|
||||
}
|
@ -3,10 +3,11 @@ use std::marker::PhantomData;
|
||||
use std::ops::RangeBounds;
|
||||
use std::ops::{Bound, Range};
|
||||
|
||||
use crate::vec::Idx;
|
||||
use crate::vec::IndexVec;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::idx::Idx;
|
||||
use crate::vec::IndexVec;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
|
@ -17,7 +17,12 @@
|
||||
pub mod bit_set;
|
||||
#[cfg(feature = "nightly")]
|
||||
pub mod interval;
|
||||
pub mod vec;
|
||||
|
||||
mod idx;
|
||||
mod slice;
|
||||
mod vec;
|
||||
|
||||
pub use {idx::Idx, slice::IndexSlice, vec::IndexVec};
|
||||
|
||||
#[cfg(feature = "rustc_macros")]
|
||||
pub use rustc_macros::newtype_index;
|
||||
|
256
compiler/rustc_index/src/slice.rs
Normal file
256
compiler/rustc_index/src/slice.rs
Normal 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 {}
|
@ -3,55 +3,13 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||
|
||||
use std::borrow::{Borrow, BorrowMut};
|
||||
use std::fmt;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::Hash;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{Deref, DerefMut, Index, IndexMut, RangeBounds};
|
||||
use std::ops::{Deref, DerefMut, RangeBounds};
|
||||
use std::slice;
|
||||
use std::vec;
|
||||
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
use crate::{Idx, IndexSlice};
|
||||
|
||||
/// 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)>,
|
||||
}
|
||||
|
||||
/// 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> {
|
||||
#[inline]
|
||||
pub fn new() -> Self {
|
||||
IndexVec { raw: Vec::new(), _marker: PhantomData }
|
||||
pub const fn new() -> Self {
|
||||
IndexVec::from_raw(Vec::new())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn from_raw(raw: Vec<T>) -> Self {
|
||||
pub const fn from_raw(raw: Vec<T>) -> Self {
|
||||
IndexVec { raw, _marker: PhantomData }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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`.
|
||||
@ -146,7 +56,7 @@ impl<I: Idx, T> IndexVec<I, T> {
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
IndexVec { raw: vec![elem; universe.len()], _marker: PhantomData }
|
||||
IndexVec::from_raw(vec![elem; universe.len()])
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -154,7 +64,7 @@ impl<I: Idx, T> IndexVec<I, T> {
|
||||
where
|
||||
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
|
||||
@ -162,8 +72,7 @@ impl<I: Idx, T> IndexVec<I, T> {
|
||||
/// be allocated only once, with a capacity of at least `n`.)
|
||||
#[inline]
|
||||
pub fn from_fn_n(func: impl FnMut(I) -> T, n: usize) -> Self {
|
||||
let indices = (0..n).map(I::new);
|
||||
Self::from_raw(indices.map(func).collect())
|
||||
IndexVec::from_raw((0..n).map(I::new).map(func).collect())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -178,7 +87,7 @@ impl<I: Idx, T> IndexVec<I, T> {
|
||||
|
||||
#[inline]
|
||||
pub fn push(&mut self, d: T) -> I {
|
||||
let idx = I::new(self.len());
|
||||
let idx = self.next_index();
|
||||
self.raw.push(d);
|
||||
idx
|
||||
}
|
||||
@ -229,7 +138,7 @@ impl<I: Idx, T> IndexVec<I, 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
|
||||
@ -248,6 +157,14 @@ impl<I: Idx, T> IndexVec<I, T> {
|
||||
&mut self[elem]
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn resize(&mut self, new_len: usize, value: T)
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
self.raw.resize(new_len, value)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn resize_to_elem(&mut self, elem: I, fill_value: impl FnMut() -> T) {
|
||||
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> {
|
||||
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> {
|
||||
#[inline]
|
||||
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
|
||||
J: IntoIterator<Item = T>,
|
||||
{
|
||||
IndexVec { raw: FromIterator::from_iter(iter), _marker: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
IndexVec::from_raw(Vec::from_iter(iter))
|
||||
}
|
||||
}
|
||||
|
||||
@ -570,7 +269,7 @@ impl<'a, I: Idx, T> IntoIterator for &'a IndexVec<I, T> {
|
||||
|
||||
#[inline]
|
||||
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]
|
||||
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> {
|
||||
type Item = &'a T;
|
||||
type IntoIter = slice::Iter<'a, T>;
|
||||
|
||||
impl<I: Idx, T> Default for IndexVec<I, T> {
|
||||
#[inline]
|
||||
fn into_iter(self) -> slice::Iter<'a, T> {
|
||||
self.raw.iter()
|
||||
fn default() -> Self {
|
||||
IndexVec::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, I: Idx, T> IntoIterator for &'a mut IndexSlice<I, T> {
|
||||
type Item = &'a mut T;
|
||||
type IntoIter = slice::IterMut<'a, T>;
|
||||
|
||||
impl<I: Idx, T, const N: usize> From<[T; N]> for IndexVec<I, T> {
|
||||
#[inline]
|
||||
fn into_iter(self) -> slice::IterMut<'a, T> {
|
||||
self.raw.iter_mut()
|
||||
fn from(array: [T; N]) -> Self {
|
||||
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)]
|
||||
mod tests;
|
||||
|
@ -16,7 +16,7 @@ use rustc_middle::ty::{self, BoundVar, InferConst, List, Ty, TyCtxt, TypeFlags,
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::Idx;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
impl<'tcx> InferCtxt<'tcx> {
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
use crate::infer::{ConstVariableOrigin, ConstVariableOriginKind};
|
||||
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::subst::GenericArg;
|
||||
use rustc_middle::ty::{self, List, TyCtxt};
|
||||
|
@ -19,8 +19,8 @@ use crate::traits::query::{Fallible, NoSolution};
|
||||
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
|
||||
use crate::traits::{PredicateObligations, TraitEngine, TraitEngineExt};
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::Idx;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::arena::ArenaAllocatable;
|
||||
use rustc_middle::mir::ConstraintCategory;
|
||||
use rustc_middle::ty::fold::TypeFoldable;
|
||||
|
@ -13,7 +13,7 @@ use rustc_data_structures::graph::implementation::{
|
||||
Direction, Graph, NodeIndex, INCOMING, OUTGOING,
|
||||
};
|
||||
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::PlaceholderRegion;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
|
@ -61,7 +61,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
};
|
||||
|
||||
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),
|
||||
var_infos.len(),
|
||||
),
|
||||
|
@ -5,7 +5,7 @@ use rustc_data_structures::{
|
||||
graph::{scc::Sccs, vec_graph::VecGraph},
|
||||
undo_log::UndoLogs,
|
||||
};
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::Idx;
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::relate::RelateResult;
|
||||
|
||||
|
@ -12,7 +12,7 @@ use rustc_data_structures::intern::Interned;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_data_structures::undo_log::UndoLogs;
|
||||
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::ty::ReStatic;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
|
@ -10,7 +10,6 @@ libloading = "0.7.1"
|
||||
tracing = "0.1"
|
||||
rustc-rayon-core = { 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_attr = { path = "../rustc_attr" }
|
||||
rustc_borrowck = { path = "../rustc_borrowck" }
|
||||
|
@ -14,7 +14,7 @@ use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::HirId;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::lint::{
|
||||
reveal_actual_level, struct_lint_level, LevelAndSource, LintExpectation, LintLevelSource,
|
||||
|
@ -254,7 +254,7 @@ impl Parse for Newtype {
|
||||
}
|
||||
}
|
||||
|
||||
impl rustc_index::vec::Idx for #name {
|
||||
impl rustc_index::Idx for #name {
|
||||
#[inline]
|
||||
fn new(value: usize) -> Self {
|
||||
Self::from_usize(value)
|
||||
|
@ -11,7 +11,6 @@ libloading = "0.7.1"
|
||||
odht = { version = "0.3.1", features = ["nightly"] }
|
||||
snap = "1"
|
||||
tracing = "0.1"
|
||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
tempfile = "3.2"
|
||||
rustc_middle = { path = "../rustc_middle" }
|
||||
rustc_attr = { path = "../rustc_attr" }
|
||||
|
@ -12,7 +12,7 @@ use rustc_data_structures::sync::{MappedReadGuard, MappedWriteGuard, ReadGuard,
|
||||
use rustc_expand::base::SyntaxExtension;
|
||||
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, StableCrateIdMap, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::Definitions;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::{self, CrateType, ExternLocation};
|
||||
use rustc_session::cstore::ExternCrateSource;
|
||||
|
@ -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::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
|
||||
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::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
|
||||
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
|
||||
|
@ -14,7 +14,7 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIndex, DefPathHash, StableCrateId};
|
||||
use rustc_hir::definitions::DefKey;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::metadata::ModChild;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
|
||||
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
|
||||
|
@ -2,7 +2,7 @@ use crate::rmeta::*;
|
||||
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_hir::def::{CtorKind, CtorOf};
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::Idx;
|
||||
use rustc_middle::ty::{ParameterizedOverTcx, UnusedGenericParams};
|
||||
use rustc_serialize::opaque::FileEncoder;
|
||||
use rustc_serialize::Encoder as _;
|
||||
|
@ -17,13 +17,13 @@ macro_rules! arena_types {
|
||||
[decode] mir: rustc_middle::mir::Body<'tcx>,
|
||||
[] steal_promoted:
|
||||
rustc_data_structures::steal::Steal<
|
||||
rustc_index::vec::IndexVec<
|
||||
rustc_index::IndexVec<
|
||||
rustc_middle::mir::Promoted,
|
||||
rustc_middle::mir::Body<'tcx>
|
||||
>
|
||||
>,
|
||||
[decode] promoted:
|
||||
rustc_index::vec::IndexVec<
|
||||
rustc_index::IndexVec<
|
||||
rustc_middle::mir::Promoted,
|
||||
rustc_middle::mir::Body<'tcx>
|
||||
>,
|
||||
|
@ -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::intravisit::{self, Visitor};
|
||||
use rustc_hir::*;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::Idx;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_span::def_id::StableCrateId;
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
|
@ -6,7 +6,7 @@ use rustc_data_structures::graph;
|
||||
use rustc_data_structures::graph::dominators::{dominators, Dominators};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
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 smallvec::SmallVec;
|
||||
|
||||
|
@ -27,7 +27,7 @@ use polonius_engine::Atom;
|
||||
pub use rustc_ast::Mutability;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
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_span::symbol::Symbol;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
@ -3096,9 +3096,11 @@ mod size_asserts {
|
||||
// tidy-alphabetical-start
|
||||
static_assert_size!(BasicBlockData<'_>, 144);
|
||||
static_assert_size!(LocalDecl<'_>, 40);
|
||||
static_assert_size!(SourceScopeData<'_>, 72);
|
||||
static_assert_size!(Statement<'_>, 32);
|
||||
static_assert_size!(StatementKind<'_>, 16);
|
||||
static_assert_size!(Terminator<'_>, 112);
|
||||
static_assert_size!(TerminatorKind<'_>, 96);
|
||||
static_assert_size!(VarDebugInfo<'_>, 80);
|
||||
// tidy-alphabetical-end
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||
use rustc_hir::ItemId;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::Idx;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_session::config::OptLevel;
|
||||
use rustc_span::source_map::Span;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_span::Span;
|
||||
|
@ -10,7 +10,7 @@ use super::spanview::write_mir_fn_spanview;
|
||||
use either::Either;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_index::Idx;
|
||||
use rustc_middle::mir::interpret::{
|
||||
alloc_range, read_target_uint, AllocBytes, AllocId, Allocation, ConstAllocation, ConstValue,
|
||||
GlobalAlloc, Pointer, Provenance,
|
||||
|
@ -8,7 +8,7 @@ use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_index::bit_set::BitMatrix;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
use smallvec::SmallVec;
|
||||
|
@ -16,7 +16,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{self as hir};
|
||||
use rustc_hir::{self, GeneratorKind};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
|
||||
use rustc_ast::Mutability;
|
||||
|
@ -14,7 +14,7 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::RangeEnd;
|
||||
use rustc_index::newtype_index;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::mir::interpret::AllocId;
|
||||
use rustc_middle::mir::{self, BinOp, BorrowKind, FakeReadCause, Mutability, UnOp};
|
||||
|
@ -10,7 +10,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, DefKind, Res};
|
||||
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_session::DataTypeKind;
|
||||
use rustc_span::symbol::sym;
|
||||
|
@ -50,7 +50,7 @@ use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::{
|
||||
Constness, ExprKind, HirId, ImplItemKind, ItemKind, Node, TraitCandidate, TraitItemKind,
|
||||
};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_query_system::dep_graph::DepNodeIndex;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
|
@ -5,7 +5,7 @@ use crate::ty::{self, ReprOptions, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_session::config::OptLevel;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
@ -41,7 +41,7 @@ use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, DocLinkResMap, LifetimeRes, Res};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap};
|
||||
use rustc_hir::Node;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_serialize::{Decodable, Encodable};
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user