1
Fork 0
rust/compiler/rustc_codegen_ssa/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
..
back Move get_tools_search_paths from FileSearch to Session 2021-09-08 18:25:47 +02:00
coverageinfo Reland - Report coverage 0 of dead blocks 2021-06-01 13:28:59 -07:00
debuginfo Make abi::Abi Copy and remove a *lot* of refs 2021-09-09 10:41:19 +02:00
mir Support #[track_caller] on closures and generators 2021-09-22 15:19:33 -05:00
traits ty::layout: replicate layout_of setup for fn_abi_of_{fn_ptr,instance}. 2021-09-18 04:41:29 +03:00
base.rs Auto merge of #88499 - eddyb:layout-off, r=nagisa 2021-09-05 16:14:41 +00:00
common.rs Remove support for floating-point constants in asm! 2021-05-14 14:58:21 +01:00
glue.rs Refactor to make interpreter and codegen backend neutral to vtable internal representation. 2021-06-15 01:59:00 +08:00
lib.rs Fix handling of +whole-archive native link modifier. 2021-08-30 11:49:49 +02:00
meth.rs Prepare inbounds_gep for opaque pointers 2021-08-04 15:51:30 +02:00
mono_item.rs rustc_target: move LayoutOf to ty::layout. 2021-09-02 01:17:14 +03:00
target_features.rs Remove crypto composite feature from allowed aarch64 features. 2021-08-03 12:07:56 +00:00