rust/compiler/rustc_middle/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
..
dep_graph Make DefPathHash->DefId panic for if the mapping fails. 2021-09-14 13:56:33 +02:00
hir Rollup merge of #89078 - camsteffen:map-ref, r=cjgillot 2021-09-21 22:54:00 +02:00
ich Fix match for placeholder region 2021-09-21 09:31:59 +01:00
infer
middle Adjust documentation for compatibility with 2021 2021-09-20 22:21:43 -04:00
mir Support #[track_caller] on closures and generators 2021-09-22 15:19:33 -05:00
query Auto merge of #88575 - eddyb:fn-abi-queries, r=nagisa 2021-09-19 21:39:47 +00:00
thir add a CastKind to Node::Cast 2021-09-09 01:32:03 +01:00
traits Auto merge of #89000 - Mark-Simulacrum:no-new-lrc, r=petrochenkov 2021-09-18 20:13:21 +00:00
ty Support #[track_caller] on closures and generators 2021-09-22 15:19:33 -05:00
util
arena.rs ty::layout: intern FnAbis as &'tcx. 2021-09-18 01:42:45 +03:00
lib.rs Gather module items after lowering. 2021-09-12 16:33:16 +02:00
lint.rs Fix #88256, remove duplicated diagnostic 2021-09-04 19:26:25 +08:00
macros.rs
tests.rs
thir.rs rename mir -> thir around abstract consts 2021-09-09 01:32:03 +01:00