Fix a performance issue with -fprint-expanded-synonyms
The type synonym expander was doing redundant work by looking at same
types again and again. This patch fixes the loop code when both of the
types can be expanded, to do O(min(n, m)) comparisons and O(n + m)
expansions, where n is expansions of the first type and m is
expansions of the second type.
Reported by sjcjoosten in T10547.
Added a regression test that was taking several minutes to type check
before this patch.
Reviewers: bgamari, simonpj, austin, ezyang
Reviewed By: bgamari, simonpj, austin, ezyang
Subscribers: simonpj, thomie
Differential Revision: https://phabricator.haskell.org/D2198
GHC Trac Issues: Trac #10547
(cherry picked from commit e4834edf4418ace657361649365979e29ebd9daa)