compiler/file_util.m:
Define standard routines for reporting that we couldn't open a file
for either input or output. Rename the one other predicate in this file
that the compiler used for that purpose, so that its call sites
can be redirected to use one of the routines intended for this purpose.
Give these routines the ability to standardize path names (by removing
"./" prefixes from relative path names, and removing all directory names
from adsolute path names) if a new option is given.
compiler/options.m:
Add that (developer-only) option.
compiler/compile_target_code.m:
compiler/copy_util.m:
compiler/export.m:
compiler/llds_out_file.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_make_hlds.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/module_cmds.m:
compiler/opt_deps_spec.m:
compiler/output_imports_graph.m:
compiler/passes_aux.m:
compiler/system_cmds.m:
compiler/write_deps_file.m:
compiler/xml_documentation.m:
Replace all call sites to the file_util.m predicates modified
by this diff. In many cases, it replaces duplicate copies of the
same code with a call. In some cases, redirect the error message
to the progress stream, where it belongs.
tests/invalid/Mercury.options:
tests/invalid/foreign_include_file_missing.err_exp3:
Compile the foreign_include_file_missing test case with the new option,
and add the expected output in C# grades, which (thanks to the option)
no longer includes the pathname of the test directory.
tests/invalid/foreign_include_file_missing.m:
Record what the new .err_exp3 file is for.
tests/warnings/help_text.err_exp:
Expect the new option.
util/mkinit.c:
Put the central list of the places that create .init files here.
compiler/compile_target_code.m:
scripts/c2init.in:
Point to util/mkinit.c as the repository of that central list.
Make some predicate names more descriptive.
util/mkinit_common.h:
Replace /* */ comments with // comments.
There are currently two separate predicates used for invoking the C# compiler.
One is in link_target_code and is used to create executables and libraries
in the C# grade. The other is compile_target_code and was previously used
by the old .NET backend to compile additional C# source files. It is currently
plugged into the code that compiles the source files used for fact tables, but
as they are not supported by the C# backed, it has never been used in practice
for this purpose.
Delete the code for invoking the C# compiler in compile_target_code, since it
will have no users after this diff and is almost certainly affected by bitrot
at this point.
compiler/compile_target_code.m:
Delete the compile_csharp_file/8 predicate. It is unused.
compiler/make.module_target.m:
Abort if we are requested to build a Java or C# foreign code file.
The only thing that currently makes such requests is compilation of
fact tables and neither the Java or C# backend supports those.
Add an explanation of an issue in an XXX.
compiler/link_target_code.m:
Add an XXX about the MS C# compiler that needs to be investigated.
runtime/mercury_grade.h:
Rename the grade modifier, and the C macro that represents it.
compiler/options.m:
Rename the --c-debug-grade option to --target-debug-grade.
compiler/compute_grade.m:
Rename the grade modifier, and the option that represents it.
Restrict the .target_debut grade modifier to MLDS grades.
compiler/handle_options.m:
Implement --target-debug-grade by having it imply --target-debug.
compiler/compile_target_code.m:
compiler/link_target_code.m:
Pay attention to either --target-debug-grade (for purposes related
to the grade itself) and to --target-debug (for all other purposes).
scripts/canonical_grade.in:
scripts/canonical_grade.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
Parse target_debug grade modifiers and --target-debug-grade options
instead of c_debug grade modifiers and --c-debug-grade options.
Add (normally commented-out) infrastructure to make it easier
to debug changes.
Restrict the .target_debut grade modifier to MLDS grades.
scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
Rename some variables to clarify the distinction between the
--target-debug option (which, like -g, enabled debugging of only one file)
and the --target-debug-grade option (which enables it for the whole
program).
configure.ac:
Make it easier to debug grade-related changes by recording
both autoconfigured and user-supplied grades that the rejected by
the canonical_grade script.
Conform to the changes above.
README.sanitizers:
doc/user_guide.texi:
grade_lib/grade_spec.m:
grade_lib/grade_string.m:
scripts/ml.in:
tests/warnings/help_text.err_exp:
tools/lmc.in:
tools/test_mercury:
Conform to the changes above.
scripts/Mmake.vars.in:
Add some XXXs about style.
compiler/options.m:
Move all the internal options after the misc options.
Move the developer options after the internal options.
Merge the oc_make_int options into the oc_internal category,
since the distinction is not that useful.
Move the unused options after the developer options.
Move the part_opmode_rebuild option to the oc_opmode category,
because it *should* be used as an opmode; the fact that it isn't
is a blemish of the current implementation.
Move all the optimization options in a given subcategory (as viewed
by the user) together.
compiler/compile_target_code.m:
Undo a misplaced change from 2022 dec 29.
compiler/options.m:
Consider all the options that used to be listed in the oc_buildsys section.
Keep many options as oc_buildsys, but reclassify others in option
categories that better fit their semantics. Create some new categories
for them.
To make that semantics more visible and understandable, give several
options more descriptive names,
Shorten some other names where this does not compromise understandability.
compiler/compile_target_code.m:
Rename do_make_init_obj_file to make_init_obj_file, after
- inlining the old make_init_obj_file predicate in its only caller, and
- deleting it to free up the name.
compiler/compute_grade.m:
compiler/globals.m:
compiler/handle_options.m:
compiler/link_target_code.m:
compiler/make.build.m:
compiler/make.check_up_to_date.m:
compiler/make.dependencies.m:
compiler/make.library_install.m:
compiler/make.program_target.m:
compiler/make.top_level.m:
compiler/mercury_compile_main.m:
compiler/op_mode.m:
Conform to the changes above.
compiler/color_schemes.m:
compiler/copy_util.m:
compiler/stack_alloc.m:
compiler/term_constr_initial.m:
Fix comments.
compiler/options.m:
Split the oc_link category into
- oc_link_c, oc_link_java and oc_link_csharp, for options that apply
to only one target language, and
- oc_link_c_cs and oc_link_c_cs_j for options that applyt to two or three
target languages.
Delete the long-obsolete mkinit_erl_command option.
The compile_to_shared_lib option had a misleading name, since it
did not contol compilation. Rename it to shared_lib_not_executable,
since that documents its purpose. (The external name stays, at least
for now.)
compiler/compile_target_code.m:
Give a predicate and some variables more descriptive names.
compiler/handle_options.m:
Document a possible bug.
compiler/link_target_code.m:
Factor out a piece of duplicated code.
In one place, reduce the extent of stringly typed programming.
compiler/make.program_target.m:
Replace an if-then-else with a switch.
compiler/mercury_compile_augment.m:
compiler/mercury_compile_llds_back_end.m:
Conform to the changes above.
compiler/mlds_to_java_file.m:
Improve a comment.
compiler/compile_target_code.m:
Replace the predicates that output various sets of compiler flags
with predicates that merely return them. The old predicates were
inconsistent; some printed newlines, some did not. The new ones
are also useful in the code of the rest of compile_target_code.m.
compiler/mercury_compile_main.m:
Call the new predicates. These calls fit in with the code around them
much better.
compiler/compile_target_code.m:
compiler/link_target_code.m:
Move the parts of compile_target_code.m that concern linking
to the new module link_target_code.m. Leave the parts concerned
with just compilation.
The new module link_target_code.m imports compile_target_code.m,
but not vice versa. To make this possible, get compile_target_code.m
to decide PIC vs non-PIC for executables, since that info is needed
during non-linking tasks, while making that decision for linking tasks
in link_target_code.m.
Reorder the contents of link_target_code.m to put related predicates
next to each other, and to put these groups of related predicates
into a meaningful order.
Inline a tiny predicate at its only call site. Replace a boolean argument
with a value of a bespoke type.
compiler/backend_libs.m:
compiler/notes/compiler_design.html:
Include and document the new module.
compiler/file_util.m:
Move a predicate here from compile_target_code.m. It is needed
by both compile_target_code.m and link_target_code.m, but it would
feel wrong for it to be exported by compile_target_code.m. It looks
much better for it to be exported by file_util.m.
compiler/make.program_target.m:
Conform to the changes above.
Move a predicate next to its only caller.
Add an XXX.
compiler/make.clean.m:
compiler/make.make_info.m:
compiler/make.module_target.m:
compiler/make.top_level.m:
compiler/mercury_compile_augment.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
Conform to the changes above.
compiler/compile_target_code.m:
Give the two main predicates that do linking more descriptive names.
Expand the comment on one, and add a comment on the other.
Make one of these predicates take as input a list of module names,
not a list of file names. Previously, we converted module names to
file names, passed them to this predicate, which then converted them
*back* to module names. The new code, by avoiding unneeded
transformations, also avoids the possibility of callers passing
file names that did not start out as module names, which therefore
cannot be *meaningfully* converted back to module names.
Move the globals argument of a predicate to one of its usual places,
because the reason for its being supplied late does not apply anymore.
Consistently use a single variable names to describe linked_target_types;
some of the old variable names were misleading.
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.top_level.m:
compiler/mercury_compile_augment.m:
compiler/mercury_compile_main.m:
Conform to the changes above.
This covers searches
- for static object file archives (usually .a files, since this is the default
value of the --library-extension option) when targeting C (we do this
for any Mercury library we want to link with), and
- for .init, .jar and .dll files (we do this *only* for the Mercury standard
library's top module).
The existing LEGACY search code treated .a, .jar and .dll files together,
and .init files separately from them. This diff keeps that treatment
for LEGACY searches, but changes things for PROPOSED searches, by searching
for .init, .jar and .dll files done *only* in the directory containing
the Mercury standard library.
compiler/globals.m:
Extend the ext_dirs_maps type with maps that specify the search paths
for the above four extensions.
Delete the dirs_ext type. Since recent events established the need
for different search paths for Mercury files in different circumstances,
the original point of this supertype (having a *single* map from
extensions to search paths) has been lost.
compiler/options.m:
Add options (which are not yet used) to control PROPOSED searches
for .a files.
Add an internal option for recording the location of the Mercury standard
library chosen by the user. The compiler sets this from the value of
another option, but if that option is not set, it falls back to the
directory named in an environment variable or a make variable
in an options file. The value of this option controls searches
for .init, .jar and .dll files.
compiler/handle_options.m:
Move the computation of the chosen standard library location here from
check_libgrades.m. Fix the potentionally-misleading wording of the
moved error messages.
Fill in the new fields of the ext_dirs_maps structure.
compiler/find_module.m:
Update the type representing search authorizations along the lines
described at the top of this commit message.
Implement the described PROPOSED searches for the four extensions,
while keeping their LEGACY searches the same.
compiler/file_names.m:
Update the type representing search specifications along the lines
described at the top of this commit message.
Provide auxiliary operations now needed by find_module.m.
compiler/check_libgrades.m:
Delete the code moved to handle_options.m. Simplify the rest of the module
as far as possible, given that the chosen stdlib dir is now available
in the option table, and we no longer need the env_optfile_variables
as inputs.
Ask to do PROPOSED searches for the Mercury std lib's main module
only in the chosen stdlib directory.
compiler/compile_target_code.m:
compiler/make.build.m:
compiler/make.library_install.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/mercury_compile_main.m:
Conform to the changes above.
compiler/options_file.m:
Fix indentation.
compiler/module_cmds.m:
Change the predicates that write out launcher script files to take
as input not a higher-order predicate that does the writing, but
simply the string to be written.
compiler/compile_target_code.m:
Conform to the change above.
... (mostly) in one place.
compiler/file_names.m:
Change the module_name_to_search_file_name predicate to
- take as input a specification of where the caller intends to search for
the file name returned by this predicate (the new search_which_dirs
input argument),
- use insts to check, at compile time, whether this specification
is compatible with the extension of the file (by intentionally causing
the call to have a mode error if they are not compatible),
- if they are compatible, return a "search authorization" that contains
the information in the search_which_dirs argument in a form that
should be known *only* to file_names.m (which issues the authorization)
and find_module.m (which acts on such authorizations).
To make the above possible, move the search_which_dirs type here
from find_module.m, move many insts on the ext type here from several
other modules, and add some new insts on that type.
Improve documentation.
compiler/find_module.m:
Delete the search_which_dirs type that this diff moves to file_names.m.
Add in its place the search_auth_dirs type, which represents search
authorizations. Make all predicates in this module take search
authorizations instead of search specifications as inputs.
The difference is that only the module_name_to_search_file_name
predicate in file_names.m, and a few functions in this module,
generate search authorizations that involve references to the
various options containing lists of directory names.
compiler/make.file_names.m:
Replace predicates that take a maybe_for_search argument with two
predicates each, one for not for search and one for search. This is
because the for search versions now take two extra arguments:
a search_which_dirs input argument and a search_auth_dirs output argument.
Factor out the common code from the resulting predicate pairs
where this is worth while.
Improve documentation.
compiler/make.timestamp.m:
Replace predicates that take a maybe_for_search argument with two
predicates each, one for not for search and one for search. This is
because the for search versions and the not_for_search versions
now call different predicates, and two separate predicates ends up
being less code that tests around all the calls.
Factor out the common code from the resulting predicate pairs
where this is worth while.
Delete the code that specifies the default list of directories
in which to search for files with given extensions, since it is now
in file_names.m (in a modified form).
compiler/analysis.framework.m:
Delete the inst definitions that this diff moves to file_names.m.
compiler/compile_target_code.m:
compiler/file_kind.m:
Provide more precise insts for the outputs of some predicates.
This is because some of their callers need those insts to satisfy
the new requirements of module_name_to_search_file_name.
compiler/make.top_level.m:
Add a note.
compiler/read_modules.m:
Conform to the changes above. Split the handling of source files
(which do not require search) from the handling of .int* and .*opt files
(which do).
compiler/analysis.file.m:
compiler/check_libgrades.m:
compiler/make.check_up_to_date.m:
compiler/make.get_module_dep_info.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_front_end.m:
compiler/mmc_analysis.m:
compiler/options_file.m:
compiler/write_deps_file.m:
Conform to the changes above.
The aim is to move all to this one place almost all the code that will
have to be updated to handle searches in the PROPOSED installed library
structure, first alongside and later in place of, searches in the LEGACY
structure. (Some code in handle_options.m, options.m and check_libgrades.m
will need to be updated as well.)
compiler/find_module.m:
Change the predicates of this module to take as input not a list of
directories to be searched, but a *specification* of how that list
should be computed. (Eventually, it should be possible to derive
this specification from the extension of the file name in most or
possibly even all cases, but that is future work.)
compiler/options.m:
Fix a misleading internal option name. (The user-facing name is
not misleading.)
compiler/maybe_error.m:
Add another purpose-specific synonym for bool, for use in changes below.
compiler/check_libgrades.m:
compiler/compile_target_code.m:
compiler/generate_dep_d_files.m:
compiler/handle_options.m:
compiler/make.check_up_to_date.m:
compiler/make.get_module_dep_info.m:
compiler/make.program_target.m:
compiler/make.timestamp.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_main.m:
compiler/mmc_analysis.m:
compiler/options_file.m:
compiler/read_modules.m:
compiler/source_file_map.m:
compiler/write_deps_file.m:
Instead of computing lists of directories to pass to the predicates
of find_module.m, pass a specification.
Add "XXX SEARCH_ERROR" markers to code that should include more info
in error messages about failed searches.
compiler/globals.m:
Add to the globals structure a field that holds the pathname component
identifying the grade (in the names of grade-specific files).
We used to compute it every time we needed it, using a relatively slow
algorithm; we now compute it just once, when the globals structure
is created by the globals_init predicate.
Put the main read-only fields of the globals into a substructure,
to make any updates of the writeable fields faster by reducing the size
of the globals structure itself,
Change the order of the arguments of globals_init, and the order of the
getter and setter predicates of the globals structure, to match the
new order of the fields in the globals structure.
Don't mix other predicates in with the getter and setter predicates.
compiler/compute_grade.m:
Delete the predicate that used to compute this pathname component
after effectively inlining its one-line definition in the globals_init
predicate.
compiler/check_libgrades.m:
compiler/compile_target_code.m:
compiler/file_names.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/implementation_defined_literals.m:
compiler/make.clean.m:
compiler/make.library_install.m:
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
Conform to the changes above.
compiler/make.library_install.m:
Add code to install .module_dep .opt and .analysis files (for all grades),
.init, .a, .so and maybe .mih files (for C grades), .jar files (for Java
grades) and .dll files (for C# grades) to the PROPOSED install directory
structure. The new code is run only if --experiment4 is specified.
Factor out some common code.
compiler/file_names.m:
Rename the internal representation of .dll files to include "cil"
in the name, and reclassify it as a grade-specific but not
architecture-specific file type.
Export some procedures now needed by make.library_install.m.
compiler/compile_target_code.m:
compiler/generate_mmakefile_fragments.m:
Conform to the changes in file_names.m.
compiler/file_names.m:
Change the predicates that return file names to return as their result
both the current, legacy filename, and the proposed filename.
For ext_cur extensions, the legacy and the proposed filenames
will always be identical. Add a predicate for these that returns
just this one filename.
compiler/comp_unit_interface.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/generate_dep_d_files.m:
compiler/generate_mmakefile_fragments.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.check_up_to_date.m:
compiler/make.clean.m:
compiler/make.dependencies.m:
compiler/make.file_names.m:
compiler/make.get_module_dep_info.m:
compiler/make.library_install.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.timestamp.m:
compiler/make.track_flags.m:
compiler/make.util.m:
compiler/make_module_file_names.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.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/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Conform to the changes above. In most places, this means ignoring
the proposed filename for now, but marking such places with "XXX LEGACY",
to make them easier to find when we *do* start to make use of the proposed
file names (first alongside the legacy names, and then without them).
In some places, make variable names more descriptive.
library/set.m:
Add utility predicate for use by a diff to one of the modules above.
NEWS.md:
Announce the new library predicate.
compiler/file_names.m
Separate "gs" (grade-specific but not architecture-specific) extensions
from "gas" (both grade- and architecture-specific) extensions.
The intent is to eventually install them into different directories,
but that is for future diffs.
Change the functions that return directory paths into predicates.
A future change will update them to return *two* directory paths:
one for the LEGACY directory structure, and one for the PROPOSED
structure.
compiler/compile_target_code.m
compiler/generate_mmakefile_fragments.m
compiler/make.clean.m
compiler/make.file_names.m
compiler/make.library_install.m
compiler/make.module_target.m
compiler/make.program_target.m
compiler/mercury_compile_llds_back_end.m
compiler/mercury_compile_main.m
compiler/module_cmds.m
Conform to the changes above.
compiler/make.library_install.m:
The main purpose of this change is to make it easier to understand
what files (meaning files with what extensions) are installed in what
target directories.
Install directories, when their initial structure was designed,
(which was designed *before* we added the --use-grade-subdirs option),
had one of two forms. For e.g. files with the .int3 extension,
one form had those files stored in two directories:
Prefix/lib/mercury/ints
Prefix/lib/mercury/ints/Mercury/int3s
while the other form had them stored in one directory
Prefix/lib/mercury/ints
with Prefix/lib/mercury/ints/Mercury/int3s being a symlink to "..", with
the directory at the end of the symlink being Prefix/lib/mercury/ints.
From the point of view of code that looked things up in the installed
program, these are equivalent, but from the point of view of the code
doing the install, they are definitely NOT equivalent.
The original code used flags named LinkSucceededN to record the
distinction. This was bad for two major and one minor reasons.
First, while such names accurately reflect the *origin* of the value
(the code that sets it tries to construct the second form, and falls
back to the first *only* if the use of symlinks is disabled
or the attempt to create a symlink fails), but the code that *uses*
those values cares only *about its implications about where it
needs to install each file*, and not about its *origin*.
The LinkSucceededN names are singularly uninformative in this respect.
Second, the code of this module effectively has two cleanly separated
halves: the first half creates directories and (if allowed) symlinks
to directories, while the second half installs files in those directories.
The LinkSucceeded argument was effectively the *only* communication
between the two halves. This meant that the two halves each have to
construct for themselves the names of all the install directories,
with any discrepancy between the two halves in this respect resulting
in an attempt to install files in nonexistent directories.
This is a double maintenance burden. (The fact that the directory path
names themselves consist of repeated elements that make them quite easily
confusable does not help matters).
Third, the code that constructed the symlinks for the different extensions
constructed a single final LinkSucceeded value that was "succeeded"
*only* if we could construct all the symlinks. If the symlink for one
extension could not be constructed, forcing the install of the files
using that extension to use the first form above, then the installs
for all the other extensions would also be done assuming that they
used the first form. This would mean that they would install the same file
in e.g. both Prefix/lib/mercury/ints/Mercury/int3s and
Prefix/lib/mercury/ints, and since the former would be a symlink
to the latter, the second install would duplicate the effect of the first.
To fix all three problems, this diff replaces the LinkSucceededN flags
with a map from extensions (actually, from the subdir name we use
to store files with those extensions) to a structure that specifies
- whether the files with that extension should be installed into
one directory (appropriate for the second form above) or
two directories (appropriate for the first form above), and
- the full path name(s) of that directory or those directories.
To make that map possible, we turn e.g. Prefix/lib/mercury/ints into
Prefix/lib/mercury/ints/Mercury/int3s by adding the last two components
at the same time. (The old code added them in two separate places.)
We actually use two such maps, one for the main part of install_library,
the part that install (mostly) non-grade-specific files into
non-grade-specific directories, and one for install_library_grade_files,
which installs grade-specific files (though not always into
grade-specific directories).
Add XXXs about deviations about expected behavior, such as the two
in the above paragraph. If they are intended behavior, then their
rationale should be documented; if they are not, then they
should be fixed.
---------------------------------------------------------
Other, less important changes follow.
When an filesystem operation fails, print an error message immediately
that *identifies the directory involved*. The old error reporting code
did not do that.
Instead of collecting lists of *actual* "did it succeed or not" flags
and then later AND-ind them together, thread that flag through
the relevant code using state variables. This yields simpler code.
Inline the one call to foldl2_install_library_grades, for two reasons.
First, it simplifies the interface of make.library_install.m by allowing
us to stop exporting a predicate, and second, it allows that predicate
argument order to match the argument order of related predicates.
Inline all calls to linked_target_file_name, because they identified
the files being installed using a linked_target_type. All other files
being installed are identified using their extensions.
compiler/make.build.m:
Delete foldl2_install_library_grades, since the only call to it,
which was make.library_install.m, has been inlined.
compiler/compile_target_code.m:
Delete linked_target_file_name, after all calls to it have been
inlined in make.library_install.m.
compiler/file_util.m:
Stop putting unnecessary spaces in shell commands.
compiler/copy_util.m:
Improve some error messages.
compiler/compile_target_code.m:
Get two predicates in this module to return error_specs instead of
printing them to stderr, since their callers know on what stream
these messages *should* be printed.
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile_main.m:
Conform to the changes in compile_target_code.m.
Function trailing with tagged trail entries does not work unless the functions
are aligned on word boundaries. In trailing grades with GCC, we have long
passed an option (-falign-functions) to force this to happen. Do the same for
clang, which supports the same option. This fixes the failure of function
trailing tests on Apple Silicon based machines.
(This does not appear an issue on Intel-based Macs, although passing
-falign-functions option there is harmless.)
scripts/mgnuc.in:
compiler/compile_target_code.m:
Tell clang to align functions on word boundaries in trailing grades.
compiler/error_spec.m:
Replace simplest_spec with spec, and simplest_no_context_spec with
no_ctxt_spec. These are now the most frequently used function symbols
to create error specs, so their name should not make them out to be
the exception.
Replace simplest_msg with msg, and simplest_no_context_msg with
no_ctxt_msg for the same reason.
Abbreviate some of the long phase names.
compiler/*.m:
Conform to the changes above. Most of these changes were done by a script,
with minor manual tidying up, which consisted mostly of fitting code
constructing error specs onto fewer lines than before.
... and other minor fixes.
library/*.m:
library/LIB_FLAGS.in:
compiler/*.m:
mdbcomp/*.m:
Fix and update copyright notices.
Fix spelling.
Delete trailing whitespace.
Move the code used for invoking commands via the shell out of the module_cmds
module and into its own module. In doing so, this moves it from the parse_tree
package into the libs package.
compiler/module_cmds.m:
Shift the code for invoking commands via the shell from here ...
compiler/system_cmds.m:
... to here.
compiler/libs.m:
Include the system_cmds module.
compiler/compile_target_code.m:
compiler/fact_table.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
Conform to the above change.
compiler/notes/compiler_design.m:
Document the new module.
... instead of ErrorStream, in more places.
compiler/compile_target_code.m:
compiler/file_util.m:
compiler/handle_options.m:
compiler/mercury_compile_front_end.m:
As above.
compiler/make.program_target.m:
compiler/mercury_compile_main.m:
compiler/xml_documentation.m:
Don't pass ErrorStream to predicates that don't need it anymore.
... and almost all calls to get_error_output_stream. Replace them
with ProgressStreams and ErrorStreams passed down from higher in the
call tree.
Use ProgressStreams, not ErrorStreams, to write out error messages about
any failures of filesystem operations. These are not appropriate to put
into a module's .err file, since they are not about an error in the
Mercury code of the module.
compiler/globals.m:
Delete the predicates that return progress streams, and the mutable
behind them.
compiler/passes_aux.m:
Delete the predicates that return progress streams. Delete the
versions of the progress-message-writing predicates that didn't get
the progress stream from their caller.
compiler/*.m:
Pass around ProgressStreams and/or ErrorStreams explicitly,
as mentioned at the top of log message.
In a few places, don't write out error_specs to ErrorStream,
returning it to be printed by our caller, or its caller etc instead.
In some of those places, this allowed the deletion an existing
ErrorStream argument.
Given that get_{progress,error}_output_stream took a ModuleName input,
deleting some of the calls to those predicates left ModuleName unused.
Delete such unused ModuleNames.
In a few places, change argument orders to conform to our usual
programming style.
Fix too-long lines.
scripts/Mmake.rules:
Add a rule for the pattern target %.depend_ints which invokes mmc
with --generate-dependencies-ints, just as %.depend invokes mmc
with --generate-dependencies.
Document the reason why this addition requires yet more code duplication.
scripts/Mmake.vars.in:
Add the make variable definitions needed by the new code in Mmake.rules.
compiler/mercury_compile_main.m:
Make it practical to use --generate-dependencies-ints in a multi-directory
project like the Mercury implementation, in which some directories
may use --generate-dependencies-ints as the target of "mmake depend",
while other directories, which come earlier in the build process,
still do "mmake depend" using just --generate-dependencies.
In such cases, mmc --generate-dependencies-ints in the later directory
may fail to generate .int0, .int or .int2 files simply because
the .int3 file of a module they import (from an earlier directory
in which "mmake depend" uses just --generate-dependencies) hasn't been
made yet. (This is what would happen if someone executed "mmake depend"
at the top level in a freshly checked out workspace.)
The practical fix is to simply report this fix using an error message
that still allows the compiler to exit with an exit status that
indicates success.
Most of the rest of this diff is there to make this possible.
compiler/error_spec.m:
Add a new phase, phase_find_files, that specifically indicates
that we couldn't read a file because we couldn't find it.
Give it a string argument naming the file, to allow mercury_compile_main.m
to replace several error_specs that each report not being able to find
one file with a single error_spec that reports not being able to find
many files.
Add a utility function for use by mercury_compile_main.m to construct
that error message.
Add another new phase, phase_make_int, that indicates a problem
we discovered in the code of a Mercury source file while trying
to decide what should got into one of the that module's interface files.
compiler/parse_error.m:
Here also use separate function symbols in the fatal_module_read_error
type for the situations "couldn't find a file" and "couldn't read a file".
Update the predicates constructing error_specs to handle this distinction
(which the callers make using the new function symbol in the above type).
compiler/compile_target_code.m:
compiler/error_util.m:
compiler/grab_modules.m:
compiler/options_file.m:
compiler/parse_module.m:
compiler/read_modules.m:
compiler/recompilation.check.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
compiler/options.m:
Add a way to detect the presence of this diff in an installed compiler.
compiler/compile_target_code.m:
Many predicates in this module used to throw an exception when given
some specific linked_target_types. Use insts to require their callers
to pass to them only the linked_target_types that they *can* handle.
This allows the deletion of the code throwing exceptions, since
the compiler now knows that such code would be unreachable.
In some cases, delete code that did NOT throw exceptions,
but was unreachable nevertheless, since its correctness could not
have been ever tested.
Move option lookups to just before the looked-up value is needed.
Clarify a predicate by converting it to use explicit nested switches.
Fix a rafe-ism.
compiler/file_util.m:
Delete the obsolete predicate report_error/3 which wrote to the implicit
current output stream.
Move a predicate that is used only in prog_event.m to prog_event.m.
Rename of the two open_temp_output predicates to avoid ambiguity.
compiler/prog_event.m:
Move a predicate from file_util.m to here, and give it
a more descriptive name.
compiler/compile_target_code.m:
Conform to the predicate rename above.
Previosly, there were three places in the compiler that had code to compute
the name of the directory where .class files are stored. Replace two of
these with calls to the third.
compiler/file_names.m:
Compute the three components of files, that is
- the dir names list that together specify a relative path,
- the file's base name and
- the file's extension string
in three separate predicates. Export the new predicate doing just
the first job; the functions doing the second and third jobs were
already exported.
Make the code computing the dir names list for .java and .class files
call get_java_dir_path. This replacement of the old get_class_dir_name
predicate is now the place that every part of the compiler calls
for this info.
As part of this last change, add the "jmercury" component to the path
for .java and .class files separately, since we need the path both
with and without this extension. This change allows a simplification
of the make_grade_subdir_name function.
compiler/compile_target_code.m:
Call the new get_java_dir_path predicate in file_names.m instead of
including a duplicate copy of its logic.
compiler/make.program_target.m:
Add an XXX on code that *looks like* it should either be in
file_names.m or use code in file_names.m, but which cannot be easily
updated using either approach, because its purpose is undocumented.
compiler/mercury_compile_main.m:
compiler/module_cmds.m:
Conform to the changes in file_names.m.
... with --use-grade-subdirs.
compiler/file_names.m:
Move all the executable and library extensions to the ext_cur_gs group,
which means their files get put into grade-specific directories if
--use-grade-subdirs is set.
Comment out the enums representing the .lib and .so extensions,
because they are never specified specifically as those extensions;
they are only ever referred to though the options holding
those extensions.
Put all executable files into subdirs named "bin", and all libraries
into subdirs named "lib". Rename the subdirs for several other extensions
as well, as we agreed on m-rev.
compiler/make.program_target.m:
Conform to the change above.
Delete duplicate computation of the filename of an "mmc --make" target.
Use a direct test of filenames to see whether a file needs to be
linked-or-copied to the current directory.
If the action of generating an executable does not execute cleanly,
clean up not just the full pathname version of the file, but its
current directory copy as well (in case it was the copy that
got the error, due to e.g. the filesystem being full).
compiler/write_deps_file.m:
Conform to the change above.
Delete a repeated computation.
compiler/compile_target_code.m:
Conform to the change above.
compiler/file_names.m:
Replace the current groups of extensions, which are based on the
shared purpose of the files with those extensions, with a smaller
number of groups, which are based on the algorithm we use to decide
in what (sub)directories we want to place files with those extensions.
The old distinctions based on purpose still remain in the naming
convention for the enum values within each of the new groups.
compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/fact_table.m:
compiler/file_kind.m:
compiler/generate_dep_d_files.m:
compiler/llds_out_file.m:
compiler/make.file_names.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_middle_passes.m:
compiler/mlds_to_c_file.m:
compiler/mlds_to_cs_file.m:
compiler/mlds_to_java_file.m:
compiler/mode_constraints.m:
compiler/module_cmds.m:
compiler/prog_foreign.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Conform to the changes above.
compiler/file_names.m:
Replace several groups of extensions that stood for semantically
different groups of extensions by one group, the "always in the
current directory" group. The enum type of the new type representing
the now larger group consists of the enum values from the types
representing the old, smaller groups. The old boundaries are thus
no longer expressed in types, but still remain in the naming schemes
of the enum values.
Once we have done the same for the six other groups of extensions,
with each group having its own pattern of where its extensions are put
under which circumstances, we can replace code that does multiple
modulename+extension to filename translations with code that does
one modulename+extension to DIRECTORY PATH translation, and then
constructs multiple filenames from that, repeating just the
"extension enum to extension string" part of the old translation
for each operand. We can do this because unlike the old extension
categories, the new ones will make clear which groups of extensions
are guarantee to map to the same directory path, and which have
no such guarantee.
compiler/compile_target_code.m:
compiler/export.m:
compiler/generate_dep_d_files.m:
compiler/make.build.m:
compiler/make.file_names.m:
compiler/make.module_dep_file.m:
compiler/make.program_target.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_make_hlds.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c_file.m:
compiler/write_deps_file.m:
Conform to the changes above.
compiler/globals.m:
Define a new enum type with three values, which represents the three
legal combination of the values of the use_subdir and use_grade_subdir
options.
Add a field of this type to the globals.
compiler/handle_options.m:
Set up the value of this field in the globals. This means initializing
it to a non-meaningful value when the globals is first created, and
filling it in with the final meaningful value when we finish the setup
of the global structure.
compiler/options.m:
Add a "setting_only_" to the internal names of the use_subdir and
use_grade_subdir options, to signal that their only valid use
from now on is in deciding the value of the new globals field.
(Their user-facing names remain unchanged.)
compiler/compile_target_code.m:
compiler/file_names.m:
compiler/make.program_target.m:
compiler/module_cmds.m:
compiler/write_deps_file.m:
Rewrite code that used to make decisions based on the values of
the use_subdir and use_grade_subdir options with code that makes
decisions based on the value of the new field. A field retrieval
followed by a three-way switch is simpler (and faster) than
two option lookups and one two-way switch inside another.
Consistently reorder the code so that the code of the simpler cases
come first.
Note a situation where we should be using an even simpler basis
for the decision.
compiler/file_names.m:
Up till now, every translation of a module_name+extension to a filename
returned a filename that always included the needed relative path.
But for some final products of compilation, such as executables
and libraries, after we have created the file under its fully
specified relative pathname, we also want to copy it to the
current directory.
We used to this in a roundabout way, by setting up a globals structure
that turned off the use_subdirs and use_grade_subdir options
(or, in some cases, just one of them), and redoing the
module_name+extension to filename translation using this modified globals.
This diff changes to a more direct approach: asking file_names.m
to return both the fully specified relative path of the filaname,
and just its local directory component, in *one* predicate call.
We do this by adding new versions that return this info
of those predicates whose callers need this info.
To make this possible, make the main translation predicate,
module_name_to_file_name_ext, return to its callers not
the list of directory components and the full relative path, but
the list of directory components and the local filename,
leaving it up to its callers to construct the full relative path
from them *without* precluding the possibility of returning
the local filename as well.
Move some comments to the place they apply to.
compiler/compile_target_code.m:
Rename the link_output_filename predicate to linked_target_file_name
and export it. linked_target_file_name was a predicate in make.util.m
that had a identical definition to linked_target_file_name, which
this diff deletes; by exporting the renamed predicate, we make it
available in make.util.m as well.
Provide a new version of linked_target_file_name,
linked_target_file_name_full_curdir, which also returns
both the full pathname and the local directory name
it gets from file_names.m.
Use the new facilities in file_names.m where relevant.
Factor out some common code.
compiler/make.program_target.m:
compiler/make.util.m:
Use the new facilities in file_names.m where relevant.
In make.util.m, delete the duplicate predicate definition.
compiler/module_cmds.m:
Rename the update_interface_X predicates to copy_dot_tmp_to_base_file_X,
because
- this better describes what they do, and
- some of the files they are invoked on are *not* interface files.
Add an extra parameter to copy_dot_tmp_to_base_file_report_any_error
that specifies what kind of file is being copied, and print *that*
as part of any error message.
Do a similar rename of update_interface_result type, and of its
function symbols.
Give more meaningful names to touch_interface_datestamp and
touch_datestamp as well.
compiler/analysis.file.m:
compiler/analysis.m:
compiler/compile_target_code.m:
compiler/export.m:
compiler/intermod.m:
compiler/make.module_target.m:
compiler/mercury_compile_front_end.m:
compiler/mercury_compile_main.m:
compiler/mercury_compile_middle_passes.m:
compiler/mlds_to_c_file.m:
compiler/recompilation.check.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
compiler/file_names.m:
Take ext_src out of the ext type, because this allows us to delete
the I/O state pair of arguments out of every file translation predicate
other than module_name_to_source_file_name and the ones that create
directories.
compiler/file_kind.m:
Delete the ext output argument of file_kind_to_extension, because
we can't return ext_src for fk_src anymore.
compiler/write_deps_file.m:
Delete a test for ext_src which could never succeed, because the
predicate in question is never called with ext_src.
Undo an accidental change from the diff that introduced
module_name_to_lib_file_name_create_dirs.
Conform to the changes above.
compiler/compile_target_code.m:
compiler/fact_table.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_make_hlds.m:
compiler/mlds_to_c_file.m:
compiler/mmc_analysis.m:
compiler/module_cmds.m:
compiler/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
compiler/file_names.m:
Split module_name_to_file_name into three versions.
- One corresponds to the old predicate's operation with do_not_create_dirs,
- one corresponds to the old predicate's operation with do_create_dirs, and
- one just returns the directory path, and lets the caller make those
directories if it wants to, using procedures that we now export.
Do the same for module_name_to_lib_file_name.
Do not do the same for fact_table_file_name, which has too few callers
to make it worthwhile.
The point is that the versions that do not create any dirs should NOT
need to take I/O state pairs as arguments, once we take ext_src
out of the ext type.
compiler/compile_target_code.m:
compiler/du_type_layout.m:
compiler/export.m:
compiler/fact_table.m:
compiler/generate_dep_d_files.m:
compiler/llds_out_file.m:
compiler/make.build.m:
compiler/make.module_dep_file.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.track_flags.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_make_hlds.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/read_modules.m:
compiler/recompilation.used_file.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Update calls to the affected predicates.
In some places, add XXXs about seemingly-strange choices about
what calls create directories and which don't.