(derived-mode-all-parents): Fix handling of cycles
* lisp/subr.el (derived-mode-all-parents): Fix the handling of cycles
so that it doesn't fill the cache with incorrect results.
(merge-ordered-lists): Improve docstring.
(provided-mode-derived-p): Swap the loops since `modes` is usually
shorter than `ps`.
* test/lisp/subr-tests.el (subr-tests--parent-mode): Simplify.
(subr-tests--mode-A, subr-tests--mode-B, subr-tests--mode-C): New funs.
(subt-tests--derived-mode-add-parents): New test.