Commit Graph

222 Commits

Author SHA1 Message Date
Zalathar
2e36990881 coverage: Convert and check span coordinates without a local file ID
For expansion region support, we will want to be able to convert and check
spans before creating a corresponding local file ID.

If we create local file IDs eagerly, but some expansion turns out to have no
successfully-converted spans, LLVM will complain about that expansion's file ID
having no regions.
2025-03-20 13:29:32 +11:00
Zalathar
d07ef5b0e1 coverage: Add LLVM plumbing for expansion regions
This is currently unused, but paves the way for future work on expansion
regions without having to worry about the FFI parts.
2025-03-20 12:40:36 +11:00
Zalathar
cc8336b6c1 coverage: Don't store a body span in FunctionCoverageInfo 2025-03-18 23:18:24 +11:00
Zalathar
cd2b978433 coverage: Don't refer to the body span when enlarging empty spans
Given that we now only enlarge empty spans to "{" or "}", there shouldn't be
any danger of enlarging beyond a function body.
2025-03-18 23:18:23 +11:00
Oli Scherer
f16f64b15a Remove inherent function that has a trait method duplicate of a commonly imported trait 2025-02-24 15:11:29 +00:00
Zalathar
bd855b6c9e coverage: Remove the old code for simplifying counters after MIR opts 2025-02-06 21:44:31 +11:00
Zalathar
20d051ec87 coverage: Defer part of counter-creation until codegen 2025-02-06 21:44:31 +11:00
Zalathar
ee7dc06cf1 coverage: Store BCB node IDs in mappings, and resolve them in codegen
Even though the coverage graph itself is no longer available during codegen,
its nodes can still be used as opaque IDs.
2025-02-06 21:44:29 +11:00
Manuel Drehwald
1f30517d40 upstream rustc_codegen_ssa/rustc_middle changes for enzyme/autodiff 2025-01-29 21:31:13 -05:00
Oli Scherer
b24f674520 Change collect_and_partition_mono_items tuple return type to a struct 2025-01-27 09:38:12 +00:00
Zalathar
ff48331588 coverage: Make query coverage_ids_info return an Option
This reflects the fact that we can't compute meaningful info for a function
that wasn't instrumented and therefore doesn't have `function_coverage_info`.
2025-01-24 16:13:11 +11:00
Zalathar
aced4dcf10 coverage: Add a synthetic test for when all spans are discarded 2024-12-19 22:03:43 +11:00
Zalathar
837a25dd41 coverage: Identify source files by ID, not by interned filename 2024-12-19 18:09:09 +11:00
Zalathar
34ed51cb83 coverage: Store coverage source regions as Span until codegen 2024-12-19 18:09:09 +11:00
Zalathar
c3780e1d22 coverage: Quietly skip functions that end up having no mappings
In codegen, a used function with `FunctionCoverageInfo` but no mappings has
historically indicated a bug. However, that will no longer be the case after
moving some fallible span-processing steps into codegen.
2024-12-19 18:09:07 +11:00
Zalathar
d416cead5a coverage: Rename some FFI fields from span to cov_span
This will avoid confusion with actual `Span` spans.
2024-12-19 17:26:01 +11:00
Zalathar
541d4e85d9 coverage: Track used functions in a set instead of a map
This patch dismantles what was left of `FunctionCoverage` in `map_data.rs`,
replaces `function_coverage_map` with a set, and overhauls how we prepare
covfun records for unused functions.
2024-12-17 14:14:19 +11:00
Zalathar
d34c365eb0 coverage: Pull function source hash out of map_data.rs 2024-12-17 13:55:20 +11:00
Zalathar
527f8127bb coverage: Pull region conversion out of map_data.rs 2024-12-17 13:55:20 +11:00
Zalathar
252276a53d coverage: Pull expression conversion out of map_data.rs 2024-12-17 13:55:20 +11:00
Zalathar
154fae1e8d coverage: Build the global file table on the fly 2024-12-17 13:55:19 +11:00
Zalathar
fe412af4fc coverage: Use is_eligible_for_coverage to filter unused functions
The checks in `is_eligible_for_coverage` include `is_fn_like`, but will also
exclude various function-like things that cannot possibly have coverage
instrumentation.
2024-12-17 13:30:11 +11:00
Zalathar
5f5745beb0 coverage: Tidy up creation of covfun records 2024-12-12 22:13:07 +11:00
Zalathar
de53fe245d coverage: Tidy up creation of covmap records 2024-12-12 22:10:42 +11:00
Zalathar
3f3a9bf7f5 coverage: Store intermediate region tables in CovfunRecord
This defers the call to `llvm_cov::write_function_mappings_to_buffer` until
just before its enclosing global variable is created.
2024-12-11 21:35:45 +11:00
Zalathar
512f3fdebe coverage: Only generate a CGU's covmap record if it has covfun records 2024-12-11 21:35:44 +11:00
Zalathar
6a8c016266 coverage: Reify CovfunRecord as an intermediate step 2024-12-11 18:25:10 +11:00
Zalathar
7c4ac71ad1 coverage: Extract function metadata handling to a covfun submodule 2024-12-11 17:49:44 +11:00
Zalathar
3a35fb6938 coverage: Unused functions don't need to store CoverageIdsInfo 2024-12-08 21:00:53 +11:00
Zalathar
4d2bfece41 coverage: Remove FunctionCoverageCollector
The information that was being collected by this builder type is now collected
by the `coverage_ids_info` query instead.
2024-12-08 20:53:57 +11:00
Zalathar
2022ef7f12 coverage: Use a query to find counters/expressions that must be zero
This query (`coverage_ids_info`) already determines which counter/expression
IDs are unused, so it only takes a little extra effort to also determine which
counters/expressions must have a value of zero.
2024-12-08 20:53:39 +11:00
Zalathar
f3f7c20f7b coverage: Move CoverageIdsInfo into mir::coverage 2024-12-08 17:50:42 +11:00
Zalathar
6fc0fe76e8 coverage: Use a query to identify which counter/expression IDs are used 2024-11-30 00:58:48 +11:00
Zalathar
121a17ccc3 coverage: All counter terms in an unused function are zero
This is currently handled automatically by the fact that codegen doesn't visit
coverage statements in unused functions, but that will no longer be the case
when unused IDs are identified by a separate query instead.
2024-11-30 00:54:53 +11:00
Zalathar
58e122fef8 coverage: Hoist and explain the check for coverage_cx 2024-11-30 00:54:53 +11:00
Zalathar
3f65114ffc coverage: Rename CrateCoverageContext to CguCoverageContext
This context is stored in `CodegenCx`, which makes it per-CGU rather than
per-crate. A single crate can have multiple CGUs.
2024-11-30 00:54:53 +11:00
Zalathar
9461f4296f Revert "Rollup merge of #133418 - Zalathar:spans, r=jieyouxu"
This reverts commit adf9b5fcd1, reversing
changes made to af1ca153d4.

