Skip to content

Commit b4988f0

Browse files
committed
rustc: keep overloaded autoderef MethodCallee's in Adjust.
1 parent 9a53c3e commit b4988f0

File tree

26 files changed

+518
-705
lines changed

26 files changed

+518
-705
lines changed

src/librustc/cfg/construct.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
412412
pred: CFGIndex,
413413
func_or_rcvr: &hir::Expr,
414414
args: I) -> CFGIndex {
415-
let method_call = ty::MethodCall::expr(call_expr.id);
416-
let fn_ty = match self.tables.method_map.get(&method_call) {
415+
let fn_ty = match self.tables.method_map.get(&call_expr.id) {
417416
Some(method) => method.ty,
418417
None => self.tables.expr_ty_adjusted(func_or_rcvr),
419418
};

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::adjustment::Ad
102102
ty::adjustment::Adjust::UnsafeFnPointer |
103103
ty::adjustment::Adjust::ClosureFnPointer |
104104
ty::adjustment::Adjust::MutToConstPointer => {}
105-
ty::adjustment::Adjust::DerefRef { autoderefs, ref autoref, unsize } => {
105+
ty::adjustment::Adjust::DerefRef { ref autoderefs, ref autoref, unsize } => {
106106
autoderefs.hash_stable(hcx, hasher);
107107
autoref.hash_stable(hcx, hasher);
108108
unsize.hash_stable(hcx, hasher);
@@ -112,7 +112,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::adjustment::Ad
112112
}
113113

114114
impl_stable_hash_for!(struct ty::adjustment::Adjustment<'tcx> { kind, target });
115-
impl_stable_hash_for!(struct ty::MethodCall { expr_id, autoderef });
116115
impl_stable_hash_for!(struct ty::MethodCallee<'tcx> { def_id, ty, substs });
117116
impl_stable_hash_for!(struct ty::UpvarId { var_id, closure_expr_id });
118117
impl_stable_hash_for!(struct ty::UpvarBorrow<'tcx> { kind, region });
@@ -626,17 +625,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ty::TypeckTables<'
626625
ich::hash_stable_nodemap(hcx, hasher, node_types);
627626
ich::hash_stable_nodemap(hcx, hasher, item_substs);
628627
ich::hash_stable_nodemap(hcx, hasher, adjustments);
629-
630-
ich::hash_stable_hashmap(hcx, hasher, method_map, |hcx, method_call| {
631-
let ty::MethodCall {
632-
expr_id,
633-
autoderef
634-
} = *method_call;
635-
636-
let def_id = hcx.tcx().hir.local_def_id(expr_id);
637-
(hcx.def_path_hash(def_id), autoderef)
638-
});
639-
628+
ich::hash_stable_nodemap(hcx, hasher, method_map);
640629
ich::hash_stable_hashmap(hcx, hasher, upvar_capture_map, |hcx, up_var_id| {
641630
let ty::UpvarId {
642631
var_id,

src/librustc/infer/mod.rs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,14 @@ impl<'tcx, T> InferOk<'tcx, T> {
564564
}
565565

566566
#[must_use = "once you start a snapshot, you should always consume it"]
567-
pub struct CombinedSnapshot {
567+
pub struct CombinedSnapshot<'a, 'tcx:'a> {
568568
projection_cache_snapshot: traits::ProjectionCacheSnapshot,
569569
type_snapshot: type_variable::Snapshot,
570570
int_snapshot: unify::Snapshot<ty::IntVid>,
571571
float_snapshot: unify::Snapshot<ty::FloatVid>,
572572
region_vars_snapshot: RegionSnapshot,
573573
was_in_snapshot: bool,
574+
_in_progress_tables: Option<Ref<'a, ty::TypeckTables<'tcx>>>,
574575
}
575576

576577
/// Helper trait for shortening the lifetimes inside a
@@ -888,7 +889,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
888889
result
889890
}
890891

891-
fn start_snapshot(&self) -> CombinedSnapshot {
892+
fn start_snapshot<'b>(&'b self) -> CombinedSnapshot<'b, 'tcx> {
892893
debug!("start_snapshot()");
893894

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

@@ -911,7 +918,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
911918
int_snapshot,
912919
float_snapshot,
913920
region_vars_snapshot,
914-
was_in_snapshot } = snapshot;
921+
was_in_snapshot,
922+
_in_progress_tables } = snapshot;
915923

916924
self.in_snapshot.set(was_in_snapshot);
917925

@@ -938,7 +946,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
938946
int_snapshot,
939947
float_snapshot,
940948
region_vars_snapshot,
941-
was_in_snapshot } = snapshot;
949+
was_in_snapshot,
950+
_in_progress_tables } = snapshot;
942951

943952
self.in_snapshot.set(was_in_snapshot);
944953

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

1648-
pub fn node_method_ty(&self, method_call: ty::MethodCall)
1649-
-> Option<Ty<'tcx>> {
1650-
self.tables
1651-
.borrow()
1652-
.method_map
1653-
.get(&method_call)
1654-
.map(|method| method.ty)
1655-
.map(|ty| self.resolve_type_vars_if_possible(&ty))
1656-
}
1657-
1658-
pub fn node_method_id(&self, method_call: ty::MethodCall)
1659-
-> Option<DefId> {
1660-
self.tables
1661-
.borrow()
1662-
.method_map
1663-
.get(&method_call)
1664-
.map(|method| method.def_id)
1665-
}
1666-
1667-
pub fn is_method_call(&self, id: ast::NodeId) -> bool {
1668-
self.tables.borrow().method_map.contains_key(&ty::MethodCall::expr(id))
1669-
}
1670-
16711657
pub fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture<'tcx>> {
16721658
self.tables.borrow().upvar_capture_map.get(&upvar_id).cloned()
16731659
}

src/librustc/middle/dead.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
9595
}
9696

9797
fn lookup_and_handle_method(&mut self, id: ast::NodeId) {
98-
let method_call = ty::MethodCall::expr(id);
99-
let method = self.tables.method_map[&method_call];
100-
self.check_def_id(method.def_id);
98+
self.check_def_id(self.tables.method_map[&id].def_id);
10199
}
102100

103101
fn handle_field_access(&mut self, lhs: &hir::Expr, name: ast::Name) {

src/librustc/middle/effect.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use self::RootUnsafeContext::*;
1414

1515
use ty::{self, Ty, TyCtxt};
16-
use ty::MethodCall;
1716
use lint;
1817

1918
use syntax::ast;
@@ -174,8 +173,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EffectCheckVisitor<'a, 'tcx> {
174173
fn visit_expr(&mut self, expr: &'tcx hir::Expr) {
175174
match expr.node {
176175
hir::ExprMethodCall(..) => {
177-
let method_call = MethodCall::expr(expr.id);
178-
let base_type = self.tables.method_map[&method_call].ty;
176+
let base_type = self.tables.method_map[&expr.id].ty;
179177
debug!("effect: method call case, base type is {:?}",
180178
base_type);
181179
if type_is_unsafe_function(base_type) {

src/librustc/middle/expr_use_visitor.rs

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -563,19 +563,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
563563
}
564564
ty::TyError => { }
565565
_ => {
566-
let overloaded_call_type =
567-
match self.mc.infcx.node_method_id(ty::MethodCall::expr(call.id)) {
568-
Some(method_id) => {
569-
OverloadedCallType::from_method_id(self.tcx(), method_id)
570-
}
571-
None => {
572-
span_bug!(
573-
callee.span,
574-
"unexpected callee type {}",
575-
callee_ty)
576-
}
577-
};
578-
match overloaded_call_type {
566+
let method = self.mc.infcx.tables.borrow().method_map[&call.id];
567+
match OverloadedCallType::from_method_id(self.tcx(), method.def_id) {
579568
FnMutOverloadedCall => {
580569
let call_scope_r = self.tcx().node_scope_region(call.id);
581570
self.borrow_expr(callee,
@@ -717,7 +706,9 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
717706
fn walk_adjustment(&mut self, expr: &hir::Expr) {
718707
let infcx = self.mc.infcx;
719708
//NOTE(@jroesch): mixed RefCell borrow causes crash
720-
let adj = infcx.tables.borrow().adjustments.get(&expr.id).map(|x| x.clone());
709+
let adj = infcx.tables.borrow().adjustments.get(&expr.id).cloned();
710+
let cmt_unadjusted =
711+
return_if_err!(self.mc.cat_expr_unadjusted(expr));
721712
if let Some(adjustment) = adj {
722713
match adjustment.kind {
723714
adjustment::Adjust::NeverToAny |
@@ -728,17 +719,13 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
728719
// Creating a closure/fn-pointer or unsizing consumes
729720
// the input and stores it into the resulting rvalue.
730721
debug!("walk_adjustment: trivial adjustment");
731-
let cmt_unadjusted =
732-
return_if_err!(self.mc.cat_expr_unadjusted(expr));
733722
self.delegate_consume(expr.id, expr.span, cmt_unadjusted);
734723
}
735-
adjustment::Adjust::DerefRef { autoderefs, autoref, unsize } => {
724+
adjustment::Adjust::DerefRef { ref autoderefs, autoref, unsize } => {
736725
debug!("walk_adjustment expr={:?} adj={:?}", expr, adjustment);
737726

738-
self.walk_autoderefs(expr, autoderefs);
739-
740727
let cmt_derefd =
741-
return_if_err!(self.mc.cat_expr_autoderefd(expr, autoderefs));
728+
return_if_err!(self.walk_autoderefs(expr, cmt_unadjusted, autoderefs));
742729

743730
let cmt_refd =
744731
self.walk_autoref(expr, cmt_derefd, autoref);
@@ -757,30 +744,30 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
757744
/// `deref()` is declared with `&self`, this is an autoref of `x`.
758745
fn walk_autoderefs(&mut self,
759746
expr: &hir::Expr,
760-
autoderefs: usize) {
761-
debug!("walk_autoderefs expr={:?} autoderefs={}", expr, autoderefs);
762-
763-
for i in 0..autoderefs {
764-
let deref_id = ty::MethodCall::autoderef(expr.id, i as u32);
765-
if let Some(method_ty) = self.mc.infcx.node_method_ty(deref_id) {
766-
let cmt = return_if_err!(self.mc.cat_expr_autoderefd(expr, i));
747+
mut cmt: mc::cmt<'tcx>,
748+
autoderefs: &[Option<ty::MethodCallee<'tcx>>])
749+
-> mc::McResult<mc::cmt<'tcx>> {
750+
debug!("walk_autoderefs expr={:?} autoderefs={:?}", expr, autoderefs);
767751

752+
for &overloaded in autoderefs {
753+
if let Some(method) = overloaded {
768754
// the method call infrastructure should have
769755
// replaced all late-bound regions with variables:
770-
let self_ty = method_ty.fn_sig().input(0);
756+
let self_ty = method.ty.fn_sig().input(0);
757+
let self_ty = self.mc.infcx.resolve_type_vars_if_possible(&self_ty);
771758
let self_ty = self.tcx().no_late_bound_regions(&self_ty).unwrap();
772759

773760
let (m, r) = match self_ty.sty {
774761
ty::TyRef(r, ref m) => (m.mutbl, r),
775-
_ => span_bug!(expr.span,
776-
"bad overloaded deref type {:?}",
777-
method_ty)
762+
_ => span_bug!(expr.span, "bad overloaded deref type {:?}", self_ty)
778763
};
779764
let bk = ty::BorrowKind::from_mutbl(m);
780-
self.delegate.borrow(expr.id, expr.span, cmt,
765+
self.delegate.borrow(expr.id, expr.span, cmt.clone(),
781766
r, bk, AutoRef);
782767
}
768+
cmt = self.mc.cat_deref(expr, cmt, overloaded)?;
783769
}
770+
Ok(cmt)
784771
}
785772

786773
/// Walks the autoref `opt_autoref` applied to the autoderef'd
@@ -863,7 +850,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
863850
pass_args: PassArgs)
864851
-> bool
865852
{
866-
if !self.mc.infcx.is_method_call(expr.id) {
853+
if !self.mc.infcx.tables.borrow().is_method_call(expr.id) {
867854
return false;
868855
}
869856

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10841084
}
10851085

10861086
hir::ExprMethodCall(.., ref args) => {
1087-
let method_call = ty::MethodCall::expr(expr.id);
1088-
let method_ty = self.tables.method_map[&method_call].ty;
1087+
let method_ty = self.tables.method_map[&expr.id].ty;
10891088
// FIXME(canndrew): This is_never should really be an is_uninhabited
10901089
let succ = if method_ty.fn_ret().0.is_never() {
10911090
self.s.exit_ln

0 commit comments

Comments
 (0)