Extracts it out of tools/check.rs to type_checker.rs which makes more sense because this is used across sub commands.