semantic: Split type retrieval code into its own module.