[m-rev.] for post-commit review: unused interface imports
Peter Wang
novalazy at gmail.com
Tue Aug 10 12:18:03 AEST 2021
On Mon, 09 Aug 2021 13:44:36 +1000 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> For review by anyone.
>
> Zoltan.
> Fix a bug in the unused import computation.
>
> compiler/unused_imports.m:
> The bug was that if a procedure is exported, then the code considered
> that any module mentioned in the type of *any* its variables was used
> in the interface, when in fact only the modules mention in the types
> of its *arguments* are used in the interface; the rest are used *only*
> in the implementation.
>
> Improve the debugging infrastructure.
>
> NEWS:
> Announce the change in the behavior of --warn-unused-imports.
>
> compiler/type_util.m:
> If a type_ctor has an unqualified sym_name, return "builtin" as its
> module name, since
>
> - after typechecking, all type_ctors will be module qualified, with
> the only exceptions being the type_ctors of builtin types; and
> - before typechecking, no type_ctors will be module qualified beyond
> whatever qualification may have been written down explicitly
> by the programmer, which makes calling the affected functions futile.
>
> diff --git a/NEWS b/NEWS
> index ac7c103b0..fc6de6e26 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -487,6 +487,10 @@ Changes to the Mercury compiler
> keep `opt1` enabled even if `opt1` is not normally enabled at optimization
> level `N`.
>
> +* Due to a bugx fix, the --warn-unused-imports is now stricter in warning
Typo: bugx
> + about modules that are imported in the interface section but are not used
> + in the interface section.
> +
> Portability improvements
> ------------------------
>
> diff --git a/compiler/type_util.m b/compiler/type_util.m
> index 22102d991..c42da43ed 100644
> --- a/compiler/type_util.m
> +++ b/compiler/type_util.m
> @@ -462,7 +462,8 @@
> %-----------------------------------------------------------------------------%
>
> type_ctor_module(type_ctor(TypeSymName, _Arity)) = ModuleName :-
> - sym_name_get_module_name_default(TypeSymName, unqualified(""), ModuleName).
> + sym_name_get_module_name_default(TypeSymName,
> + unqualified("builtin"), ModuleName).
>
> type_ctor_name(type_ctor(TypeSymName, _Arity)) =
> unqualify_name(TypeSymName).
> @@ -471,8 +472,8 @@ type_ctor_arity(type_ctor(_TypeSymName, Arity)) = Arity.
>
> type_ctor_module_name_arity(type_ctor(TypeSymName, Arity), ModuleName, Name,
> Arity) :-
> - sym_name_get_module_name_default_name(TypeSymName, unqualified(""),
> - ModuleName, Name).
> + sym_name_get_module_name_default_name(TypeSymName,
> + unqualified("builtin"), ModuleName, Name).
>
Consider adding the explanation from the log message
regarding why these return "builtin" as a comment.
The rest looks fine.
Peter
More information about the reviews
mailing list