Run dialect and imports before hoisting anything

The dialect and imports were being run after hoisted code. Now they are
run first, before type declarations.