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 ensure and try_get_with #45312

Merged
merged 2 commits into from
Oct 20, 2017
Merged

Conversation

theotherjimmy
Copy link
Contributor

There was a bit of code shared between try_get_with and ensure, after I
added ensure. I refactored that shared code into a query-agnostic method
called read_node_index.

The new method read_node_index will attempt to find the node
index (DepNodeIndex) of a query. When read_node_index finds the
DepNodeIndex, it marks the current query as a reader of the node it's
requesting the index of.

This is used by try_get_with and ensure as it elides the unimportant (to
them) details of if the query is invalidated by previous changed computation (Red)
or new and if they had to mark the query green. For both try_get_with and
ensure, they just need to know if they can lookup the results or have to
reevaluate.

@nikomatsakis this is the refactor we discussed in the comment thread of #45228

There was a bit of code shared between `try_get_with` and `ensure`, after I
added `ensure`. I refactored that shared code into a query-agnostic method
called `read_node_index`.

The new method `read_node_index` will attempt to find the node
index (`DepNodeIndex`) of a query. When `read_node_index` finds the
`DepNodeIndex`, it marks the current query as a reader of the node it's
requesting the index of.

This is used by `try_get_with` and `ensure` as it elides the unimportant (to
them) details of if the query is invalidated by previous changed computation (Red)
or new and if they had to mark the query green. For both `try_get_with` and
`ensure`, they just need to know if they can lookup the results or have to
reevaluate.
@rust-highfive
Copy link
Collaborator

r? @arielb1

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

@michaelwoerister
Copy link
Member

Thanks for the PR, @theotherjimmy!

I like the code deduplication. However could you:

  • move the function to plumbing.rs and make it private there? I'd like to publicly expose as little functionality as possible from DepGraph. I don't want to give the wrong impression that anybody is supposed to directly call DepGraph methods (unless they really know what they are doing).
  • rename the function to better reflect what it is actually doing? It can be something verbose like try_mark_green_and_read().

@kennytm kennytm added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 16, 2017
@theotherjimmy
Copy link
Contributor Author

move the function to plumbing.rs and make it private there?

The argument for privacy makes sense and I'll move it. The reason that I put it where I did, is that it did not need to be duplicated for each query type.

rename the function to better reflect what it is actually doing?

Ah, the hardest problem in computer science: naming. try_mark_green_and_read() is fine for a private function, but I would like public ones to be a tad less verbose.

Another commit is on the way with the move and rename. Don't hold your breath, it may be a few hours.

@michaelwoerister
Copy link
Member

The reason that I put it where I did, is that it did not need to be duplicated for each query type.

You could try and see if you can make this a free-standing function in plumbing.rs, outside of the macro. Then it would not be duplicated. You'll probably have to make it pub(super) then.

@theotherjimmy
Copy link
Contributor Author

Thanks for the tip. I'll give that a try.

@theotherjimmy
Copy link
Contributor Author

theotherjimmy commented Oct 16, 2017

@michaelwoerister I pushed up a commit that should address your review comments. I also moved the implementation of try_mark_green_and_read into TyCtxt as it took in a TyCtxt and a DepGraph, which is redundant as TyCtxt contains a DepGraph. This also has the benefit of reducing the number of arguments to the try_mark_green_and_read method.

@theotherjimmy
Copy link
Contributor Author

Please excuse the rebase. I forgot to delete the old implementation of read_node_index from graph.rs.

This should limit the availability of `try_mark_green_and_read` making
it harder to abuse.
@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 17, 2017
@michaelwoerister
Copy link
Member

Thanks @theotherjimmy! I think you've found the right place to put the function.

@bors r+

@bors
Copy link
Contributor

bors commented Oct 17, 2017

📌 Commit 229bee3 has been approved by michaelwoerister

@michaelwoerister michaelwoerister 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 Oct 17, 2017
@bors
Copy link
Contributor

bors commented Oct 19, 2017

⌛ Testing commit 229bee3 with merge 07a3441...

bors added a commit that referenced this pull request Oct 19, 2017
Refactor `ensure` and `try_get_with` into `read_node_index`

There was a bit of code shared between `try_get_with` and `ensure`, after I
added `ensure`. I refactored that shared code into a query-agnostic method
called `read_node_index`.

The new method `read_node_index` will attempt to find the node
index (`DepNodeIndex`) of a query. When `read_node_index` finds the
`DepNodeIndex`, it marks the current query as a reader of the node it's
requesting the index of.

This is used by `try_get_with` and `ensure` as it elides the unimportant (to
them) details of if the query is invalidated by previous changed computation (Red)
or new and if they had to mark the query green. For both `try_get_with` and
`ensure`, they just need to know if they can lookup the results or have to
reevaluate.

@nikomatsakis this is the [refactor we discussed](#45228 (comment)) in the comment thread of #45228
@bors
Copy link
Contributor

bors commented Oct 19, 2017

💔 Test failed - status-travis

@kennytm
Copy link
Member

kennytm commented Oct 19, 2017

@bors retry

@theotherjimmy theotherjimmy changed the title Refactor ensure and try_get_with into read_node_index Refactor ensure and try_get_with Oct 19, 2017
@bors
Copy link
Contributor

bors commented Oct 20, 2017

⌛ Testing commit 229bee3 with merge 354eb16...

bors added a commit that referenced this pull request Oct 20, 2017
Refactor `ensure` and `try_get_with`

There was a bit of code shared between `try_get_with` and `ensure`, after I
added `ensure`. I refactored that shared code into a query-agnostic method
called `read_node_index`.

The new method `read_node_index` will attempt to find the node
index (`DepNodeIndex`) of a query. When `read_node_index` finds the
`DepNodeIndex`, it marks the current query as a reader of the node it's
requesting the index of.

This is used by `try_get_with` and `ensure` as it elides the unimportant (to
them) details of if the query is invalidated by previous changed computation (Red)
or new and if they had to mark the query green. For both `try_get_with` and
`ensure`, they just need to know if they can lookup the results or have to
reevaluate.

@nikomatsakis this is the [refactor we discussed](#45228 (comment)) in the comment thread of #45228
@bors
Copy link
Contributor

bors commented Oct 20, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: michaelwoerister
Pushing 354eb16 to master...

@bors bors merged commit 229bee3 into rust-lang:master Oct 20, 2017
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.

6 participants