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

Rollup of 8 pull requests #68405

Merged
merged 25 commits into from
Jan 21, 2020
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2ccf65c
Remove appendix from LICENCE-APACHE
XAMPPRocky Dec 30, 2019
d088d8a
Revert previous attempt at detecting unsatisfiable predicates
Aaron1011 Jan 16, 2020
171fe82
Filter and test predicates using `normalize_and_test_predicates` for …
Aaron1011 Jan 16, 2020
c431cd7
Fix typo
Aaron1011 Jan 17, 2020
3fef3d8
Add @weiznich's regression test
Aaron1011 Jan 17, 2020
8fa8b81
Fix some tests failing in `--pass check` mode
petrochenkov Jan 17, 2020
45dd44c
Add `riscv64gc-unknown-linux-gnu` into target list in build-manifest
msizanoen1 Jan 18, 2020
fd90e56
Add failing #[track_caller] test with fn pointers.
anp Jan 17, 2020
0ee9221
InstanceDef::requires_caller_location limited to items.
anp Jan 17, 2020
19d8527
rustc_mir: don't require a self argument for ReifyShim.
eddyb Jan 19, 2020
72dffac
Test that ReifyShim + caller_location return the def site.
anp Jan 19, 2020
6be3446
Added minor clarification to specification of realloc.
mjp41 Jan 20, 2020
fdef4f1
Delete unused "next" variants from formatting infrastructure
Mark-Simulacrum Jan 1, 2020
4919b96
Move run/getcount to functions
Mark-Simulacrum Jan 1, 2020
9ae32c9
Drop args from Formatter
Mark-Simulacrum Jan 1, 2020
a804a45
Fix UI test
Mark-Simulacrum Jan 20, 2020
3e0bfe1
rustdoc: Correct order of `async` and `unsafe` in `async unsafe fn`s
ollie27 Jan 20, 2020
ec7f209
Rollup merge of #67734 - XAMPPRocky:master, r=skade
JohnTitor Jan 20, 2020
e1bd9b3
Rollup merge of #67795 - Mark-Simulacrum:fmt-argument, r=dtolnay
JohnTitor Jan 20, 2020
eff6381
Rollup merge of #68290 - petrochenkov:passcheck, r=oli-obk
JohnTitor Jan 20, 2020
bff216c
Rollup merge of #68297 - Aaron1011:fix/new-const-prop-bounds, r=oli-obk
JohnTitor Jan 20, 2020
8d2bac8
Rollup merge of #68302 - anp:caller-fn-ptr, r=eddyb,oli-obk
JohnTitor Jan 20, 2020
67b87c8
Rollup merge of #68339 - msizanoen1:patch-1, r=pietroalbini
JohnTitor Jan 20, 2020
32ecb6f
Rollup merge of #68381 - mjp41:master, r=Dylan-DPC
JohnTitor Jan 20, 2020
f6406f7
Rollup merge of #68397 - ollie27:rustdoc_async_unsafe, r=Centril
JohnTitor Jan 20, 2020
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
Prev Previous commit
Next Next commit
rustc_mir: don't require a self argument for ReifyShim.
  • Loading branch information
eddyb authored and anp committed Jan 19, 2020
commit 19d8527890b59ed25432fbf5a9f1bd75ac814ae2
80 changes: 53 additions & 27 deletions src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx

let mut result = match instance {
ty::InstanceDef::Item(..) => bug!("item {:?} passed to make_shim", instance),
ty::InstanceDef::VtableShim(def_id) => {
build_call_shim(tcx, instance, Adjustment::DerefMove, CallKind::Direct(def_id), None)
}
ty::InstanceDef::VtableShim(def_id) => build_call_shim(
tcx,
instance,
Some(Adjustment::DerefMove),
CallKind::Direct(def_id),
None,
),
ty::InstanceDef::FnPtrShim(def_id, ty) => {
let trait_ = tcx.trait_of_item(def_id).unwrap();
let adjustment = match tcx.lang_items().fn_trait_kind(trait_) {
Expand All @@ -50,15 +54,15 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
let sig = tcx.erase_late_bound_regions(&ty.fn_sig(tcx));
let arg_tys = sig.inputs();

build_call_shim(tcx, instance, adjustment, CallKind::Indirect, Some(arg_tys))
build_call_shim(tcx, instance, Some(adjustment), CallKind::Indirect, Some(arg_tys))
}
// We are generating a call back to our def-id, which the
// codegen backend knows to turn to an actual call, be it
// a virtual call, or a direct call to a function for which
// indirect calls must be codegen'd differently than direct ones
// (such as `#[track_caller]`).
ty::InstanceDef::ReifyShim(def_id) => {
build_call_shim(tcx, instance, Adjustment::Identity, CallKind::Direct(def_id), None)
build_call_shim(tcx, instance, None, CallKind::Direct(def_id), None)
}
ty::InstanceDef::ClosureOnceShim { call_once: _ } => {
let fn_mut = tcx.lang_items().fn_mut_trait().unwrap();
Expand All @@ -68,7 +72,13 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
.unwrap()
.def_id;

build_call_shim(tcx, instance, Adjustment::RefMut, CallKind::Direct(call_mut), None)
build_call_shim(
tcx,
instance,
Some(Adjustment::RefMut),
CallKind::Direct(call_mut),
None,
)
}
ty::InstanceDef::DropGlue(def_id, ty) => build_drop_shim(tcx, def_id, ty),
ty::InstanceDef::CloneShim(def_id, ty) => {
Expand Down Expand Up @@ -648,7 +658,7 @@ impl CloneShimBuilder<'tcx> {
fn build_call_shim<'tcx>(
tcx: TyCtxt<'tcx>,
instance: ty::InstanceDef<'tcx>,
rcvr_adjustment: Adjustment,
rcvr_adjustment: Option<Adjustment>,
call_kind: CallKind,
untuple_args: Option<&[Ty<'tcx>]>,
) -> BodyAndCache<'tcx> {
Expand Down Expand Up @@ -680,14 +690,16 @@ fn build_call_shim<'tcx>(
let mut local_decls = local_decls_for_sig(&sig, span);
let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE };

let rcvr_arg = Local::new(1 + 0);
let rcvr_l = Place::from(rcvr_arg);
let rcvr_place = || {
assert!(rcvr_adjustment.is_some());
Place::from(Local::new(1 + 0))
};
let mut statements = vec![];

let rcvr = match rcvr_adjustment {
Adjustment::Identity => Operand::Move(rcvr_l),
Adjustment::Deref => Operand::Copy(tcx.mk_place_deref(rcvr_l)),
Adjustment::DerefMove => Operand::Move(tcx.mk_place_deref(rcvr_l)),
let rcvr = rcvr_adjustment.map(|rcvr_adjustment| match rcvr_adjustment {
Adjustment::Identity => Operand::Move(rcvr_place()),
Adjustment::Deref => Operand::Copy(tcx.mk_place_deref(rcvr_place())),
Adjustment::DerefMove => Operand::Move(tcx.mk_place_deref(rcvr_place())),
Adjustment::RefMut => {
// let rcvr = &mut rcvr;
let ref_rcvr = local_decls.push(temp_decl(
Expand All @@ -703,15 +715,15 @@ fn build_call_shim<'tcx>(
source_info,
kind: StatementKind::Assign(box (
Place::from(ref_rcvr),
Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_l),
Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_place()),
)),
});
Operand::Move(Place::from(ref_rcvr))
}
};
});

