Skip to content

Commit dfd6f92

Browse files
gselzerhinerm
authored andcommitted
Replace copyOp warning with javadoc
1 parent 39d49ea commit dfd6f92

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

scijava/scijava-ops/src/main/java/org/scijava/ops/impl/DefaultOpEnvironment.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,31 @@ private OpCandidate findSimplifiedMatch(OpRef ref, List<OpCandidate> candidates)
442442
return new MatchingResult(candidates, matches, Collections.singletonList(ref)).singleMatch();
443443
}
444444

445-
// WARNING: If no copy Computers.Arity1 exists for copyType (i.e. a
446-
// Computers.Arity1<copyType, copyType>) then this method will result in an
447-
// infinite recursive loop. This problem can be immediately solved by ensuring
448-
// that a copy Op Computers.Arity1<copyType, copyType> exists, and will be
449-
// permanently fixed with the introduction of hints (see
450-
// scijava/scijava-ops#43)
445+
/**
446+
* Finds a {@code copy} Op designed to copy an Op's output (of {@link Type}
447+
* {@code copyType}) back into the preallocated output during simplification.
448+
* <p>
449+
* NB Simplification is forbidden here because we are asking for a
450+
* {@code Computers.Arity1<T, T>} copy Op (for some {@link Type}
451+
* {@code type}). Suppose that no direct match existed, and we tried to find a
452+
* simplified version. This simplified version, because it is a
453+
* Computers.Arity1, would need a {@lnk Computers.Arity<T, T>} copy Op to copy
454+
* the output of the simplified Op back into the preallocated output. But this
455+
* call is already identical to the Op we asked for, and we know that there is
456+
* no direct match, thus we go again into simplification. This thus causes an
457+
* infinite loop (and eventually a {@link StackOverflowError}. This means that
458+
* we cannot find a simplified copy Op <b>unless a direct match can be
459+
* found</b>, at which point we might as well just use the direct match.
460+
* <p>
461+
* Adaptation is similarly forbidden, as to convert most Op types to
462+
* {@link Arity1} you would need an identical copy Op.
463+
*
464+
* @param copyType - the {@link Type} that we need to be able to copy
465+
* @param hints
466+
* @return an {@code Op} able to copy data between {@link Object}s of
467+
* {@link Type} {@code copyType}
468+
* @throws OpMatchingException
469+
*/
451470
private Computers.Arity1<?, ?> simplifierCopyOp(Type copyType, Hints hints) throws OpMatchingException{
452471
Type copierType = Types.parameterize(Computers.Arity1.class, new Type[] {copyType, copyType});
453472
OpRef copierRef = inferOpRef(copierType, "copy", new HashMap<>());

0 commit comments

Comments
 (0)