Commit Graph

33 Commits

Author SHA1 Message Date
Zoltan Somogyi
6bdd8b84ee Move maybe_changed to maybe_succeeded.m and rename it.
compiler/maybe_util.m:
    Move the maybe_changed type from several modules of the compiler
    to maybe_succeeded.m, and rename it to maybe_util.m.

compiler/libs.m:
compiler/notes/compiler_design.html:
    Implement and document the rename.

compiler/common.m:
compiler/compile_target_code.m:
compiler/decide_type_repn.m:
compiler/det_analysis.m:
compiler/det_util.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/file_util.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.top_level.m:
compiler/make.track_flags.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_c_type.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/module_cmds.m:
compiler/parse_tree_out.m:
compiler/process_util.m:
compiler/recompilation.version.m:
compiler/write_module_interface_files.m:
    Conform to the changes above.
2023-04-21 17:24:30 +10:00
Zoltan Somogyi
733fb81703 Fix a parallel->sequential performance regression.
compiler/make.program_target.m:
    Replace two sequential folds with potentially parallel folds.

compiler/make.build.m:
    Fix the fold arity in the name of the parallel fold predicate.
2022-12-02 20:18:19 +11:00
Zoltan Somogyi
5a0387e030 Move foldl3_* predicates out of make.build.m.
compiler/make.track_flags.m:
    Move foldl3_maybe_stop_at_error_sn here, since it is only used here,
    along with a copy of foldl3_maybe_stop_at_error_loop, then

    - inline it at its only call site, and
    - delete the now-unused predicate.

    Simplify the local copy of foldl3_maybe_stop_at_error_loop
    by specializing it to its only set of top level arguments,
    and rename it after its now-singular purpose.

compiler/make.dependencies.m:
    Move foldl3_maybe_stop_at_error_{mi,fi} here, together with
    foldl3_maybe_stop_at_error_loop, and the type and inst it uses,
    since they are only called from here. There are not any changes
    in the code moved here (yet).

compiler/make.build.m:
    Delete the moved code.
2022-12-01 16:12:00 +11:00
Zoltan Somogyi
4a8058059e Specialize some folds for their operations.
compiler/make.build.m:
    Replace foldl2_maybe_stop_at_error_{df,str,tt} with
    foldl2_make_module_targets, foldl2_install_library_grades and
    foldl2_make_top_targets respectively. Each of the new predicates
    now knows

    - the operation being folded over the given list,
    - the type of the elements in the list it folds over,
    - the types of the two accumulators,

    The first is also expressed in the new predicate name, while the
    second and third of these are expressed in its type signature.

    Another change in each signature is the replacement of the higher order
    argument specifying the operation with the its optional arguments, if any.

    The loop predicates that do the work in each case are unchanged,
    at least for now.

    Replace foldl2_maybe_stop_at_error_maybe_parallel_df with
    foldl_make_module_targets_maybe_parallel, making the same changes as above.

    Delete foldl2_maybe_stop_at_error_{mi,fi} and
    foldl2_maybe_stop_at_error_maybe_parallel_mi, since they turned out
    to be unused. (Their foldl3 versions do look to be needed.)

compiler/make.dependencies.m:
    Conform to the changes above.

    Give some predicates more expressive names.

compiler/make.module_target.m:
    Replace two predicates make_module_target and
    make_module_target_extra_options, with only the latter taking
    a list of extra options, with just one predicate,
    named make_module_target but taking a list of extra options.
    This allows foldl2_make_module_targets to work the same whether or not
    the list of extra options is empty.

    Conform to the changes above.

compiler/make.program_target.m:
    Conform to the changes above, including by exporting the predicate
    install_library_grade predicate for foldl2_install_library_grades.

compiler/make.top_level.m:
    Conform to the changes above, including by exporting the predicate
    make_target predicate for foldl2_make_top_targets. Rename this
    predicate to make_top_target to help differentiate it from
    make_module_target.
2022-12-01 14:06:24 +11:00
Zoltan Somogyi
e46a560c91 Monomorphize some polymorphic predicates.
compiler/make.build.m:
    Replace three polymorphic predicates that fold over lists of values
    of type T with two, three and five monomorphic predicates respectively.
    The monomorphic versions fold over lists of elements of specified types.
    The list of monomorphic versions needed should be useful information for
    simplifying the make package's overuse of higher order constructs.

    The replaced predicates were mostly just interfaces to the predicates
    that looped over the lists. This diff leaves those predicates alone.

compiler/make.dependencies.m:
    Make the same change to deps_set_foldl3_maybe_stop_at_error and to
    map_find_module_deps (only the first of which does a fold).
    For map_find_module_deps, also change the argument order, because
    operating on the second argument first, and on the first argument second,
    is confusing.

compiler/make.make_info.m:
    Replace a pair type, which some of the above fold operated over,
    with a bespoke type, because its structure and semantics was related
    to existing bespoke types.

