Class InfiniteStreamSourceOrError


final class InfiniteStreamSourceOrError extends TypedSymbolAccess
A stream whose source the compiler can PROVE infinite may not reach a stage that waits for the end of the stream (E10050) - decision 15(a), phase 1. Before this, cat Forever() | sort compiled and ran out of memory.

A source is infinite when (NeverEndingIterationMarker holds the proofs):

  • its type is a CLOSED class (not open, not abstract) iterated directly, whose effective hasNext() always returns true - cat Forever();
  • its type is a closed class whose iterator() always returns such an iterator;
  • it is a call to a function (or method) that always returns such an iterator - cat endless().

cat a, b is infinite when ANY source is.

What waits for the end is the never-completes set, StreamStages.waitsForEnd(int) (sort, tail, join, group, split) plus the async barrier, through THE shared walk (StreamStages.walk(List, boolean, Predicate)), and then the termination: | collect and a > into anything that retains. uniq and a retaining tee are deliberately NOT refused: they stream, and a later head ends the pipeline (rule B). A head before the waiting stage bounds the stream, so cat Forever() | head 3 | sort compiles.

The verdict is written back into STREAM_SOURCE_BOUNDED (FALSE), so phase 7 routes the source as unbounded. A source phase 3 already classed unbounded (Stdin, UDP, TCPConnection) has had its stages checked there with a stricter rule; only the termination is checked here, which phase 3 never checks. Unknown and provably-finite sources are untouched.