rust/compiler
bors cc705b8012 Auto merge of #116046 - Zalathar:fn-cov-info, r=cjgillot
coverage: Move most per-function coverage info into `mir::Body`

Currently, all of the coverage information collected by the `InstrumentCoverage` pass is smuggled through MIR in the form of individual `StatementKind::Coverage` statements, which must then be reassembled by coverage codegen.

That's awkward for a number of reasons:
- While some of the coverage statements do care about their specific position in the MIR control-flow graph, many of them don't, and are just tacked onto the function's first BB as metadata carriers.
- MIR inlining can result in coverage statements being duplicated, so coverage codegen has to jump through hoops to avoid emitting duplicate mappings.
- MIR optimizations that would delete coverage statements need to carefully copy them into the function's first BB so as not to omit them from coverage reports.
- The order in which coverage codegen sees coverage statements is dependent on MIR optimizations/inlining, which can cause unnecessary churn in the emitted coverage mappings.
- We don't have a good way to annotate MIR-level functions with extra coverage info that doesn't belong in a statement.

---

This PR therefore takes most of the per-function coverage info and stores it in a field in `mir::Body` as `Option<Box<FunctionCoverageInfo>>`.

(This adds one pointer to the size of `mir::Body`, even when coverage is not enabled.)

Coverage statements still need to be injected into MIR in some cases, but only when they actually affect codegen (counters) or are needed to detect code that has been optimized away as unreachable (counters/expressions).

---

By the end of this PR, the information stored in `FunctionCoverageInfo` is:

- A hash of the function's source code (needed by LLVM's coverage map format)
- The number of coverage counters added by coverage instrumentation
- A table of coverage expressions, associating each expression ID with its operator (add or subtract) and its two operands
- The list of mappings, associating each covered code region with a counter/expression/zero value

---

~~This is built on top of #115301, so I'll rebase and roll a reviewer once that lands.~~
r? `@ghost`
`@rustbot` label +A-code-coverage
2023-10-18 18:48:34 +00:00
..
rustc Split out the stable part of smir into its own crate to prevent accidental usage of forever unstable things 2023-09-25 14:38:27 +00:00
rustc_abi docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_arena rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
rustc_ast Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb 2023-10-15 13:23:55 +00:00
rustc_ast_lowering docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_ast_passes docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_ast_pretty Auto merge of #116822 - notriddle:notriddle/rust-logo, r=fmease 2023-10-17 04:41:20 +00:00
rustc_attr docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_baked_icu_data docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_borrowck revert rust-lang/rust#114586 2023-10-18 06:19:04 +00:00
rustc_builtin_macros docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_codegen_cranelift docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_codegen_gcc docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_codegen_llvm coverage: Explicitly note that counter/expression IDs are function-local 2023-10-18 23:44:36 +11:00
rustc_codegen_ssa Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb 2023-10-15 13:23:55 +00:00
rustc_const_eval Auto merge of #116815 - Nilstrieb:more-funny-pretty-printers, r=compiler-errors 2023-10-18 09:57:07 +00:00
rustc_data_structures Auto merge of #116830 - nnethercote:rustc_type_ir, r=compiler-errors 2023-10-18 03:55:36 +00:00
rustc_driver docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_driver_impl Auto merge of #116814 - estebank:windows-ice-path, r=petrochenkov 2023-10-18 07:45:56 +00:00
rustc_error_codes docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_error_messages docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_errors Rollup merge of #115196 - chenyukang:yukang-fix-86094, r=estebank 2023-10-16 06:26:20 +02:00
rustc_expand docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_feature docs: add Rust logo to more compiler crates 2023-10-16 15:38:08 -07:00
rustc_fluent_macro rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
rustc_fs_util
rustc_graphviz rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
rustc_hir Auto merge of #115670 - Zoxc:outline-panic-macro-1, r=Mark-Simulacrum 2023-10-01 05:56:47 +00:00
rustc_hir_analysis Auto merge of #116887 - lcnr:alias-ty-constructor, r=compiler-errors 2023-10-18 15:17:48 +00:00
rustc_hir_pretty Fiddle with State functions. 2023-10-11 10:46:55 +11:00
rustc_hir_typeck Auto merge of #116887 - lcnr:alias-ty-constructor, r=compiler-errors 2023-10-18 15:17:48 +00:00
rustc_incremental Auto merge of #115964 - bjorn3:cgu_reuse_tracker_global_state, r=cjgillot 2023-10-13 00:09:30 +00:00
rustc_index Preserve DebugInfo in DeadStoreElimination. 2023-10-06 15:46:11 +00:00
rustc_infer Auto merge of #116885 - aliemjay:rollup-plbeppt, r=aliemjay 2023-10-18 11:55:41 +00:00
rustc_interface Automatically enable cross-crate inlining for small functions 2023-10-17 19:53:51 -04:00
rustc_lexer Update lexer emoji diagnostics to Unicode 15.0 2023-07-29 08:47:21 +08:00
rustc_lint Auto merge of #116885 - aliemjay:rollup-plbeppt, r=aliemjay 2023-10-18 11:55:41 +00:00
rustc_lint_defs Auto merge of #115822 - compiler-errors:stabilize-rpitit, r=jackh726 2023-10-14 07:29:08 +00:00
rustc_llvm rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
rustc_log use env variable to control thread ids in rustc_log 2023-10-10 09:39:47 +08:00
rustc_macros Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
rustc_metadata Automatically enable cross-crate inlining for small functions 2023-10-17 19:53:51 -04:00
rustc_middle Auto merge of #116046 - Zalathar:fn-cov-info, r=cjgillot 2023-10-18 18:48:34 +00:00
rustc_mir_build coverage: Attach an optional FunctionCoverageInfo to mir::Body 2023-10-18 21:20:29 +11:00
rustc_mir_dataflow Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
rustc_mir_transform coverage: Store expression data in function coverage info 2023-10-18 23:44:34 +11:00
rustc_monomorphize rustc_monomorphize: Introduce check_fn_args_move_size() 2023-10-07 10:29:37 +02:00
rustc_parse Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb 2023-10-15 13:23:55 +00:00
rustc_parse_format rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
rustc_passes Automatically enable cross-crate inlining for small functions 2023-10-17 19:53:51 -04:00
rustc_plugin_impl rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
rustc_privacy Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
rustc_query_impl rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
rustc_query_system Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
rustc_resolve Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
rustc_serialize rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
rustc_session Automatically enable cross-crate inlining for small functions 2023-10-17 19:53:51 -04:00
rustc_smir Add MonoItems and Instance to stable_mir 2023-10-16 12:01:24 -07:00
rustc_span debug Span::ctxt() call detection 2023-10-16 19:50:29 -07:00
rustc_symbol_mangling Remove Print::Error 2023-10-17 18:02:57 +02:00
rustc_target Rename ACTIVE_FEATURES as UNSTABLE_FEATURES. 2023-10-16 08:17:23 +11:00
rustc_trait_selection Auto merge of #116887 - lcnr:alias-ty-constructor, r=compiler-errors 2023-10-18 15:17:48 +00:00
rustc_traits Detect cycle errors hidden by opaques during monomorphization 2023-09-13 17:35:44 +00:00
rustc_transmute Remove the MaybeTransmutableQuery<&'l Dfa<...>, C> impl. 2023-10-06 11:25:32 +11:00
rustc_ty_utils Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
rustc_type_ir Rewrite Box<T>::try_fold_with. 2023-10-17 16:26:37 +11:00
stable_mir Add MonoItems and Instance to stable_mir 2023-10-16 12:01:24 -07:00