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

Apparent regression in implied bounds #27583

Closed
nikomatsakis opened this issue Aug 7, 2015 · 8 comments
Closed

Apparent regression in implied bounds #27583

nikomatsakis opened this issue Aug 7, 2015 · 8 comments
Labels
A-type-system Area: Type system

Comments

@nikomatsakis
Copy link
Contributor

In the RFC 1214 branch, I found that at some point after a rebase (where a new snapshot was introduced), a new implied bound was needed. I believe this is specific to stage0, but I am not sure. I didn't have time to minimize or dig deeply, so i've marked the offending bound for now with a FIXME.

@nikomatsakis
Copy link
Contributor Author

OK, so, stranger and stranger. Now that we have a new stage0, this where clause that was previously required seems...to lead to an error? If I remove it, though, things work. Bizarre.

@nikomatsakis
Copy link
Contributor Author

Seems like I should put some effort into trying to narrow down the test case better.

@nikomatsakis
Copy link
Contributor Author

This test seems to fail.

use std::cell::Cell;
use std::marker::PhantomData;

pub trait Delegate<'tcx> { }

pub struct InferCtxt<'a, 'tcx: 'a> {
    x: PhantomData<&'a Cell<&'tcx ()>>
}

pub struct MemCategorizationContext<'t, 'a: 't, 'tcx : 'a> {
    x: &'t InferCtxt<'a, 'tcx>,
}

pub struct ExprUseVisitor<'d, 't, 'a: 't, 'tcx:'a+'d> {
    typer: &'t InferCtxt<'a, 'tcx>,
    mc: MemCategorizationContext<'t, 'a, 'tcx>,
    delegate: &'d mut (Delegate<'tcx>+'d),
}

impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
    pub fn new(delegate: &'d mut Delegate<'tcx>,
               typer: &'t InferCtxt<'a, 'tcx>)
               -> ExprUseVisitor<'d,'t,'a,'tcx>
    {
        ExprUseVisitor {
            typer: typer,
            mc: MemCategorizationContext::new(typer),
            delegate: delegate,
        }
    }
}

impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
    pub fn new(typer: &'t InferCtxt<'a, 'tcx>) -> MemCategorizationContext<'t, 'a, 'tcx> {
        MemCategorizationContext { x: typer }
    }
}

fn main() { }

@nikomatsakis
Copy link
Contributor Author

This MAY be related to object defaults -- if I change &'d mut Delegate<'tcx> to &'d mut (Delegate<'tcx>+'d), it works.

@nikomatsakis
Copy link
Contributor Author

OK, this is definitely some kind of wacky node-id confusion. If I change &'d mut Delegate<'tcx> to &'d mut (Delegate<'tcx>), the test passes!

@steveklabnik steveklabnik added the A-type-system Area: Type system label Aug 13, 2015
@nikomatsakis
Copy link
Contributor Author

OK, I found the problem. The problem is that the lub_free_regions code is really not very smart. In particular, for some 'a and 'b pair, it considers where 'a <= 'b or 'b <= 'a and otherwise falls back to 'static. It does not consider that there might be some other 'c such that 'a <= 'c and 'b <= 'c (in this case, 'tcx is such a region).

@nikomatsakis
Copy link
Contributor Author

I believe that adding parens makes things work simply because it permutes the ordering of various operations in region inference, causing slightly different LUB operations to arise in which the right variables are seen at the right time. I haven't fully verified this.

@nikomatsakis
Copy link
Contributor Author

(And, of course, we are not guaranteed a "best" answer here, so this is another case where region inference is (currently) bound to be somewhat inadequate.)

bors added a commit that referenced this issue Aug 22, 2015
Issue #27583 was caused by the fact that `LUB('a,'b)` yielded `'static`, even if there existed a region `'tcx:'a+'b`. This PR replaces the old very hacky code for computing how free regions relate to one another with something rather more robust. This solves the issue for #27583, though I think that similar bizarro bugs can no doubt arise in other ways -- the root of the problem is that the region-inference code was written in an era when a LUB always existed, but that hasn't held for some time. To *truly* solve this problem, it needs to be generalized to cope with that reality. But let's leave that battle for another day.

r? @aturon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

2 participants