let (callee, mut args) = match call_kind {
CallKind::Indirect => (rcvr, vec![]),
CallKind::Indirect => (rcvr.unwrap(), vec![]),
CallKind::Direct(def_id) => {
let ty = tcx.type_of(def_id);
(
Expand All @@ -720,21 +732,35 @@ fn build_call_shim<'tcx>(
user_ty: None,
literal: ty::Const::zero_sized(tcx, ty),
}),
vec![rcvr],
rcvr.into_iter().collect::<Vec<_>>(),
)
}
};

let mut arg_range = 0..sig.inputs().len();

// Take the `self` ("receiver") argument out of the range (it's adjusted above).
if rcvr_adjustment.is_some() {
arg_range.start += 1;
}

// Take the last argument, if we need to untuple it (handled below).
if untuple_args.is_some() {
arg_range.end -= 1;
}

// Pass all of the non-special arguments directly.
args.extend(arg_range.map(|i| Operand::Move(Place::from(Local::new(1 + i)))));

// Untuple the last argument, if we have to.
if let Some(untuple_args) = untuple_args {
let tuple_arg = Local::new(1 + (sig.inputs().len() - 1));
args.extend(untuple_args.iter().enumerate().map(|(i, ity)| {
let arg_place = Place::from(Local::new(1 + 1));
Operand::Move(tcx.mk_place_field(arg_place, Field::new(i), *ity))
Operand::Move(tcx.mk_place_field(Place::from(tuple_arg), Field::new(i), *ity))
}));
} else {
args.extend((1..sig.inputs().len()).map(|i| Operand::Move(Place::from(Local::new(1 + i)))));
}

let n_blocks = if let Adjustment::RefMut = rcvr_adjustment { 5 } else { 2 };
let n_blocks = if let Some(Adjustment::RefMut) = rcvr_adjustment { 5 } else { 2 };
let mut blocks = IndexVec::with_capacity(n_blocks);
let block = |blocks: &mut IndexVec<_, _>, statements, kind, is_cleanup| {
blocks.push(BasicBlockData {
Expand All @@ -752,7 +778,7 @@ fn build_call_shim<'tcx>(
func: callee,
args,
destination: Some((Place::return_place(), BasicBlock::new(1))),
cleanup: if let Adjustment::RefMut = rcvr_adjustment {
cleanup: if let Some(Adjustment::RefMut) = rcvr_adjustment {
Some(BasicBlock::new(3))
} else {
None
Expand All @@ -762,13 +788,13 @@ fn build_call_shim<'tcx>(
false,
);

if let Adjustment::RefMut = rcvr_adjustment {
if let Some(Adjustment::RefMut) = rcvr_adjustment {
// BB #1 - drop for Self
block(
&mut blocks,
vec![],
TerminatorKind::Drop {
location: Place::from(rcvr_arg),
location: rcvr_place(),
target: BasicBlock::new(2),
unwind: None,
},
Expand All @@ -777,13 +803,13 @@ fn build_call_shim<'tcx>(
}
// BB #1/#2 - return
block(&mut blocks, vec![], TerminatorKind::Return, false);
if let Adjustment::RefMut = rcvr_adjustment {
if let Some(Adjustment::RefMut) = rcvr_adjustment {
// BB #3 - drop if closure panics
block(
&mut blocks,
vec![],
TerminatorKind::Drop {
location: Place::from(rcvr_arg),
location: rcvr_place(),
target: BasicBlock::new(4),
unwind: None,
},
Expand Down