compiler/make.program_target.m:
    Conform to the changes above. In two cases, replaces nested folds
    with sequences of folds, both because this is simpler, and because
    it avoids the need for an extra variant of the fold.

compiler/make.module_target.m:
compiler/make.top_level.m:
compiler/make.track_flags.m:
compiler/make.util.m:
    Conform to the changes above.
2022-12-01 07:08:38 +11:00
Zoltan Somogyi
764e19c358 Fix misleading message. 2022-11-17 22:53:40 +11:00
Zoltan Somogyi
6f82724091 Pass streams explicitly at the top levels.
compiler/mercury_compile_main.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
    Pass progress and error streams explicitly in these top modules
    of the compiler. Use "XXX STREAM" to mark places where we could switch
    from using stderr for both the progress and error streams to using
    module-specific files as the progress and/or error streams.

compiler/passes_aux.m:
    Add a "maybe_" prefix to the names of the predicates that print progress
    messages at the appropriate verbosity levels, as their printing of those
    messages is conditional.

    Provide versions of those predicates that take explicitly specified
    streams to write to, and mark the versions that write to the current
    output stream as obsolete.

    The predicate that wrote progress messages for procedures
    used to have two versions, one taking a pred_proc_id, and one taking
    a pred_id/proc_id pair. Delete the latter, because the arity difference
    that differentiated the two versions is now needed for the difference
    between supplying and not supplying an explicit stream.

compiler/file_util.m:
compiler/hlds_error_util.m:
compiler/write_error_spec.m:
    Delete several predicates that wrote to the current output stream,
    since all their callers now use the versions that specify an explicit
    output stream.

compiler/check_promise.m:
compiler/check_typeclass.m:
compiler/closure_analysis.m:
compiler/complexity.m:
compiler/cse_detection.m:
compiler/deforest.m:
compiler/delay_construct.m:
compiler/delay_partial_inst.m:
compiler/deps_map.m:
compiler/direct_arg_in_out.m:
compiler/grab_modules.m:
compiler/handle_options.m:
compiler/hhf.m:
compiler/inlining.m:
compiler/make.module_dep_file.m:
compiler/ml_proc_gen.m:
compiler/ml_top_gen.m:
compiler/mode_constraints.m:
compiler/modes.m:
compiler/polymorphism.m:
compiler/purity.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/saved_vars.m:
compiler/simplify_proc.m:
compiler/size_prof.m:
compiler/stack_opt.m:
compiler/switch_detection.m:
compiler/typecheck.m:
compiler/unique_modes.m:
compiler/unneeded_code.m:
compiler/write_module_interface_files.m:
    Get these modules to take an explicitly specified stream to which
    to write progress messages when they are invoked from mercury_compile_*.m.

    For predicates in these modules that can be invoked both directly
    by mercury_compile_*.m *and* by other modules, the latter effectively
    as a subcontractor, make them take a maybe(stream), with the intention
    being that all the other modules that use the predicate as a subcontractor
    would pass a "no". This avoids the need to pass progress streams
    down to the internals of other passes, and also avoids overwhelming
    the user invoking the compiler with unnecessary details.

    As above, and also delete a progress message that shouldn't be needed
    anymore.

    Move a test of option value compatibility from
    mercury_compile_middle_passes.m to handle_options.m, where it belongs.

compiler/float_regs.m:
    Write a debug message to the debug stream.

compiler/pd_info.m:
    Include the progress stream in the pd_info structure, because this is
    the simplest way to ensure that all parts of the partial deduction pass
    have access to it.

compiler/make.build.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
    Make the minimal changes needed to conform to the changes above.
    The rest can be done when the make package is converted to consistently
    use explicit streams.

compiler/bytecode_gen.m:
compiler/structure_reuse.direct.m:
compiler/structure_reuse.versions.m:
compiler/structure_sharing.analysis.m:
    Make the minimal changes needed to conform to the changes above.
    The rest can be done when these modules start being maintained again.

compiler/Mercury.options:
    Stop specifying --no-warn-implicit-stream-calls for mercury_compile_*.m,
    since this diff makes that unnecessary.

    Start specifying --no-warn-implicit-stream-calls for some modules that
    are not currently being actively maintained, because the addition of
    progress-reporting predicates that take explicitly specified streams
    would otherwise cause the generation of such warnings for them.
2022-11-01 11:33:41 +11:00
Zoltan Somogyi
307b1dc148 Split up error_util.m into five modules.
compiler/error_spec.m:
    This new module contains the part of the old error_util.m that defines
    the error_spec type, and some functions that can help construct pieces
    of error_specs. Most modules of the compiler that deal with errors
    will need to import only this part of the old error_util.m.

    This change also renames the format_component type to format_piece,
    which matches our long-standing naming convention for variables containing
    (lists of) values of this type.

compiler/write_error_spec.m:
    This new module contains the part of the old error_util.m that
    writes out error specs, and converts them to strings.

    This diff marks as obsolete the versions of predicates that
    write out error specs to the current output stream, without
    *explicitly* specifying the intended stream.

