-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Operator dispatch #18486
Operator dispatch #18486
Conversation
727f5ed
to
4babfe8
Compare
It occurs to me that we could have a special rule for operators that eagerly coerces fixed-length arrays into slices, much as we eagerly reborrow pointers. But I'm not super enthusiastic about it: special rules are annoying, it won't work super reliably (e.g., not for |
(Oh, one other thing. If we make |
If we add this special rule, and change
Wouldn't the last part require being able to use integers as generic parameters? As in |
Can't wait to give this a go, thanks @nikomatsakis! |
4babfe8
to
15666ae
Compare
@japaric yes, it would suffer from the same limitations about length. Yes so perhaps we should "eagerly-unsize" fixed-length arrays used with operators. It handles arbitrary sizes and is more ergonomic. Deriving could be fixed either by using operators or by just modifying deriving to understand that (for things like Eq etc), if something is a fixed-length array, it ought to first convert to a slice. Hmm. As a bonus, I think it's not very hard to do. |
One possible downside I can see is that |
(Note though that this efficiency argument could be side-stepped by not using operator form) |
@japaric ok, I prototyped the |
15666ae
to
cd7341e
Compare
Does this change in semantics completely preclude future implementation of the ad-hoc operator overloading (rust-lang/rfcs#399)? |
@SiegeLord this is not a change in semantics, it's just tightening up the semantics we have. It doesn't preclude going to ad-hoc operator overloading in particular, though obviously that would require further changes. |
060398a
to
d1bf6c5
Compare
@nikomatsakis How does this PR affects issues #8280 and #10337? |
* to all lengths. | ||
*/ | ||
|
||
#![doc(primitive = "tuple")] |
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 guessing “tuple” is a mistake 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.
yes. although as this is a private module it hardly matters...
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.
actually I have no idea what that annotation does :) anyway, correction in commit ec67675
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.
@nikomatsakis This marks the documentation for the primitive types as they are handled in links and things like that, e.g. for tuple and slice.
*/ | ||
|
||
#![stable] | ||
#![experimental] // not yet reviewed |
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.
So now it’s stable and experimental?
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.
Um... too late to be making edits, I guess.
@sinistersnare yes it will fix those issues. |
ec67675
to
38d6e44
Compare
38d6e44
to
0132580
Compare
0132580
to
a907540
Compare
@@ -1980,7 +1980,7 @@ mod tests { | |||
let (left, right) = values.split_at_mut(2); | |||
{ | |||
let left: &[_] = left; | |||
assert!(left[0..left.len()] == [1, 2]); | |||
assert!(left[0..left.len()] == [1, 2][]); |
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.
Can't [1, 2][]
be written just as &[1, 2]
?
a907540
to
8b2bbe6
Compare
upon (e.g., `&int` added to `int`).
…ths 0...32 and repair various cases where slices and fixed-length arrays were being compared.
8b2bbe6
to
54628b2
Compare
Key points are: 1. `a + b` maps directly to `Add<A,B>`, where `A` and `B` are the types of `a` and `b`. 2. Indexing and slicing autoderefs consistently.
this `&x` sigil is all about.
…iscussed in an API meeting
54628b2
to
81c00e6
Compare
@alexcrichton is that a known failure? |
Sadly not yet, that's the first time I've ever seen that :( |
@alexcrichton it could be the fault of this PR, plausibly, though make check passes locally (linux) |
The error code listed corresponds to 0xc0000005 and googling for that points to it being some form of access violation, so we may have just uncovered a bug in gcc or ld (who knows!). |
@alexcrichton let's see if it repeats. not obvious to me how what I did would be at fault, but then I did change operator resolution, so in principle it COULD affect things. |
This branch cleans up overloaded operator resolution so that it is strictly based on the traits in `ops`, rather than going through the normal method lookup mechanism. It also adds full support for autoderef to overloaded index (whereas before autoderef only worked for non-overloaded index) as well as for the slicing operators. This is a [breaking-change]: in the past, we were accepting combinations of operands that were not intended to be accepted. For example, it was possible to compare a fixed-length array and a slice, or apply the `!` operator to a `&int`. See the first two commits in this pull-request for examples. One downside of this change is that comparing fixed-length arrays doesn't always work as smoothly as it did before. Before this, comparisons sometimes worked due to various coercions to slices. I've added impls for `Eq`, `Ord`, etc for fixed-lengths arrays up to and including length 32, but if the array is longer than that you'll need to either newtype the array or convert to slices. Note that this plays better with deriving in any case than the previous scheme. Fixes #4920. Fixes #16821. Fixes #15757. cc @alexcrichton cc @aturon
This branch cleans up overloaded operator resolution so that it is strictly based on the traits in
ops
, rather than going through the normal method lookup mechanism. It also adds full support for autoderef to overloaded index (whereas before autoderef only worked for non-overloaded index) as well as for the slicing operators.This is a [breaking-change]: in the past, we were accepting combinations of operands that were not intended to be accepted. For example, it was possible to compare a fixed-length array and a slice, or apply the
!
operator to a&int
. See the first two commits in this pull-request for examples.One downside of this change is that comparing fixed-length arrays doesn't always work as smoothly as it did before. Before this, comparisons sometimes worked due to various coercions to slices. I've added impls for
Eq
,Ord
, etc for fixed-lengths arrays up to and including length 32, but if the array is longer than that you'll need to either newtype the array or convert to slices. Note that this plays better with deriving in any case than the previous scheme.Fixes #4920.
Fixes #16821.
Fixes #15757.
cc @alexcrichton
cc @aturon