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

Tidy state view #1086

Merged
merged 20 commits into from
Sep 14, 2017
Merged

Tidy state view #1086

merged 20 commits into from
Sep 14, 2017

Conversation

ben-clayton
Copy link
Contributor

Fixes: #1068
Fixes: #24

@ben-clayton ben-clayton force-pushed the tidy-state branch 2 times, most recently from dedf4aa to 80071ff Compare September 11, 2017 22:46
@@ -531,7 +531,7 @@ public void setHoveredItem(TreeItem hoveredItem, Follower.Prefetcher<Void> follo
@Override
protected boolean isFollowable(Object element) {
ApiState.Node node = (ApiState.Node)element;
return node.getData() != null && node.getData().hasValuePath();
return node != null && node.getData() != null && node.getData().hasValuePath();
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this change. element being null here violates a precondition and represents a bug that should be fixed rather than ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@@ -62,7 +62,7 @@ public ApiState(
atoms.addListener(new AtomStream.Listener() {
@Override
public void onAtomsSelected(AtomIndex index) {
load(stateTree(index), false);
Copy link
Member

Choose a reason for hiding this comment

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

Undo - this is specifically written to handle null selection, which mean deselection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -77,15 +78,10 @@ private Paths() {
return Path.State.newBuilder().setAfter(command).build();
}

public static Path.Any stateTree(AtomIndex atom) {
Copy link
Member

Choose a reason for hiding this comment

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

Undo - This is part of handling null selections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return null;
}

public static Path.Any parentOf(Path.Any path) {
Copy link
Member

Choose a reason for hiding this comment

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

This is incomplete and I don't think it's necessary. This is trying to future-proof something without actually making it future-proof. Please undo this and just add the global state case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is trying to future-proof something without actually making it future-proof

I'd say it is more than just future-proofing. You had an ad-hoc collection of find functions that would need to be duplicated for findGlobalState. Yes, what I have changed to is incomplete, but it's as incomplete as your old findState. I'd rather implement the full set than roll back to a bunch of random functions. This approach mirrors the go-side, where parent-traversal is used for numerous cases.

Copy link
Member

Choose a reason for hiding this comment

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

but it's as incomplete as your old findState

I disagree with that assertion. findState was incomplete in the sense that the state path was the only path it could find, but it correctly handled every kind of path. parentOf pretends to be able to find the parent of any path, but it does not.

I know this is how it's done in go, and it works OK there due to the implicit interfaces. However, in Java the protos are immutable and the constant toBuilder().build() to wrap it in Path.Any for it to then just be unwrapped is a lot of overhead for something that is not complete and only used to determine if a path has a state root.

I propose, for now, we simply change findState to isStatePath, returning a boolean, since that's all that it's actually used for. This makes the change to handle the new global state root very simple. We then look at how we can do the parent relationship better. I would prefer if it was part of the proto.


atoms.addListener(new AtomStream.Listener() {
@Override
public void onAtomsSelected(AtomIndex index) {
load(Paths.any(stateTree(index.getCommand())), false);
Path.StateTree path = stateTree(index.getCommand());
Copy link
Member

Choose a reason for hiding this comment

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

Instead of building the proto twice, simply pass the context into the stateTree method (see the commandTree method)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -369,6 +369,8 @@ message Slice {
// State is a path to a subset of the GlobalState at a point in a capture.
message State {
Command after = 1;
// If non-nil, then the state is filtered to the specified context.
ID context = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Won't this break links to objects in another context which is shared?

ctx1 = newContext(nil)
ctx1...[1] = newTexture()
ctx2 = newContext(ctx1)
ctx2.bindTexture(1)

If in the UI I am filtering to ctx2, the link will attempt to go to ctx1, which is now no longer part of the tree, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it won't - because the server will return absolute GlobalState paths for followed links. The state tree nodes will also use GlobalState paths so that everything is absolute.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

State paths are used as relative paths to the most relevant part of the GlobalState (as considered by GAPIS).

Create a new interface for an API’s state (State)
Makes it possible to lookup the APIs from a path.

Also: Declare ID as a global for each API.
Currently unused, but will be soon.
The old approach didn’t scale for more complicated paths.
Name() uses fields that can vary over time.
Use the visitor pattern to implement:
 • toNode() - Takes a path.Any, returns an unboxed Node type.
 • toAny() - Inverse of toNode.
 • parentOf() - Returns the parent node of the given node.
 • setParent() - Returns a copy of the node with the parent changed.
 • toString()

Long and verbose, but is explicit and does the job. Happy to try and replace portions with reflection magic - I just want something that works for now.
@ben-clayton
Copy link
Contributor Author

Updated with a final CL that fixes the state tree reparenting. PTAL

@ben-clayton ben-clayton merged commit 58a8d27 into google:master Sep 14, 2017
@ben-clayton ben-clayton deleted the tidy-state branch September 14, 2017 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants