Skip to content

Future-prove collections::VecMap #20150

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 1 commit into from

Conversation

tbu-
Copy link
Contributor

@tbu- tbu- commented Dec 23, 2014

Since VecMap might want to have key type parameter at some point, add a key
type parameter now, so that code running today will still run when actual
generalization of the key is added.

The trait VecMapKey should really be private, but this is blocked by the fact
that you cannot export a struct, function or trait implementation with one of
the type parameters being bound by a private trait.

@rust-highfive
Copy link
Contributor

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@tbu-
Copy link
Contributor Author

tbu- commented Dec 23, 2014

#20148 would be really helpful here.

@Gankra
Copy link
Contributor

Gankra commented Dec 23, 2014

Want to think about this some more. CC me.

@tbu-
Copy link
Contributor Author

tbu- commented Dec 23, 2014

@gankro The same should be done for Bitv and BitvSet.

@tbu-
Copy link
Contributor Author

tbu- commented Dec 23, 2014

VecMapKey should probably be #[doc(hidden)] for now.

@tbu-
Copy link
Contributor Author

tbu- commented Dec 27, 2014

@gankro Have you thought about this?

@Gankra
Copy link
Contributor

Gankra commented Dec 28, 2014

@tbu- Sorry, I was planning to work all this week but decided at the last minute that taking a one-week vacation would probably be better for my sanity. Going through some discussion back-logs today, will get back to proper reviewing ~monday.

@Gankra
Copy link
Contributor

Gankra commented Dec 30, 2014

CC @huonw @aturon @alexcrichton

@Gankra
Copy link
Contributor

Gankra commented Dec 30, 2014

If we simply use VecMap<V, K>, it would be back-compat to add the K using default type params, right?

v: Vec<Option<V>>,
invariant_type: InvariantType<K>,
Copy link
Member

Choose a reason for hiding this comment

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

Why InvariantType rather than CovariantType?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I don't understand the exact semantics and only know that InvariantType is the strictest. CovariantType would be more correct here?

@huonw
Copy link
Member

huonw commented Dec 30, 2014

@gankro it seems a little strange to have that order of type params, but it does seem like something that might be back-compat?

}

// Tell inference to not infer `uint`.
struct _Nothing;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with this trick, can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this struct, inference will assume that uint is the only thing that implements VecMapKey, and will infer the key type to uint, which would make making VecMap truly generic over its key type a backward-incompatible change.

@Gankra
Copy link
Contributor

Gankra commented Dec 30, 2014

I'm torn. This feels like the right thing to do, but also a bit over-engineer-y. But also I want to make it more over-engineer-y. :S

@tbu-
Copy link
Contributor Author

tbu- commented Dec 30, 2014

@gankro I'm not intending this to be the actual solution, this should just provide possible backward-compatiblity when making VecMap generic over its key type.

To furtherly prevent people from implementing this trait, we could add add a function signature to the trait that is impossible to achieve in safe code, like fn() -> PhantomType with enum PhantomType { } (the best however would be if we could just not expose this trait).

@Gankra Gankra assigned aturon and unassigned brson Jan 2, 2015
@aturon
Copy link
Member

aturon commented Jan 4, 2015

@tbu- Sorry for taking so long to weigh in on this. Do you mind holding off until after we (1) fully resolve the int debate and (2) ship alpha next week? We don't plan to stabilize VecMap for alpha, and I'd like more time to think about this when the current dust settles. (We're all a little overwhelmed trying to get alpha out the door.)

@tbu-
Copy link
Contributor Author

tbu- commented Jan 4, 2015

@aturon I have no problem with this, but keep in mind that this affects other uint-key collections too, like Bitv and BitvSet.

@aturon
Copy link
Member

aturon commented Jan 4, 2015

@tbu- Good point :-) Regardless, we'll need to settle this question during the alpha cycle.

Since `VecMap` might want to have key type parameter at some point, add a key
type parameter now, so that code running today will still run when actual
generalization of the key is added.

The trait `VecMapKey` should really be private, but this is blocked by the fact
that you cannot export a struct, function or trait implementation with one of
the type parameters being bound by a private trait.
@tbu- tbu- force-pushed the pr_collections_key branch from 66465f0 to 2e6285e Compare January 17, 2015 09:33
@tbu- tbu- closed this Jan 17, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants