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

Queries for Crate Metadata #41653

Merged
merged 1 commit into from
May 3, 2017
Merged

Queries for Crate Metadata #41653

merged 1 commit into from
May 3, 2017

Conversation

hackeryarn
Copy link
Contributor

@hackeryarn hackeryarn commented Apr 30, 2017

This resolves following parts of #41417:

  • fn stability(&self, def: DefId) -> Option<attr::Stability>;
  • fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;

r? @nikomatsakis

@carols10cents carols10cents added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 1, 2017
cstore.item_generics_cloned(def_id).types.into_iter().map(|def| {
def.object_lifetime_default
}).collect()
ty::tls::with_opt(|opt_tcx| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nikomatsakis it seems that this call isn't able to retrieve tcx properly in a few scenarios. Is there a more appropriate way to reach tcx from this location?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, yes, the reason you are having this problem is that the tcx is not constructed yet. In general, fetching the tcx out of TLS is frowned upon, except for very limited cases (e.g., in a Debug impl) where there is basically no way to thread it down manually.

For now, you might want to leave those methods that are in code without access to a tcx -- but really the right answer is to convert these computations into "on-demand computations" themselves (e.g., resolve-lifetimes probably wants to become a query).

Copy link
Member

Choose a reason for hiding this comment

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

The reason item_generics_cloned is named the way it is (I should've commented it, shouldn't I?) is because it's item_generics (what is now generics_of), but returning a clone of the data that does not require a TyCtxt.

@hackeryarn
Copy link
Contributor Author

@nikomatsakis thanks for explanation. I've removed the commits that were causing the issues. This should be ready for review now.

I've also started a comment on the original issue to keep track of all the conversions that needed to be skipped at the time. #41417 (comment)

@bors
Copy link
Contributor

bors commented May 1, 2017

☔ The latest upstream changes (presumably #41611) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -599,7 +611,8 @@ define_maps! { <'tcx>

[] describe_def: DescribeDef(DefId) -> Option<Def>,
[] def_span: DefSpan(DefId) -> Span,

[] stability: Stability(DefId) -> Option<attr::Stability>,
[] deprecation: Deprecation(DefId) -> Option<attr::Deprecation>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nikomatsakis how do you prefer this to be implemented. I noticed that @cramertj and I diverged here. @cramertj is using the metadata_dep_node function while I am declaring new DepNode methods for these, as suggested by @eddyb in #41593.

I just want alignment here since we still have majority of the queries to convert.

@@ -115,6 +115,8 @@ provide! { <'tcx> tcx, def_id, cdata
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
describe_def => { cdata.get_def(def_id.index) }
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
stability => { cdata.get_stability(def_id.index) }
deprecation => { cdata.get_deprecation(def_id.index) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nikomatsakis this is another place of divergence with @cramertj. Should we be referencing the methods on cdata, or moving them into this implementation?

Copy link
Contributor

Choose a reason for hiding this comment

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

it probably depends on how big the method is. I think I'd rather keep the methods if they are more than a line or two, so that the macro remains only short expressions.

@eddyb
Copy link
Member

eddyb commented May 2, 2017

@achernyak You'll want to use git pull --rebase to avoid/remove the merge commits.

@hackeryarn hackeryarn force-pushed the master branch 2 times, most recently from 2fb07a4 to 120fe3f Compare May 2, 2017 11:47
@hackeryarn
Copy link
Contributor Author

@eddyb I've removed the merge commits.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Great!

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 2, 2017

📌 Commit c1d97c7 has been approved by nikomatsakis

frewsxcv added a commit to frewsxcv/rust that referenced this pull request May 3, 2017
Queries for Crate Metadata

This resolves following parts of rust-lang#41417:
* `fn stability(&self, def: DefId) -> Option<attr::Stability>;`
* `fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;`

r? @nikomatsakis
bors added a commit that referenced this pull request May 3, 2017
Rollup of 7 pull requests

- Successful merges: #41217, #41625, #41640, #41653, #41656, #41657, #41705
- Failed merges:
@bors bors merged commit c1d97c7 into rust-lang:master May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants