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

Make TyKind Copy and change ty.kind() to return TyKind #77482

Closed
wants to merge 8 commits into from

Conversation

LeSeulArtichaut
Copy link
Contributor

Implements T-compiler MCP rust-lang/compiler-team#363.
This should be perf-tested.

r? @lcnr cc @nikomatsakis

@LeSeulArtichaut LeSeulArtichaut added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 3, 2020
@rust-highfive
Copy link
Collaborator

Some changes occurred in intra-doc-links.

cc @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 3, 2020
@lcnr
Copy link
Contributor

lcnr commented Oct 3, 2020

❤️

@bors try @rust-timer perf

@bors
Copy link
Contributor

bors commented Oct 3, 2020

⌛ Trying commit 5268ae7 with merge a9b36da2412359e22b389fab4829683fdbe81dbb...

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small nits, otherwise this is a lot cleaner than before. Thanks!

compiler/rustc_middle/src/ty/codec.rs Show resolved Hide resolved
compiler/rustc_middle/src/ty/error.rs Outdated Show resolved Hide resolved
@@ -575,7 +575,7 @@ impl<T> Trait<T> for X {
// This will also work for `impl Trait`.
let def_id = if let ty::Param(param_ty) = proj_ty.self_ty().kind() {
let generics = self.generics_of(body_owner_def_id);
generics.type_param(param_ty, self).def_id
generics.type_param(&param_ty, self).def_id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to instead take ParamTy by value in type_param, but using a reference is fine for now here

compiler/rustc_middle/src/ty/print/pretty.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/ty/relate.rs Outdated Show resolved Hide resolved
@@ -347,7 +347,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
"`Self`",
err,
None,
projection,
projection.as_ref(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

followup: probably take Option<ProjectionTy> in suggest_restriction

*r_ty.kind() == Str || is_std_string(r_ty) ||
(Ref(_, l_ty, _), Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str
if (l_ty.kind() == Str || is_std_string(l_ty)) && (
r_ty.kind() == Str || is_std_string(r_ty) ||
&format!("{:?}", rhs_ty) == "&&str"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated, but we really shouldn't compare on format!("{:?}", rhs_ty) here

@lcnr
Copy link
Contributor

lcnr commented Oct 3, 2020

used the wrong rust-timer command

edit: and again

@rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@jyn514 jyn514 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. I-compiletime Issue: Problems and improvements with respect to compile times. labels Oct 3, 2020
@bors
Copy link
Contributor

bors commented Oct 3, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: a9b36da2412359e22b389fab4829683fdbe81dbb (a9b36da2412359e22b389fab4829683fdbe81dbb)

@rust-timer
Copy link
Collaborator

Queued a9b36da2412359e22b389fab4829683fdbe81dbb with parent 6f56fbd, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (a9b36da2412359e22b389fab4829683fdbe81dbb): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@LeSeulArtichaut
Copy link
Contributor Author

Also cc @eddyb in case you're interested in the perf results

@lcnr
Copy link
Contributor

lcnr commented Oct 3, 2020

not sure about perf, cycles looks quite positive, wall-time is probably about neutral all considered and instructions got worse.

I would have expected that we mostly just instantly match on ty.kind() which requires loading it from memory anyways, so I don't fully get why this increases the instruction count here.

@lcnr
Copy link
Contributor

lcnr commented Oct 3, 2020

I think using ref patterns here ends up causing worse codegen when returning TyKind by value in kind.

So we probably get better perf - and cleaner code - if we eliminate these.

experimented in https://godbolt.org/z/o3bsM3

@@ -325,8 +325,8 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
) -> RelateResult<'tcx, Ty<'tcx>> {
let tcx = relation.tcx();
debug!("super_relate_tys: a={:?} b={:?}", a, b);
match (&a.kind(), &b.kind()) {
(&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
match (a.kind(), b.kind()) {
Copy link
Contributor

@lcnr lcnr Oct 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this was the main reason for the regression. Relate is quite hot and &a.kind() results in suboptimal codegen

@lcnr
Copy link
Contributor

lcnr commented Oct 3, 2020

let's try again

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Oct 3, 2020

⌛ Trying commit 380e230 with merge ab3feb4f1ad1434df143ec7dc8c54097cc1b387c...

@bors
Copy link
Contributor

bors commented Oct 3, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: ab3feb4f1ad1434df143ec7dc8c54097cc1b387c (ab3feb4f1ad1434df143ec7dc8c54097cc1b387c)

@rust-timer
Copy link
Collaborator

Queued ab3feb4f1ad1434df143ec7dc8c54097cc1b387c with parent 738d4a7, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (ab3feb4f1ad1434df143ec7dc8c54097cc1b387c): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

@lcnr
Copy link
Contributor

lcnr commented Oct 6, 2020

See https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Make.20TyKind.20Copy.20and.20change.20ty.2Ekind%28%29.20to.20.E2.80.A6.20compiler-team.23363/near/212460531 for some discussion about this.

A huge thanks for @LeSeulArtichaut for implementing this MCP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. I-compiletime Issue: Problems and improvements with respect to compile times. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants