2542 Commits

Author SHA1 Message Date
Guillaume Gomez
ad21c6d898
Rollup merge of #145266 - camsteffen:reduce-queries, r=petrochenkov
Reduce some queries around associated items
2025-08-14 11:39:38 +02:00
Guillaume Gomez
6ac5c28412
Rollup merge of #144727 - Stypox:add-tracing-to-resolve, r=RalfJung
Add tracing to resolve-related functions

Resolve-related functions are not called often but still make up for ~3% of execution time for non-repetitive programs (as seen in the first table below, obtained from running the rust snippet at the bottom with `n=1`). On the other hand, for repetitive programs they become less relevant (I tested the same snippet but with `n=100` and got ~1.5%), and it appears that only `try_resolve` is called more often (see the last two tables).

The first table was obtained by opening the trace file in https://ui.perfetto.dev and running the following query:

```sql
select "TOTAL PROGRAM DURATION" as name, count(*), max(ts + dur) as "sum(dur)", 100.0 as "%", null as "min(dur)", null as "max(dur)", null as "avg(dur)", null as "stddev(dur)" from slices union select "TOTAL OVER ALL SPANS (excluding events)" as name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" and dur > 0 union select name, count(*), sum(dur), cast(cast(sum(dur) as float) / (select max(ts + dur) from slices) * 1000 as int) / 10.0 as "%", min(dur), max(dur), cast(avg(dur) as int) as "avg(dur)", cast(sqrt(avg(dur*dur)-avg(dur)*avg(dur)) as int) as "stddev(dur)" from slices where parent_id is null and name != "frame" and name != "step" group by name order by sum(dur) desc, count(*) desc
```

<img width="1687" height="242" alt="image" src="https://github.com/user-attachments/assets/4d4bd890-869b-40f3-a473-8e4c42b02da4" />

The following two tables show how many `resolve` spans there per subname/subcategory, and how much time is spent in each. The first is for `n=1` and the second for `n=100`. The query that was used is:

```sql
select args.string_value as name, count(*), max(dur), avg(dur), sum(dur) from slices inner join args USING (arg_set_id) where args.key = "args." || slices.name and name = "resolve" group by args.string_value
```

<img width="1688" height="159" alt="image" src="https://github.com/user-attachments/assets/a8749856-c099-492e-a86e-6d67b146af9c" />

<img width="1688" height="159" alt="image" src="https://github.com/user-attachments/assets/ce3ac1b5-5c06-47d9-85a6-9b921aea348e" />

The snippet I tested with Miri to obtain the above traces is:

```rust
fn main() {
    let n: usize = std::env::args().nth(1).unwrap().parse().unwrap();
    let mut v = (0..n).into_iter().collect::<Vec<_>>();
    for i in &mut v {
        *i += 1;
    }
}
```
2025-08-14 11:39:35 +02:00
Guillaume Gomez
e7e3a37e9a
Rollup merge of #144949 - nnethercote:more-Printer-cleanups, r=davidtwco
More `Printer` cleanups

A sequel to rust-lang/rust#144776.

r? ```@davidtwco```
2025-08-13 18:42:59 +02:00
Cameron Steffen
d4eb0947f1 Cleanup assoc parent utils 2025-08-13 09:33:09 -05:00
Stypox
cd4676c40d
Turn _span into _trace as trace span name
_span could possibly be confused with the Span type in rustc
2025-08-11 14:45:46 +02:00
Stypox
99769bc301
Add tracing to resolve-related functions 2025-08-11 14:34:23 +02:00
Deadbeef
2736d66a1f rename TraitRef::from_method to from_assoc
also add a note to `GenericArgs::truncate_to`
2025-08-09 14:22:01 +08:00
Stuart Cook
33f1862ef0
Rollup merge of #145033 - nnethercote:fix-144994, r=fmease
Reimplement `print_region` in `type_name.rs`.

Broken by rust-lang/rust#144776; this is reachable after all.

Fixes rust-lang/rust#144994.

The commit also adds a lot more cases to the `type-name-basic.rs`, because it's currently very anaemic. This includes some cases where region omission does very badly; these are marked with FIXME.

r? `@fmease`
2025-08-07 20:49:48 +10:00
Stuart Cook
622b21e80b
Rollup merge of #144682 - nxsaken:strict_overflow_ops, r=Mark-Simulacrum
Stabilize `strict_overflow_ops`

Closes rust-lang/rust#118260
2025-08-07 20:49:47 +10:00
Nicholas Nethercote
8074e672f0 Reimplement print_region in type_name.rs.
Broken by #144776; this is reachable after all.

Fixes #144994.

