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 upIgnore expected type in diverging blocks #39485
Conversation
rust-highfive
assigned
alexcrichton
Feb 3, 2017
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
Also, please use a more descriptive title (e.g. "Allow diverging blocks to have a type different than that of their trailing expression." but that's maybe too long). |
rust-highfive
assigned
nikomatsakis
and unassigned
alexcrichton
Feb 3, 2017
This comment has been minimized.
This comment has been minimized.
|
@canndrew instead of removing the affected tests, can you move at least one of them into a |
This comment has been minimized.
This comment has been minimized.
|
cc @eddyb |
This comment has been minimized.
This comment has been minimized.
|
Oh, I see he already commented =) |
nikomatsakis
changed the title
Small inference fix
Allow diverging blocks to have arbitrary types
Feb 3, 2017
nikomatsakis
changed the title
Allow diverging blocks to have arbitrary types
Ignore expected type in diverging blocks
Feb 3, 2017
This comment has been minimized.
This comment has been minimized.
|
It occurs to me that we perhaps ought to crater this too. That is, I guess that this can lead to types becoming constrained that were not otherwise (as we saw in #39009). |
This comment has been minimized.
This comment has been minimized.
|
Is there a way to skip debuginfo tests when testing rustc? They always fail for me and it throws me off because sometimes I think the other tests have succeeded when I've gotten that far. As for the failing run-pass tests. This now fails (unable to infer enough type information for fn foo() -> Result<Foo, isize> {
return Ok(Foo {
x: Bar { x: 22 },
a: return Err(32)
});
}Which is unfortunate. Shouldn't inference be able to infer that the Also, this now fails (unable to infer enough type information for pub fn index_colors<Pix>(image: &ImageBuffer<Pix, Vec<u8>>)
-> ImageBuffer<Luma<u8>, Vec<u8>>
where Pix: Pixel<Subpixel=u8> + 'static,
{
let mut indices: ImageBuffer<_,Vec<_>> = loop { };
for (pixel, idx) in image.pixels().zip(indices.pixels_mut()) {
// failured occurred here ^^ because we were requiring that we
// could project Pixel or Subpixel from `T_indices` (type of
// `indices`), but the type is insufficiently constrained
// until we reach the return below.
}
indices
}Which makes sense, but is also unfortunate. (Because the function body is diverging, the type of |
canndrew
added a commit
to canndrew/rust
that referenced
this pull request
Feb 4, 2017
This comment has been minimized.
This comment has been minimized.
Well, the whole change here is basically that it doesn't have to. (Since it is dead-code.) cc @eddyb -- it makes sense that this would be causing some back-compat issues, but it's a drag. Definitely have to do a crater run I guess. |
This comment has been minimized.
This comment has been minimized.
|
Started a crater run. |
This comment has been minimized.
This comment has been minimized.
Root regressions
|
canndrew
added some commits
Feb 3, 2017
This comment has been minimized.
This comment has been minimized.
|
So, according to that crater run there's 4 directly-broken packages: libimagestore and tera have already been fixed upstream, they just need to publish new versions or get people using those new versions. lion has been yanked from crates.io and twig can be fixed easily enough. Of course if we did default to What's everyone's take on all this?
Sure, I was just surprised that it didn't still force that particular bit of unification to happen. |
canndrew
force-pushed the
canndrew:inference-fix-39297
branch
from
d35e5b1
to
18be42c
Feb 9, 2017
This comment has been minimized.
This comment has been minimized.
|
I've fixed the two failing tests. |
This comment has been minimized.
This comment has been minimized.
|
@canndrew ok, well, seems like we might as well go through with this. I feel like the current behavior is pretty inconsistent.
I'm not sure I understand what you mean here by "default to |
This comment has been minimized.
This comment has been minimized.
Sounds good to me.
I just meant set the type variable which can't be inferred to |
This comment has been minimized.
This comment has been minimized.
|
@canndrew I see. Well, I'm not a big fan of that idea, for a couple of reasons. For one thing, it would re-create the problem we are trying to fix here. Consider e.g. something like this: let mut v = vec![];
if condition {
return;
v.push(vec![]); // this type variable is created in dead code
}Now the type of In general, the rule of "dead code halts information flow up the tree (i.e., from expression to where expression is used)" but not "side-to-side" seems pretty good to me. Among other things, since the code is dead, there is (indeed) no data or information flow up the tree, and we can't know if you intended to add conversion and so forth. |
This comment has been minimized.
This comment has been minimized.
|
cc @Nercury -- twig-rs may be affected by this change. The testing of the PR got this error:
This PR affects information flow around dead-code. The problem seems to be that the type of this variable |
nikomatsakis
added
the
relnotes
label
Feb 16, 2017
This comment has been minimized.
This comment has been minimized.
|
I'm marking this for relnotes, since it does affect code. The relnotes could read: "Fixed bugs around how type inference interacts with dead-code. The existing code generally ignores the type of dead-code unless a type-hint is provided; this can cause surprising inference interactions particularly around defaulting. The new code uniformly ignores the result type of dead-code." |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
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
Feb 16, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry
* appveyor timeout
…On Thu, Feb 16, 2017 at 1:47 PM, bors ***@***.***> wrote:
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 17, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry
* network failure
…On Thu, Feb 16, 2017 at 9:26 PM, bors ***@***.***> wrote:
|
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis twig was my early Rust project that is not finished and is paused now, so the breakage won't cause any issues |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Feb 17, 2017
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit 18be42c
into
rust-lang:master
Feb 17, 2017
bors
referenced this pull request
Feb 17, 2017
Closed
Detect missing `;` on methods with return type `()` #39231
TimNN
referenced this pull request
Feb 20, 2017
Closed
Type inference regression in recent nightly #39984
nikomatsakis
referenced this pull request
Feb 21, 2017
Open
Tracking issue for `resolve_trait_on_defaulted_unit` compatibility lint #39216
TimNN
referenced this pull request
Feb 25, 2017
Closed
Type inference failure in unreachable code #40073
This comment has been minimized.
This comment has been minimized.
|
There was some concerns about what is expected breakage and what is not in #39984 but I suspect they are more likely to be answered here. There is this code that returns an So, is it expected breakage that the dead branch of code is 1) required to have fully known types but 2) is not type-inferred, unlike live branches, so these dead branches must have additional type annotations, which they wouldn't need if they were live branches? |
canndrew commentedFeb 3, 2017
As per comment: #39297 (comment)