Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompose Adjustment into smaller steps and remove the method map. #42281

Merged
merged 14 commits into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/libcollections/tests/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,22 @@ fn test_push() {
fn test_push_unique() {
let mut heap = BinaryHeap::<Box<_>>::from(vec![box 2, box 4, box 9]);
assert_eq!(heap.len(), 3);
assert!(*heap.peek().unwrap() == box 9);
assert!(**heap.peek().unwrap() == 9);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's happening here? some lints firing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yupp! Comparison operators are now understood by the "unnecessary allocation" lint.

heap.push(box 11);
assert_eq!(heap.len(), 4);
assert!(*heap.peek().unwrap() == box 11);
assert!(**heap.peek().unwrap() == 11);
heap.push(box 5);
assert_eq!(heap.len(), 5);
assert!(*heap.peek().unwrap() == box 11);
assert!(**heap.peek().unwrap() == 11);
heap.push(box 27);
assert_eq!(heap.len(), 6);
assert!(*heap.peek().unwrap() == box 27);
assert!(**heap.peek().unwrap() == 27);
heap.push(box 3);
assert_eq!(heap.len(), 7);
assert!(*heap.peek().unwrap() == box 27);
assert!(**heap.peek().unwrap() == 27);
heap.push(box 103);
assert_eq!(heap.len(), 8);
assert!(*heap.peek().unwrap() == box 103);
assert!(**heap.peek().unwrap() == 103);
}

fn check_to_vec(mut data: Vec<i32>) {
Expand Down
12 changes: 3 additions & 9 deletions src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

hir::ExprIndex(ref l, ref r) |
hir::ExprBinary(_, ref l, ref r) if self.tables.is_method_call(expr.id) => {
hir::ExprBinary(_, ref l, ref r) if self.tables.is_method_call(expr) => {
self.call(expr, pred, &l, Some(&**r).into_iter())
}

hir::ExprUnary(_, ref e) if self.tables.is_method_call(expr.id) => {
hir::ExprUnary(_, ref e) if self.tables.is_method_call(expr) => {
self.call(expr, pred, &e, None::<hir::Expr>.iter())
}

Expand Down Expand Up @@ -412,16 +412,10 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
pred: CFGIndex,
func_or_rcvr: &hir::Expr,
args: I) -> CFGIndex {
let method_call = ty::MethodCall::expr(call_expr.id);
let fn_ty = match self.tables.method_map.get(&method_call) {
Some(method) => method.ty,
None => self.tables.expr_ty_adjusted(func_or_rcvr),
};

let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
// FIXME(canndrew): This is_never should probably be an is_uninhabited.
if fn_ty.fn_ret().0.is_never() {
if self.tables.expr_ty(call_expr).is_never() {
self.add_unreachable_node()
} else {
ret
Expand Down
35 changes: 11 additions & 24 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use std::mem;
use syntax_pos::symbol::InternedString;
use ty;

impl_stable_hash_for!(struct ty::ItemSubsts<'tcx> { substs });

impl<'a, 'tcx, T> HashStable<StableHashingContext<'a, 'tcx>> for &'tcx ty::Slice<T>
where T: HashStable<StableHashingContext<'a, 'tcx>> {
fn hash_stable<W: StableHasherResult>(&self,
Expand Down Expand Up @@ -101,19 +99,20 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::adjustment::Ad
ty::adjustment::Adjust::ReifyFnPointer |
ty::adjustment::Adjust::UnsafeFnPointer |
ty::adjustment::Adjust::ClosureFnPointer |
ty::adjustment::Adjust::MutToConstPointer => {}
ty::adjustment::Adjust::DerefRef { autoderefs, ref autoref, unsize } => {
autoderefs.hash_stable(hcx, hasher);
ty::adjustment::Adjust::MutToConstPointer |
ty::adjustment::Adjust::Unsize => {}
ty::adjustment::Adjust::Deref(ref overloaded) => {
overloaded.hash_stable(hcx, hasher);
}
ty::adjustment::Adjust::Borrow(ref autoref) => {
autoref.hash_stable(hcx, hasher);
unsize.hash_stable(hcx, hasher);
}
}
}
}

impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
impl_stable_hash_for!(struct ty::MethodCall { expr_id, autoderef });
impl_stable_hash_for!(struct ty::MethodCallee<'tcx> { def_id, ty, substs });
impl_stable_hash_for!(struct ty::adjustment::OverloadedDeref<'tcx> { region, mutbl });
impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });

Expand Down Expand Up @@ -601,11 +600,10 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
hcx: &mut StableHashingContext<'a, 'tcx>,
hasher: &mut StableHasher<W>) {
let ty::TypeckTables {
ref type_relative_path_defs,
ref type_dependent_defs,
ref node_types,
ref item_substs,
ref node_substs,
ref adjustments,
ref method_map,
ref upvar_capture_map,
ref closure_tys,
ref closure_kinds,
Expand All @@ -622,21 +620,10 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
} = *self;

hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
ich::hash_stable_nodemap(hcx, hasher, type_relative_path_defs);
ich::hash_stable_nodemap(hcx, hasher, type_dependent_defs);
ich::hash_stable_nodemap(hcx, hasher, node_types);
ich::hash_stable_nodemap(hcx, hasher, item_substs);
ich::hash_stable_nodemap(hcx, hasher, node_substs);
ich::hash_stable_nodemap(hcx, hasher, adjustments);

ich::hash_stable_hashmap(hcx, hasher, method_map, |hcx, method_call| {
let ty::MethodCall {
expr_id,
autoderef
} = *method_call;

let def_id = hcx.tcx().hir.local_def_id(expr_id);
(hcx.def_path_hash(def_id), autoderef)
});

ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
let ty::UpvarId {
var_id,
Expand Down
40 changes: 13 additions & 27 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,14 @@ impl<'tcx, T> InferOk<'tcx, T> {
}

#[must_use = "once you start a snapshot, you should always consume it"]
pub struct CombinedSnapshot {
pub struct CombinedSnapshot<'a, 'tcx:'a> {
projection_cache_snapshot: traits::ProjectionCacheSnapshot,
type_snapshot: type_variable::Snapshot,
int_snapshot: unify::Snapshot<ty::IntVid>,
float_snapshot: unify::Snapshot<ty::FloatVid>,
region_vars_snapshot: RegionSnapshot,
was_in_snapshot: bool,
_in_progress_tables: Option<Ref<'a, ty::TypeckTables<'tcx>>>,
}

/// Helper trait for shortening the lifetimes inside a
Expand Down Expand Up @@ -888,7 +889,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
result
}

fn start_snapshot(&self) -> CombinedSnapshot {
fn start_snapshot<'b>(&'b self) -> CombinedSnapshot<'b, 'tcx> {
debug!("start_snapshot()");

let in_snapshot = self.in_snapshot.get();
Expand All @@ -901,6 +902,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
float_snapshot: self.float_unification_table.borrow_mut().snapshot(),
region_vars_snapshot: self.region_vars.start_snapshot(),
was_in_snapshot: in_snapshot,
// Borrow tables "in progress" (i.e. during typeck)
// to ban writes from within a snapshot to them.
_in_progress_tables: match self.tables {
InferTables::InProgress(ref tables) => tables.try_borrow().ok(),
_ => None
}
}
}

Expand All @@ -911,7 +918,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
int_snapshot,
float_snapshot,
region_vars_snapshot,
was_in_snapshot } = snapshot;
was_in_snapshot,
_in_progress_tables } = snapshot;

self.in_snapshot.set(was_in_snapshot);

Expand All @@ -938,7 +946,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
int_snapshot,
float_snapshot,
region_vars_snapshot,
was_in_snapshot } = snapshot;
was_in_snapshot,
_in_progress_tables } = snapshot;

self.in_snapshot.set(was_in_snapshot);

Expand Down Expand Up @@ -1645,29 +1654,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
!traits::type_known_to_meet_bound(self, ty, copy_def_id, span)
}

pub fn node_method_ty(&self, method_call: ty::MethodCall)
-> Option<Ty<'tcx>> {
self.tables
.borrow()
.method_map
.get(&method_call)
.map(|method| method.ty)
.map(|ty| self.resolve_type_vars_if_possible(&ty))
}