The commit also adds a lot more cases to the `type-name-basic.rs`,
because it's currently very anaemic. This includes some cases where
region omission does very badly; these are marked with FIXME.
2025-08-07 12:46:33 +10:00
Nicholas Nethercote
42a1042f9b Rename some PrettyPrinter methods.
More consistency.
2025-08-06 12:58:23 +10:00
Nicholas Nethercote
b8adda6194 Rename some Printer methods.
I find these name clearer, and starting them all with `print_` makes
things more consistent.
2025-08-06 12:58:20 +10:00
Nicholas Nethercote
b0c36dd4c7 Rename most of the printers.
Three of them are named `AbsolutePathPrinter`, which is confusing, so
give those names that better indicate how they are used. And then there
is `SymbolPrinter` and `SymbolMangler`, which are renamed as
`LegacySymbolMangler` and `V0SymbolMangler`, better indicating their
similarity.
2025-08-05 19:11:37 +10:00
Samuel Tardieu
58a7b873cf
Rollup merge of #144890 - WaffleLapkin:project_fields, r=lcnr
Add `InterpCx::project_fields`

I was hoping for a much bigger improvement and this is lukewarm at best ^^'

Still, I think this makes sense.
2025-08-05 03:51:40 +02:00
Samuel Tardieu
a1e41a0227
Rollup merge of #144776 - nnethercote:Printer-cleanups, r=cjgillot
`Printer` cleanups

The trait `Printer` is implemented by six types, and the sub-trait `PrettyPrinter` is implemented by three of those types. The traits and the impls are complex and a bit of a mess. This PR starts to clean them up.

r? ``@davidtwco``
2025-08-05 03:51:34 +02:00
Waffle Lapkin
cf7b67420b
add project_fields helper function 2025-08-04 11:34:46 +02:00
Stuart Cook
0225f8b09c
Rollup merge of #144706 - zachs18:fix-144661, r=RalfJung
Do not give function allocations alignment in consteval and Miri.

We do not yet have a (clear and T-lang approved) design for how `#[align(N)]` on functions should affect function pointers' addresses on various platforms, so for now do not give function pointers alignment in consteval and Miri.

----

Old summary:

Not a full solution to <https://github.com/rust-lang/rust/issues/144661>, but fixes the immediate issue by making function allocations all have alignment 1 in consteval, ignoring `#[rustc_align(N)]`, so the compiler doesn't know if any offset other than 0 is non-null.

A more "principlied" solution would probably be to make function pointers to `#[instruction_set(arm::t32)]` functions be at offset 1 of an align-`max(2, align attribute)` allocation instead of at offset 0 of their allocation during consteval, and on wasm to either disallow `#[align(N)]` where N > 1, or to pad the function table such that the function pointer of a `#[align(N)]` function is a multiple of `N` at runtime.
2025-08-04 11:24:39 +10:00
Nicholas Nethercote
2434d8cecf Remove unused arg from path_append_impl.
None of the impls use it.
2025-08-03 19:58:59 +10:00
Nicholas Nethercote
1698c8e322 Rename Printer variables.
Currently they are mostly named `cx`, which is a terrible name for a
type that impls `Printer`/`PrettyPrinter`, and is easy to confuse with
other types like `TyCtxt`. This commit changes them to `p`. A couple of
existing `p` variables had to be renamed to make way.
2025-08-03 19:58:00 +10:00
Nicholas Nethercote
e7d6a0776b Remove type_name::AbsolutePathPrinter::comma_sep.
It's equivalent to the default `PrettyPrinter::comma_sep`.
2025-08-03 19:58:00 +10:00
Nicholas Nethercote
df524163be Mark Printer methods as unreachable where appropriate.
This helps me understand the structure of the code a lot.

If any of these are actually reachable, we can put the old code back,
add a new test case, and we will have improved our test coverage.
2025-08-03 19:58:00 +10:00
zachs18
fe720181b5
Update compiler/rustc_const_eval/src/interpret/memory.rs
Replace commented-out code with link to context for change.

Co-authored-by: Ralf Jung <post@ralfj.de>
2025-08-01 11:06:13 -05:00
Stypox
88c9a256a9
Add EnteredTraceSpan::or_if_tracing_disabled 2025-07-31 21:51:29 +02:00
Stypox
188f7367bf
Add tracing to more functions related to step.rs 2025-07-31 21:51:29 +02:00
Stypox
4e806c8a34
Add tracing calls to eval_statement/terminator 2025-07-31 21:51:29 +02:00
Zachary S
f554c79ef8 Do not give function allocations alignment in consteval or miri. 2025-07-31 12:50:40 -05:00
Jana Dönszelmann
26c28ee2ef
Rollup merge of #144726 - jdonszelmann:move-attr-data-structures, r=lcnr
merge rustc_attr_data_structures into rustc_hir

this move was discussed on zulip: [#t-compiler > attribute parsing rework @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/attribute.20parsing.20rework/near/528530091)

Many PRs in the attribute rework depend on this move.
2025-07-31 17:19:40 +02:00
Stypox
bb08a4dfc7
Make Miri's enter_trace_span! call const_eval's 2025-07-31 15:42:29 +02:00
Jana Dönszelmann
e1d3ad89c7
remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
Stypox
e1f674cfa9
Use specific name for "frame" span field
Otherwise the field would be named "message" by default
2025-07-31 00:40:00 +02:00
Stypox
3b5fec08f1
Use new enter_trace_span! syntax for layout_of & friends 2025-07-31 00:40:00 +02:00
Stypox
8e786169e8
Uniform enter_trace_span! and add documentation
The macro was uniformed between rustc_const_eval and miri
2025-07-31 00:40:00 +02:00
Nurzhan Sakén
3ff3a1ee00 Stabilize strict_overflow_ops 2025-07-30 23:39:35 +04:00
Cameron Steffen
172af038a7 Rename trait_of_item -> trait_of_assoc 2025-07-28 09:53:50 -05:00
bors
d242a8bd5a Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLii
Some `let chains` clean-up

Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one

r? compiler
2025-07-28 05:25:23 +00:00
Kivooeo
43725ed819 use let chains in ast, borrowck, codegen, const_eval 2025-07-28 06:08:48 +05:00
Ralf Jung
296586fb02 miri: for ABI mismatch errors, say which argument is the problem 2025-07-27 22:26:10 +02:00
Camille GILLOT
967ba2f93d Remove const deduplication from the interpreter. 2025-07-23 23:54:37 +00:00
Camille GILLOT
0460c92d52 Remove useless lifetime parameter. 2025-07-23 23:54:37 +00:00
Camille GILLOT
9ff071219b Give an AllocId to ConstValue::Slice. 2025-07-23 23:54:37 +00:00
Matthias Krüger
16c10c9145
Rollup merge of #144256 - oli-obk:type-id-ice, r=RalfJung
Don't ICE on non-TypeId metadata within TypeId

fixes rust-lang/rust#144253

r? ``````````@RalfJung``````````
2025-07-23 15:59:30 +02:00
Oli Scherer
b2f8b40633 Don't ICE on non-TypeId metadata within TypeId 2025-07-21 14:23:20 +00:00
Ralf Jung
3f9be406a6 fix handling of base address for TypeId allocations 2025-07-20 22:14:27 +02:00
Ralf Jung
7672e4ed85 interpret: fix TypeId pointers being considered data pointers 2025-07-19 10:29:13 +02:00
Matthias Krüger
a59efc61f9
Rollup merge of #144123 - oli-obk:ctfe-unsize, r=RalfJung
Generalize `unsize` and `unsize_into` destinations

Just something that I noticed during other work. We do this for most such functions, so let's do it here, too.

r? ``@RalfJung``
2025-07-18 19:14:47 +02:00
Matthias Krüger
b3827e4f37
Rollup merge of #142673 - oli-obk:uninit-read-mem, r=RalfJung
Show the offset, length and memory of uninit read errors

r? ``@RalfJung``

I want to improve memory dumps in general. Not sure yet how to do so best within rust diagnostics, but in a perfect world I could generate a dummy in-memory file (that contains the rendered memory dump) that we then can then provide regular rustc `Span`s to. So we'd basically report normal diagnostics for them with squiggly lines and everything.
2025-07-18 19:14:43 +02:00
Oli Scherer
c65d3ce365 Generalize unsize and unsize_into destinations 2025-07-18 13:09:34 +00:00
Oli Scherer
652ba279ec Show the memory of uninit reads 2025-07-18 07:47:08 +00:00
Matthias Krüger
accf61dd42
Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errors
fix `-Zsanitizer=kcfi` on `#[naked]` functions

fixes https://github.com/rust-lang/rust/issues/143266

With `-Zsanitizer=kcfi`, indirect calls happen via generated intermediate shim that forwards the call. The generated shim preserves the attributes of the original, including `#[unsafe(naked)]`. The shim is not a naked function though, and violates its invariants (like having a body that consists of a single `naked_asm!` call).

My fix here is to match on the `InstanceKind`, and only use `codegen_naked_asm` when the instance is not a `ReifyShim`. That does beg the question whether there are other `InstanceKind`s that could come up. As far as I can tell the answer is no: calling via `dyn` seems to work find, and `#[track_caller]` is disallowed in combination with `#[naked]`.

r? codegen
````@rustbot```` label +A-naked
cc ````@maurer```` ````@rcvalle````
2025-07-18 04:27:51 +02:00
Oli Scherer
12eedafc38 Report the range of uninit bytes in CTFE errors 2025-07-17 20:00:51 +00:00