Skip to content

Conversation

@gselzer
Copy link
Member

@gselzer gselzer commented Oct 18, 2023

@ctrueden noted here that current logic could throw errors if there are multiple InfoTreeGenerators that match a particular Op signature, and outlined two choices:

  1. Hide InfoTreeGenerator, so people can't implement it, and hardcode the priority.
  2. Implement a priority system, and when multiple InfoTreeGenerators could reify the signature, choose the highest priority.

This PR chooses option 2 as it is the less-API-breaking change, and because a priority-based system makes more sense than encoding an ordering by e.g. position in a List. This PR doesn't hide InfoTreeGenerator, but it also does not prevent us doing so in the future, and I'm not particularly against hiding it until we decide we need it.

Hiding InfoTreeGenerator would be as simple as moving it to a non-exported package. I still believe we'd want to service-load the implementations, as otherwise we'd probably introduce sub-package dependencies, failing the build, but that should still work if we move the package of the InfoTreeGenerator.

Closes scijava/scijava#87

This allows us to sort them, and find the highest-priority
@gselzer gselzer added the bug Something isn't working label Oct 18, 2023
@gselzer gselzer requested a review from ctrueden October 18, 2023 18:32
@gselzer gselzer self-assigned this Oct 18, 2023
@gselzer gselzer merged commit 45f4c15 into main Oct 18, 2023
@gselzer gselzer deleted the scijava/scijava-ops-engine/info-tree-generator-extensible branch October 18, 2023 18:41
Copy link
Member

@ctrueden ctrueden left a comment

Choose a reason for hiding this comment

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

👍 OK!


@Override
default double getPriority() {
return Priority.NORMAL;
Copy link
Member

Choose a reason for hiding this comment

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

@gselzer Make it makes sense for the Prioritized interface itself to have this default?

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 kinda like the fact that it doesn't - it makes you think about what the priority should be amongst the existing implementations. And there's the fact that this was the smallest necessary change to avoid our bug.

if (suitableGenerators.size() > 1) throw new IllegalArgumentException(
"Signature " + signature +
" is able to be reified by multiple generators: " + suitableGenerators);
return suitableGenerators.get(0);
Copy link
Member

Choose a reason for hiding this comment

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

What if the top two InfoTreeGenerator instances have the same priority? Should we fail fast? (I don't have an opinion, just pointing out that right now, on ties, one of them arbitrarily wins.)

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'm going to say YAGNI for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Consider whether InfoChainGenerator should be extensible

3 participants