Reverting due to <https://github.com/rust-lang/rust/issues/133606>.
2024-11-29 14:57:01 +11:00
Zalathar
2748009aad coverage: Identify source files by ID, not by interned filename 2024-11-24 23:46:41 +11:00
Zalathar
b9fb1a69d2 coverage: Store coverage source regions as Span until codegen 2024-11-24 23:46:39 +11:00
Zalathar
87fe7def12 coverage: Rename some FFI fields from span to cov_span
This will avoid confusion with actual `Span` spans.
2024-11-24 23:29:02 +11:00
Zalathar
619a272612 coverage: Ignore functions that end up having no mappings
A used function with no mappings has historically indicated a bug, but that
will no longer be the case after moving some fallible span-processing steps
into codegen.
2024-11-24 23:28:02 +11:00
Matthias Krüger
b95232dabb
Rollup merge of #132675 - Zalathar:empty-spans, r=jieyouxu
coverage: Restrict empty-span expansion to only cover `{` and `}`

Coverage instrumentation has some tricky code for converting a coverage-relevant `Span` into a set of start/end line/byte-column coordinates that will be embedded in the CGU's coverage metadata.

A big part of this complexity is special code for handling empty spans, which are expanded into non-empty spans (if possible) because LLVM's coverage reporter does not handle empty spans well.

This PR simplifies that code by restricting it to only apply in two specific situations: when the character after the empty span is `{`, or the character before the empty span is `}`.

(As an added benefit, this means that the expanded spans no longer extend awkwardly beyond the end of a physical line, which was common under the previous implementation.)

Along the way, this PR also removes some unhelpful code for dealing with function source code spread across multiple files. Functions currently can't have coverage spans in multiple files, and if that ever changes (e.g. to properly support expansion regions) then this code will need to be completely overhauled anyway.
2024-11-10 17:43:07 +01:00
Zalathar
925dfc8608 coverage: Pass a LocalFileId to CoverageSpan::from_source_region 2024-11-10 11:58:44 +11:00
Zalathar
996bdabc2a coverage: Remove unhelpful code for handling multiple files per function
Functions currently can't have mappings in multiple files, and if that ever
changes (e.g. to properly support expansion regions), this code will need to be
completely overhauled anyway.
2024-11-08 20:43:08 +11:00
Zalathar
3f9c54caf0 coverage: Add GlobalFileId for stricter type-checking of file IDs
We already had a dedicated `LocalFileId` index type, but previously we used a
raw `u32` for global file IDs, because index types were harder to pass through
FFI.
2024-11-08 20:43:08 +11:00
Zalathar
19d5dc0ed1 coverage: Tidy up coverage-specific FFI functions 2024-11-05 15:32:36 +11:00
Zalathar
b790e4473c coverage: Extract safe FFI wrapper functions to llvm_cov 2024-11-05 15:32:34 +11:00
Jubilee Young
b895bf4fdc compiler: Directly use rustc_abi in codegen 2024-11-03 12:30:32 -08:00
Zalathar
8dddd1ae60 coverage: Avoid ICE when coverage_cx is unexpectedly unavailable 2024-10-31 21:25:43 +11:00
Zalathar
4bd84b23a8 Use a type-safe helper to cast &str and &[u8] to *const c_char 2024-10-28 21:31:32 +11:00