rust/compiler
Matthias Krüger 52bfceb8f9
Rollup merge of #113428 - Zalathar:operand, r=davidtwco
coverage: Replace `ExpressionOperandId` with enum `Operand`

*This is one step in my larger coverage refactoring ambitions described at <https://github.com/rust-lang/compiler-team/issues/645>.*

LLVM coverage has a concept of “mapping expressions” that allow a span's execution count to be computed as a simple arithmetic expression over other counters/expressions, instead of requiring a dedicated physical counter for every control-flow branch.

These expressions have an operator (`+` or `-`) and two operands. Operands are currently represented as `ExpressionOperandId`, which wraps a `u32` with the following semantics:

- 0 represents a special counter that always has a value of zero
- Values ascending from 1 represent counter IDs
- Values descending from `u32::MAX` represent the IDs of other expressions

---

This change replaces that whole `ExpressionOperandId` scheme with a simple enum that explicitly distinguishes between the three cases.

This lets us remove a lot of fiddly code for dealing with the different operand kinds:
- Previously it was only possible to distinguish between counter-ID operands and expression-ID operands by comparing the operand ID with the total number of counters in a function. This is unnecessary now that the enum distinguishes them explicitly.
- There's no need for expression IDs to descend from `u32::MAX` and then get translated into zero-based indices in certain places. Now that they ascend from zero, they can be used as indices directly.
- There's no need to reserve ID number 0 for the special zero operand, since it can just have its own variant in the enum, so counter IDs can count up from 0.

(Making counter IDs ascend from 0 also lets us fix an off-by-one error in the query for counting the total number of counters, which would cause LLVM to emit an extra unused counter for every instrumented function.)

---

This PR may be easiest to review as individual patches, since that breaks it up into clearly distinct parts:
- Replace a `u32` wrapper with an explicit enum, without changing the semantics of the underlying IDs being stored.
- Change the numbering scheme used by `Operand::Expression` to make expression IDs ascend from 0 (instead of descending from `u32::MAX`).
- Change the numbering scheme used by `Operand::Counter` to make counter IDs ascend from 0 (instead of ascending from 1).
2023-08-01 17:39:10 +02:00
..
rustc inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_abi inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_arena Extend unused_must_use to cover block exprs 2023-06-15 17:59:13 +08:00
rustc_ast Parse generic const items 2023-07-28 22:21:33 +02:00
rustc_ast_lowering Lower generic const items to HIR 2023-07-28 22:21:40 +02:00
rustc_ast_passes inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_ast_pretty Parse generic const items 2023-07-28 22:21:33 +02:00
rustc_attr Add infrastructure #[rustc_confusables] attribute to allow targeted 2023-07-16 19:22:03 +08:00
rustc_baked_icu_data
rustc_borrowck Auto merge of #111753 - cjgillot:simp-place-conflict, r=compiler-errors 2023-08-01 03:53:19 +00:00
rustc_builtin_macros inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_codegen_cranelift Merge commit '1eded3619d0e55d57521a259bf27a03906fdfad0' into sync_cg_clif-2023-07-22 2023-07-22 13:32:34 +00:00
rustc_codegen_gcc Use standard Rust capitalization rules for names containing "LTO". 2023-07-31 16:21:02 +10:00
rustc_codegen_llvm Make coverage counter IDs count up from 0, not 1 2023-08-01 11:29:55 +10:00
rustc_codegen_ssa Rollup merge of #113717 - cuishuang:master, r=Nilstrieb 2023-07-31 22:49:47 +02:00
rustc_const_eval Rollup merge of #113773 - compiler-errors:err-layout-bail, r=cjgillot 2023-07-29 06:13:05 +02:00
rustc_data_structures Rollup merge of #114313 - ttsugriy:sm-insert, r=petrochenkov 2023-08-01 06:55:55 +02:00
rustc_driver Update rustix 2023-07-03 07:20:51 +00:00
rustc_driver_impl Use a builder instead of boolean/option arguments 2023-07-25 13:51:15 +00:00
rustc_error_codes error/E0691: include alignment in error message 2023-07-21 11:04:16 +02:00
rustc_error_messages inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_errors Rollup merge of #114068 - matthiaskrgr:fmt_args_rustc_1, r=WaffleLapkin 2023-07-30 14:25:09 +02:00
rustc_expand inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_feature Mark lazy_type_alias as incomplete 2023-07-29 19:47:15 +00:00
rustc_fluent_macro Fix diagnostics with errors 2023-05-26 10:44:18 +00:00
rustc_fs_util
rustc_graphviz
rustc_hir Lower generic const items to HIR 2023-07-28 22:21:40 +02:00
rustc_hir_analysis Rollup merge of #114267 - compiler-errors:rpitit-opaque-bounds, r=spastorino 2023-07-31 16:57:55 +02:00
rustc_hir_pretty Lower generic const items to HIR 2023-07-28 22:21:40 +02:00
rustc_hir_typeck Rollup merge of #114267 - compiler-errors:rpitit-opaque-bounds, r=spastorino 2023-07-31 16:57:55 +02:00
rustc_incremental inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
rustc_index Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_infer Rollup merge of #114267 - compiler-errors:rpitit-opaque-bounds, r=spastorino 2023-07-31 16:57:55 +02:00
rustc_interface replace atty crate with std's isTerminal 2023-07-26 18:09:50 +03:00
rustc_lexer Update lexer emoji diagnostics to Unicode 15.0 2023-07-29 08:47:21 +08:00
rustc_lint Rollup merge of #114286 - nbdd0121:upcast, r=compiler-errors 2023-07-31 16:57:56 +02:00
rustc_lint_defs fix(resolve): update the ambiguity glob binding as warning recursively 2023-07-29 00:19:50 +08:00
rustc_llvm Update the minimum external LLVM to 15 2023-07-27 14:07:08 -07:00
rustc_log inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_macros inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_metadata Rollup merge of #113741 - compiler-errors:rpitit-projects-to-missing-opaque, r=spastorino 2023-07-30 17:50:48 -07:00
rustc_middle Make coverage counter IDs count up from 0, not 1 2023-08-01 11:29:55 +10:00
rustc_mir_build Lower generic const items to HIR 2023-07-28 22:21:40 +02:00
rustc_mir_dataflow inline format!() args up to and including rustc_codegen_llvm 2023-07-30 14:22:50 +02:00
rustc_mir_transform Make coverage counter IDs count up from 0, not 1 2023-08-01 11:29:55 +10:00
rustc_monomorphize Rollup merge of #113872 - nnethercote:tweak-cgu-sorting, r=pnkfelix 2023-07-27 06:04:12 +02:00
rustc_parse Rollup merge of #114256 - Urgau:fix-issue-114180, r=WaffleLapkin 2023-07-30 20:36:35 +02:00
rustc_parse_format Fix unit tests 2023-07-19 16:37:09 +00:00
rustc_passes Lower generic const items to HIR 2023-07-28 22:21:40 +02:00
rustc_plugin_impl
rustc_privacy Weaken unnameable_types lint 2023-07-30 14:02:21 +03:00
rustc_query_impl fix couple of clippy findings: 2023-07-23 10:50:14 +02:00
rustc_query_system inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
rustc_resolve Rollup merge of #113920 - bvanjoi:fix-81413, r=petrochenkov 2023-07-31 22:49:50 +02:00
rustc_serialize Upgrade to indexmap 2.0.0 2023-07-03 13:51:54 -07:00
rustc_session Fix a comment. 2023-07-31 16:21:02 +10:00
rustc_smir Rollup merge of #114165 - ouz-a:smir1, r=spastorino 2023-07-31 22:51:14 +02:00
rustc_span Simplify Span::can_be_used_for_suggestions a little tiny bit 2023-07-30 15:37:39 +00:00
rustc_symbol_mangling Auto merge of #113708 - rcvalle:rust-cfi-fix-100778, r=compiler-errors 2023-07-27 02:48:38 +00:00
rustc_target Add definitions for riscv64_linux_android target 2023-07-26 11:46:48 -07:00
rustc_trait_selection Rollup merge of #114200 - compiler-errors:detect-tail-unsize-then-upcast, r=lcnr 2023-07-31 22:51:16 +02:00
rustc_traits refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
rustc_transmute Don't attempt to compute layout of type referencing error 2023-07-27 18:24:08 +00:00
rustc_ty_utils Rollup merge of #114267 - compiler-errors:rpitit-opaque-bounds, r=spastorino 2023-07-31 16:57:55 +02:00
rustc_type_ir inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00