compiler/error_sort.m:
    This new module contains the part of the old error_util.m that
    sorts lists of error specs and error msgs.

compiler/error_type_util.m:
    This new module contains the part of the old error_util.m that
    convert types to format_pieces that generate readable output.

compiler/parse_tree.m:
compiler/notes/compiler_design.html:
    Include and document the new modules.

compiler/error_util.m:
    The code remaining in the original error_util.m consists of
    general utility predicates and functions that don't fit into
    any of the modules above.

    Delete an unneeded pair of I/O states from the argument list
    of a predicate.

compiler/file_util.m:
    Move the unable_to_open_file predicate here from error_util.m,
    since it belongs here. Mark another predicate that writes
    to the current output stream as obsolete.

compiler/hlds_error_util.m:
    Mark two predicates that wrote out error_spec to the current output
    stream as obsolete, and add versions that take an explicit output stream.

compiler/Mercury.options:
    Compile the modules that call the newly obsoleted predicates
    with --no-warn-obsolete, for the time being.

compiler/*.m:
    Conform to the changes above, mostly by updating import_module
    declarations, and renaming format_component to format_piece.
2022-10-12 20:50:16 +11:00
Zoltan Somogyi
54ee339aef Simplify the truncation of error files.
compiler/make.build.m:
    Simplify the code that copies a limited number of lines from a .err file
    to the output of mmc --make.
2022-03-15 12:21:04 +11:00
Zoltan Somogyi
25b4b67403 Carve io.file.m out of io.m.
library/io.file.m:
library/io.m:
    Move two sections of io.m, the "file handling predicates" section
    and the "handling temporary files" section to the new submodule io.file.m.

    Leave behind in io.m "forwarding predicates", predicates that do nothing
    except call the moved predicates in io.file.m, to provide backward
    compatibility. But do mark the forwarding predicates as obsolete,
    to tell people to update their (at their leisure, since the obsoleteness
    warning can be turned off).

    Also leave behind in io.m the definitions of the two types used
    by some parameters of some of the moved predicates. Document the reason
    why this is done.

library/MODULES_DOC:
    List the new module among the documented modules.

NEWS:
    Announce the changes.

browser/browse.m:
browser/interactive_query.m:
browser/listing.m:
compiler/analysis.file.m:
compiler/compile_target_code.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
compiler/parse_module.m:
compiler/passes_aux.m:
compiler/prog_event.m:
compiler/recompilation.check.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
deep_profiler/conf.m:
deep_profiler/mdprof_cgi.m:
library/dir.m:
mdbcomp/program_representation.m:
ssdb/ssdb.m:
    Call the file operation predicates directly in io.file.m, not indirectly
    through io.m.

    In two modules, add a #include of fcntl.h in C code. These modules contain
    C code that needs this #include, but until now, they got it via a copy
    in an automatically generated C header file of a foreign_decl pragma
    in io.m that contained that #include. This diff moves that foreign_decl
    to io.file.m, removing that crutch.

tests/debugger/browser_test.m:
tests/hard_coded/bit_buffer_test.m:
tests/hard_coded/bitmap_test.m:
tests/hard_coded/construct_bug.m:
tests/hard_coded/dir_fold.m:
tests/hard_coded/dir_test.m:
tests/hard_coded/read_binary_int16.m:
tests/hard_coded/read_binary_int32.m:
tests/hard_coded/read_binary_int64.m:
tests/hard_coded/read_binary_uint16.m:
tests/hard_coded/read_binary_uint32.m:
tests/hard_coded/read_binary_uint64.m:
tests/hard_coded/read_bitmap_size.m:
tests/hard_coded/remove_file.m:
tests/hard_coded/write_binary.m:
tests/hard_coded/write_binary_int8.m:
tests/hard_coded/write_binary_multibyte_int.m:
tests/hard_coded/write_binary_uint8.m:
    Call the file operation predicates directly in io.file.m, not indirectly
    through io.m.
2022-03-08 06:01:21 +11:00
Zoltan Somogyi
7cba325c94 Make options_file.m return either info or error.
compiler/options_file.m:
    Change the interface of three lookup predicates to return
    either the information they are intended to look up, or a list of
    error_specs, but not both. The old code would have made sense
    if some error_specs generated during the lookup could be warnings,
    but they are always errors.

compiler/make.build.m:
    Do not make room for warnings in make build's setup, because
    (a) the code that filled in that slot with info from options_file.m
    could never put any warnings in there, and (b) most users of that
    data structure ignored that slot anyway.

    Don't take parameters that are unneeded after this change.

compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/mercury_compile_main.m:
    Conform to the changes above.

compiler/maybe_error.m:
    Add a utility predicate.
2022-01-23 02:05:23 +11:00
Julien Fischer
42148d216e Fix compilation in C# and Java grades.
compiler/make.build.m:
    Add a missing import that is only required the above grades.

compiler/Mercury.options.m:
    Do not warn about unused imports in the above module.
2022-01-13 19:01:44 +11:00
Zoltan Somogyi
fe3994f324 Carve three modules out of make.m.
compiler/make.top_level.m:
compiler/make.track_flags.m:
compiler/make.make_info.m:
    Carve these three modules out of make.m.

    make.top_level.m contains the top level of the mmc --make algorithm.

    make.track_flags.m contains code for keeping track of which options
    were used to compile which modules.

    make.make_info.m defines the make_info structure used by all the
    submodules of make.m, as well as a few other utility types.

compiler/notes/compiler_design.html:
    Document the new modules.

compiler/make.m:
    Delete the code that has been moved to the new modules, leaving
    make.m as purely a package.

    Include make.build.m in the interface, so we can delete the forwarding
    predicate we used to have here for use by mercury_compile_main.m.

compiler/Mercury.options:
    Make make.top_level.m and make.track_flags inherit make.m's old
    -no-warn-implicit-stream-calls option.

compiler/file_names.m:
    Move a utility function about extensions here from make.m.
    This also allows the removal of an undesirable module import of make.m
    in write_deps_file.m.

compiler/make.build.m:
    Move a type here from make.m, since it is needed to allow
    mercury_compile_main.m call this module directly (i.e. not through
    a forwarding predicate in make.m).

compiler/make.dependencies.m:
compiler/make.deps_set.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/options_file.m:
compiler/write_deps_file.m:
    Conform to the changes above. This mostly means having each module make.X
    actually import the modules it uses, instead of relying on make.m
    importing them, and getting those imports via make.int0.

    In a few cases, it means having each module make.X NOT import the modules
    it does NOT use, since after the "package-ification" of make.m,
    we now get warnings about these imports being unused.
2022-01-10 12:22:42 +11:00
Zoltan Somogyi
2112988e84 Include environment vars in options_variables.
compiler/options_file.m:
    As above. This allows all lookup operations on options_variables
    to stop requiring access to the I/O state.

compiler/make.build.m:
compiler/make.m:
compiler/make.program_target.m:
    Stop passing now-unneeded I/O state pairs.

compiler/mercury_compile_main.m:
    Stop passing now-unneeded I/O state pairs.

    Do pass the complete environment variable map to the function
    that initializes options_variables.
2021-08-30 17:27:01 +10:00
Zoltan Somogyi
eaab6be179 Inline build_module_with_options_and_output_redirect.
compiler/make.build.m:

compiler/make.build.m:
    Delete build_module_with_options_and_output_redirect after inlining it
    at its only call site. It added nothing but complexity and opacity.

    Similarly inline and then delete the auxiliary predicates it used.

    Delete the types that are not needed after the above.

compiler/make.module_target.m:
    Inline build_module_with_options_and_output_redirect at its call site.
2021-08-19 16:38:03 +10:00
Zoltan Somogyi
4ed45593b6 Inline all calls to build_module_with_options.
compiler/make.build.m:
    Delete build_module_with_options after inlining it at all its call sites.
    The resulting code is easier to understand, and should be easier
    to modify.

    Transfer its documentation, suitably modified, to its replacement.

compiler/make.module_dep_file.m:
    Inline build_module_with_options at its call site.
2021-08-19 12:58:15 +10:00
Zoltan Somogyi
51c9d1be45 Inline all calls to build_with_output_redirect.
compiler/make.build.m:
    Delete build_with_output_redirect after inlining it at all its call sites.
    The resulting code is easier to understand, and crucially, it should be
    easier to modify to *avoid* redirecting the current output stream,
    with output going to explicitly specified streams instead.

compiler/make.program_target.m:
    Inline build_with_output_redirect at its call sites.
2021-08-18 23:10:16 +10:00
Zoltan Somogyi
d35abe848e Split build_with_check_for_interrupt into two.
compiler/process_util.m:
    Replace build_with_check_for_interrupt with setup_checking_for_interrupt
    and teardown_checking_for_interrupt, two new predicates whose code is
    respectively the part of build_with_check_for_interrupt before and after
    the main higher order call. This makes the code at the former call sites
    significantly easier to read, especially the ones which had higher order
    calls inside higher order calls inside higher order calls.

    Move a type that process_util.m does not need anymore to
    make.program_target.m.

compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
    Conform to the changes above.
2021-08-18 21:27:16 +10:00
Zoltan Somogyi
da7fb6c9cb Avoid overuse of higher order code.
compiler/make.build.m:
    The old predicate old build_with_module_options_args_invoked had two parts.

    - The first part tried to compute some info for a higher order call,
      and then if this succeeded, then
    - the second part just made that call.

    Move the first part into setup_for_build_with_module_options,
    a new predicate that returns a bespoke variation of the maybe_error type.
    Make it return the error_specs it generates instead of printing them out,
    to allow the caller more control over when, and to what stream,
    they are printed.

    Export setup_for_build_with_module_options.

    Delete the build_with_module_options_args predicate, since its
    only two callers (both in mercury_compile_main.m) now call
    setup_for_build_with_module_options instead.

    Avoid printing non-helpful warnings.

    Fix documentation rot.

compiler/mercury_compile_main.m:
    Rewrite both calls to build_with_module_options_args to instead

    - call setup_for_build_with_module_options, and then
    - execute the code that used to be in the closure passed to
      build_with_module_options_args.

    The advantage is two-fold:

    - we don't have to contort the closure to conform to an ill-fitting
      higher-order type, by passing dummy input args and ignoring
      unnecessary output args, and

    - all the relevant code is one place, and can be understood much more
      easily.

    One of the call sites was itself in a predicate that was passed
    a closure. Inline this predicate in its only call site, which
    allows further simplification.

compiler/make.m:
    Export a type to mercury_compile_main.m.

    Make an initialization more understandable.
2021-08-18 14:48:42 +10:00
Zoltan Somogyi
775dad0599 Move the maybe_succeeded type to maybe_succeeded.m.
compiler/maybe_succeeded.m:
    The new module.

compiler/libs.m:
    Include the new module in the libs package.

compiler/notes/compiler_design.html:
    Document the new module.

compiler/check_libgrades.m:
compiler/compile_target_code.m:
compiler/file_util.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/module_cmds.m:
compiler/process_util.m:
    Conform to the move.
2021-08-13 03:08:19 +10:00
Zoltan Somogyi
3667fe6d59 Simplify some code. 2021-08-12 16:52:39 +10:00
Zoltan Somogyi
1a29beae9e Add a mki_ prefix to make_info's fields. 2021-08-12 07:00:31 +10:00
Zoltan Somogyi
cb340cf714 Replace bools with maybe_succeeded ...
... and other bespoke types.

compiler/process_util.m:
    Define the maybe_succeeded type, and two operations on it.

compiler/make.m:
    Define the maybe_keep_going and maybe_invoked_by_mmc_make types.

    Use the new types instead of bools where applicable.

compiler/check_libgrades.m:
compiler/compile_target_code.m:
compiler/file_util.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/module_cmds.m:
    Use the new types instead of bools where applicable.

    Do not look up the value of the keep_going option in the globals
    when its value (converted to the maybe_keep_going type) is available
    in the make_info.

    Use standard terminology in variable names.
2021-08-12 06:06:39 +10:00
Zoltan Somogyi
0d7c8a7654 Specify pred or func for all pragmas.
*/*.m:
    As above.

configure.ac:
    Require the installed compiler to support this capability.
2021-06-16 15:23:58 +10:00
Zoltan Somogyi
d48cbb5d70 Use explicit streams in some more modules.
compiler/closure_analysis.m:
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
    As above.

compiler/compiler_util.m:
    Delete the old report_warning predicate, and replace it with
    a renamed report_warning_to_stream predicate.

compiler/Mercury.options:
    Don't specify --no-warn-implicit-stream-calls for the above modules.

compiler/make.build.m:
compiler/make.program_target.m:
compiler/mercury_compile_main.m:
compiler/tupling.m:
    Conform to the changes above.
2021-06-11 17:17:54 +10:00
Zoltan Somogyi
93c306916a Specify streams explicitly in more modules.
compiler/module_cmds.m:
    Require all callers to specify output streams explicitly.

compiler/compile_target_code.m:
    Require callers to specify output streams explicitly in most cases.

    In the remaining cases, add "XXX STREAM" comments to request that
    the explicit streams be passed later.

    Add XXXs where preserving old behavior results in wrong-looking code.

    Modify the signature of compile_java_files to encode the invariant that
    the list of Java files given to it may not be empty.

compiler/error_util.m:
    Provide a version of an error predicate that takes explicit streams.

compiler/make.build.m:
    Mark predicates that help redirect implicit streams as predicates
    that should not be used.

