-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
5155d5e
to
ce3019d
Compare
I fixed tests breakage (forgot to add Notes lines). |
Any news on this? |
} | ||
|
||
impl<'a> AssociatedWeight for TypeVariants<'a> { | ||
// First number is for "global" weight and second number is for bigger precision |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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!
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 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 |
@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. |
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 |
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. |
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. |
@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`. |
There was a problem hiding this comment.
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
"
@GuillaumeGomez other than the typo I just commented on, I think this looks good. |
af591bb
to
d21360b
Compare
I fixed the typo. |
☔ The latest upstream changes (presumably #33425) made this pull request unmergeable. Please resolve the merge conflicts. |
…mpl, this message will be displayed instead
Add more comments for the global understanding
b5bfb8e
to
2c829c1
Compare
All fixed. |
2c829c1
to
4a3acfd
Compare
@bors r+ rollup |
📌 Commit 4a3acfd has been approved by |
…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
(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...) |
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