Skip to content
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

Regression in type parameter defaults in types and impls #30123

Closed
bluss opened this Issue Nov 30, 2015 · 24 comments

Comments

Projects
None yet
7 participants
@bluss
Copy link
Contributor

bluss commented Nov 30, 2015

This regression is only visible in cross-crate code; NOTE it's very likely it's due to an actual rustc bug fix.

Here is some playpen code for illustration anyway.

Given a struct with default parameters and two constructor functions:

pub struct Graph<N, E, Ty = Directed, Ix: IndexType = DefIndex> {
    nodes: Vec<Node<N, Ix>>,
    edges: Vec<Edge<E, Ix>>,
    ty: PhantomData<Ty>,
}


impl<N, E> Graph<N, E, Directed> {
    pub fn new() -> Self {
        Graph{nodes: Vec::new(), edges: Vec::new(), ty: PhantomData}
    }
}

impl<N, E> Graph<N, E, Undirected> {
    pub fn new_undirected() -> Self {
        Graph{nodes: Vec::new(), edges: Vec::new(), ty: PhantomData}
    }
}

In Rust 1.4 or later (current stable and current nightly), both must be called like this to compile:

    let g = Graph::<i32, i32>::new();
    let ug = Graph::<i32, i32, _>::new_undirected();

In current stable Rust 1.4, the following compiles if you import Graph across crates!

let ug = Graph::<i32, i32>::new_undirected();

This is invalid in current nightly Rust ~1.6, see travis build example; the testcases are in their own crates.

tests/ograph.rs:1018:18: 1018:48 error: no associated item named `new_undirected` found for type `petgraph::graph::Graph<_, ()>` in the current scope
tests/ograph.rs:1018     let mut gr = Graph::<_, ()>::new_undirected();
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Dec 17, 2015

This does seem more like a bug fix, but I'm not sure what would have triggered it.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Dec 17, 2015

triage: P-high

It's important to decide if this is now doing the correct thing.

@rust-highfive rust-highfive added P-high and removed I-nominated labels Dec 17, 2015

@nikomatsakis nikomatsakis self-assigned this Dec 17, 2015

@bluss

This comment has been minimized.

Copy link
Contributor Author

bluss commented Dec 17, 2015

I'm sure it's an acceptable fix, but I think we want issues for all regressions, no matter why they happen.

I was mostly amused that there was no way to write a type hinted call of Graph::new_undirected() that would simultaneously compile with Rust 1.4 (requires 2 type params) and Rust 1.6 (requires three); you have to hint the types through the returned value instead.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Dec 21, 2015

The 2-type-param version was working only by a bug - we have no plans of working around that.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jan 6, 2016

@arielb1 do you think you know what fixed it? maybe something in metadata got corrected?

@brson brson added the relnotes label Jan 6, 2016

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jan 8, 2016

I'm trying to bisect to find out what changed, then write a test case.

@bluss

This comment has been minimized.

Copy link
Contributor Author

bluss commented Jan 11, 2016

See the issue link ^ I'm not crazy, the issue has now appeared somewhere else too 😄

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jan 11, 2016

Bisecting is proceeding slowly...

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jan 14, 2016

My bisection attempt failed.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jan 14, 2016

@brson :( if you like, I can try tracing through the relevant code paths with git blame to try and find likely candidates

@bluss

This comment has been minimized.

Copy link
Contributor Author

bluss commented Jan 14, 2016

I looked and my guess landed on a metadata change that @arielb1 did, would explain the cross crate only behavior.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jan 14, 2016

@bluss seems likely, I agree.

On Thu, Jan 14, 2016 at 4:38 PM, bluss notifications@github.com wrote:

I looked and my guess landed on a metadata change that @arielb1
https://github.com/arielb1 did, would explain the cross crate only
behavior.


Reply to this email directly or view it on GitHub
#30123 (comment).

@bluss

This comment has been minimized.

Copy link
Contributor Author

bluss commented Jan 14, 2016

The commit was db817ce

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jan 14, 2016

This commit should not have changed anything, but I imagine there is a bug here.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jan 16, 2016

@nikomatsakis nah that's ok. It's not a huge deal. I did start another bisect though. I'm having a hard time summarizing this change for the release notes. There are a lot of technical pieces here. Can somebody try?

@bluss

This comment has been minimized.

Copy link
Contributor Author

bluss commented Jan 16, 2016

@arielb1 My guess could have landed totally wrong. Don't know why I tried. You all know this better than me. For example, as the ImageBuffer example shows, type parameter defaults don't have to be involved, which has me a bit confounded.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jan 18, 2016

I am still trying to bisect.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jan 19, 2016

f5fbefa caused it.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Jan 19, 2016

brson added a commit to brson/rust that referenced this issue Jan 19, 2016

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jan 19, 2016

I think the culprit is that I added the

child_name_bindings.define_type(def, DUMMY_SP, modifiers);
@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jan 19, 2016

That indeed seems to be the change (commenting it out makes things compile again).

Could someone who understands resolve tell me how the change could cause that kind of effects?

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jan 21, 2016

I'm going to close this issue then as "not a bug", since we know that commit caused it.

rthomas added a commit to rthomas/rust that referenced this issue Feb 1, 2016

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Feb 21, 2016

@arielb1 Coming back to this, I remember that you removed some metadata code for saving inherent methods: wouldn't they be picked up by resolve, instead of letting typeck do UFCS resolution?

@hatahet

This comment has been minimized.

Copy link
Contributor

hatahet commented Feb 27, 2016

@brson:

My bisection attempt failed.

What caused it to fail the first time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.