Files
mercury/tests/invalid_submodules/missing_parent_import.err_exp
Zoltan Somogyi 8e66e5c38b Auto-repair missing parent imports when making .int* files.
If the process of making .int0/.int/.int2 files has no errors other than
missing imports of parent modules (i.e. we import module a.b.c but not a.b),
we have for a while now reported this fact when making those files, which
required programmers to fix the error before they could compile other modules
that need those interface files. However, the fix is obvious: add the missing
imports, either as ":- import_module" or ":- use_module" declarations.

Given this fact, there is no point in interrupting the programmer's workflow:
the compiler can itself add the missing declaration to the interface file
it is generating. Reporting the missing parent imports later, when the module
is compiled to the target language, still guarantees that the programmer will
fix the error, but they can do so at a time of their choosing.

compiler/check_import_accessibility.m:
    Report missing parent imports as DelayedSpecs, separately from the Specs
    for other kinds of module accessibility errors, to make the above possible.

    Report separately the set of parent modules whose imports are missing
    from the interface and implementation sections.

    Delete an unused function symbol.

compiler/grab_modules.m:
    When making the aug_make_int_unit structure from which we generate
    .int0/.int/.int2 files, automatically add the missing parent imports
    returned by check_import_accessibility.m to it. Actually, add them
    as ":- use_module" declarations, since this is the less invasive
    alternative. (In the sense that they make the "missing parent import"
    error go away, but do not interfere with the detection of *other* kinds
    of errors.)

    Also, record DelayedSpecs in a new slot in the aug_make_int_unit.

compiler/prog_parse_tree.m:
    Add this new slot.

compiler/comp_unit_interface.m:
    When making .int0/.int/.int2 files, if there is a reason why
    we cannot make them, get the DelayedSpecs from the aug_make_int_unit
    and report them together with all other error_specs, since this will
    not cause any *added* interruptions to the programmer's workflow.
    But in the *absence* of any such reason, throw the DelayedSpecs away.

compiler/module_qual.qualify_items.m:
    Conform to the change in prog_parse_tree.m.

compiler/convert_import_use.m:
    Improve style.

tests/invalid_submodules/missing_parent_import.err_exp:
tests/invalid_submodules/missing_parent_import.m:
tests/invalid_submodules/missing_parent_import_helper_1.m:
tests/invalid_submodules/missing_parent_import_helper_2.m:
    Move this test case here from tests/invalid_make_int, since
    after this diff, the compiler no longer reports missing parent imports
    when making .int files. Make the test case a bit tougher, since this is
    now possible, and update the expected output file to account for the
    errors that we never look for when making .int files.

tests/invalid_make_int/Mmakefile:
tests/invalid_submodules/Mmakefile:
    Disable the moved test case in its original directory,
2025-05-12 21:26:51 +10:00

1.5 KiB

missing_parent_import.m:028: In module `missing_parent_import': error:
missing_parent_import.m:028: the absence of an `:- import_module' or
missing_parent_import.m:028: `:- use_module' declaration for
missing_parent_import.m:028: `missing_parent_import_helper_1' prevents access
missing_parent_import.m:028: to the `:- import_module' and `:- use_module'
missing_parent_import.m:028: declarations for its child modules
missing_parent_import.m:028: `missing_parent_import_helper_1.child' and
missing_parent_import.m:028: `missing_parent_import_helper_1.child2'.
missing_parent_import.m:035: In clause for predicate `main'/2:
missing_parent_import.m:035: error: call to undefined predicate
missing_parent_import.m:035: `child.hello'/2.
missing_parent_import.m:035: (The possible parent module
missing_parent_import.m:035: `missing_parent_import_helper_1' has not been
missing_parent_import.m:035: imported.)
missing_parent_import.m:038: In clause for predicate `main'/2:
missing_parent_import.m:038: error: call to undefined predicate
missing_parent_import.m:038: `missing_parent_import_helper_2.sub.hello'/2.
missing_parent_import.m:038: (The module `missing_parent_import_helper_2.sub'
missing_parent_import.m:038: has not been imported.)