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

Introduce an arena type which may be used to allocate a list of types with destructors #59536

Merged
merged 6 commits into from
Apr 12, 2019

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Mar 29, 2019

You can also specify that you want deserializers for &'tcx [T] and &'tcx T for a type in the list, which will allocate those using the arena.

Based on #59517 and #59533. Look at the last commit for the interesting changes.

An alternative to #56448. cc @michaelwoerister @eddyb

r? @oli-obk

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 29, 2019
rustc::ty::subst::SubstsRef<$tcx>
)>,
[decode] specialization_graph: rustc::traits::specialization_graph::Graph,
], $tcx);
Copy link
Contributor Author

@Zoxc Zoxc Mar 29, 2019

Choose a reason for hiding this comment

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

The list of types are declared here with a macro.

@eddyb
Copy link
Member

eddyb commented Mar 29, 2019

r=me on that last commit, very nice!

#[inline]
default fn arena<'a>(_: &'a Arena<'tcx>) -> Option<&'a TypedArena<Self>> {
None
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This impl can conflict with the types in the list :(

error[E0119]: conflicting implementations of trait `arena::ArenaAllocatable<'_>` for type `std::collections::HashSet<hir::item_local_id_inner::ItemLocalId, std::hash::BuildHasherDefault<rustc_data_structures::fx::FxHasher>>`:
  --> src\librustc\arena.rs:42:13
   |
4  |  / macro_rules! arena_types {
5  |  |     ($macro:path, $args:tt, $tcx:lifetime) => (
6  |  |         $macro!($args, [
   |  |_________-
7  | ||             [] vtable_method: Option<(
8  | ||                 rustc::hir::def_id::DefId,
9  | ||                 rustc::ty::subst::SubstsRef<$tcx>
...  ||
15 | ||             [] item_local_set: rustc::util::nodemap::ItemLocalSet,
16 | ||         ], $tcx);
   | ||_________________- in this macro invocation
17 |  |     )
18 |  | }
   |  |_- in this expansion of `arena_types!`
...
37 | /  macro_rules! impl_arena_allocatable {
38 | |      ([], [$($a:tt $name:ident: $ty:ty,)*], $tcx:lifetime) => {
39 | |          $(
40 | |              impl_specialized_decodable!($a $ty, $tcx);
41 | |
42 | |              impl<$tcx> ArenaAllocatable<$tcx> for $ty {
   | |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::collections::HashSet<hir::item_local_id_inner::ItemLocalId, std::hash::BuildHasherDefault<rustc_data_structures::fx::FxHasher>>`
...  |
49 | |      }
50 | |  }
   | |__- in this expansion of `impl_arena_allocatable!`
...
54 |    arena_types!(impl_arena_allocatable, [], 'tcx);
   |    ----------------------------------------------- in this macro invocation
...
62 |    impl<'tcx, T: Copy> ArenaAllocatable<'tcx> for T {
   |    ------------------------------------------------ first implementation here
   |
   = note: upstream crates may add new impl of trait `std::marker::Copy` for type `std::collections::HashSet<hir::item_local_id_inner::ItemLocalId, std::hash::BuildHasherDefault<rustc_data_structures::fx::FxHasher>>` in future versions

error: aborting due to previous error

Do we have some way to express an ArenaAllocatable or Copy bound?

Copy link
Member

Choose a reason for hiding this comment

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

Oh wow, it would be nice to be able to rely on sets and maps never being Copy...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found a way around this using a marker trait.

@bors
Copy link
Contributor

bors commented Mar 30, 2019

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

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 30, 2019

I added a DropArena type which allows allocating types with destructors in a single arena. It's intended for types which we only allocate for the local crate or per crate. It allocates slower since it has to record the destructors, but is more memory efficient than using multiple almost empty arenas.

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 30, 2019

@bors try

@bors
Copy link
Contributor

bors commented Mar 30, 2019

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout the-arena (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self the-arena --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
warning: Cannot merge binary files: Cargo.lock (HEAD vs. heads/homu-tmp)
Auto-merging Cargo.lock
CONFLICT (content): Merge conflict in Cargo.lock
Automatic merge failed; fix conflicts and then commit the result.

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 31, 2019

@bors try

bors added a commit that referenced this pull request Mar 31, 2019
Introduce an arena type which may be used to allocate a list of types with destructors

You can also specify that you want deserializers for `&'tcx [T]` and `&'tcx T` for a type in the list, which will allocate those using the arena.

Based on #59517 and #59533. Look at the last commit for the interesting changes.

An alternative to #56448. cc @michaelwoerister @eddyb

r? @oli-obk
@bors
Copy link
Contributor

bors commented Mar 31, 2019

⌛ Trying commit 114a000 with merge bb306b0...

@bors
Copy link
Contributor

bors commented Mar 31, 2019

☀️ Try build successful - checks-travis
Build commit: bb306b0

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 31, 2019

@rust-timer build bb306b0

@rust-timer
Copy link
Collaborator

Success: Queued bb306b0 with parent befeeb7, comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit bb306b0

@Zoxc
Copy link
Contributor Author

Zoxc commented Apr 4, 2019

The last 3 commits also need a review here.

@Zoxc
Copy link
Contributor Author

Zoxc commented Apr 5, 2019

@bors try

@bors
Copy link
Contributor

bors commented Apr 5, 2019

⌛ Trying commit 43e33ea with merge 55ed5f73fc9910209ee1affaa62b5c688ce6b872...

@bors
Copy link
Contributor

bors commented Apr 5, 2019

☀️ Try build successful - checks-travis
Build commit: 55ed5f73fc9910209ee1affaa62b5c688ce6b872

@bors
Copy link
Contributor

bors commented Apr 12, 2019

⌛ Testing commit 223f1c7 with merge 2226c09...

bors added a commit that referenced this pull request Apr 12, 2019
Introduce an arena type which may be used to allocate a list of types with destructors

You can also specify that you want deserializers for `&'tcx [T]` and `&'tcx T` for a type in the list, which will allocate those using the arena.

Based on #59517 and #59533. Look at the last commit for the interesting changes.

An alternative to #56448. cc @michaelwoerister @eddyb

r? @oli-obk
@bors
Copy link
Contributor

bors commented Apr 12, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: eddyb
Pushing 2226c09 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 12, 2019
@bors bors merged commit 223f1c7 into rust-lang:master Apr 12, 2019
@Zoxc Zoxc deleted the the-arena branch April 12, 2019 09:09
bors added a commit that referenced this pull request Apr 13, 2019
[WIP] Use arenas to avoid Lrc in queries #1

Based on #59536.
@Dylan-DPC-zz Dylan-DPC-zz removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Apr 15, 2019
bors added a commit that referenced this pull request Apr 21, 2019
[WIP] Use arenas to avoid Lrc in queries #1

Based on #59536.
bors added a commit that referenced this pull request Apr 22, 2019
[WIP] Use arenas to avoid Lrc in queries #1

Based on #59536.
bors added a commit that referenced this pull request Apr 25, 2019
[WIP] Use arenas to avoid Lrc in queries #1

Based on #59536.
bors added a commit that referenced this pull request Apr 27, 2019
Use arenas to avoid Lrc in queries #1

Based on #59536.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants