Skip to content

Commit cc09cb5

Browse files
committed
Record whether a Call in MIR corresponds to a call in HIR
1 parent 6ddab3e commit cc09cb5

File tree

17 files changed

+58
-17
lines changed

17 files changed

+58
-17
lines changed

src/librustc/ich/impls_mir.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,13 @@ for mir::TerminatorKind<'gcx> {
194194
mir::TerminatorKind::Call { ref func,
195195
ref args,
196196
ref destination,
197-
cleanup } => {
197+
cleanup,
198+
from_hir_call, } => {
198199
func.hash_stable(hcx, hasher);
199200
args.hash_stable(hcx, hasher);
200201
destination.hash_stable(hcx, hasher);
201202
cleanup.hash_stable(hcx, hasher);
203+
from_hir_call.hash_stable(hcx, hasher);
202204
}
203205
mir::TerminatorKind::Assert { ref cond,
204206
expected,

src/librustc/mir/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,9 @@ pub enum TerminatorKind<'tcx> {
10491049
destination: Option<(Place<'tcx>, BasicBlock)>,
10501050
/// Cleanups to be done if the call unwinds.
10511051
cleanup: Option<BasicBlock>,
1052+
/// Whether this is from a call in HIR, rather than from an overloaded
1053+
/// operator. True for overloaded function call.
1054+
from_hir_call: bool,
10521055
},
10531056

10541057
/// Jump to the target if the condition has the expected value,
@@ -2810,6 +2813,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
28102813
ref args,
28112814
ref destination,
28122815
cleanup,
2816+
from_hir_call,
28132817
} => {
28142818
let dest = destination
28152819
.as_ref()
@@ -2820,6 +2824,7 @@ impl<'tcx> TypeFoldable<'tcx> for Terminator<'tcx> {
28202824
args: args.fold_with(folder),
28212825
destination: dest,
28222826
cleanup,
2827+
from_hir_call,
28232828
}
28242829
}
28252830
Assert {

src/librustc/mir/visit.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ macro_rules! make_mir_visitor {
468468
TerminatorKind::Call { ref $($mutability)* func,
469469
ref $($mutability)* args,
470470
ref $($mutability)* destination,
471-
cleanup } => {
471+
cleanup,
472+
from_hir_call: _, } => {
472473
self.visit_operand(func, source_location);
473474
for arg in args {
474475
self.visit_operand(arg, source_location);

src/librustc_codegen_llvm/mir/block.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,13 @@ impl FunctionCx<'a, 'll, 'tcx> {
412412
bug!("undesugared DropAndReplace in codegen: {:?}", terminator);
413413
}
414414

415-
mir::TerminatorKind::Call { ref func, ref args, ref destination, cleanup } => {
415+
mir::TerminatorKind::Call {
416+
ref func,
417+
ref args,
418+
ref destination,
419+
cleanup,
420+
from_hir_call: _
421+
} => {
416422
// Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar.
417423
let callee = self.codegen_operand(&bx, func);
418424

src/librustc_mir/borrow_check/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
667667
ref args,
668668
ref destination,
669669
cleanup: _,
670+
from_hir_call: _,
670671
} => {
671672
self.consume_operand(ContextKind::CallOperator.new(loc), (func, span), flow_state);
672673
for arg in args {

src/librustc_mir/borrow_check/nll/invalidation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
203203
ref args,
204204
ref destination,
205205
cleanup: _,
206+
from_hir_call: _,
206207
} => {
207208
self.consume_operand(ContextKind::CallOperator.new(location), func);
208209
for arg in args {

src/librustc_mir/build/expr/into.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
264264
);
265265
exit_block.unit()
266266
}
267-
ExprKind::Call { ty, fun, args } => {
267+
ExprKind::Call { ty, fun, args, from_hir_call } => {
268268
// FIXME(canndrew): This is_never should probably be an is_uninhabited
269269
let diverges = expr.ty.is_never();
270270
let intrinsic = match ty.sty {
@@ -326,6 +326,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
326326
} else {
327327
Some((destination.clone(), success))
328328
},
329+
from_hir_call,
329330
},
330331
);
331332
success.unit()

src/librustc_mir/build/matches/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
361361
args: vec![val, expect],
362362
destination: Some((eq_result.clone(), eq_block)),
363363
cleanup: Some(cleanup),
364+
from_hir_call: false,
364365
});
365366

366367
// check the result

src/librustc_mir/dataflow/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation
795795
self.propagate_bits_into_entry_set_for(in_out, *target, dirty_list);
796796
}
797797
}
798-
mir::TerminatorKind::Call { cleanup, ref destination, func: _, args: _ } => {
798+
mir::TerminatorKind::Call { cleanup, ref destination, .. } => {
799799
if let Some(unwind) = cleanup {
800800
if !self.dead_unwinds.contains(bb) {
801801
self.propagate_bits_into_entry_set_for(in_out, unwind, dirty_list);

src/librustc_mir/dataflow/move_paths/builder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,13 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
380380
self.gather_operand(value);
381381
self.gather_init(location, InitKind::Deep);
382382
}
383-
TerminatorKind::Call { ref func, ref args, ref destination, cleanup: _ } => {
383+
TerminatorKind::Call {
384+
ref func,
385+
ref args,
386+
ref destination,
387+
cleanup: _,
388+
from_hir_call: _,
389+
} => {
384390
self.gather_operand(func);
385391
for arg in args {
386392
self.gather_operand(arg);

src/librustc_mir/hair/cx/expr.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc::ty::cast::CastKind as TyCastKind;
2121
use rustc::hir;
2222
use rustc::hir::def_id::LocalDefId;
2323
use rustc::mir::{BorrowKind};
24+
use syntax_pos::Span;
2425

2526
impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
2627
type Output = Expr<'tcx>;
@@ -232,16 +233,17 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
232233

233234
let kind = match expr.node {
234235
// Here comes the interesting stuff:
235-
hir::ExprKind::MethodCall(.., ref args) => {
236+
hir::ExprKind::MethodCall(_, method_span, ref args) => {
236237
// Rewrite a.b(c) into UFCS form like Trait::b(a, c)
237-
let expr = method_callee(cx, expr, None);
238+
let expr = method_callee(cx, expr, method_span,None);
238239
let args = args.iter()
239240
.map(|e| e.to_ref())
240241
.collect();
241242
ExprKind::Call {
242243
ty: expr.ty,
243244
fun: expr.to_ref(),
244245
args,
246+
from_hir_call: true,
245247
}
246248
}
247249

@@ -254,7 +256,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
254256

255257
// rewrite f(u, v) into FnOnce::call_once(f, (u, v))
256258

257-
let method = method_callee(cx, expr, None);
259+
let method = method_callee(cx, expr, fun.span,None);
258260

259261
let arg_tys = args.iter().map(|e| cx.tables().expr_ty_adjusted(e));
260262
let tupled_args = Expr {
@@ -268,6 +270,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
268270
ty: method.ty,
269271
fun: method.to_ref(),
270272
args: vec![fun.to_ref(), tupled_args.to_ref()],
273+
from_hir_call: true,
271274
}
272275
} else {
273276
let adt_data = if let hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) =
@@ -321,6 +324,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
321324
ty: cx.tables().node_id_to_type(fun.hir_id),
322325
fun: fun.to_ref(),
323326
args: args.to_ref(),
327+
from_hir_call: true,
324328
}
325329
}
326330
}
@@ -812,6 +816,7 @@ fn user_annotated_ty_for_adt(
812816
fn method_callee<'a, 'gcx, 'tcx>(
813817
cx: &mut Cx<'a, 'gcx, 'tcx>,
814818
expr: &hir::Expr,
819+
span: Span,
815820
overloaded_callee: Option<(DefId, &'tcx Substs<'tcx>)>,
816821
) -> Expr<'tcx> {
817822
let temp_lifetime = cx.region_scope_tree.temporary_scope(expr.hir_id.local_id);
@@ -832,7 +837,7 @@ fn method_callee<'a, 'gcx, 'tcx>(
832837
Expr {
833838
temp_lifetime,
834839
ty,
835-
span: expr.span,
840+
span,
836841
kind: ExprKind::Literal {
837842
literal: ty::Const::zero_sized(cx.tcx(), ty),
838843
user_ty,
@@ -1093,11 +1098,12 @@ fn overloaded_operator<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
10931098
expr: &'tcx hir::Expr,
10941099
args: Vec<ExprRef<'tcx>>)
10951100
-> ExprKind<'tcx> {
1096-
let fun = method_callee(cx, expr, None);
1101+
let fun = method_callee(cx, expr, expr.span, None);
10971102
ExprKind::Call {
10981103
ty: fun.ty,
10991104
fun: fun.to_ref(),
11001105
args,
1106+
from_hir_call: false,
11011107
}
11021108
}
11031109

@@ -1132,7 +1138,7 @@ fn overloaded_place<'a, 'gcx, 'tcx>(
11321138
// construct the complete expression `foo()` for the overloaded call,
11331139
// which will yield the &T type
11341140
let temp_lifetime = cx.region_scope_tree.temporary_scope(expr.hir_id.local_id);
1135-
let fun = method_callee(cx, expr, overloaded_callee);
1141+
let fun = method_callee(cx, expr, expr.span, overloaded_callee);
11361142
let ref_expr = Expr {
11371143
temp_lifetime,
11381144
ty: ref_ty,
@@ -1141,6 +1147,7 @@ fn overloaded_place<'a, 'gcx, 'tcx>(
11411147
ty: fun.ty,
11421148
fun: fun.to_ref(),
11431149
args,
1150+
from_hir_call: false,
11441151
},
11451152
};
11461153

src/librustc_mir/hair/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ pub enum ExprKind<'tcx> {
150150
ty: Ty<'tcx>,
151151
fun: ExprRef<'tcx>,
152152
args: Vec<ExprRef<'tcx>>,
153+
// Whether this is from a call in HIR, rather than from an overloaded
154+
// operator. True for overloaded function call.
155+
from_hir_call: bool,
153156
},
154157
Deref {
155158
arg: ExprRef<'tcx>,

src/librustc_mir/shim.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
468468
args: vec![Operand::Move(ref_loc)],
469469
destination: Some((dest, next)),
470470
cleanup: Some(cleanup),
471+
from_hir_call: true,
471472
}, false);
472473
}
473474

@@ -766,7 +767,8 @@ fn build_call_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
766767
Some(BasicBlock::new(3))
767768
} else {
768769
None
769-
}
770+
},
771+
from_hir_call: true,
770772
}, false);
771773

772774
if let Adjustment::RefMut = rcvr_adjustment {

src/librustc_mir/transform/lower_128bit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ impl Lower128Bit {
121121
args: vec![lhs, rhs],
122122
destination: Some((place, bb)),
123123
cleanup: None,
124+
from_hir_call: false,
124125
},
125126
});
126127
}

src/librustc_mir/transform/promote_consts.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
258258
};
259259

260260
match terminator.kind {
261-
TerminatorKind::Call { mut func, mut args, .. } => {
261+
TerminatorKind::Call { mut func, mut args, from_hir_call, .. } => {
262262
self.visit_operand(&mut func, loc);
263263
for arg in &mut args {
264264
self.visit_operand(arg, loc);
@@ -272,7 +272,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
272272
func,
273273
args,
274274
cleanup: None,
275-
destination: Some((Place::Local(new_temp), new_target))
275+
destination: Some((Place::Local(new_temp), new_target)),
276+
from_hir_call,
276277
},
277278
..terminator
278279
};

src/librustc_mir/transform/qualify_min_const_fn.rs

+1
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ fn check_terminator(
318318
TerminatorKind::Call {
319319
func,
320320
args,
321+
from_hir_call: _,
321322
destination: _,
322323
cleanup: _,
323324
} => {

src/librustc_mir/util/elaborate_drops.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,9 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
545545
args: vec![Operand::Move(Place::Local(ref_place))],
546546
destination: Some((unit_temp, succ)),
547547
cleanup: unwind.into_option(),
548+
from_hir_call: true,
548549
},
549-
source_info: self.source_info
550+
source_info: self.source_info,
550551
}),
551552
is_cleanup: unwind.is_cleanup(),
552553
};
@@ -903,7 +904,8 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
903904
func: Operand::function_handle(tcx, free_func, substs, self.source_info.span),
904905
args: args,
905906
destination: Some((unit_temp, target)),
906-
cleanup: None
907+
cleanup: None,
908+
from_hir_call: false,
907909
}; // FIXME(#43234)
908910
let free_block = self.new_block(unwind, call);
909911

0 commit comments

Comments
 (0)