pub fn node_method_id(&self, method_call: ty::MethodCall)
-> Option<DefId> {
self.tables
.borrow()
.method_map
.get(&method_call)
.map(|method| method.def_id)
}

pub fn is_method_call(&self, id: ast::NodeId) -> bool {
self.tables.borrow().method_map.contains_key(&ty::MethodCall::expr(id))
}

pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture<'tcx>> {
self.tables.borrow().upvar_capture_map.get(&upvar_id).cloned()
}
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}

fn lookup_and_handle_method(&mut self, id: ast::NodeId) {
let method_call = ty::MethodCall::expr(id);
let method = self.tables.method_map[&method_call];
self.check_def_id(method.def_id);
self.check_def_id(self.tables.type_dependent_defs[&id].def_id());
}

fn handle_field_access(&mut self, lhs: &hir::Expr, name: ast::Name) {
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use self::RootUnsafeContext::*;

use ty::{self, Ty, TyCtxt};
use ty::MethodCall;
use lint;

use syntax::ast;
Expand Down Expand Up @@ -174,8 +173,8 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
match expr.node {
hir::ExprMethodCall(..) => {
let method_call = MethodCall::expr(expr.id);
let base_type = self.tables.method_map[&method_call].ty;
let def_id = self.tables.type_dependent_defs[&expr.id].def_id();
let base_type = self.tcx.type_of(def_id);
debug!("effect: method call case, base type is {:?}",
base_type);
if type_is_unsafe_function(base_type) {
Expand Down
Loading