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

Migrate a slew of metadata methods to queries #44142

Merged
merged 29 commits into from
Sep 8, 2017

Conversation

alexcrichton
Copy link
Member

@alexcrichton alexcrichton commented Aug 29, 2017

This PR intends to make more progress on #41417, knocking off some low-hanging fruit.

Closes #44190
cc #44137

@alexcrichton
Copy link
Member Author

r? @nikomatsakis

@rust-highfive
Copy link
Collaborator

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@kennytm
Copy link
Member

kennytm commented Aug 29, 2017

CI timed out after 3 hours, with run-pass/rustc-rust-log.rs failed with signal 6 i.e. SIGABRT. The error log is >4 MB consisting of DEBUG logs. It is legit last time this happens (#43028 (comment)).

[00:46:45] ---- [run-pass] run-pass/rustc-rust-log.rs stdout ----
[00:46:45] 	
[00:46:45] error: compilation failed!
[00:46:45] status: signal: 6
[00:46:45] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/run-pass/rustc-rust-log.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass" "--target=x86_64-unknown-linux-gnu" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/rustc-rust-log.stage2-x86_64-unknown-linux-gnu" "-Crpath" "-O" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/rustc-rust-log.stage2-x86_64-unknown-linux-gnu.run-pass.libaux"
[00:46:45] stdout:
[00:46:45] ------------------------------------------
[00:46:45] 
[00:46:45] ------------------------------------------
[00:46:45] stderr:
[00:46:45] ------------------------------------------

[] DeriveRegistrarFn(DefId),
[] ForeignCrateDisambiguator(DefId),
[] CrateHash(DefId),
[] ForeignOriginalCrateName(DefId),
Copy link
Member

Choose a reason for hiding this comment

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

@nikomatsakis @michaelwoerister Is there not a better way to deal with this?

Copy link
Contributor

Choose a reason for hiding this comment

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

The problem being the duplication? I'd like to combine this macro with the query macro, I'm not sure if something is blocking that.

@@ -140,7 +138,27 @@ provide! { <'tcx> tcx, def_id, cdata,
is_panic_runtime => { cdata.is_panic_runtime(&tcx.dep_graph) }
is_compiler_builtins => { cdata.is_compiler_builtins(&tcx.dep_graph) }
has_global_allocator => { cdata.has_global_allocator(&tcx.dep_graph) }
is_sanitizer_runtime => { cdata.is_sanitizer_runtime(&tcx.dep_graph) }
is_profiler_runtime => { cdata.is_profiler_runtime(&tcx.dep_graph) }
panic_strategy => { cdata.panic_strategy(&tcx.dep_graph) }
Copy link
Member

Choose a reason for hiding this comment

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

Aren't a bunch of these just reading crate-level attributes? Why can't we do that directly through tcx.get_attrs?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could, but it would mean that if we allow "free" access, then any change to crate attributes will require recompiling everything. Not sure if that's a problem.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm but that could be solved by putting a Symbol (for the name of the attribute) in the query, which is what you want most of the time anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not all of these are crate attributes as well, some of them, like the panic strategy, can be affected by command line flags as well. The others, sure, but perhaps that's a refactoring for another time?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm if there aren't many of them then this PR is probably fine.

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.

This all seems ok to me. Regarding @eddyb's comments, my take is that:

  • we could (and should) revisit the question of how to autogenerate dep-node variants and query variants (I'd prefer if you did not have to duplicate), but it seems orthogonal from this PR;
  • we could consider accessing the crate attributes directly, but I don't see a strong reason to do so.

In particular, accessing crate attributes directly would imply that we would have more coarse-grained incremental. This is not in and of itself a problem, as I don't know that modifying crate attributes was ever intended to be a "supported" incremental use case, but I also don't see much reason to actively make it not work, now that @alexcrichton already did the work.

If the concern is that we are making too many hashmaps or something like that, I think I'd prefer to keep the queries, but add some flags to make a query "direct" or something, in which it is not cached (and presumably then also doesn't help much with incremental). That way we can control this trade-off with minimal effort. (Or does that feel like overkill?)

@eddyb
Copy link
Member

eddyb commented Aug 29, 2017

@nikomatsakis The thing is that there's a handful of methods that were never required, all they do is they read the crate attributes and IMO having the extra method in between muddles that.

@alexcrichton
Copy link
Member Author

I tracked down some incremental test failures with the help of @nikomatsakis and the conclusion is that this PR will regress some current incremental tests due to new dependency nodes getting introduced. We decided, though, that the regression is ok for now. The red/green system will fix the regressions and so for now I'll just tag them with a FIXME

@arielb1 arielb1 added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 29, 2017
@alexcrichton
Copy link
Member Author

Ok I've updated queries to work with CrateNum instead of DefId and ignored the failing tests.

re-r? @nikomatsakis

@nikomatsakis
Copy link
Contributor

@eddyb

The thing is that there's a handful of methods that were never required, all they do is they read the crate attributes and IMO having the extra method in between muddles that.

It appears I never responded to this. I know I started one... anyway, I actually think the queries do serve (potentially) a purpose. First off, they are clearly (to me) better documentation of the intent than "open-coding" some logic that trawls through the attributes on the crate. That is, I'd prefer that most of the compiler doesn't directly deal in attributes, but uses a helper method to encapsulate that logic (that doesn't necessarily have to be a query).

Second, in terms of incremental logic, having queries does serve a real purpose since it allows us to control change propagation. This is what I was trying to say: having a query means that, once red-green is working, if the user changes the crate attributes, we will be able to avoid recompiling everything (since many things consult these crate attributes, e.g. symbol creation), unless they happen to have changed the result of one of those queries.

Now, it may be that we could just have helper methods instead of the queries: I wouldn't be opposed to that, but it will result in coarser grained incremental support.

@alexcrichton
Copy link
Member Author

I've pushed up a fix for the broken test and one more query translated

@bors
Copy link
Contributor

bors commented Aug 31, 2017

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

},
extern_mod_stmt_cnum: |tcx, id| {
let id = tcx.hir.definitions().find_node_for_hir_id(id);
tcx.sess.cstore.extern_mod_stmt_cnum_untracked(id)
Copy link
Member Author

Choose a reason for hiding this comment

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

This method and postorder_cnums below are something I wanted to ask about here. So what's happening here is that in this query it's reaching into the cstore via the CrateStore trait into various untracked methods to actually perform the computation.

Is that ok? Does that mean that these aren't tracked properly? Should the dep nodes be manually created here? Just wanted to make sure to flag this!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think what should happen is that we should treat these as "input" queries -- and hence always re-execute them. Really, I think that robably all the metadata-poking queries should be this way, and we should just lean on red-green to let us only invalidate things that are truly invalidated by changing metadata.

(Cc @michaelwoerister)

Copy link
Member Author

Choose a reason for hiding this comment

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

cc #44234 as well, where I believe we're discussing this basically

// Once red/green incremental compilation lands we should be able to
// remove this because while the crate changes often the lint level map
// will change rarely.
self.dep_graph.with_ignore(|| {
Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to make sure I called this out as well. This with_ignore was necessary to not instantly break all of the incremental tests!

I imagine though that with red/green this'll always generate the same value, so the node's always green even though it needs to be recomputed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's the idea, yeah

item_body => {
if let Some(cached) = tcx.hir.get_inlined_body_untracked(def_id) {
return cached;
}
Copy link
Member

Choose a reason for hiding this comment

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

You can remove this if and the get_inlined_body_untracked method, as the result will be cached anyway.

@@ -1313,6 +1343,14 @@ define_maps! { <'tcx>
[] get_lang_items: get_lang_items_node(CrateNum) -> Rc<LanguageItems>,
[] defined_lang_items: DefinedLangItems(CrateNum) -> Rc<Vec<(DefIndex, usize)>>,
[] missing_lang_items: MissingLangItems(CrateNum) -> Rc<Vec<LangItem>>,
[] item_body: ItemBody(DefId) -> &'tcx hir::Body,
Copy link
Member

Choose a reason for hiding this comment

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

Can this be named extern_const_body?

@bors
Copy link
Contributor

bors commented Sep 1, 2017

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

@bors
Copy link
Contributor

bors commented Sep 7, 2017

💔 Test failed - status-travis

@kennytm
Copy link
Member

kennytm commented Sep 7, 2017

Same error as #43742 (comment)? Something's wrong with the sanitizers.

@bors retry

@bors
Copy link
Contributor

bors commented Sep 8, 2017

⌛ Testing commit fd0aa64 with merge dead08c...

bors added a commit that referenced this pull request Sep 8, 2017
Migrate a slew of metadata methods to queries

This PR intends to make more progress on #41417, knocking off some low-hanging fruit.

Closes #44190
cc #44137
@nikomatsakis nikomatsakis added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 8, 2017
@alexcrichton
Copy link
Member Author

Everything passed except two builders on OSX which are timing out due to travis issues. I'm going to merge and deal with fallout if there's any (which seems highly unlikely)

@alexcrichton alexcrichton merged commit fd0aa64 into rust-lang:master Sep 8, 2017
@alexcrichton
Copy link
Member Author

Travis and AppVeyor

@alexcrichton alexcrichton deleted the dllimport-query branch September 8, 2017 14:52
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 15, 2017
This commit alters the `query` function in the dep graph module to preallocate
memory using `with_capacity` instead of relying on automatic growth. Discovered
in rust-lang#44576 it was found that for the syntex_syntax clean incremental benchmark
the peak memory usage was found when the dep graph was being saved, particularly
the `DepGraphQuery` data structure itself. PRs like rust-lang#44142 which add more
queries end up just making this much larger!

I didn't see an immediately obvious way to reduce the size of the
`DepGraphQuery` object, but it turns out that `with_capacity` helps quite a bit!
Locally 831 MB was used [before] this commit, and 770 MB is in use at the peak
of the compiler [after] this commit. That's a nice 7.5% improvement! This won't
quite make up for the losses in rust-lang#44142 but I figured it's a good start.

[before]: https://gist.github.com/alexcrichton/2d2b9c7a65503761925c5a0bcfeb0d1e
[before]: https://gist.github.com/alexcrichton/6da51f2a6184bfb81694cc44f06deb5b
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 15, 2017
…elwoerister

rustc: Preallocate when building the dep graph

This commit alters the `query` function in the dep graph module to preallocate
memory using `with_capacity` instead of relying on automatic growth. Discovered
in rust-lang#44576 it was found that for the syntex_syntax clean incremental benchmark
the peak memory usage was found when the dep graph was being saved, particularly
the `DepGraphQuery` data structure itself. PRs like rust-lang#44142 which add more
queries end up just making this much larger!

I didn't see an immediately obvious way to reduce the size of the
`DepGraphQuery` object, but it turns out that `with_capacity` helps quite a bit!
Locally 831 MB was used [before] this commit, and 770 MB is in use at the peak
of the compiler [after] this commit. That's a nice 7.5% improvement! This won't
quite make up for the losses in rust-lang#44142 but I figured it's a good start.

[before]: https://gist.github.com/alexcrichton/2d2b9c7a65503761925c5a0bcfeb0d1e
[before]: https://gist.github.com/alexcrichton/6da51f2a6184bfb81694cc44f06deb5b
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 16, 2017
…elwoerister

rustc: Preallocate when building the dep graph

This commit alters the `query` function in the dep graph module to preallocate
memory using `with_capacity` instead of relying on automatic growth. Discovered
in rust-lang#44576 it was found that for the syntex_syntax clean incremental benchmark
the peak memory usage was found when the dep graph was being saved, particularly
the `DepGraphQuery` data structure itself. PRs like rust-lang#44142 which add more
queries end up just making this much larger!

I didn't see an immediately obvious way to reduce the size of the
`DepGraphQuery` object, but it turns out that `with_capacity` helps quite a bit!
Locally 831 MB was used [before] this commit, and 770 MB is in use at the peak
of the compiler [after] this commit. That's a nice 7.5% improvement! This won't
quite make up for the losses in rust-lang#44142 but I figured it's a good start.

[before]: https://gist.github.com/alexcrichton/2d2b9c7a65503761925c5a0bcfeb0d1e
[before]: https://gist.github.com/alexcrichton/6da51f2a6184bfb81694cc44f06deb5b
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Sep 16, 2017
…elwoerister

rustc: Preallocate when building the dep graph

This commit alters the `query` function in the dep graph module to preallocate
memory using `with_capacity` instead of relying on automatic growth. Discovered
in rust-lang#44576 it was found that for the syntex_syntax clean incremental benchmark
the peak memory usage was found when the dep graph was being saved, particularly
the `DepGraphQuery` data structure itself. PRs like rust-lang#44142 which add more
queries end up just making this much larger!

I didn't see an immediately obvious way to reduce the size of the
`DepGraphQuery` object, but it turns out that `with_capacity` helps quite a bit!
Locally 831 MB was used [before] this commit, and 770 MB is in use at the peak
of the compiler [after] this commit. That's a nice 7.5% improvement! This won't
quite make up for the losses in rust-lang#44142 but I figured it's a good start.

[before]: https://gist.github.com/alexcrichton/2d2b9c7a65503761925c5a0bcfeb0d1e
[before]: https://gist.github.com/alexcrichton/6da51f2a6184bfb81694cc44f06deb5b
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 17, 2017
…elwoerister

rustc: Preallocate when building the dep graph

This commit alters the `query` function in the dep graph module to preallocate
memory using `with_capacity` instead of relying on automatic growth. Discovered
in rust-lang#44576 it was found that for the syntex_syntax clean incremental benchmark
the peak memory usage was found when the dep graph was being saved, particularly
the `DepGraphQuery` data structure itself. PRs like rust-lang#44142 which add more
queries end up just making this much larger!

I didn't see an immediately obvious way to reduce the size of the
`DepGraphQuery` object, but it turns out that `with_capacity` helps quite a bit!
Locally 831 MB was used [before] this commit, and 770 MB is in use at the peak
of the compiler [after] this commit. That's a nice 7.5% improvement! This won't
quite make up for the losses in rust-lang#44142 but I figured it's a good start.

[before]: https://gist.github.com/alexcrichton/2d2b9c7a65503761925c5a0bcfeb0d1e
[before]: https://gist.github.com/alexcrichton/6da51f2a6184bfb81694cc44f06deb5b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants