Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #134177

Merged
merged 169 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
95bf875
Fix a bug when synthetic AST node were searched in the AST ID map and…
ChayimFriedman2 Nov 25, 2024
f091ec6
Migrate `add_turbo_fish` to `SyntaxEditor`
ShoyuVanilla Nov 24, 2024
c876903
Add macro expansion test for raw variable names
Nov 26, 2024
4866fb4
Revert #18197
alibektas Nov 26, 2024
c33c951
Remove target.is_some() to handle it later inside ra::flycheck
alibektas Nov 26, 2024
f3d83ba
Preparing for merge from rust-lang/rust
lnicola Nov 28, 2024
ad6e993
Merge from rust-lang/rust
lnicola Nov 28, 2024
0d2b785
Merge pull request #18567 from lnicola/sync-from-rust
lnicola Nov 28, 2024
fa87a3e
Change `GetManyMutError` to match T-libs-api decision
ChayimFriedman2 Nov 28, 2024
fb662a2
Remove redundant associated type bounds from dyn
compiler-errors Nov 30, 2024
b747197
Merge pull request #18577 from compiler-errors/redundant-dyn-atb
lnicola Nov 30, 2024
5a52142
Fix debug configuration querying not inheriting environment
Veykril Dec 2, 2024
0946570
Merge pull request #18586 from Veykril/push-kolxkxyntxtt
Veykril Dec 2, 2024
03ae70d
fix: Fix syntax fixup inserting unnecessary semicolons
Veykril Dec 2, 2024
54a1a96
Merge pull request #18587 from Veykril/push-urrlrursyrws
Veykril Dec 2, 2024
86387c8
Merge pull request #18561 from markmurphydev/macro_name_raw_variable
Veykril Dec 2, 2024
aede6e1
Advertise completions and inlay hints resolve server capabilities bas…
SomeoneToIgnore Dec 3, 2024
f555fc4
Merge pull request #18589 from SomeoneToIgnore/proper-resolve-adverti…
Veykril Dec 3, 2024
97feb03
Only show status bar item in relevant files
darichey Dec 3, 2024
f4c968a
Merge pull request #18592 from darichey/status-bar-visibility
Veykril Dec 3, 2024
fef7ca0
Merge pull request #18555 from ChayimFriedman2/issue-17321
Veykril Dec 3, 2024
879312e
Support `AsyncFnX` traits
ChayimFriedman2 Dec 3, 2024
b94c535
internal: Make exclude characters for typing assists configurable, de…
tareknaser Nov 17, 2024
68cd579
chore: deprecate `typing.autoClosingAngleBrackets` configuration
tareknaser Dec 3, 2024
337725d
Remove references to platform-intrinsic ABI
Dec 3, 2024
bc00304
Fixed another bug with glob imports
ChayimFriedman2 Dec 4, 2024
0d328a8
Improve soundness a bit by making `TaggedArcPtr::try_as_arc_owned()` …
ChayimFriedman2 Dec 4, 2024
45f0e81
Fix shadowing of record enum variant in patterns
ChayimFriedman2 Dec 4, 2024
01870ba
Merge pull request #18606 from ChayimFriedman2/improve-soundness-just…
lnicola Dec 4, 2024
941616e
Merge pull request #18607 from ChayimFriedman2/pattern-record-no-record
lnicola Dec 4, 2024
272aeca
Merge pull request #18595 from markmurphydev/remove_platform_intrinsic
lnicola Dec 4, 2024
c1c6e71
Merge pull request #18605 from ChayimFriedman2/wildcard-imports
Veykril Dec 4, 2024
d83f0fe
Merge pull request #18522 from tareknaser/configure_typing_exclude_chars
Veykril Dec 4, 2024
05aac8c
Better parser recovery for incomplete attributes
Veykril Dec 4, 2024
7efe7eb
fix: Don't create empty path nodes
Veykril Dec 4, 2024
1e47f7d
Update mbe test output
Veykril Dec 4, 2024
2f3e352
Merge pull request #18608 from Veykril/push-rrozmpnyknkx
Veykril Dec 4, 2024
d2ee916
Complete derive helper attributes
ChayimFriedman2 Dec 3, 2024
9296578
Extend reported unsafe operations
ChayimFriedman2 Dec 4, 2024
0370527
Merge pull request #18604 from ChayimFriedman2/complete-helpers
Veykril Dec 4, 2024
1b54eea
Merge pull request #18609 from ChayimFriedman2/unsafe-coverage
Veykril Dec 4, 2024
baf4862
feat: migrate `sort_items` assist to use `SyntaxFactory`
tareknaser Nov 27, 2024
a1fa497
refactor: change target parameter to a reference in add_rewrite method
tareknaser Dec 4, 2024
2b4dc9c
Fix parsing of parenthesized type args and RTN
Veykril Dec 3, 2024
609621d
Merge pull request #18593 from Veykril/push-nokqpzuqtmww
Veykril Dec 4, 2024
2a949d8
Store some hir_def Paths in the type ref source maps
ChayimFriedman2 Nov 19, 2024
63acf60
Lay the foundation for diagnostics in ty lowering, and implement a fi…
ChayimFriedman2 Nov 20, 2024
1aae522
Complete diagnostics in ty lowering groundwork
ChayimFriedman2 Nov 21, 2024
61e8403
feat: migrate introduce_named_generic assist to use SyntaxFactory
tareknaser Oct 28, 2024
7fa84a3
fix: remove make_mut from introduce_named_generic assist
tareknaser Oct 28, 2024
797eb3e
define syntax_editor_add_generic_param
tareknaser Oct 30, 2024
54b597c
fix: implement `syntax_editor_create_generic_param_list`
tareknaser Nov 12, 2024
e275203
fix: refactor syntax_editor_add_generic_param to handle new generic p…
tareknaser Nov 22, 2024
cfd5f7a
fix: refactor `syntax_editor_add_generic_param` to handle adding new …
tareknaser Nov 27, 2024
e7fd49c
fix: refactor `syntax_editor_add_generic_param`
tareknaser Dec 3, 2024
d453198
fix: correct token type for closing angle bracket
tareknaser Dec 3, 2024
b1e0d31
fix: refactor `introduce_named_generic` assist
tareknaser Dec 4, 2024
60e0e02
refactor: move editing for ast using `SyntaxEditor` to a separate file
tareknaser Dec 4, 2024
39aab98
Merge pull request #18541 from ChayimFriedman2/different-generic-args
Veykril Dec 4, 2024
d5f3ed8
Do not report warnings from proc macros, ever
ChayimFriedman2 Dec 4, 2024
6120a8a
fix: update `introduce_named_generic` to use `type_param` directly
tareknaser Dec 4, 2024
3640db2
Merge pull request #18611 from ChayimFriedman2/proc-macro-warn
Veykril Dec 4, 2024
a9afc99
Disable `<` typing handler again
Veykril Dec 5, 2024
b8db0c5
Merge pull request #18616 from Veykril/push-pkumxswtxspo
Veykril Dec 5, 2024
0a99a9f
fix: rename `syntax_editor_add_generic_param` to `add_generic_param`
tareknaser Dec 5, 2024
a19e1df
fix: Fix parsing of integer/keyword name refs in various places
Veykril Dec 5, 2024
4883a12
Merge pull request #18618 from Veykril/push-ysklqzomkyvp
Veykril Dec 5, 2024
7038073
fix: Panic when displaying generic params with defaults
ShoyuVanilla Dec 5, 2024
f9351a8
Merge pull request #18619 from ShoyuVanilla/issue-18613
Veykril Dec 5, 2024
085ea34
Parse lifetime bounds in lifetime param into TypeBoundList
Veykril Dec 5, 2024
0d8e511
Merge pull request #18620 from Veykril/push-pyulxnouvxkq
Veykril Dec 5, 2024
64832b0
fix: Resolve generic parameters within use captures
Veykril Dec 5, 2024
f31547d
Merge pull request #18621 from Veykril/push-suuyuvsmqpyq
Veykril Dec 5, 2024
6ef7f8e
Merge pull request #18483 from tareknaser/syntax_factory_introduce_na…
davidbarsky Dec 5, 2024
23339cb
Merge pull request #18538 from tareknaser/syntax_factory_sort_items
davidbarsky Dec 5, 2024
59a5b38
fix: Fix parsing of dyn T in generic arg on 2015 edition
Veykril Dec 5, 2024
d5c7e64
Merge pull request #18622 from Veykril/push-wlzptrukvyup
Veykril Dec 5, 2024
3db9b1d
fix: Fix parser getting stuck for bad asm expressions
Veykril Dec 6, 2024
c2253c2
Merge pull request #18625 from Veykril/push-npnxwpxuzlqz
Veykril Dec 6, 2024
069fb0f
Make bracket typing handler work on more things
Veykril Nov 4, 2024
2c91563
Add implict unsafety inlay hints for extern blocks
Veykril Dec 4, 2024
0267610
Merge pull request #18610 from Veykril/push-kynytqktmnxq
Veykril Dec 6, 2024
b4dc94d
Merge pull request #18474 from Veykril/push-nvtxykxkwnvs
Veykril Dec 6, 2024
8466efc
Merge pull request #18594 from ChayimFriedman2/async-closures
Veykril Dec 6, 2024
0631f46
Merge pull request #18563 from alibektas/workspace_key_high_precedence
Veykril Dec 6, 2024
2a06000
Merge pull request #18551 from ShoyuVanilla/migrate-turbofish-assist
Veykril Dec 6, 2024
a086560
Improve heuristics for on typing semicolon insertion
Veykril Dec 6, 2024
9549e47
Merge pull request #18627 from Veykril/push-tzvnrnytrksr
Veykril Dec 6, 2024
3fe75c7
Add typing handler for param list pipe
Veykril Dec 6, 2024
fbd6713
fix: Properly determine `SyntaxEditor` replacement intersection
Giga-Bowser Nov 17, 2024
25c0a00
fix: Don't produce `ChangedAncestor` for `SyntaxToken`s
Giga-Bowser Nov 17, 2024
8877598
minor: Add `token` constructor to `SyntaxFactory`
Giga-Bowser Nov 21, 2024
0eed197
minor: Add `expr_bin` constructor to `SyntaxFactory`
Giga-Bowser Nov 21, 2024
ff6b020
feat: Migrate `flip_binexpr` assist to `SyntaxEditor`
Giga-Bowser Nov 21, 2024
418ad88
feat: Migrate `flip_trait_bound` assist to `SyntaxEditor`
Giga-Bowser Nov 22, 2024
806ffb7
minor: Add `token_tree` constructor to `SyntaxFactory`
Giga-Bowser Nov 23, 2024
254198c
feat: Migrate `flip_comma` assist to `SyntaxEditor`
Giga-Bowser Nov 23, 2024
5b2fcf3
Merge pull request #18628 from Veykril/push-sqpymrtxysmw
Veykril Dec 6, 2024
667697e
Highlight right angle as part of fat arrow in macro rules arm
Veykril Dec 6, 2024
fb79ab7
Merge pull request #18629 from Veykril/push-wlsvxwomumpp
Veykril Dec 6, 2024
29a6631
Temporarily disable completion resolve support for helix
Veykril Dec 6, 2024
78496f8
Temporarily disable completion resolve support for neovim
Veykril Dec 6, 2024
998f978
Merge pull request #18630 from Veykril/push-ystzsxpywnxn
Veykril Dec 7, 2024
8358c13
Merge pull request #18575 from Giga-Bowser/flip-assists
Veykril Dec 7, 2024
afdf4c8
Watch for user config ratoml
alibektas Aug 25, 2024
1907786
Coerce two `FnDef`s to fn pointers even if they are the same, if they…
ChayimFriedman2 Dec 7, 2024
7625d76
Merge pull request #18633 from ChayimFriedman2/unify-fn
Veykril Dec 8, 2024
ee30005
Fix a test that didn't test what it should
ChayimFriedman2 Dec 8, 2024
30e3d23
fix: Map new replacement nodes to their mutable equivalents in `Synta…
Giga-Bowser Nov 18, 2024
b4c83da
Merge pull request #18531 from Giga-Bowser/map-new-nodes
Veykril Dec 9, 2024
c6e8a0e
Merge pull request #18635 from ChayimFriedman2/fix-test
Veykril Dec 9, 2024
3fc7101
Fix config guard lock for ratoml tests
Veykril Oct 30, 2024
c7b6c95
Merge pull request #18441 from Veykril/lw-psyvmlotlvqn
Veykril Dec 9, 2024
4148b53
Remove unstable attributes in minicore
lnicola Dec 9, 2024
be43a67
Merge pull request #18642 from lnicola/rm-minicore-unstable
lnicola Dec 9, 2024
b9f809a
Rename test fixture crates to ra_test_fixture
Veykril Dec 9, 2024
770265d
Remove patch sysroot cfg-if hack
Veykril Dec 9, 2024
dc9bcef
Merge pull request #18643 from Veykril/push-muwuzmowptnn
Veykril Dec 9, 2024
641bca6
Merge pull request #18644 from Veykril/push-nolvpzqvoqwx
Veykril Dec 9, 2024
67c9287
fix: Non-exhaustive structs may be empty
Veykril Dec 9, 2024
244b1fd
Merge pull request #18645 from Veykril/push-yruoyrvrsntw
Veykril Dec 9, 2024
2ad6d71
Disable pipe on typing handler
Veykril Dec 9, 2024
91adfec
Merge pull request #18647 from Veykril/push-nsrrmmnzzoym
Veykril Dec 9, 2024
ab6382e
minor: enhance name suggestion for `Arc<T>` and `Rc<T>`
roife Dec 9, 2024
cbc0069
Draft completion hashing
SomeoneToIgnore Dec 9, 2024
e8e3949
Always compute the hash when r-a wants the imports to be resolved
SomeoneToIgnore Dec 9, 2024
78ea49e
Stop excluding Helix from the general resolve path
SomeoneToIgnore Dec 9, 2024
160cb32
Unite more bool hashing
SomeoneToIgnore Dec 9, 2024
9aebb5c
crates/r-a: Fix typo in debug message
yuki0iq Dec 9, 2024
b203c73
Avoid hashing completion-related ranges as those may change during /r…
SomeoneToIgnore Dec 9, 2024
61c0b26
Clippy fixes
SomeoneToIgnore Dec 9, 2024
a73a6a0
Add diagnostic fix to remove unnecessary wrapper in type mismatch
Giga-Bowser Nov 1, 2024
4898f3f
fix: Handle the final statement in `SyntaxFactory::block_expr` properly
Giga-Bowser Nov 14, 2024
b76734f
minor: Migrate `remove_unnecessary_wrapper` to `SyntaxEditor`
Giga-Bowser Nov 15, 2024
edbfa31
Merge pull request #18650 from yuki0iq/fix-typo
lnicola Dec 10, 2024
95670ac
Merge pull request #18649 from roife/fix-issue-18648
lnicola Dec 10, 2024
f94953d
Address the feedback from Veykril
SomeoneToIgnore Dec 10, 2024
1ce1560
Address the feedback from pascalkuthe
SomeoneToIgnore Dec 10, 2024
3bc26ba
minor: Add `item_enum` constructor to `SyntaxFactory`
Giga-Bowser Dec 10, 2024
028ca8e
De-duplicate and improve definition of core::ffi::c_char
arichardson Nov 13, 2024
e8bcce7
Remove l4re from the unsigned char operating system list
arichardson Dec 4, 2024
dd3e98c
Add references to the specific ABI documents
arichardson Dec 10, 2024
d9bb8fc
minor: Add `whitespace` constructor to `SyntaxFactory`
Giga-Bowser Dec 5, 2024
26e7e4f
minor: Add `ty_infer` constructor to `SyntaxFactory`
Giga-Bowser Dec 10, 2024
3b78166
minor: Migrate `generate_enum_variant` to `SyntaxEditor`
Giga-Bowser Dec 10, 2024
0b121ef
feat: preserve order of parameters in extract_functions
roife Dec 10, 2024
7c4ac71
coverage: Extract function metadata handling to a `covfun` submodule
Zalathar Dec 11, 2024
611c72f
Merge pull request #18656 from roife/fix-issue-18639
Veykril Dec 11, 2024
b20d1b8
Merge pull request #18657 from Giga-Bowser/generate-enum-variant
Veykril Dec 11, 2024
e1a27b8
Merge pull request #18653 from SomeoneToIgnore/hash-completions
Veykril Dec 11, 2024
536eea3
Merge pull request #18458 from Giga-Bowser/master
Veykril Dec 11, 2024
6a8c016
coverage: Reify `CovfunRecord` as an intermediate step
Zalathar Dec 11, 2024
1649eb6
Preparing for merge from rust-lang/rust
lnicola Dec 11, 2024
5db2aa8
Merge from rust-lang/rust
lnicola Dec 11, 2024
884f57f
Bump rustc crates
lnicola Dec 11, 2024
e6fbb5c
fix: Swallow rustfmt parsing panics
Veykril Dec 11, 2024
8172088
Merge pull request #18662 from lnicola/sync-from-rust
lnicola Dec 11, 2024
a18e38e
Merge pull request #18663 from Veykril/push-syoklzkntykn
Veykril Dec 11, 2024
9e6b7c1
coverage: Adjust a codegen test to ignore the order of covmap/covfun …
Zalathar Dec 11, 2024
512f3fd
coverage: Only generate a CGU's covmap record if it has covfun records
Zalathar Dec 11, 2024
3f3a9bf
coverage: Store intermediate region tables in `CovfunRecord`
Zalathar Dec 11, 2024
48b8832
wasm(32|64): update alignment string
durin42 Dec 11, 2024
55806e5
document check_expr_field
Dec 10, 2024
fe516ef
Rollup merge of #132975 - arichardson:ffi-c-char, r=tgross35
matthiaskrgr Dec 11, 2024
2e60288
Rollup merge of #133598 - ChayimFriedman2:get-many-mut-detailed-err, …
matthiaskrgr Dec 11, 2024
90a42c2
Rollup merge of #134148 - dev-ardi:cleanup_check_field_expr, r=compil…
matthiaskrgr Dec 11, 2024
13c13ee
Rollup merge of #134163 - Zalathar:covfun, r=SparrowLii,jieyouxu
matthiaskrgr Dec 11, 2024
eefefbe
Rollup merge of #134165 - durin42:wasm-target-string, r=jieyouxu
matthiaskrgr Dec 11, 2024
531e578
Rollup merge of #134170 - lnicola:sync-from-ra, r=lnicola
matthiaskrgr Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ pub(crate) unsafe fn create_module<'ll>(
// See https://github.com/llvm/llvm-project/pull/118004
target_data_layout = target_data_layout.replace("-i128:128", "");
}
if sess.target.arch.starts_with("wasm32") || sess.target.arch.starts_with("wasm64") {
// LLVM 20 updates the wasm(32|64) layout to correctly align 128 bit integers to 128 bit.
// See https://github.com/llvm/llvm-project/pull/119204
target_data_layout = target_data_layout.replace("-i128:128", "");
}
}

// Ensure the data-layout values hardcoded remain the defaults.
Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,34 @@ impl CoverageSpan {
}
}

/// Holds tables of the various region types in one struct.
///
/// Don't pass this struct across FFI; pass the individual region tables as
/// pointer/length pairs instead.
///
/// Each field name has a `_regions` suffix for improved readability after
/// exhaustive destructing, which ensures that all region types are handled.
#[derive(Clone, Debug, Default)]
pub(crate) struct Regions {
pub(crate) code_regions: Vec<CodeRegion>,
pub(crate) branch_regions: Vec<BranchRegion>,
pub(crate) mcdc_branch_regions: Vec<MCDCBranchRegion>,
pub(crate) mcdc_decision_regions: Vec<MCDCDecisionRegion>,
}

impl Regions {
/// Returns true if none of this structure's tables contain any regions.
pub(crate) fn has_no_regions(&self) -> bool {
let Self { code_regions, branch_regions, mcdc_branch_regions, mcdc_decision_regions } =
self;

code_regions.is_empty()
&& branch_regions.is_empty()
&& mcdc_branch_regions.is_empty()
&& mcdc_decision_regions.is_empty()
}
}

/// Must match the layout of `LLVMRustCoverageCodeRegion`.
#[derive(Clone, Debug)]
#[repr(C)]
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ pub(crate) fn write_filenames_to_buffer<'a>(
pub(crate) fn write_function_mappings_to_buffer(
virtual_file_mapping: &[u32],
expressions: &[ffi::CounterExpression],
code_regions: &[ffi::CodeRegion],
branch_regions: &[ffi::BranchRegion],
mcdc_branch_regions: &[ffi::MCDCBranchRegion],
mcdc_decision_regions: &[ffi::MCDCDecisionRegion],
regions: &ffi::Regions,
) -> Vec<u8> {
let ffi::Regions { code_regions, branch_regions, mcdc_branch_regions, mcdc_decision_regions } =
regions;
llvm::build_byte_buffer(|buffer| unsafe {
llvm::LLVMRustCoverageWriteFunctionMappingsToBuffer(
virtual_file_mapping.as_ptr(),
Expand Down
210 changes: 32 additions & 178 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::ffi::CString;
use std::iter;

use itertools::Itertools as _;
Expand All @@ -9,21 +8,22 @@ use rustc_codegen_ssa::traits::{
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_index::IndexVec;
use rustc_middle::mir::coverage::MappingKind;
use rustc_middle::ty::{self, TyCtxt};
use rustc_middle::{bug, mir};
use rustc_session::RemapFileNameExt;
use rustc_session::config::RemapPathScopeComponents;
use rustc_span::def_id::DefIdSet;
use rustc_span::{Span, Symbol};
use rustc_target::spec::HasTargetSpec;
use tracing::debug;

use crate::common::CodegenCx;
use crate::coverageinfo::llvm_cov;
use crate::coverageinfo::map_data::FunctionCoverage;
use crate::coverageinfo::{ffi, llvm_cov};
use crate::coverageinfo::mapgen::covfun::prepare_covfun_record;
use crate::llvm;

mod covfun;

/// Generates and exports the coverage map, which is embedded in special
/// linker sections in the final binary.
///
Expand Down Expand Up @@ -80,47 +80,28 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
let filenames_val = cx.const_bytes(&filenames_buffer);
let filenames_ref = llvm_cov::hash_bytes(&filenames_buffer);

// Generate the coverage map header, which contains the filenames used by
// this CGU's coverage mappings, and store it in a well-known global.
generate_covmap_record(cx, covmap_version, filenames_size, filenames_val);

let mut unused_function_names = Vec::new();

// Encode coverage mappings and generate function records
for (instance, function_coverage) in function_coverage_map {
debug!("Generate function coverage for {}, {:?}", cx.codegen_unit.name(), instance);

let mangled_function_name = tcx.symbol_name(instance).name;
let source_hash = function_coverage.source_hash();
let is_used = function_coverage.is_used();

let coverage_mapping_buffer =
encode_mappings_for_function(tcx, &global_file_table, &function_coverage);

if coverage_mapping_buffer.is_empty() {
if function_coverage.is_used() {
bug!(
"A used function should have had coverage mapping data but did not: {}",
mangled_function_name
);
} else {
debug!("unused function had no coverage mapping data: {}", mangled_function_name);
continue;
}
}
let covfun_records = function_coverage_map
.into_iter()
.filter_map(|(instance, function_coverage)| {
prepare_covfun_record(tcx, &global_file_table, instance, &function_coverage)
})
.collect::<Vec<_>>();

// If there are no covfun records for this CGU, don't generate a covmap record.
// Emitting a covmap record without any covfun records causes `llvm-cov` to
// fail when generating coverage reports, and if there are no covfun records
// then the covmap record isn't useful anyway.
// This should prevent a repeat of <https://github.com/rust-lang/rust/issues/133606>.
if covfun_records.is_empty() {
return;
}

if !is_used {
unused_function_names.push(mangled_function_name);
}
for covfun in &covfun_records {
unused_function_names.extend(covfun.mangled_function_name_if_unused());

generate_covfun_record(
cx,
mangled_function_name,
source_hash,
filenames_ref,
coverage_mapping_buffer,
is_used,
);
covfun::generate_covfun_record(cx, filenames_ref, covfun)
}

// For unused functions, we need to take their mangled names and store them
Expand All @@ -141,6 +122,11 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
llvm::set_linkage(array, llvm::Linkage::InternalLinkage);
llvm::set_initializer(array, initializer);
}

// Generate the coverage map header, which contains the filenames used by
// this CGU's coverage mappings, and store it in a well-known global.
// (This is skipped if we returned early due to having no covfun records.)
generate_covmap_record(cx, covmap_version, filenames_size, filenames_val);
}

/// Maps "global" (per-CGU) file ID numbers to their underlying filenames.
Expand Down Expand Up @@ -208,7 +194,7 @@ rustc_index::newtype_index! {

/// Holds a mapping from "local" (per-function) file IDs to "global" (per-CGU)
/// file IDs.
#[derive(Default)]
#[derive(Debug, Default)]
struct VirtualFileMapping {
local_to_global: IndexVec<LocalFileId, GlobalFileId>,
global_to_local: FxIndexMap<GlobalFileId, LocalFileId>,
Expand All @@ -222,10 +208,10 @@ impl VirtualFileMapping {
.or_insert_with(|| self.local_to_global.push(global_file_id))
}

fn into_vec(self) -> Vec<u32> {
// This conversion should be optimized away to ~zero overhead.
// In any case, it's probably not hot enough to worry about.
self.local_to_global.into_iter().map(|global| global.as_u32()).collect()
fn to_vec(&self) -> Vec<u32> {
// This clone could be avoided by transmuting `&[GlobalFileId]` to `&[u32]`,
// but it isn't hot or expensive enough to justify the extra unsafety.
self.local_to_global.iter().map(|&global| GlobalFileId::as_u32(global)).collect()
}
}

Expand All @@ -236,83 +222,6 @@ fn span_file_name(tcx: TyCtxt<'_>, span: Span) -> Symbol {
Symbol::intern(&name)
}

/// Using the expressions and counter regions collected for a single function,
/// generate the variable-sized payload of its corresponding `__llvm_covfun`
/// entry. The payload is returned as a vector of bytes.
///
/// Newly-encountered filenames will be added to the global file table.
fn encode_mappings_for_function(
tcx: TyCtxt<'_>,
global_file_table: &GlobalFileTable,
function_coverage: &FunctionCoverage<'_>,
) -> Vec<u8> {
let counter_regions = function_coverage.counter_regions();
if counter_regions.is_empty() {
return Vec::new();
}

let expressions = function_coverage.counter_expressions().collect::<Vec<_>>();

let mut virtual_file_mapping = VirtualFileMapping::default();
let mut code_regions = vec![];
let mut branch_regions = vec![];
let mut mcdc_branch_regions = vec![];
let mut mcdc_decision_regions = vec![];

// Currently a function's mappings must all be in the same file as its body span.
let file_name = span_file_name(tcx, function_coverage.function_coverage_info.body_span);

// Look up the global file ID for that filename.
let global_file_id = global_file_table.global_file_id_for_file_name(file_name);

// Associate that global file ID with a local file ID for this function.
let local_file_id = virtual_file_mapping.local_id_for_global(global_file_id);
debug!(" file id: {local_file_id:?} => {global_file_id:?} = '{file_name:?}'");

// For each counter/region pair in this function+file, convert it to a
// form suitable for FFI.
for (mapping_kind, region) in counter_regions {
debug!("Adding counter {mapping_kind:?} to map for {region:?}");
let span = ffi::CoverageSpan::from_source_region(local_file_id, region);
match mapping_kind {
MappingKind::Code(term) => {
code_regions.push(ffi::CodeRegion { span, counter: ffi::Counter::from_term(term) });
}
MappingKind::Branch { true_term, false_term } => {
branch_regions.push(ffi::BranchRegion {
span,
true_counter: ffi::Counter::from_term(true_term),
false_counter: ffi::Counter::from_term(false_term),
});
}
MappingKind::MCDCBranch { true_term, false_term, mcdc_params } => {
mcdc_branch_regions.push(ffi::MCDCBranchRegion {
span,
true_counter: ffi::Counter::from_term(true_term),
false_counter: ffi::Counter::from_term(false_term),
mcdc_branch_params: ffi::mcdc::BranchParameters::from(mcdc_params),
});
}
MappingKind::MCDCDecision(mcdc_decision_params) => {
mcdc_decision_regions.push(ffi::MCDCDecisionRegion {
span,
mcdc_decision_params: ffi::mcdc::DecisionParameters::from(mcdc_decision_params),
});
}
}
}

// Encode the function's coverage mappings into a buffer.
llvm_cov::write_function_mappings_to_buffer(
&virtual_file_mapping.into_vec(),
&expressions,
&code_regions,
&branch_regions,
&mcdc_branch_regions,
&mcdc_decision_regions,
)
}

/// Generates the contents of the covmap record for this CGU, which mostly
/// consists of a header and a list of filenames. The record is then stored
/// as a global variable in the `__llvm_covmap` section.
Expand Down Expand Up @@ -350,61 +259,6 @@ fn generate_covmap_record<'ll>(
cx.add_used_global(llglobal);
}

/// Generates the contents of the covfun record for this function, which
/// contains the function's coverage mapping data. The record is then stored
/// as a global variable in the `__llvm_covfun` section.
fn generate_covfun_record(
cx: &CodegenCx<'_, '_>,
mangled_function_name: &str,
source_hash: u64,
filenames_ref: u64,
coverage_mapping_buffer: Vec<u8>,
is_used: bool,
) {
// Concatenate the encoded coverage mappings
let coverage_mapping_size = coverage_mapping_buffer.len();
let coverage_mapping_val = cx.const_bytes(&coverage_mapping_buffer);

let func_name_hash = llvm_cov::hash_bytes(mangled_function_name.as_bytes());
let func_name_hash_val = cx.const_u64(func_name_hash);
let coverage_mapping_size_val = cx.const_u32(coverage_mapping_size as u32);
let source_hash_val = cx.const_u64(source_hash);
let filenames_ref_val = cx.const_u64(filenames_ref);
let func_record_val = cx.const_struct(
&[
func_name_hash_val,
coverage_mapping_size_val,
source_hash_val,
filenames_ref_val,
coverage_mapping_val,
],
/*packed=*/ true,
);

// Choose a variable name to hold this function's covfun data.
// Functions that are used have a suffix ("u") to distinguish them from
// unused copies of the same function (from different CGUs), so that if a
// linker sees both it won't discard the used copy's data.
let func_record_var_name =
CString::new(format!("__covrec_{:X}{}", func_name_hash, if is_used { "u" } else { "" }))
.unwrap();
debug!("function record var name: {:?}", func_record_var_name);

let llglobal = llvm::add_global(cx.llmod, cx.val_ty(func_record_val), &func_record_var_name);
llvm::set_initializer(llglobal, func_record_val);
llvm::set_global_constant(llglobal, true);
llvm::set_linkage(llglobal, llvm::Linkage::LinkOnceODRLinkage);
llvm::set_visibility(llglobal, llvm::Visibility::Hidden);
llvm::set_section(llglobal, cx.covfun_section_name());
// LLVM's coverage mapping format specifies 8-byte alignment for items in this section.
// <https://llvm.org/docs/CoverageMappingFormat.html>
llvm::set_alignment(llglobal, Align::EIGHT);
if cx.target_spec().supports_comdat() {
llvm::set_comdat(cx.llmod, llglobal, &func_record_var_name);
}
cx.add_used_global(llglobal);
}

/// Each CGU will normally only emit coverage metadata for the functions that it actually generates.
/// But since we don't want unused functions to disappear from coverage reports, we also scan for
/// functions that were instrumented but are not participating in codegen.
Expand Down
Loading
Loading