[m-rev.] diff: Delete unused imports.
Peter Wang
novalazy at gmail.com
Fri Apr 1 12:15:41 AEDT 2022
On Thu, 31 Mar 2022 11:19:38 +1100 Peter Wang <novalazy at gmail.com> wrote:
>
> I think "use" is about resolving names. If a source file mentions a name
> "foo" which refers to a "foo" in another module, that's a use.
> The other "use" I can think of is importing a module for its typeclass
> instances. An instance declaration may be used without being explicitly
> named.
I think I'm on the right track with this. Then what about this?
The compiler could maintain a table of
- explicitly imported modules
- the locations where those imports occur, for error reporting
- two flags indicating whether an imported module was used
in the interface section or the implementation section
of the current module for:
1. resolving a name mentioned in the current module
to an entity exported by the imported module; or
2. satisfying a typeclass constraint using a typeclass instance
exported by that module.
Maintaining the table at each point that a "use" can arise is
conceptually straightforward compared to the unused_imports.m analysis,
which has to work backwards.
There's one more reason a module may need to be imported: the language
requires that if a submodule is imported then all its ancestor modules
are imported as well. Bug #490 proposes to remove that requirement.
Peter
More information about the reviews
mailing list