Refactor: move typecheck pass into its own module in preparation for finishing it.