compiler/make.module_target.m:
compiler/make.program_target.m:
    Add "XXX STREAM" comments to request that the explicit streams
    be passed later.

compiler/module_qual.m:
    Provide a means to construct the debug output stream.

compiler/module_qual.collect_mq_info.m:
    Use the debug output stream where relevant.

compiler/analysis.m:
compiler/export.m:
compiler/recompilation.check.m:
compiler/source_file_map.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the changes above, mostly by passing explicit streams.

compiler/Mercury.options:
    Stop specifying --no-warn-implicit-stream-calls for the above modules
    (those that had it specified in the first place).

    Delete a long-unneeded workaround.

compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
    Specify progress and output streams explicitly when calling the modules
    above (not in other places, just yet).
2021-05-17 22:55:06 +10:00
Zoltan Somogyi
a19a5f0267 Delete the Erlang backend from the compiler.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_backend.m:
compiler/erl_call_gen.m:
compiler/erl_code_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
compiler/erlang_rtti.m:
compiler/mercury_compile_erl_back_end.m:
    Delete these modules, which together constitute the Erlang backend.

compiler/notes/compiler_design.html:
    Delete references to the deleted modules.

compiler/parse_tree_out_type_repn.m:
    Update the format we use to represent the sets of foreign_type and
    foreign_enum declarations for a type as part of its item_type_repn_info,
    now that Erlang is no longer a target language.

compiler/parse_type_repn.m:
    Accept both the updated version of the item_type_repn_info and the
    immediately previous version, since the installed compiler will
    initially generate that previous version. However, stop accepting
    an even older version that we stopped generating several months ago.

compiler/parse_pragma_foreign.m:
    When the compiler finds a reference to Erlang as a foreign language,
    add a message about support for Erlang being discontinued to the error
    message.

    Make the code parsing foreign_decls handle the term containing
    the foreign language the same way as the codes parsing foreign
    codes, procs, types and enums.

    Add a mechanism to help parse_mutable.m to do the same.

compiler/parse_mutable.m:
    When the compiler finds a reference to Erlang as a foreign language,
    print an error message about support for Erlang being discontinued.

compiler/compute_grade.m:
    When the compiler finds a reference to Erlang as a grade component,
    print an informational message about support for Erlang being discontinued.

compiler/pickle.m:
compiler/make.build.m:
    Delete Erlang foreign procs and types.

compiler/add_foreign_enum.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pred.m:
compiler/add_solver.m:
compiler/add_type.m:
compiler/check_libgrades.m:
compiler/check_parse_tree_type_defns.m:
compiler/code_gen.m:
compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/const_struct.m:
compiler/convert_parse_tree.m:
compiler/dead_proc_elim.m:
compiler/decide_type_repn.m:
compiler/deps_map.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/foreign.m:
compiler/globals.m:
compiler/granularity.m:
compiler/handle_options.m:
compiler/hlds_code_util.m:
compiler/hlds_data.m:
compiler/hlds_module.m:
compiler/inlining.m:
compiler/int_emu.m:
compiler/intermod.m:
compiler/item_util.m:
compiler/lambda.m:
compiler/lco.m:
compiler/llds_out_file.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_separate_items.m:
compiler/make_hlds_warn.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_target_util.m:
compiler/ml_top_gen.m:
compiler/mlds.m:
compiler/mlds_dump.m:
compiler/mlds_to_c_export.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_data.m:
compiler/mlds_to_cs_export.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_cs_type.m:
compiler/mlds_to_java_export.m:
compiler/mlds_to_java_file.m:
compiler/mlds_to_java_type.m:
compiler/module_imports.m:
compiler/parse_pragma_foreign.m:
compiler/parse_tree_out.m:
compiler/polymorphism.m:
compiler/pragma_c_gen.m:
compiler/prog_data.m:
compiler/prog_data_foreign.m:
compiler/prog_foreign.m:
compiler/prog_item.m:
compiler/simplify_goal_scope.m:
compiler/special_pred.m:
compiler/string_encoding.m:
compiler/top_level.m:
compiler/uint_emu.m:
compiler/write_deps_file.m:
    Remove references to Erlang as a backend or as a target language.

tests/invalid/bad_foreign_code.{m,err_exp}:
tests/invalid/bad_foreign_decl.{m,err_exp}:
tests/invalid/bad_foreign_enum.{m,err_exp}:
tests/invalid/bad_foreign_export.{m,err_exp}:
tests/invalid/bad_foreign_export_enum.{m,err_exp}:
tests/invalid/bad_foreign_import_module.{m,err_exp}:
tests/invalid/bad_foreign_proc.{m,err_exp}:
tests/invalid/bad_foreign_type.{m,err_exp}:
    Add a test for Erlang as an invalid foreign language. Expect both the
    new error message for this new error, and the updated list of now-valid
    foreign languages on all errors.
2020-10-29 13:24:49 +11:00
Zoltan Somogyi
409cbcb6a3 Unify getopt.m and getopt_io.m ...
... using an approach proposed by Peter, with an extra twist from Julien.

Instead of having two modules, getopt.m and getopt_io.m, with the former
defining predicates that do not take an I/O state pair, and the latter
defining predicates that do take an I/O state pair, put both kinds of
predicates into a single module. The versions with an I/O state pair
have an "_io" suffix added to their names for disambiguation.
Both versions are a veneer on top of a common infrastructure,
which relies on a simple type class to implement the operation
"give the contents of the file with this name". The predicate versions
with I/O state pairs have a normal implementation of this typeclass,
while the predicate versions that do not have I/O state pairs
have an implementation that always returns an error indication.

The above change just about doubles the number of exported predicates.
We already had two versions of most exported predicates that differed
in whether we returned errors in the form of a string, or in the form
of a structured representation, with names of the latter having
an "_se" suffix. Since we agreed that the structured representation
is the form we want to encourage, this diff deletes the string versions,
and deletes the "_se" suffix from the predicate names that used to have them.
(It still remains at the end of the name of a type.) This "undoubling"
should offset the effect of the doubling in the previous paragraph.

Eventually, we want to have just one module, getopt.m, containing
the updated code described above, but for now, we put the same code
into both getopt_io.m and getopt.m to prevent too big a shock to
people with existing code that uses getopt_io.m.

