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 upGeneralize binary operators #23673
Conversation
rust-highfive
assigned
pnkfelix
Mar 24, 2015
This comment has been minimized.
This comment has been minimized.
|
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
hmm the rebase is encountering a problem, I may push a tweaked version soon |
This comment has been minimized.
This comment has been minimized.
|
Huzzah! |
This comment has been minimized.
This comment has been minimized.
|
OK, things are looking good locally. I'll push a revised version shortly that passes make check. |
nikomatsakis
force-pushed the
nikomatsakis:issue-23319-binops-ng-5
branch
2 times, most recently
from
1c310fb
to
e4fcdea
Mar 25, 2015
This comment has been minimized.
This comment has been minimized.
|
For some odd reason I see a failure locally in the |
nikomatsakis
force-pushed the
nikomatsakis:issue-23319-binops-ng-5
branch
from
e4fcdea
to
82fdbdb
Mar 25, 2015
This comment has been minimized.
This comment has been minimized.
|
oh and cc @eddyb -- this changed the flow around coercions a bit, though nothing that should really affect you |
This comment has been minimized.
This comment has been minimized.
|
@bors try |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 25, 2015
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
nikomatsakis
force-pushed the
nikomatsakis:issue-23319-binops-ng-5
branch
2 times, most recently
from
40f1d55
to
5265d57
Mar 25, 2015
tbu-
reviewed
Mar 25, 2015
| map.insert(i, i); | ||
| } | ||
|
|
||
| // measure | ||
| b.iter(|| { | ||
| let k = rng.gen() % n; | ||
| let k = rng.gen::<usize>() % n; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Mar 25, 2015
Author
Contributor
Hmm, I presume because that would alter what is being tested when run on 32-bit and 64-bit systems? Makes sense. I can change to u32.
nikomatsakis
force-pushed the
nikomatsakis:issue-23319-binops-ng-5
branch
from
5265d57
to
1dbddda
Mar 25, 2015
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis don't run the |
This comment has been minimized.
This comment has been minimized.
|
@eddyb ah, that might indeed be the problem... |
This comment has been minimized.
This comment has been minimized.
|
We should consider trying to remove that fragility, perhaps in a similar manner that |
pnkfelix
reviewed
Mar 25, 2015
| @@ -23,4 +23,6 @@ fn main() { | |||
| unsafe { libc::exit(0 as libc::c_int); } | |||
| }); | |||
| 2_usize + (loop {}); | |||
| //~^ ERROR E0277 | |||
This comment has been minimized.
This comment has been minimized.
pnkfelix
Mar 25, 2015
Member
Hmm. I don't think you should have moved this test into compile-fail.
Were you intending to make a copy of it?
Could you fix the test by explicitly forcing the type of the looping expression, e.g.:
(2 + { let x: i8 = loop { }; x });
This comment has been minimized.
This comment has been minimized.
pnkfelix
Mar 25, 2015
Member
(this was supposed to be a comment on commit f8a658c ; maybe its resolved in follow-on commits.)
This comment has been minimized.
This comment has been minimized.
pnkfelix
Mar 25, 2015
Member
(of course it might be even nicer to not require the type annotation at all, since after all the addition is an unreachable expression in the control flow. but I'd be satisfied with an annotation rather than trying to go further.)
This comment has been minimized.
This comment has been minimized.
pnkfelix
referenced
this pull request
in nikomatsakis/rust
Mar 25, 2015
pnkfelix
referenced
this pull request
in nikomatsakis/rust
Mar 25, 2015
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis okay. Overall I think this is a nice cleanup compared to the previous code. its mostly just a bunch of questions from me. Along with a few things that might have been mistakes on your part; hopefully its clear from the comments. You can r=me (preferably after addressing the review notes, though). |
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix the problem with lang-item-public had to do with the fact that there are no impls for Add, so you get type errors in the end iirc. I did debate about that for a while. I guess I could bring in the Add trait to keep the original code. |
shepmaster
referenced this pull request
Mar 26, 2015
Open
Order of operands to equality expression matters when inferring a AsRef implementation #23762
This comment has been minimized.
This comment has been minimized.
|
|
nikomatsakis
added some commits
Mar 24, 2015
nikomatsakis
force-pushed the
nikomatsakis:issue-23319-binops-ng-5
branch
from
1dbddda
to
7595c25
Mar 30, 2015
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 30, 2015
This comment has been minimized.
This comment has been minimized.
bors
merged commit 7595c25
into
rust-lang:master
Mar 30, 2015
This was referenced Mar 30, 2015
andersk
referenced this pull request
Mar 31, 2015
Closed
error: type annotations required: cannot resolve `<f32 as core::ops::Add<_>>::Output == f32` [E0284] #38
This comment has been minimized.
This comment has been minimized.
|
This necessitated extra type annotations in the |
This comment has been minimized.
This comment has been minimized.
|
Oh, I guess it must be, since c92bdcb made the same change to rustc’s internal copy of |
nikomatsakis commentedMar 24, 2015
The current binary operator code assumed that if the LHS was a scalar (
i32etc), then the RHS had to match. This is not true with multidispatch. This PR generalizes the existing code to (primarily) use the traits -- this also allows us to defer the precise type-checking when the types aren't fully known. The one caveat is the unstable SIMD types, which don't fit in with the current traits -- in that case, the LHS type must be known to be SIMD ahead of time.There is one semi-hacky bit in that during writeback, for builtin operators, if the types resolve to scalars (i32 etc) then we clear the method override. This is because we know what the semantics are and it is more efficient to generate the code directly. It also ensures that we can use these overloaded operators in constants and so forth.
cc @japaric
cc @aturon
Fixes #23319 (and others).