RequirementMachine: Fix subtle corner case where we could insert duplicate rewrite rules
RequirementMachine: Fix subtle corner case where we could insert duplicate rewrite rules

RewriteSystem::addRule() did two things before adding the rewrite rule:

- Simplify both sides. If both sides are now equal, discard the rule.

- If the last symbol on the left hand side was a superclass or concrete type
  symbol, simplify the substitution terms in that symbol.

The problem is that the second step can produce a term which can be further
simplified, and in particular, one that is exactly equal to the left hand
side of some other rule.

To fix this, swap the order of the two steps. The only wrinkle is now we
have to check for a concrete type symbol at the end of _both_ the left hand
side and right hand side, since we don't orient the rule until we simplify
both sides.

I don't have a reduced test case for this one, but it was revealed by
compiler_crashers_2_fixed/0109-sr4737.swift after I introduced the trie.

benlangmuir/swift,apple/swift,benlangmuir/swift,rudkx/swift,xwu/swift,atrick/swift,ahoppen/swift,apple/swift,JGiola/swift,gregomni/swift,ahoppen/swift,atrick/swift,atrick/swift,glessard/swift,roambotics/swift,apple/swift,gregomni/swift,glessard/swift,benlangmuir/swift,roambotics/swift,JGiola/swift,hooman/swift,gregomni/swift,hooman/swift,hooman/swift,roambotics/swift,glessard/swift,glessard/swift,benlangmuir/swift,xwu/swift,glessard/swift,benlangmuir/swift,roambotics/swift,apple/swift,JGiola/swift,xwu/swift,gregomni/swift,rudkx/swift,xwu/swift,xwu/swift,ahoppen/swift,atrick/swift,JGiola/swift,hooman/swift,xwu/swift,gregomni/swift,hooman/swift,xwu/swift,apple/swift,atrick/swift,JGiola/swift,JGiola/swift,hooman/swift,atrick/swift,rudkx/swift,ahoppen/swift,rudkx/swift,benlangmuir/swift,rudkx/swift,roambotics/swift,apple/swift,glessard/swift,rudkx/swift,hooman/swift,gregomni/swift,ahoppen/swift,ahoppen/swift,roambotics/swift