rust/compiler/rustc_mir_transform/src
Aaron Hill 94b19fac26
Support #[track_caller] on closures and generators
This PR allows applying a `#[track_caller]` attribute to a
closure/generator expression. The attribute as interpreted as applying
to the compiler-generated implementation of the corresponding trait
method (`FnOnce::call_once`, `FnMut::call_mut`, `Fn::call`, or
`Generator::resume`).

This feature does not have its own feature gate - however, it requires
`#![feature(stmt_expr_attributes)]` in order to actually apply
an attribute to a closure or generator.

This is implemented in the same way as for functions - an extra
location argument is appended to the end of the ABI. For closures,
this argument is *not* part of the 'tupled' argument storing the
parameters - the final closure argument for `#[track_caller]` closures
is no longer a tuple.

For direct (monomorphized) calls, the necessary support was already
implemented - we just needeed to adjust some assertions around checking
the ABI and argument count to take closures into account.

For calls through a trait object, more work was needed.
When creating a `ReifyShim`, we need to create a shim
for the trait method (e.g. `FnOnce::call_mut`) - unlike normal
functions, closures are never invoked directly, and always go through a
trait method.

Additional handling was needed for `InstanceDef::ClosureOnceShim`. In
order to pass location information throgh a direct (monomorphized) call
to `FnOnce::call_once` on an `FnMut` closure, we need to make
`ClosureOnceShim` aware of `#[tracked_caller]`. A new field
`track_caller` is added to `ClosureOnceShim` - this is used by
`InstanceDef::requires_caller` location, allowing codegen to
pass through the extra location argument.

Since `ClosureOnceShim.track_caller` is only used by codegen,
we end up generating two identical MIR shims - one for
`track_caller == true`, and one for `track_caller == false`. However,
these two shims are used by the entire crate (i.e. it's two shims total,
not two shims per unique closure), so this shouldn't a big deal.
2021-09-22 15:19:33 -05:00
..
coverage Migrate to 2021 2021-09-20 22:21:42 -04:00
inline Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
abort_unwinding_calls.rs Treat drop_in_place as nounwind with -Z panic-in-drop=abort 2021-09-10 14:18:15 +01:00
add_call_guards.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
add_moves_for_packed_drops.rs Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
add_retag.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
check_const_item_mutation.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
check_packed_ref.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
check_unsafety.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
cleanup_post_borrowck.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
const_debuginfo.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
const_goto.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
const_prop.rs Rename rustc_mir to rustc_const_eval. 2021-09-07 20:46:26 +02:00
deaggregator.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
deduplicate_blocks.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
dest_prop.rs Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
dump_mir.rs Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
early_otherwise_branch.rs Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
elaborate_drops.rs Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
function_item_references.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
generator.rs Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
inline.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
instcombine.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
lib.rs Make rustc_mir_dataflow::framework::graphviz and rustc_mir_transform::MirPass public 2021-09-15 11:41:37 -07:00
lower_intrinsics.rs Introduce NullOp::AlignOf 2021-09-13 00:08:35 +01:00
lower_slice_len.rs don't clone types that are Copy (clippy::clone_on_copy) 2021-09-11 10:18:56 +02:00
match_branches.rs Rename rustc_mir to rustc_const_eval. 2021-09-07 20:46:26 +02:00
multiple_return_terminators.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
nrvo.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
remove_noop_landing_pads.rs Move the dataflow framework to its own crate. 2021-09-07 19:57:07 +02:00
remove_storage_markers.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
remove_unneeded_drops.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
remove_zsts.rs Disable RemoveZsts in generators to avoid query cycles 2021-09-15 18:48:29 +02:00
required_consts.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
separate_const_switch.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
shim.rs Support #[track_caller] on closures and generators 2021-09-22 15:19:33 -05:00
simplify.rs Do not collapse goto chains beginning with the start block 2021-09-18 07:28:55 +02:00
simplify_branches.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
simplify_comparison_integral.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
simplify_try.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
uninhabited_enum_branching.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00
unreachable_prop.rs Move rustc_mir::transform to rustc_mir_transform. 2021-09-07 00:43:14 +02:00