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

selectors: fix for edge case around recursion clauses with an immediate edge. #334

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

warpfork
Copy link
Collaborator

See also the diff in the ipld/ipld repo for the new fixture,
which includes some explanation.

This would be a somewhat silly selector to write, but,
it doesn't seem to be something we should reject at compile time, either;
so, we must handle it gracefully.

Along the way, I documented some code that was sparse in comments.

I also added a shortcut to traversals so that a selector that
explicitly states it's not interested in anything (by returning a
non-nil but empty slice for its interests) is treated differently
than a nil return for interests (which means "I don't know; hit me
with everything you've got and lemme see"). This means that our
edge case here with edges (...heh) doesn't cause the traversal
to create an iterator that it doesn't really need, etc.

We turn out to need both that shortcut, and less panicky methods on
ExploreRecursiveEdge, and the edge case branch in ExploreRecursive...
because traversals are pre-order. Decide is called first, then
Interests, and then Explore. Therefore informing the Explore method
alone about this situation is not sufficient.

Previously, a recursion clause with an edge as its immediate and only
child would get a passing grade by the compiler (same as now),
but would panic when actually used (oh dear).

@warpfork
Copy link
Collaborator Author

Seealso matching specs PR: ipld/ipld#172 .

Should fix ipni/index-provider#144 .

@warpfork warpfork requested review from mvdan and masih January 19, 2022 03:01
Copy link
Contributor

@mvdan mvdan left a comment

Choose a reason for hiding this comment

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

Changes SGTM, except the bit about nil vs empty - that seems like a red flag to me.

traversal/walk.go Show resolved Hide resolved
…te edge.

See also the diff in the ipld/ipld repo for the new fixture,
which includes some explanation.

This would be a somewhat silly selector to write, but,
it doesn't seem to be something we should reject at compile time, either;
so, we must handle it gracefully.

Along the way, I documented some code that was sparse in comments.

I also added a shortcut to traversals so that a selector that
explicitly states it's not interested in anything (by returning a
non-nil but empty slice for its interests) is treated differently
than a nil return for interests (which means "I don't know; hit me
with everything you've got and lemme see").  This means that our
edge case here with edges (...heh) doesn't cause the traversal
to create an iterator that it doesn't really need, etc.

We turn out to need both that shortcut, *and* less panicky methods on
ExploreRecursiveEdge, *and* the edge case branch in ExploreRecursive...
because traversals are pre-order.  Decide is called first, then
Interests, and then Explore.  Therefore informing the Explore method
alone about this situation is not sufficient.

Previously, a recursion clause with an edge as its immediate and only
child would get a passing grade by the compiler (same as now),
but would panic when actually used (oh dear).
@warpfork warpfork force-pushed the selectors-fix-recursion-with-immediate-edge branch from 3dfd9e6 to 9e5da0e Compare January 21, 2022 01:45
@warpfork warpfork merged commit 19f6e52 into master Jan 21, 2022
@warpfork warpfork deleted the selectors-fix-recursion-with-immediate-edge branch January 21, 2022 01:50
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