mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-24 13:43:04 +00:00
Auto merge of #44878 - Nashenas88:master, r=nikomatsakis
Store a new Region value every time we create a new region variable Paired with @spastorino to walk through this and implement #44870.
This commit is contained in:
commit
4531131bf3
1
src/Cargo.lock
generated
1
src/Cargo.lock
generated
@ -1668,6 +1668,7 @@ dependencies = [
|
|||||||
"rustc_const_math 0.0.0",
|
"rustc_const_math 0.0.0",
|
||||||
"rustc_data_structures 0.0.0",
|
"rustc_data_structures 0.0.0",
|
||||||
"rustc_errors 0.0.0",
|
"rustc_errors 0.0.0",
|
||||||
|
"serialize 0.0.0",
|
||||||
"syntax 0.0.0",
|
"syntax 0.0.0",
|
||||||
"syntax_pos 0.0.0",
|
"syntax_pos 0.0.0",
|
||||||
]
|
]
|
||||||
|
@ -406,7 +406,7 @@ impl DepGraph {
|
|||||||
for (current_dep_node_index, edges) in current_dep_graph.edges.iter_enumerated() {
|
for (current_dep_node_index, edges) in current_dep_graph.edges.iter_enumerated() {
|
||||||
let start = edge_list_data.len() as u32;
|
let start = edge_list_data.len() as u32;
|
||||||
// This should really just be a memcpy :/
|
// This should really just be a memcpy :/
|
||||||
edge_list_data.extend(edges.iter().map(|i| SerializedDepNodeIndex(i.index)));
|
edge_list_data.extend(edges.iter().map(|i| SerializedDepNodeIndex::new(i.index())));
|
||||||
let end = edge_list_data.len() as u32;
|
let end = edge_list_data.len() as u32;
|
||||||
|
|
||||||
debug_assert_eq!(current_dep_node_index.index(), edge_list_indices.len());
|
debug_assert_eq!(current_dep_node_index.index(), edge_list_indices.len());
|
||||||
|
@ -14,23 +14,7 @@ use dep_graph::DepNode;
|
|||||||
use ich::Fingerprint;
|
use ich::Fingerprint;
|
||||||
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
||||||
|
|
||||||
/// The index of a DepNode in the SerializedDepGraph::nodes array.
|
newtype_index!(SerializedDepNodeIndex);
|
||||||
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug,
|
|
||||||
RustcEncodable, RustcDecodable)]
|
|
||||||
pub struct SerializedDepNodeIndex(pub u32);
|
|
||||||
|
|
||||||
impl Idx for SerializedDepNodeIndex {
|
|
||||||
#[inline]
|
|
||||||
fn new(idx: usize) -> Self {
|
|
||||||
assert!(idx <= ::std::u32::MAX as usize);
|
|
||||||
SerializedDepNodeIndex(idx as u32)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn index(self) -> usize {
|
|
||||||
self.0 as usize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Data for use when recompiling the **current crate**.
|
/// Data for use when recompiling the **current crate**.
|
||||||
#[derive(Debug, RustcEncodable, RustcDecodable)]
|
#[derive(Debug, RustcEncodable, RustcDecodable)]
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
#![feature(conservative_impl_trait)]
|
#![feature(conservative_impl_trait)]
|
||||||
|
#![feature(const_fn)]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
#![feature(i128_type)]
|
#![feature(i128_type)]
|
||||||
#![cfg_attr(windows, feature(libc))]
|
#![cfg_attr(windows, feature(libc))]
|
||||||
@ -71,7 +72,7 @@ extern crate graphviz;
|
|||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate owning_ref;
|
extern crate owning_ref;
|
||||||
extern crate rustc_back;
|
extern crate rustc_back;
|
||||||
extern crate rustc_data_structures;
|
#[macro_use] extern crate rustc_data_structures;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate rustc_const_math;
|
extern crate rustc_const_math;
|
||||||
extern crate rustc_errors as errors;
|
extern crate rustc_errors as errors;
|
||||||
|
@ -43,30 +43,6 @@ pub mod visit;
|
|||||||
pub mod transform;
|
pub mod transform;
|
||||||
pub mod traversal;
|
pub mod traversal;
|
||||||
|
|
||||||
macro_rules! newtype_index {
|
|
||||||
($name:ident, $debug_name:expr) => (
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
|
|
||||||
RustcEncodable, RustcDecodable)]
|
|
||||||
pub struct $name(u32);
|
|
||||||
|
|
||||||
impl Idx for $name {
|
|
||||||
fn new(value: usize) -> Self {
|
|
||||||
assert!(value < (u32::MAX) as usize);
|
|
||||||
$name(value as u32)
|
|
||||||
}
|
|
||||||
fn index(self) -> usize {
|
|
||||||
self.0 as usize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Debug for $name {
|
|
||||||
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
|
||||||
write!(fmt, "{}{}", $debug_name, self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Types for locals
|
/// Types for locals
|
||||||
type LocalDecls<'tcx> = IndexVec<Local, LocalDecl<'tcx>>;
|
type LocalDecls<'tcx> = IndexVec<Local, LocalDecl<'tcx>>;
|
||||||
|
|
||||||
|
@ -38,6 +38,43 @@ impl Idx for u32 {
|
|||||||
fn index(self) -> usize { self as usize }
|
fn index(self) -> usize { self as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! newtype_index {
|
||||||
|
($name:ident) => (
|
||||||
|
newtype_index!($name, unsafe { ::std::intrinsics::type_name::<$name>() });
|
||||||
|
);
|
||||||
|
|
||||||
|
($name:ident, $debug_name:expr) => (
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
|
||||||
|
RustcEncodable, RustcDecodable)]
|
||||||
|
pub struct $name(u32);
|
||||||
|
|
||||||
|
impl $name {
|
||||||
|
// HACK use for constants
|
||||||
|
#[allow(unused)]
|
||||||
|
const fn const_new(x: u32) -> Self {
|
||||||
|
$name(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Idx for $name {
|
||||||
|
fn new(value: usize) -> Self {
|
||||||
|
assert!(value < (::std::u32::MAX) as usize);
|
||||||
|
$name(value as u32)
|
||||||
|
}
|
||||||
|
fn index(self) -> usize {
|
||||||
|
self.0 as usize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ::std::fmt::Debug for $name {
|
||||||
|
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
|
write!(fmt, "{}{}", $debug_name, self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct IndexVec<I: Idx, T> {
|
pub struct IndexVec<I: Idx, T> {
|
||||||
pub raw: Vec<T>,
|
pub raw: Vec<T>,
|
||||||
|
@ -17,5 +17,6 @@ rustc_const_eval = { path = "../librustc_const_eval" }
|
|||||||
rustc_const_math = { path = "../librustc_const_math" }
|
rustc_const_math = { path = "../librustc_const_math" }
|
||||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
rustc_data_structures = { path = "../librustc_data_structures" }
|
||||||
rustc_errors = { path = "../librustc_errors" }
|
rustc_errors = { path = "../librustc_errors" }
|
||||||
|
serialize = { path = "../libserialize" }
|
||||||
syntax = { path = "../libsyntax" }
|
syntax = { path = "../libsyntax" }
|
||||||
syntax_pos = { path = "../libsyntax_pos" }
|
syntax_pos = { path = "../libsyntax_pos" }
|
||||||
|
@ -311,19 +311,7 @@ struct CFG<'tcx> {
|
|||||||
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
|
basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
newtype_index!(ScopeId);
|
||||||
pub struct ScopeId(u32);
|
|
||||||
|
|
||||||
impl Idx for ScopeId {
|
|
||||||
fn new(index: usize) -> ScopeId {
|
|
||||||
assert!(index < (u32::MAX as usize));
|
|
||||||
ScopeId(index as u32)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn index(self) -> usize {
|
|
||||||
self.0 as usize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
/// The `BlockAnd` "monad" packages up the new basic block along with a
|
/// The `BlockAnd` "monad" packages up the new basic block along with a
|
||||||
|
@ -18,6 +18,8 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
|
|||||||
|
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
#![feature(box_syntax)]
|
#![feature(box_syntax)]
|
||||||
|
#![feature(const_fn)]
|
||||||
|
#![feature(core_intrinsics)]
|
||||||
#![feature(i128_type)]
|
#![feature(i128_type)]
|
||||||
#![feature(rustc_diagnostic_macros)]
|
#![feature(rustc_diagnostic_macros)]
|
||||||
#![feature(placement_in_syntax)]
|
#![feature(placement_in_syntax)]
|
||||||
@ -30,7 +32,8 @@ extern crate bitflags;
|
|||||||
extern crate graphviz as dot;
|
extern crate graphviz as dot;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
extern crate rustc_data_structures;
|
#[macro_use] extern crate rustc_data_structures;
|
||||||
|
extern crate serialize as rustc_serialize;
|
||||||
extern crate rustc_errors;
|
extern crate rustc_errors;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
|
@ -15,12 +15,15 @@ use rustc::mir::{Mir, Location, Rvalue, BasicBlock, Statement, StatementKind};
|
|||||||
use rustc::mir::visit::{MutVisitor, Lookup};
|
use rustc::mir::visit::{MutVisitor, Lookup};
|
||||||
use rustc::mir::transform::{MirPass, MirSource};
|
use rustc::mir::transform::{MirPass, MirSource};
|
||||||
use rustc::infer::{self, InferCtxt};
|
use rustc::infer::{self, InferCtxt};
|
||||||
|
use rustc::util::nodemap::FxHashSet;
|
||||||
|
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
|
||||||
use syntax_pos::DUMMY_SP;
|
use syntax_pos::DUMMY_SP;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
|
struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
|
||||||
lookup_map: HashMap<RegionVid, Lookup>,
|
lookup_map: HashMap<RegionVid, Lookup>,
|
||||||
|
regions: IndexVec<RegionIndex, Region>,
|
||||||
infcx: InferCtxt<'a, 'gcx, 'tcx>,
|
infcx: InferCtxt<'a, 'gcx, 'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +32,7 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
|
|||||||
NLLVisitor {
|
NLLVisitor {
|
||||||
infcx,
|
infcx,
|
||||||
lookup_map: HashMap::new(),
|
lookup_map: HashMap::new(),
|
||||||
|
regions: IndexVec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,8 +40,9 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
|
|||||||
self.lookup_map
|
self.lookup_map
|
||||||
}
|
}
|
||||||
|
|
||||||
fn renumber_regions<T>(&self, value: &T) -> T where T: TypeFoldable<'tcx> {
|
fn renumber_regions<T>(&mut self, value: &T) -> T where T: TypeFoldable<'tcx> {
|
||||||
self.infcx.tcx.fold_regions(value, &mut false, |_region, _depth| {
|
self.infcx.tcx.fold_regions(value, &mut false, |_region, _depth| {
|
||||||
|
self.regions.push(Region::default());
|
||||||
self.infcx.next_region_var(infer::MiscVariable(DUMMY_SP))
|
self.infcx.next_region_var(infer::MiscVariable(DUMMY_SP))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -143,4 +148,11 @@ impl MirPass for NLL {
|
|||||||
let _results = visitor.into_results();
|
let _results = visitor.into_results();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||||
|
struct Region {
|
||||||
|
points: FxHashSet<Location>,
|
||||||
|
}
|
||||||
|
|
||||||
|
newtype_index!(RegionIndex);
|
||||||
|
Loading…
Reference in New Issue
Block a user