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

Add rustc_on_unimplemented for Index implementation on slice #33401

Merged
merged 5 commits into from
May 12, 2016

Conversation

GuillaumeGomez
Copy link
Member

Reopening of #31071.

It also extends the possibility of #[rustc_on_unimplemented] by providing a small type filter in order to find the ones which corresponds the most.

r? @pnkfelix

@GuillaumeGomez
Copy link
Member Author

I fixed tests breakage (forgot to add Notes lines).

@GuillaumeGomez
Copy link
Member Author

cc @nikomatsakis

@GuillaumeGomez
Copy link
Member Author

Any news on this?

}

impl<'a> AssociatedWeight for TypeVariants<'a> {
// First number is for "global" weight and second number is for bigger precision
Copy link
Member

Choose a reason for hiding this comment

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

what two numbers is this comment referring to? (Did this used to return (usize, usize) or something?

Copy link
Member

Choose a reason for hiding this comment

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

oh, weird; from fn get_weight_diff, I guess you are effectively encoding a pair (x, y), where y < 10, as x * 10 + y?

Copy link
Member

Choose a reason for hiding this comment

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

In which case you should probably say something like "the digit in the ten's place is for "global weight" and the digit in the one's place is for bigger precision."

(Though I haven't read enough yet to understand the phrases "global weight" and "bigger precision" here.)

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems like a bad idea... if we're into microoptimizations here, a number that can't be larger than two digits can be a u8 :) Otherwise, just use a pair.

Copy link
Member

Choose a reason for hiding this comment

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

(i'm inclined to agree with @durka; it doesn't seem like it would be that onerous to write the match using (u32, u32) or something.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Then let's go for the tuple!

@pnkfelix
Copy link
Member

I'm debating about whether I would like to see more tests or not.

On the one hand: It would be good to have tests demonstrating the behavior in cases that aren't just usize/u32/i32

And I might like to also see concrete examples of the kind of scenario I mentioned above, namely where "many small differences accumulating to eventually become larger than one big difference in weight."

On the other hand, this code is by its very nature a mere heuristic. We almost certainly want to allow ourselves plenty of freedom to revise how the "best" candidate impl is chosen, which means that having a large test suite that ties down the particular numbers chosen in fn get_weight could be a bad idea.

@pnkfelix
Copy link
Member

@GuillaumeGomez overall I'm really happy with this PR (despite the tone of some of my commentary above).

I think I'll just say: r=me after the nits are addressed.

@pnkfelix
Copy link
Member

One more throw-away thought: I wonder whether there would be any value to the end user to have a compilation mode (selected via some flag, perhaps --verbose ...) where it would present all of the most coarsely matching impls, rather than trying to pick the best of the coarse via the second finer grain pass.

@GuillaumeGomez
Copy link
Member Author

One more throw-away thought: I wonder whether there would be any value to the end user to have a compilation mode (selected via some flag, perhaps --verbose ...) where it would present all of the most coarsely matching impls, rather than trying to pick the best of the coarse via the second finer grain pass.

That's a comment I already had and I didn't really know how to address it. So I thought about doing something like:

If you meant to use usize, here's a tip: [usize rustc_on_unimplemented message]
If you meant to use Range, here's a tip: [Range rustc_on_unimplemented message]
...

However, I'm afraid it'll just flood the output in the case there are many potential corresponding types. But maybe I'm wrong, I'd be glad to have a second thought about my thinking.

@GuillaumeGomez
Copy link
Member Author

To address this comment: the "big" weight number (so in 12, it's 1) determines a first category. The second number (so 2 in here) only applies to the types of the same categories and doesn't really have any other meaning than differentiating them for the moment. I made this algorithm as easy as possible to maintain and potentially evolve, so I need to add more comments and more clarity.

@GuillaumeGomez
Copy link
Member Author

@pnkfelix: I think I had addressed all the nits. Do you see anything else?


// Here, we run the "big" filter. Little example:
//
// We receive a `String`, an `u32` and in `i32`.
Copy link
Member

Choose a reason for hiding this comment

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

typo: "an i32", not "in i32"

@pnkfelix
Copy link
Member

@GuillaumeGomez other than the typo I just commented on, I think this looks good.

@GuillaumeGomez
Copy link
Member Author

I fixed the typo.

@bors
Copy link
Contributor

bors commented May 11, 2016

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

@GuillaumeGomez GuillaumeGomez force-pushed the index_indication branch 3 times, most recently from b5bfb8e to 2c829c1 Compare May 11, 2016 14:52
@GuillaumeGomez
Copy link
Member Author

All fixed.

@pnkfelix
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 11, 2016

📌 Commit 4a3acfd has been approved by pnkfelix

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 11, 2016
…pnkfelix

Add rustc_on_unimplemented for Index implementation on slice

Reopening of rust-lang#31071.

It also extends the possibility of `#[rustc_on_unimplemented]` by providing a small type filter in order to find the ones which corresponds the most.

r? @pnkfelix
bors added a commit that referenced this pull request May 11, 2016
Rollup of 3 pull requests

- Successful merges: #33401, #33489, #33558
- Failed merges: #33342, #33475, #33517
@bors bors merged commit 4a3acfd into rust-lang:master May 12, 2016
@GuillaumeGomez GuillaumeGomez deleted the index_indication branch May 12, 2016 07:19
@bluss bluss added the relnotes Marks issues that should be documented in the release notes of the next release. label May 13, 2016
@pnkfelix
Copy link
Member

(since this is tagged with relnotes, I'll just note that a portion of the changes introduced here were subsequently reverted in #33491 , so just take care to double check the state of the actual code in terms of what is written in the release notes...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants