Improve letrec-values type-checking

Split into two passes in order to be able to find
more cases where the RHS doesn't refer to the bindings
in the letrec.

Closes PR 13124
Move TR's Tarjan's algorithm to a separate file

Also generalize so that it can be used in other
parts of the codebase.
Use Tarjan's algorithm for typechecking letrecs

This allows us to type-check non-recursive sequences of
letrec-values clauses in the right order. In other words,
we will type-check the clauses in reverse topological
order (the reverse of the dependency order).

Clauses that are recursive go through the usual
type-checking process, injecting Undefined where necessary.