library/getopt.m:
library/getopt_io.m:
    Make the changes described above.

library/Mmakefile:
    Instead of building both getopt_io.m and getopt.m from getopt_template,
    build getopt.m from getopt_io.m.

tools/bootcheck:
    Delete references to getopt_template.

compiler/typecheck_errors.m:
    When a type error involves one of the getopt/getopt_io predicates
    whose interfaces are changed by this diff, tell the user about
    how these changes could have caused the error, and thus what the
    probable fix is.

compiler/handle_options.m:
browser/parse.m:
deep_profiler/mdprof_cgi.m:
deep_profiler/mdprof_create_feedback.m:
deep_profiler/mdprof_dump.m:
deep_profiler/mdprof_procrep.m:
deep_profiler/mdprof_report_feedback.m:
deep_profiler/mdprof_test.m:
profiler/mercury_profile.m:
slice/mcov.m:
slice/mdice.m:
slice/mslice.m:
slice/mtc_diff.m:
slice/mtc_union.m:
tests/hard_coded/space.m:
    Use the updated getopt interface.

compiler/compile_target_code.m:
compiler/compute_grade.m:
compiler/deforest.m:
compiler/det_report.m:
compiler/format_call.m:
compiler/globals.m:
compiler/goal_expr_to_goal.m:
compiler/make.build.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_main.m:
compiler/ml_top_gen.m:
compiler/module_cmds.m:
compiler/op_mode.m:
compiler/optimization_options.m:
compiler/options.m:
compiler/write_module_interface_files.m:
tools/make_optimization_options_middle:
tools/make_optimization_options_start:
    Replace references to getopt_io.m with references to getopt.m.

tests/invalid/getopt_io_old.{m,err_exp}:
tests/invalid/getopt_old.{m,err_exp}:
tests/invalid/getopt_old_se.{m, err_exp}:
    New test cases for the extra help

tests/invalid/Mmakefile:
    Enable the new test cases.
2020-10-09 19:30:46 +11:00
Zoltan Somogyi
c2f92d5454 Partition extensions into ".m" and "all others".
This is a first step towards a much finer grained partition.

compiler/file_names.m:
    Split the ext type into ext_src and ext_other, as mentioned above.

    Add the first predicate for checking whether a string falls into
    a given category of extensions.

    Add an XXX proposing a better solution for an old problem that does not
    actually arise in practice.

compiler/compile_target_code.m:
    Split the two-moded predicate maybe_pic_object_file_extension into
    two separate one-mode predicates, one for each old mode. The
    implementations of the two modes were already separate, because
    the two modes already did different jobs: while one went from PIC
    to an "extension", the other went from an "extension string" to PIC.
    Until now, "extension" and "extension string" were equivalent;
    after this diff, they aren't anymore.

    Delete an unused argument.

compiler/make.util.m:
    Split the two-moded predicate target_extension into
    two separate one-mode predicates, one for each old mode,
    for the same reason as maybe_pic_object_file_extension above:
    the fact that "extension" and "extension string" are now distinct.

compiler/options_file.m:
    Move debug infrastructure here from mercury_compile_main.m, to help
    debug possible problems with options files. (I had such a problem
    while writing this diff.)

    Improve how progress messages are printed.

compiler/options.m:
    Make an error message more useful.

compiler/mercury_compile_main.m:
    Add infrastructure for debugging possible problems with command lines.
    (I had such a problem while writing this diff.)

compiler/analysis.m:
    Conform to the changes above. Put the arguments of some methods
    into the same order as similar predicates in file_names.m.

compiler/find_module.m:
    Conform to the changes above. Delete an unused argument,

compiler/analysis.file.m:
compiler/du_type_layout.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.deps_set.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/prog_foreign.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/source_file_map.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
2020-08-17 23:43:15 +10:00
Zoltan Somogyi
6696c1051f Fix misleading predicate name. 2020-08-15 10:42:26 +10:00
Zoltan Somogyi
52c0919975 Make filename extensions a separate type, ...
... to allow later changes to its definition.

compiler/file_names.m:
    We used to represent filename extensions simply as strings. This meant
    all calls to the predicates in file_names.m that convert module names
    to file names with various suffixes had to go through a complicated
    sequence of tests that effectively partition the extensions into
    several classes, with all extensions in a class being treated the same
    but different classes being treated differently. And since this general
    translation process is quite convoluted (which is not helped by it
    being spread across several predicates), it is very hard to construct
    a correctness argument for it.

    It would be better to represent the different classes of extensions
    explicitly, in a du type, with each function symbol of that type
    representing all the extensions in the corresponding class (in the sense
    of the paragraph above). However, getting there in one diff would make
    that diff far too hard to test and to review. So this first diff
    starts by simply making extension a notag type.

    The above is the first step in implementing one old XXX. This diff
    fully implements another old XXX, which is to make the argument order
    of several predicates friendly to higher order code.

    Add infrastructure for profiling how often this code makes directories.

    Delete an unused type.

    Add comments outlining proposed future improvements.

compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/elds_to_erlang.m:
compiler/export.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/find_module.m:
compiler/generate_dep_d_files.m:
compiler/grab_modules.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mmc_analysis.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/module_imports.m:
compiler/parse_tree_out.m:
compiler/prog_foreign.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/recompilation.usage.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
    Conform to the change to file_names.m.

    Consistently use "Ext" for the abstract representation of extensions
    and "ExtStr" for their string representation.

    In a few places, add "XXX EXT" where the code manipulates extensions
    as strings in a way that potentially inferferes with the partition
    of extensions into classes.

    In a few places, rename predicates to avoid ambiguities. factor out
    common code, delete unneeded arguments, replace bools with bespoke types,
    and make similar minor improvements.

    In a few places, remove rafe-isms, such as the use ^elem.
2020-08-14 20:30:36 +10:00
Zoltan Somogyi
ac50b3cbd1 Do not use exceptions in options_file.m.
And add tests for how the compiler handles both valid and invalid
options files.

compiler/options_file.m:
    This diff rewrites options_file.m in a straightforward, direct style that
    returns indications of errors as error_specs rather than as exceptions.
    A recent diff started on this task; this diff finishes it.

    The new approach has several advantages.

    - The control flow is much simpler, and therefore more understandable.
      Correctness arguments for propositions such as "this code closes
      all the file streams that it opens" are now much simpler to make.

    - We now report errors using error_specs, which contain context
      information, while previously, each error was described only
      by a string, without context info.

    - Once we detect and report one error, we can continue to read the
      rest of the input. This allows a single compiler invocation to find
      and report several errors, not just the first.

    - Since we now return the gathered set of error_specs instead of printing
      them, the predicates of this file don't have to take globals structures
      as arguments, which allows our callers to avoid constructing those
      structures.

    - Deep profiling, which cannot handle exceptions, now works on
      the code of this module.

    Change over to using trace goals for debugging prints, since continuing
    to use debug_make_msg would require a globals structure.

    Add an XXX on a likely bug.

    Add a mechanism for writing out a database of variable names and values.

compiler/mercury_compile_main.m:
    Conform to the changes in options_file.m. Document where exactly
    we could avoid constructing a globals just for options_file.m.

    If the right option is given, get options_file to write out the database
    of variable names and values it has just read in, to enable the
    functionality of this module to be tested.

compiler/options.m:
doc/user_guide.texi:
    Add a new developer option, --dump-options-file, to control the above.

compiler/make.build.m:
compiler/make.m:
compiler/make.program_target.m:
    Conform to the changes in options_file.m.

compiler/file_util.m:
    Fix an error message.

tests/Mmakefile:
tools/bootcheck:
    List options_file and invalid_options_file as two new test directories.

    Fix a command in bootcheck.

tests/options_file/Mmakefile:
    Add a mechanism for testing whether options_file.m builds mapping
    from make variable names to values that we expect.

tests/Mmake.common:
    Provide a mechanism for comparing dumped options_files against
    their expected contents, for use by tests/invalid_options_file/Mmakefile.

    Fix a comment.

tests/options_file/basic_test.m:
tests/options_file/basic_test.optfile_exp:
tests/options_file/basic_test.options_file:
tests/options_file/basic_test.options_file.sub0:
tests/options_file/basic_test.options_file.sub1:
    A simple test case for exercising all the usual options_file constructs.

tests/invalid_options_file/Mmakefile:
    Add a mechanism for testing whether options_file.m generates
    the error messages we expect for various kinds of errors in options files.

tests/invalid_options_file/no_assign.{m,options_file,err_exp}:
tests/invalid_options_file/no_var.{m,options_file,err_exp}:
tests/invalid_options_file/nonexistent_file.{m,options_file,err_exp}:
tests/invalid_options_file/undefined_var.{m,options_file,err_exp}:
tests/invalid_options_file/unterminated_string.{m,options_file,err_exp}:
tests/invalid_options_file/unterminated_var.{m,options_file,err_exp}:
    Six test cases to test six different kinds of errors that can be
    detected by options_file.m.
2020-06-12 04:14:00 +10:00
Zoltan Somogyi
1fe767018b Carve make.build.m out of make.util.m.
compiler/make.build.m:
compiler/make.util.m:
    As above. Make.build.m contains the parts of the old make.util.m
    that deal with executing the actions that bring targets up to date.
    This change improves the cohesion of both modules (though make.util.m's
    still isn't great).

compiler/notes/compiler_design.html:
    Document the new module.

compiler/make.m:
    Include the new submodule.

compiler/Mercury.options:
    Insist that all submodules of make.m have definitions in the same order
    as declarations.

compiler/make.dependencies.m:
compiler/options_file.m:
    Fix the order mismatches that Mercury.options used to cover up.

compiler/mercury_compile_main.m:
    Import make.build instead of make.util.
2020-03-16 21:47:08 +11:00