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

Refactor variance and remove last [pub] map #41734

Merged
merged 10 commits into from
May 6, 2017

Conversation

nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented May 3, 2017

This PR refactors variance to work in a more red-green friendly way. Because red-green doesn't exist yet, it has to be a bit hacky. The basic idea is this:

  • We compute a big map with the variance for all items in the crate; when you request variances for a particular item, we read it from the crate
  • We now hard-code that traits are invariant (which they are, for deep reasons, not gonna' change)
  • When building constraints, we compute the transitive closure of all things within the crate that depend on what using TransitiveRelation
    • this lets us gin up the correct dependencies when requesting variance of a single item

Ah damn, just remembered, one TODO:

  • Update the variance README -- ah, I guess the README updates I did are sufficient

r? @michaelwoerister

There are now two queries: crate and item. The crate one computes the
variance of all items in the crate; it is sort of an implementation
detail, and not meant to be used. The item one reads from the crate one,
synthesizing correct deps in lieu of the red-green algorithm.

At the same time, remove the `variance_computed` flag, which was a
horrible hack used to force invariance early on (e.g. when type-checking
constants). This is only needed because of trait applications, and
traits are always invariant anyway. Therefore, we now change to take
advantage of the query system:

- When asked to compute variances for a trait, just return a vector
  saying 'all invariant'.
- Remove the corresponding "inferreds" from traits, and tweak the
  constraint generation code to understand that traits are always
  inferred.
make it work for traits etc uniformly
(Now that variances are not part of signature.)
@alexcrichton alexcrichton added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 4, 2017
/// variance of every item in the local crate. You should not use it
/// directly, because to do so will make your pass dependent on the
/// HIR of every item in the local crate. Instead, use
/// `tcx.item_variances()` to get the variance for a *particular*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably say tcx.variances_of().

f: Base<'a, 'a, 'b, 'c>
}

#[rustc_variance] // Combine + and o to yield o (just pay attention to 'a here)
struct Derived3<'a:'b, 'b, 'c> { //~ ERROR [o, -, *]
//~^ ERROR parameter `'c` is never used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these error messages disappear?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I now halt compilation if we see any #[rustc_variance] annotations, rather than continuing on and reporting errors from other passes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

into two queries:

- `crate_variances` computes the variance for all items in the current crate.
- `item_variances` accesses the variance for an individual reading; it
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this should be variances_of

@michaelwoerister
Copy link
Member

I've looked through this PR, in particular regarding the dependency tracking related pieces, and it looks good to me. However, I know very little about the code in question here, so I'd feel better if someone else code also do a pass over the changes. @nikomatsakis suggested that @pnkfelix might be a good candidate for that.

r? @pnkfelix
Thanks!

@pnkfelix
Copy link
Member

pnkfelix commented May 5, 2017

Looks fine to me.

@bors r+

@bors
Copy link
Contributor

bors commented May 5, 2017

📌 Commit 79de56a has been approved by pnkfelix

@pnkfelix
Copy link
Member

pnkfelix commented May 5, 2017

@bors r-

@nikomatsakis I halted bors to give you a chance to address the item_variances/variances_of nit(s) noted above. Feel free to re-mark as r=me whenever you want.

@nikomatsakis
Copy link
Contributor Author

@pnkfelix ❤️

@nikomatsakis
Copy link
Contributor Author

@bors r=pnkfelix

@bors
Copy link
Contributor

bors commented May 5, 2017

📌 Commit 3da5daf has been approved by pnkfelix

frewsxcv added a commit to frewsxcv/rust that referenced this pull request May 5, 2017
…iance, r=pnkfelix

Refactor variance and remove last `[pub]` map

This PR refactors variance to work in a more red-green friendly way. Because red-green doesn't exist yet, it has to be a bit hacky. The basic idea is this:

- We compute a big map with the variance for all items in the crate; when you request variances for a particular item, we read it from the crate
- We now hard-code that traits are invariant (which they are, for deep reasons, not gonna' change)
- When building constraints, we compute the transitive closure of all things within the crate that depend on what using `TransitiveRelation`
    - this lets us gin up the correct dependencies when requesting variance of a single item

Ah damn, just remembered, one TODO:

- [x] Update the variance README -- ah, I guess the README updates I did are sufficient

r? @michaelwoerister
bors added a commit that referenced this pull request May 5, 2017
Rollup of 9 pull requests

- Successful merges: #41064, #41307, #41512, #41582, #41678, #41722, #41734, #41761, #41763
- Failed merges:
@bors bors merged commit 3da5daf into rust-lang:master May 6, 2017
@bors
Copy link
Contributor

bors commented May 6, 2017

⌛ Testing commit 3da5daf with merge 42a4f37...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants