Stream: t-compiler/wg-mir-opt

Topic: interning links


nikomatsakis (Sep 30 2019 at 19:28, on Zulip):

So @Santiago Pastorino you were asking about interning

nikomatsakis (Sep 30 2019 at 19:30, on Zulip):

I don't see anything in the rustc-guide

nikomatsakis (Sep 30 2019 at 19:30, on Zulip):

what I usually do when I want to remember how this works, though,

nikomatsakis (Sep 30 2019 at 19:30, on Zulip):

is to start by digging around in one of the intern methods...

nikomatsakis (Sep 30 2019 at 19:31, on Zulip):

but they have subtle differences

nikomatsakis (Sep 30 2019 at 19:31, on Zulip):

e.g., intern_promoted simply allocates from an arena

nikomatsakis (Sep 30 2019 at 19:31, on Zulip):

it's a good one to look at, but not quite what you want

nikomatsakis (Sep 30 2019 at 19:32, on Zulip):

still, there you can see the self.arena access, looking at (I think) this field

Wesley Wiser (Sep 30 2019 at 19:32, on Zulip):

(I had to add interning stuff in a recent PR. This commit is where that happens if that's helpful. src/librustc/ty/context.rs is the main bit.)

nikomatsakis (Sep 30 2019 at 19:33, on Zulip):

In your case though @Santiago Pastorino you want to create a List

nikomatsakis (Sep 30 2019 at 19:33, on Zulip):

this is a rather special type

Santiago Pastorino (Sep 30 2019 at 19:34, on Zulip):

yeah, so it's not possible to subslice

nikomatsakis (Sep 30 2019 at 19:34, on Zulip):

I think this is a relevant example

nikomatsakis (Sep 30 2019 at 19:34, on Zulip):

the slice_interners! macro usage

nikomatsakis (Sep 30 2019 at 19:35, on Zulip):

that macro is creating methods like _intern_predicates

nikomatsakis (Sep 30 2019 at 19:35, on Zulip):

this...seems kind of dumb

nikomatsakis (Sep 30 2019 at 19:35, on Zulip):

in that there are pretty identical wrappers for each of those cases

nikomatsakis (Sep 30 2019 at 19:36, on Zulip):

like intern_predicates

nikomatsakis (Sep 30 2019 at 19:36, on Zulip):

that just check for an empty slice and then fall through

nikomatsakis (Sep 30 2019 at 19:36, on Zulip):

so we could probably generate those too

nikomatsakis (Sep 30 2019 at 19:36, on Zulip):

(but maybe there are some cases that work differently, not sure)

nikomatsakis (Sep 30 2019 at 19:36, on Zulip):

anyway, I guess that's the model you want to follow

nikomatsakis (Sep 30 2019 at 19:37, on Zulip):

(and maybe try to cleanup the code duplication for the zero-length case, too...)

Santiago Pastorino (Sep 30 2019 at 19:37, on Zulip):

cool, thanks

Santiago Pastorino (Sep 30 2019 at 19:37, on Zulip):

I'm finishing a thing related to the PR I've opened and going after this thing next, probably tomorrow

Santiago Pastorino (Oct 09 2019 at 15:59, on Zulip):

@nikomatsakis was going after this but I'm getting ....

Santiago Pastorino (Oct 09 2019 at 16:00, on Zulip):

this means ... the actual interning code, using slice_interners! macro

Santiago Pastorino (Oct 09 2019 at 16:00, on Zulip):

getting ...

Santiago Pastorino (Oct 09 2019 at 16:00, on Zulip):
error[E0277]: the trait bound `mir::ProjectionElem<mir::Local, &ty::TyS<'_>>: std::marker::Copy` is not satisfied
    --> src/librustc/ty/context.rs:2252:30
     |
2247 | / macro_rules! slice_interners {
2248 | |     ($($field:ident: $method:ident($ty:ty)),+) => (
2249 | |         $(impl<'tcx> TyCtxt<'tcx> {
2250 | |             pub fn $method(self, v: &[$ty]) -> &'tcx List<$ty> {
2251 | |                 self.interners.$field.intern_ref(v, || {
2252 | |                     Interned(List::from_arena(&self.interners.arena, v))
     | |                              ^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `mir::ProjectionElem<mir::Local, &ty::TyS<'_>>`
...    |
2256 | |     );
2257 | | }
     | |_- in this expansion of `slice_interners!`
2258 |
2259 | / slice_interners!(
2260 | |     type_list: _intern_type_list(Ty<'tcx>),
2261 | |     substs: _intern_substs(GenericArg<'tcx>),
2262 | |     canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo),
...    |
2268 | |     place_elems: _intern_place_elems(PlaceElem<'tcx>)
2269 | | );
     | |__- in this macro invocation
     |
    ::: src/librustc/ty/mod.rs:625:5
     |
625  |       fn from_arena<'tcx>(arena: &'tcx SyncDroplessArena, slice: &[T]) -> &'tcx List<T> {
     |       --------------------------------------------------------------------------------- required by `ty::List::<T>::from_arena`
     |
     = help: the following implementations were found:
               <mir::ProjectionElem<(), ()> as std::marker::Copy>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `rustc`.
Santiago Pastorino (Oct 09 2019 at 16:02, on Zulip):

why does that need to be Copy?

Santiago Pastorino (Oct 09 2019 at 16:02, on Zulip):

what can we do in the case of projection then?

Santiago Pastorino (Oct 09 2019 at 16:23, on Zulip):

I see, ProjectionElem could be Copy but it's generic and we are not imposing those generics be Copy

Santiago Pastorino (Oct 09 2019 at 16:23, on Zulip):

but PlaceElem can be Copy and I think it's reasonable to do so

Santiago Pastorino (Oct 09 2019 at 16:26, on Zulip):

https://github.com/rust-lang/rust/pull/65197/commits/04e491aee1f78e1ed8be5a76c320b3b52fabd281

Last update: Nov 17 2019 at 08:25UTC