Skip to content

Refactor ty::FnSig to contain a &'tcx Slice<Ty<'tcx>>#38097

Merged
bors merged 2 commits into
rust-lang:masterfrom
Mark-Simulacrum:fn-sig-slice
Dec 6, 2016
Merged

Refactor ty::FnSig to contain a &'tcx Slice<Ty<'tcx>>#38097
bors merged 2 commits into
rust-lang:masterfrom
Mark-Simulacrum:fn-sig-slice

Conversation

@Mark-Simulacrum

@Mark-Simulacrum Mark-Simulacrum commented Dec 1, 2016

Copy link
Copy Markdown
Member

We refactor this in order to achieve the following wins:

  • Decrease the size of FnSig (Vec + bool: 32, &Slice + bool: 24).
  • Potentially decrease total allocated memory due to arena-allocating FnSig inputs/output; since they are allocated in the type list arena, other users of type lists can reuse the same allocation for an equivalent type list.
  • Remove the last part of the type system which needs drop glue (Refactor TraitObject to Slice<ExistentialPredicate> #37965 removed the other remaining part). This makes arenas containing FnSig faster to drop (since we don't need to drop a Vec for each one), and makes reusing them without clearing/dropping potentially possible.

r? @eddyb

Comment thread src/librustc/ty/relate.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be done with .map.

Comment thread src/librustc/ty/structural_impls.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can just fold the list wholesale.

Comment thread src/librustc/ty/sty.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The elision abuse here looks odd.

Comment thread src/librustc/ty/sty.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could keep this returning a slice.

Comment thread src/librustc_trans/callee.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're using iter::once a bit too much - try arrays instead.

Comment thread src/librustc_trans/common.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you avoid .into_iter() on slices? It's just .iter().

Comment thread src/librustc_typeck/astconv.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why would this be needed? Looks like a bug?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TypeFoldable isn't implemented for &[Ty<'tcx>], which is what we have, so we need to cast it to a vector in order to pass it here. This is rather unfortunate, but I'm not sure how much we can do. It may be worth pointing out that the use is a visit_with on it, so it's possible this can be refactored into passing either the slice or an iterator to solve this problem. I can look into that if you'd like.

@KalitaAlexey

Copy link
Copy Markdown
Contributor

What is purpose of this?

@Mark-Simulacrum

Copy link
Copy Markdown
Member Author

I believe there are a couple of purposes:

  • Decreasing the size of FnSig
    • Vec + bool: 32, &Slice + bool: 24.
  • Potentially decrease total allocated memory due to arena-allocating FnSig inputs/output; since they are allocated in the type list arena, other users of type lists can reuse the same allocation for an equivalent type list.
  • Remove the last part of the type system which needs drop glue (Refactor TraitObject to Slice<ExistentialPredicate> #37965 removed the other remaining part)

@eddyb may be able to suggest other reasons.


@eddyb Ready for another review pass.

@bors

bors commented Dec 2, 2016

Copy link
Copy Markdown
Collaborator

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

@Mark-Simulacrum

Copy link
Copy Markdown
Member Author

Rebased.

Comment thread src/librustc_typeck/lib.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you use slice iterators, here and elsewhere?

@eddyb

eddyb commented Dec 2, 2016

Copy link
Copy Markdown
Contributor

@Mark-Simulacrum Can you move the contents of that comment into the description? You may also want to mention that the drop glue thing is about arenas, both in terms of cost of dropping/reusing the temporary ones currently and experiments with unified arenas in the future.

@eddyb

eddyb commented Dec 2, 2016

Copy link
Copy Markdown
Contributor

@rust-lang/compiler Any objections? This is ready to land otherwise, modulo a few "style" tweaks.

@Mark-Simulacrum

Copy link
Copy Markdown
Member Author

Fixed style nit (I couldn't find any other places I chained iter::once together).

Added the comment for reasons why we want this to the description.

@bors

bors commented Dec 6, 2016

Copy link
Copy Markdown
Collaborator

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

@Mark-Simulacrum

Copy link
Copy Markdown
Member Author

Rebased.

@eddyb

eddyb commented Dec 6, 2016

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Dec 6, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit 296ec5f has been approved by eddyb

@bors

bors commented Dec 6, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 296ec5f with merge ff261d3...

bors added a commit that referenced this pull request Dec 6, 2016
Refactor ty::FnSig to contain a &'tcx Slice<Ty<'tcx>>

We refactor this in order to achieve the following wins:

 - Decrease the size of `FnSig` (`Vec` + `bool`: 32, `&Slice` + `bool`: 24).
 - Potentially decrease total allocated memory due to arena-allocating `FnSig` inputs/output; since they are allocated in the type list arena, other users of type lists can reuse the same allocation for an equivalent type list.
 - Remove the last part of the type system which needs drop glue (#37965 removed the other remaining part). This makes arenas containing `FnSig` faster to drop (since we don't need to drop a Vec for each one), and makes reusing them without clearing/dropping potentially possible.

r? @eddyb
@bors bors merged commit 296ec5f into rust-lang:master Dec 6, 2016
@michaelwoerister

Copy link
Copy Markdown
Member

Nice!

@Mark-Simulacrum Mark-Simulacrum deleted the fn-sig-slice branch December 27, 2016 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants