[propagate_anchors] detect component cycles, fix infinite loop #1023
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1022
cyclical composites with infinite component depth are now correctly detected and skipped with a warning (they will probably just error out down the pipeline anyway).
We traverse the component trees in depth-first order while keeping track of the glyphs that we are currently visiting so we can detect cycles as they happen.EDIT: I now copied @cmyr's solution from googlefonts/fontc#907
We now keep track of the composites that are waiting for their components as we process the queue, as well as the length of the queue at that point, and if we encounter the same glyph twice without the queue having gotten smaller it means we aren't making any more progress, thus we have a cycle.
Also, since we currently can only resolve component refs between master layers, for now we skip processing the other layers (fontc propagate_anchors.rs similarly only does master layers, see #1017).