Skip to content

Print regions in type_name. #145284

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Aug 12, 2025

Currently they are skipped, which is a bit weird, and it sometimes causes malformed output like Foo<> and dyn Bar<, A = u32>.

Most regions are erased by the time type_name does its work. So all regions are now printed as '_ in non-optional places. Not perfect, but better than the status quo.

c_name is updated to trim lifetimes from MIR pass names, so that the PASS_NAMES sanity check still works. It is also renamed as simplify_pass_type_name and made non-const, because it doesn't need to be const and the non-const implementation is much shorter.

The commit also renames should_print_region as should_print_optional_region, which makes it clearer that it only applies to some regions.

Fixes #145168.

r? @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 12, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 12, 2025

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot

This comment has been minimized.

@nnethercote nnethercote force-pushed the type_name-print-regions branch from 6779af2 to 36f25a0 Compare August 12, 2025 11:40
@rustbot
Copy link
Collaborator

rustbot commented Aug 12, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot

This comment has been minimized.

@nnethercote
Copy link
Contributor Author

@lcnr: new code is up. Quite a bit has changed.

@rustbot ready

@nnethercote nnethercote force-pushed the type_name-print-regions branch from 36f25a0 to 3720e1a Compare August 12, 2025 21:47
@rustbot

This comment has been minimized.

@nnethercote
Copy link
Contributor Author

I updated again. c_name is now non-const, which is much nicer, and renamed as simplify_pass_type_name.

@rustbot ready

@lcnr
Copy link
Contributor

lcnr commented Aug 13, 2025

I updated again. c_name is now non-const, which is much nicer, and renamed as simplify_pass_type_name.

@rustbot ready

i would expect that we've done it in a const block for 👻 perf 👻 reasons? 🤔

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Aug 13, 2025
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 13, 2025
@rust-bors
Copy link

rust-bors bot commented Aug 13, 2025

☀️ Try build successful (CI)
Build commit: fc05a4f (fc05a4f44af11286e3ae4b0ab02b85685f709d2b, parent: 1553adfe6884a8f6c28f5a673d3e605535ee0113)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (fc05a4f): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.0% [0.2%, 4.3%] 70
Regressions ❌
(secondary)
1.2% [0.1%, 5.3%] 57
Improvements ✅
(primary)
-1.4% [-1.4%, -1.4%] 1
Improvements ✅
(secondary)
-0.5% [-1.4%, -0.0%] 3
All ❌✅ (primary) 0.9% [-1.4%, 4.3%] 71

Max RSS (memory usage)

Results (secondary 4.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.2% [1.7%, 5.6%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (secondary 3.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.0% [3.0%, 6.0%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.8% [-5.8%, -5.8%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 464.093s -> 466.402s (0.50%)
Artifact size: 377.76 MiB -> 377.46 MiB (-0.08%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 13, 2025
@bors
Copy link
Collaborator

bors commented Aug 14, 2025

☔ The latest upstream changes (presumably #145366) made this pull request unmergeable. Please resolve the merge conflicts.

@nnethercote nnethercote force-pushed the type_name-print-regions branch from 3720e1a to 75552ef Compare August 14, 2025 03:52
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (28ae7e3): comparison URL.

Overall result: ❌ regressions - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.5%] 12
Regressions ❌
(secondary)
0.5% [0.2%, 2.0%] 17
Improvements ✅
(primary)
-0.7% [-0.7%, -0.7%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [-0.7%, 0.5%] 13

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results (secondary -0.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.3% [-3.3%, -3.3%] 1
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.1%, secondary -0.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.9% [0.9%, 0.9%] 1
Improvements ✅
(primary)
-0.1% [-0.1%, -0.1%] 3
Improvements ✅
(secondary)
-0.4% [-0.7%, -0.1%] 6
All ❌✅ (primary) -0.1% [-0.1%, -0.1%] 3

Bootstrap: 468.653s -> 469.476s (0.18%)
Artifact size: 377.36 MiB -> 377.32 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 14, 2025
@nnethercote
Copy link
Contributor Author

Thanks for the review comments! This one needed a lot of work.

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Aug 14, 2025

📌 Commit 75552ef has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 14, 2025
@theemathas
Copy link
Contributor

I assume that this type_name output is acceptable?

use std::any::type_name;

macro_rules! t {
    ($ty:ty, $str:literal) => {
        assert_eq!(type_name::<$ty>(), $str);
    };
}

trait Trait<'a> {}
#[allow(dead_code)]
struct Thing<'a>(&'a i32);

fn main() {
    t!(dyn for<'a> Trait<'a>, "dyn foo::Trait<'_>");
    t!(dyn Trait<'static>, "dyn foo::Trait<'_>");
    t!(fn(Thing<'static>), "fn(foo::Thing<'_>)");
    t!(for<'a> fn(Thing<'a>), "fn(foo::Thing<'_>)");
}

@lcnr
Copy link
Contributor

lcnr commented Aug 14, 2025

are the remaining regressions spurious? It looks like it's still perf negative 🤔 :x

@lcnr
Copy link
Contributor

lcnr commented Aug 14, 2025

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 14, 2025
@lcnr
Copy link
Contributor

lcnr commented Aug 14, 2025

I assume that this type_name output is acceptable?

use std::any::type_name;

macro_rules! t {
    ($ty:ty, $str:literal) => {
        assert_eq!(type_name::<$ty>(), $str);
    };
}

trait Trait<'a> {}
#[allow(dead_code)]
struct Thing<'a>(&'a i32);

fn main() {
    t!(dyn for<'a> Trait<'a>, "dyn foo::Trait<'_>");
    t!(dyn Trait<'static>, "dyn foo::Trait<'_>");
    t!(fn(Thing<'static>), "fn(foo::Thing<'_>)");
    t!(for<'a> fn(Thing<'a>), "fn(foo::Thing<'_>)");
}

yeah, not ideal, but better than the status quo at lesat 😁

@nnethercote nnethercote force-pushed the type_name-print-regions branch from 75552ef to 00492e3 Compare August 14, 2025 11:01
@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Aug 14, 2025
@rustbot

This comment has been minimized.

@nnethercote
Copy link
Contributor Author

I reinstated the MirLint const.

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Aug 14, 2025

📌 Commit 00492e3 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 14, 2025
@nnethercote
Copy link
Contributor Author

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 14, 2025
Currently they are skipped, which is a bit weird, and it sometimes
causes malformed output like `Foo<>` and `dyn Bar<, A = u32>`.

Most regions are erased by the time `type_name` does its work. So all
regions are now printed as `'_` in non-optional places. Not perfect, but
better than the status quo.

`c_name` is updated to trim lifetimes from MIR pass names, so that the
`PASS_NAMES` sanity check still works. It is also renamed as
`simplify_pass_type_name` and made non-const, because it doesn't need
to be const and the non-const implementation is much shorter.

The commit also renames `should_print_region` as
`should_print_optional_region`, which makes it clearer that it only
applies to some regions.

Fixes rust-lang#145168.
@nnethercote nnethercote force-pushed the type_name-print-regions branch from 00492e3 to 8296ad0 Compare August 14, 2025 11:13
@rustbot
Copy link
Collaborator

rustbot commented Aug 14, 2025

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@nnethercote
Copy link
Contributor Author

I fixed the submodules. Maybe this time it'll be ok? :)

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Aug 14, 2025

📌 Commit 8296ad0 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Butchered std::any::type_name output for trait object types with lifetime params
6 participants