Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upfuture-proof type-checking of binary operators #23319
Comments
This comment has been minimized.
This comment has been minimized.
|
triage: P-backcompat-lang (1.0 beta) |
rust-highfive
added
the
P-backcompat-lang
label
Mar 12, 2015
rust-highfive
added this to the 1.0 beta milestone
Mar 12, 2015
nikomatsakis
self-assigned this
Mar 12, 2015
This comment has been minimized.
This comment has been minimized.
|
I've been working more on this. It turns out that my preferred solution (treat everything like a trait match) did not work because The idea is simple: for each binary operator This does cause some breakage, mostly when the RHS is an application of some generic trait method, e.g. Here is an example diff. I can tell you that the resulting code is definitely more readable to someone who has to come and read it for the first time (since that person was me, when making the change): #[inline]
fn is_infinite(self) -> bool {
- self == Float::infinity() || self == Float::neg_infinity()
+ self == f32::infinity() || self == f32::neg_infinity()
}There is one unresolved question. In my current branch, we don't do coercions for either side. This caused one broken change, where a I think I can restore the old coercion behavior, at the cost that trait dispatch viability is based only on the LHS. This will potentially impact future auto-ref fallback, because the decision of whether to autoref or not will be based solely on the LHS. |
This comment has been minimized.
This comment has been minimized.
Note: Presumably this will also break |
This comment has been minimized.
This comment has been minimized.
|
Example of code that fails to compile today but I think should compile (and compiles on my branch): http://is.gd/38Z70g |
This comment has been minimized.
This comment has been minimized.
|
After some discussion with @aturon, we decided that the better thing to do is revert to the previous approach (all traits, all the time) with some hacky code for SIMD. Basically using |
nikomatsakis commentedMar 12, 2015
We need to invest a bit of energy to be sure that the way we handle binary operators is future-proof with possible plans:
@japaric has been doing some work on this in this PR #22993 and there is discussion there, including my preferred solution ;)