New semantic analyzer: don't add submodules to symbol tables (#7005)
Previously we added each submodule implicitly to the the symbol table of
the parent package. This PR removes this and instead we look up names from
the modules dictionary if they aren't found in the symbol table. The change
only affects the new semantic analyzer.
This provides a foundation that should make #6828 much easier to address. It
also arguably cleans up the code.
Also refactor some related code to avoid duplication.
This isn't a pure refactor since some error messages are slightly different.