Skip to content

Implement Default on SnapshotVec, UnificationTable and unification stores. #11

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

Merged
merged 2 commits into from
Aug 18, 2018

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Jul 27, 2018

This is needed for rust-lang/rust#52591. How will we update the dependency, do we need a release?

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

I can merge as is, but do you want to tweak the new stuff?

@@ -17,6 +17,8 @@ pub trait UnificationStore: ops::Index<usize, Output = VarValue<Key<Self>>> + Cl
type Value: UnifyValue;
type Snapshot;

// FIXME(eddyb) (not backwards-compat) this should
// use a `Default` bound on the trait instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

You might as well change this to use Default if you want. We can always issue a new major version.

@@ -75,13 +75,20 @@ pub trait SnapshotVecDelegate {
fn reverse(values: &mut Vec<Self::Value>, action: Self::Undo);
}

impl<D: SnapshotVecDelegate> SnapshotVec<D> {
pub fn new() -> SnapshotVec<D> {
// HACK(eddyb) manual impl avoids `Default` bound on `D`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I don't like the capital HACK -- using a manual impl isn't a hack -- using derive would be, given the way that Rust works right now, since it'd be easy but wrong.

I'd rather say "Use a manual impl to avoid unnecessary Default bound on D."

Copy link
Member Author

Choose a reason for hiding this comment

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

What's wrong is the way Rust works right now, IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree :) it's just that leaving a comment here won't change it!

Copy link
Contributor

Choose a reason for hiding this comment

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

wasn't there an RFC about this, giving some more convenient way to opt out, at least?

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to tag the places that could/should be fixed later.

src/unify/mod.rs Outdated
@@ -236,6 +236,8 @@ impl<K: UnifyKey> VarValue<K> {
// Option<U>:LatticeValue.

impl<S: UnificationStore> UnificationTable<S> {
// FIXME(eddyb) (not backwards-compat) this should
// use a `Default` bound on `S` instead.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather just have UnificationStore require Default. It's not a trait that others outside the crate are meant to implement.

@nikomatsakis
Copy link
Contributor

@eddyb yeah, once we merge, I can push a new release to crates.io

@eddyb eddyb force-pushed the none-of-you-are-free-of-default branch from e2c335f to 8dc607d Compare August 18, 2018 20:12
@eddyb eddyb merged commit f94c3b2 into rust-lang:master Aug 18, 2018
@eddyb eddyb deleted the none-of-you-are-free-of-default branch August 18, 2018 20:14
@eddyb
Copy link
Member Author

eddyb commented Aug 18, 2018

Oh @nikomatsakis didn't make github:rust-lang-nursery:compiler an owner 😿.

nikomatsakis pushed a commit to nikomatsakis/ena that referenced this pull request Feb 7, 2022
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.

2 participants