Commit Graph

1539 Commits

Author SHA1 Message Date
bors 41aa06ecf9 Auto merge of #116033 - bvanjoi:fix-116032, r=petrochenkov
report `unused_import` for empty reexports even it is pub

Fixes #116032

An easy fix. r? `@petrochenkov`

(Discovered this issue while reviewing #115993.)
2023-10-23 20:24:09 +00:00
bohan 482275b194 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
Zalathar 6af9fef085 coverage: Emit the filenames section before encoding per-function mappings
Most coverage metadata is encoded into two sections in the final executable.
The `__llvm_covmap` section mostly just contains a list of filenames, while the
`__llvm_covfun` section contains encoded coverage maps for each instrumented
function.

The catch is that each per-function record also needs to contain a hash of the
filenames list that it refers to. Historically this was handled by assembling
most of the per-function data into a temporary list, then assembling the
filenames buffer, then using the filenames hash to emit the per-function data,
and then finally emitting the filenames table itself.

However, now that we build the filenames table up-front (via a separate
traversal of the per-function data), we can hash and emit that part first, and
then emit each of the per-function records immediately after building. This
removes the awkwardness of having to temporarily store nearly-complete
per-function records.
2023-10-22 23:17:15 +11:00
Zalathar de4cfbca2e coverage: Encode function mappings without re-sorting them
The main change here is that `VirtualFileMapping` now uses an internal hashmap
to de-duplicate incoming global file IDs. That removes the need for
`encode_mappings_for_function` to re-sort its mappings by filename in order to
de-duplicate them.

(We still de-duplicate runs of identical filenames to save work, but this is
not load-bearing for correctness, so a sort is not necessary.)
2023-10-22 20:37:39 +11:00
Zalathar 88159cafa7 coverage: Encapsulate local-to-global file mappings 2023-10-22 20:37:39 +11:00
Zalathar e985ae5a45 coverage: Build the global file table ahead of time 2023-10-22 20:37:37 +11:00
Zalathar 86b55cccff coverage: Fetch expressions and mappings separately
The combined `get_expressions_and_counter_regions` method was an artifact of
having to prepare the expressions and mappings at the same time, to avoid
ownership/lifetime problems with temporary data used by both.

Now that we have an explicit transition from `FunctionCoverageCollector` to the
final `FunctionCoverage`, we can prepare any shared data during that step and
store it in the final struct.
2023-10-22 20:11:48 +11:00
Zalathar 371883a05a coverage: Split `FunctionCoverage` into distinct collector/finished phases
This gives us a clearly-defined place to run code after the instance's MIR has
been traversed by codegen, but before we emit its `__llvm_covfun` record.
2023-10-22 20:11:45 +11:00
Zalathar 6f1ca8d9eb coverage: Change query `codegened_and_inlined_items` to a plain function
This query has a name that sounds general-purpose, but in fact it has
coverage-specific semantics, and (fortunately) is only used by coverage code.

Because it is only ever called once (from one designated CGU), it doesn't need
to be a query, and we can change it to a regular function instead.
2023-10-21 12:20:05 +11:00
Zalathar cdeeffde64 coverage: Move unused-function helpers closer to where they are used 2023-10-21 12:20:05 +11:00
Zalathar e964ea5bf5 coverage: Emit mappings for unused functions without generating stubs 2023-10-21 12:20:05 +11:00
Oli Scherer e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer 60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
bors 94c4e5c411 Auto merge of #115214 - Urgau:rfc-3127-trim-paths, r=compiler-errors
Implement rustc part of RFC 3127 trim-paths

This PR implements (or at least tries to) [RFC 3127 trim-paths](https://github.com/rust-lang/rust/issues/111540), the rustc part. That is `-Zremap-path-scope` with all of it's components/scopes.

`@rustbot` label: +F-trim-paths
2023-10-19 19:09:29 +00:00
Zalathar 33da0978ac coverage: Explicitly note that counter/expression IDs are function-local 2023-10-18 23:44:36 +11:00
Zalathar 13b2d604ec coverage: Store expression data in function coverage info
Even though expression details are now stored in the info structure, we still
need to inject `ExpressionUsed` statements into MIR, because if one is missing
during codegen then we know that it was optimized out and we can remap all of
its associated code regions to zero.
2023-10-18 23:44:34 +11:00
Zalathar 6da319f635 coverage: Store all of a function's mappings in function coverage info
Previously, mappings were attached to individual coverage statements in MIR.
That necessitated special handling in MIR optimizations to avoid deleting those
statements, since otherwise codegen would be unable to reassemble the original
list of mappings.

With this change, a function's list of mappings is now attached to its MIR
body, and survives intact even if individual statements are deleted by
optimizations.
2023-10-18 23:42:39 +11:00
Zalathar 4099ab1997 coverage: Make expression simplification non-destructive
Instead of modifying the accumulated expressions in-place, we now build a set
of expressions that are known to be zero, and then consult that set on the fly
when converting the expression data for FFI.

This will be necessary when moving mappings and expression data into function
coverage info, which can't be mutated during codegen.
2023-10-18 22:29:31 +11:00
Zalathar 8efdd4cca6 coverage: Collect a function's coverage mappings into a single list
This is an intermediate step towards being able to store all of a function's
mappings in function coverage info.
2023-10-18 21:24:01 +11:00
Zalathar 79f935b96c coverage: Rename `Operand` to `CovTerm`
Later patches in this PR will use `CovTerm` to represent things that are not
expression operands.
2023-10-18 21:23:58 +11:00
Zalathar a18c5f3b75 coverage: Store the number of counters/expressions in function coverage info
Coverage codegen can now allocate arrays based on the number of
counters/expressions originally used by the instrumentor.

The existing query that inspects coverage statements is still used for
determining the number of counters passed to `llvm.instrprof.increment`. If
some high-numbered counters were removed by MIR optimizations, the instrumented
binary can potentially use less memory and disk space at runtime.
2023-10-18 21:22:40 +11:00
Zalathar c479bc7f3b coverage: Attach an optional `FunctionCoverageInfo` to `mir::Body`
This allows coverage information to be attached to the function as a whole when
appropriate, instead of being smuggled through coverage statements in the
function's basic blocks.

As an example, this patch moves the `function_source_hash` value out of
individual `CoverageKind::Counter` statements and into the per-function info.

When synthesizing unused functions for coverage purposes, the absence of this
info is taken to indicate that a function was not eligible for coverage and
should not be synthesized.
2023-10-18 21:20:29 +11:00
Urgau eccc9e6628 [RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopes 2023-10-17 10:11:30 +02:00
Michael Howell 2ff2624722 docs: add Rust logo to more compiler crates
c6e6ecb1af added it to some of the
compiler's crates, but avoided adding it to all of them to reduce
bit-rot. This commit adds to more.
2023-10-16 15:38:08 -07:00
Michael Goulet b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
bors 130ff8cb6c Auto merge of #115964 - bjorn3:cgu_reuse_tracker_global_state, r=cjgillot
Remove cgu_reuse_tracker from Session

This removes a bit of global mutable state.

It will now miss post-lto cgu reuse when ThinLTO determines that a cgu doesn't get changed, but there weren't any tests for this anyway and a test for it would be fragile to the exact implementation of ThinLTO in LLVM.
2023-10-13 00:09:30 +00:00
bors df4379b4eb Auto merge of #116510 - scottmcm:no-1-simd-v2, r=compiler-errors
Copy 1-element arrays as scalars, not vectors

For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.

Inspired by https://github.com/rust-lang/rust/issues/101210#issuecomment-1732470941, which pointed out that `Option<[u8; 1]>` was codegenning worse than `Option<u8>`.

(I'm not sure *why* LLVM doesn't optimize out `<1 x u8>`, but might as well just not emit it in the first place in this codepath.)

---

I think I bit off too much in #116479; let me try just the scalar case first.

r? `@ghost`
2023-10-12 18:45:01 +00:00
bjorn3 3dfd9dfe7c Remove an LTO dependent cgu_reuse_tracker.set_actual_reuse call 2023-10-09 18:38:51 +00:00
Camille GILLOT 098fc9715e Make FnDef 1-ZST in LLVM debuginfo. 2023-10-08 16:42:45 +00:00
Scott McMurray ae9cec5839 Copy 1-element arrays as scalars, not vectors
For `[T; 1]` it's silly to copy as `<1 x T>` when we can just copy as `T`.
2023-10-07 00:10:32 -07:00
Jubilee ea3454eabb
Rollup merge of #116223 - catandcoder:master, r=cjgillot
Fix misuses of a vs an

Fixes the misuse of "a" vs "an", according to English grammatical
expectations and using https://www.a-or-an.com/
2023-10-05 00:56:29 -07:00
cui fliter f44d116e1f Fix misuses of a vs an
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-10-04 08:01:11 +08:00
Zalathar ee9d00f6b8 coverage: Let each coverage statement hold a vector of code regions
This makes it possible for a `StatementKind::Coverage` to hold more than one
code region, but that capability is not yet used.
2023-10-03 13:03:39 +11:00
Zalathar 59a11af1f9 coverage: Mappings for unused functions can all be zero
There is no need to include a dummy counter reference in the coverage mappings
for an unused function.
2023-10-03 13:03:39 +11:00
Nikita Popov 5bcf4f26ac Limit to LLVM 17.0.2 to work around WinEH codegen bug 2023-10-02 11:06:38 +02:00
Erik Desjardins 31ee8b1818 Reapply: Mark drop calls in landing pads cold instead of noinline
Co-authored-by: Max Fan <git@max.fan>
Co-authored-by: Nikita Popov <npopov@redhat.com>
2023-10-02 10:37:53 +02:00
bors 9136560d32 Auto merge of #115933 - oli-obk:simd_shuffle_const, r=workingjubilee
Prototype using const generic for simd_shuffle IDX array

cc https://github.com/rust-lang/rust/issues/85229

r? `@workingjubilee` on the design

TLDR: there is now a `fn simd_shuffle_generic<T, U, const IDX: &'static [u32]>(x: T, y: T) -> U;` intrinsic that allows replacing

```rust
simd_shuffle(a, b, const { stuff })
```

with

```rust
simd_shuffle_generic::<_, _, {&stuff}>(a, b)
```

which makes the compiler implementations much simpler, if we manage to at some point eliminate `simd_shuffle`.

There are some issues with this today though (can't do math without bubbling it up in the generic arguments). With this change, we can start porting the simple cases and get better data on the others.
2023-09-30 04:05:26 +00:00
bors a327e753bc Auto merge of #115986 - onur-ozkan:fix-cross-compilation-lto-problem, r=wesleywiser
allow LTO on `proc-macro` crates with `-Zdylib-lto`

ref https://github.com/rust-lang/rust/pull/115986#issuecomment-1732316361

Fixes #110296
2023-09-29 03:57:17 +00:00
bors 5ae769f06b Auto merge of #116144 - lcnr:subst-less, r=oli-obk
subst -> instantiate

continues #110793, there are still quite a few uses of `subst` and `substitute`, but changing them all in the same PR was a bit too much, so I've stopped here for now.
2023-09-26 21:32:44 +00:00
lcnr 3c52a3e280 subst -> instantiate 2023-09-26 09:37:55 +02:00
Florian Schmiderer 91544e6a93 Pass name of object file to LLVM so it can correctly emit S_OBJNAME 2023-09-25 19:31:58 +02:00
Florian Schmiderer 3409ca65d8 Add OwnedTargetMachine to manage llvm:TargetMachine. Uses pointers
instead of &'static mut and provides safe interface to create/dispose
it.
2023-09-24 21:11:37 +02:00
onur-ozkan bdd66b3f98 allow LTO on `proc-macro` crates with `-Zdylib-lto`
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2023-09-23 17:08:43 +03:00
Oli Scherer 2ba911c832 Have a single struct for queries and hook 2023-09-22 16:26:20 +00:00
Oli Scherer 2157f31731 Add a way to decouple the implementation and the declaration of a TyCtxt method. 2023-09-22 09:23:15 +00:00
Zalathar 041a232b62 coverage: Don't bother renumbering expressions on the Rust side
The LLVM API that we use to encode coverage mappings already has its own code
for removing unused coverage expressions and renumbering the rest.

This lets us get rid of our own complex renumbering code, making it easier to
change our coverage code in other ways.
2023-09-21 18:32:49 +10:00
Zalathar 527c629cd9 coverage: Explicitly simplify coverage expressions in codegen
After coverage instrumentation and MIR transformations, we can sometimes end up
with coverage expressions that always have a value of zero. Any expression
operand that refers to an always-zero expression can be replaced with a literal
`Operand::Zero`, making the emitted coverage mapping data smaller and simpler.

This simplification step is mostly redundant with the simplifications performed
inline in `expressions_with_regions`, except that it does a slightly more
thorough job in some cases (because it checks for always-zero expressions
*after* other simplifications).

However, adding this simplification step will then let us greatly simplify that
code, without affecting the quality of the emitted coverage maps.
2023-09-21 18:32:49 +10:00
Zalathar 659575aade coverage: Make the zero counter a constant 2023-09-21 18:32:49 +10:00
Oli Scherer 1a01e57d27 Prototype using const generic for simd_shuffle IDX array 2023-09-18 15:10:28 +00:00
Ralf Jung 3ee65c28e9 cannot have Direct for unsized types 2023-09-15 10:45:37 +02:00