The crash that this diff fixes occurred when giving a command such as
"print Var^1" to mdb, where the first argument of Var is a direct arg.
runtime/mercury_ml_expand_body.h:
When deconstructing a term with a direct arg, return NULL
as the value of expand_info->chosen_arg_word_sized_ptr.
The crash occurred when we returned a non-null pointer,
which violated the expectations of trace/mercury_trace_vars.c
and its callers. (Not surprising, since those that function and
its callers were written long before the direct_arg optimization
was added to the system.)
runtime/mercury_deconstruct.h:
Document the rationale behind the above changes. (The contents of
mercury_ml_expand_body.h are #included in mercury_deconstruct.c.)
trace/mercury_trace_vars.c:
Add the debugging code I used to track down this issue, in disabled form.
Fix missing copyright year.
trace/mercury_trace_browse.c:
Delete obsolete comment.
Fix missing copyright years.
tests/debugger/direct_arg_test.{m,inp,exp}:
A test case for this bug.
tests/debugger/Mmakefile:
Enable the new test case.
compiler/hlds_out_type_table.m:
When dumping out the data constructors in the type table,
if a constructor has names for some of its fields,
put the name and the type of each field on different lines.
In the original test case for this bug, of which direct_arg_test.m
is an extreme simplification, pretty much every line overflows
without this.
Also, factor out some duplicated code, and replace bools with values
of a bespoke type.
configure.ac:
Require the installed compiler to support that option.
STANDARD_MCFLAGS:
Specify that option.
compiler/canonicalize_interface.m:
compiler/comp_unit_interface.m:
compiler/inst_user.m:
compiler/parse_module.m:
compiler/switch_util.m:
compiler/type_ctor_info.m:
deep_profiler/mdprof_dump.m:
library/digraph.m:
slice/mcov.m:
Delete unused equivalence types that were picked up by the option.
... in some contexts.
compiler/unused_types.m:
Implement the easy part of the above, the part that happens
*after* we collect the info about which equivalence types are used.
Document why we can report unused equivalence types only in some contexts.
compiler/prog_data_used_modules.m:
Define an extension of the used_modules type that also records
which equivalence types were expanded in the module.
Define the operations we need on this extended type.
compiler/equiv_type.m:
Invoke one of those operations to record the expansions of equivalence
types, if requested to do so.
Inline the predicate that used to do this at its only call site.
compiler/hlds_module.m:
Replace the used_module field in the module_info with a value of
the extended type that includes not just the old used_modules info,
but also the set of expanded equivalence types.
Delete a utility predicate on the old field. The last call to this
predicate was deleted on 2022 march 30.
compiler/equiv_type_parse_tree.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile_make_hlds.m:
compiler/unused_imports.m:
Conform to the changes above.
tests/warnings/warn_dead_procs.{m,err_exp}:
This test case already tests for warnings about unused du types.
Extend it to also test for unused eqv types.
library/int32.m:
Add these library operations.
NEWS.md:
Announce the new operations.
compiler/lookup_switch_util.m:
Use the checked operations added by this diff and other recent diffs
to replace unchecked casts.
Until now, the only integer type we generated dense switches
(including lookup switches) for was int itself; we did not do so
for any sized and/or unsigned integer types.
compiler/switch_util.m:
Simplify the representation of whether a switch is on an integer type.
The new version makes it impossible to make the mistake that caused
bug582 in the first place: not having a single representation for
for the switch being on *any* kind of integer type.
This fix requires solving a problem we never had to solve before:
representing information such as the min and max case values
in a way that works for every integer type, signed or unsigned,
sized or not. The solution that this diff adopts is to use int32s
to represent those limits, which implies that whatever the type
of the integer value being switched on, we will generate a dense
or a lookup switch for it only if all case values fit into an int32.
Since case values over two billion are vanishingly rare, this should be
an acceptable restriction.
Use uints instead of ints to represent counts of things.
Delete an unneeded pair of arguments.
compiler/lookup_switch_util.m:
Conform to the changes in switch_util.m. Use some of the new types
there to make arguments in arguments lists less confusable.
Provide some new utility operations.
Add XXXs where the basic operations we need seem not to exist.
compiler/dense_switch.m:
compiler/lookup_switch.m:
Use the new types in switch_util.m that can represent switches
on any integer type.
compiler/ml_lookup_switch.m:
compiler/ml_simplify_switch.m:
compiler/ml_string_switch.m:
compiler/ml_switch_gen.m:
compiler/switch_gen.m:
Conform to the changes above, and thereby gain the ability
to generate switches on integer types other than int itself.
library/int64.m:
Add a (commmented-out) declaration of an operation that could
help resolve one of the issues in new code in the modules above.
Similar operations would be needed in the modules of other
sized integer types as well.
library/library.m:
Fix a typo.
tests/hard_coded/bug582.{m,exp}:
Add a test case for this issue. Note that while we test whether
we get the expected output, there is no simple automatic way
to detect whether it was generated using a lookup table.
tests/hard_coded/Mmakefile:
Enable the new test case.
The old equiv_type.m's growth was organic, not planned. It mixed predicates
operating on different levels, and even predicates on the same level
were not always logically organized.
compiler/equiv_type_parse_tree.m:
This module contains the bulk of the old equiv_type.m, the part
concerned with processing parse tree items and their major components.
compiler/equiv_type.m:
The part of the old equiv_type.m that deals with expanding equivalences
inside basic parts of program representations.
compiler/parse_tree.m:
compiler/notes/compiler_design.html:
Include and document the new module.
compiler/decide_type_repn.m:
compiler/mercury_compile_make_hlds.m:
Conform to the changes above.
compiler/recompilation.record_uses.m:
Rename the eqv_expand_info type to item_recomp_deps to better document
its purpose (it is to record which equivalence expansions *an item
depends on*). Finish documenting the type itself.
Rename the predicates operating on values of that type accordingly,
together with the variables in their clauses.
Since the point of the type is to record info about an item,
make the main predicate that constructs values of this type
take *the id the actual item* as input. Previously, it was just
a sym_name that was part of the item id. We still need that version
in two places (where we don't know the final item id yet), but use it
only when we have to. In each case, document *why* we have to.
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/qual_info.m:
compiler/add_pragma_type_spec.m:
Conform to the changes above.
Use a consistent naming scheme for the variables of the renamed type.
In one case, stop using a "some [!StateVar]" scope that hurts
readability more than it helps.
compiler/unused_args_warn_pragma.m:
The existing code processed only the first procedure of each predicate,
skipping all the later procedures. It had a comment saying that it
warns about an unused arg only if it was unused in all modes,
but this claim was false.
Replace this old code with new code that
- gathers the set of unused args in each procedure, recording
which ones have mode "unused",
- considers all the procedures of a predicate together, and then
- generates either a single warning for the predicate as a whole,
or separate warnings for each procedure that has unused arguments.
We now generate a single warning for the predicate only if all the
procedures agree both on which arguments are unused, and on
which of those are *marked* by the mode as unused. Of course,
most of the time this will be the case simply because most predicates
have just one procedure.
Stop module qualifying predicate names in the warnings we generate,
since we do not generate warnings for imported predicates.
Color the unqualified name as the subject of the diagnostic.
When reporting unused args, list the arguments with "unused" modes
separately from the other arguments.
Simplify the interface with our caller in unused_args.m.
compiler/unused_args.m:
Conform to the simplified interface with unused_args_warn_pragma.m.
compiler/hlds_error_util.m:
Add a new version of an existing utility function.
tests/warnings/unused_args_some_modes.{m,err_exp}:
Add a test case for the new capability.
tests/warnings/Mmakefile:
Enable the new test case.
Stop mixing "VAR = VALUE" and "Var += VALUE" definitions
of make variables. Give some make variables better names.
Move some dependency definitions out of a block of rules.
tests/warnings/Mercury.options:
Enable --warn-unused-args for the new test case.
Delete some accidentally-duplicated entries.
tests/warnings/unused_args_test.err_exp:
Update the expected output.
After this, I think all modules in the check_hlds package belong there.
compiler/inst_match.m:
compiler/mode_test.m:
Move these modules from the check_hlds package to the hlds package
because most of their uses are outside the semantic analysis passes
that the check_hlds package is intended to contain.
compiler/inst_merge.m:
Move this module from the check_hlds package to the hlds package
because it is imported by only two modules, instmap.m and inst_match.m,
and after this diff, both are in the hlds package.
compiler/implementation_defined_literals.m:
Move this module from the check_hlds package to the hlds package
because it does a straightforward program transformation that
does not have anything to do with semantic analysis (though its
invocation does happen between semantic analysis passes).
compiler/notes/compiler_design.html:
Update the documentation of the goal_path.m module. (I checked the
documentation of the moved modules, which did not need updates,
and found the need for this instead.)
compiler/*.m:
Conform to the changes above. (For many modules, this deletes
their import of the check_hlds package itself.)
compiler/unused_args_analysis.m:
New module containing the parts of the old unused_args.m
that deal with the intermodule analysis framework.
compiler/unused_args_base_ops.m:
New module containing the parts of the old unused_args.m
that define and operate on the main data structure we use
to find out which variables are unused.
compiler/unused_args_optimize.m:
New module containing the parts of the old unused_args.m
that "optimize out" unused arguments.
compiler/unused_args_warn_pragma.m:
New module containing the parts of the old unused_args.m
that generate warnings about unused arguments, and that generate
unused_args pragmas for .opt files. The module contains both
because they share the same test for whether we want to ignore
any unused arguments in a predicate.
compiler/unused_args.m:
Delete the moved code.
compiler/transform_hlds.m:
compiler/notes/compiler_design.html:
Include and document the new modules.
compiler/mercury_compile_middle_passes.m:
compiler/mmc_analysis.m:
Conform to the changes above.
compiler/unused_args.m:
Rename the "usage_info" type to "required_by". Document the meaning
of its contents.
Rename the low-level predicates that operate on this data structure
accordingly. Make them fit consistently into the same pattern:
X_{is,are}_required_by_Y.
In the argument lists of these predicates, pass values of arg_var_in_proc
as a unit, instead of passing them as two separate components, one of which
was easily confusable with another argument that has the opposite role.
To make this possible *and* non-misleading, reorder arguments as needed.
In one case, replace a call to list.foldl with an explicit loop
to make the reordering possible.
Give the high-level predicates that operate on this data structure
more descriptive names as well. Document the logic behind the fixpoint
iteration.
compiler/unused_args.m:
Replace "fixup_x" naming scheme with "delete_unused_args_in_x".
Fix some misleading comments.
Add some comments on not-chosen alternative approaches.
Move a utility predicate to the end of the module,
and give it a simpler interface.
compiler/higher_order.specialize_in_module.m:
Document the meaning of a field.
compiler/add_pragma_type_spec.m:
compiler/hlds_module.m:
Change the code filling and using that field to avoid misleading
variable and predicate names. Add some extra documentation
where that can help.
compiler/add_pragma_decl.m:
compiler/add_pragma_gen.m:
compiler/add_pragma_impl.m:
These three new modules add declarative pragmas, implementation pragmas,
and compiler-generated pragmas to the HLDS respectively.
compiler/add_pragma_util.m:
This new module contains the parts of the old add_pragma.m
that are needed by more than one of the three modules above.
compiler/add_pragma.m:
Delete this module.
compiler/notes/compiler_design.html:
Update the relevant documentation.
compiler/add_pragma_tabling.m:
Use standard length section dividers.
compiler/make_hlds.m:
Include the new modules.
compiler/make_hlds_passes.m:
Import the new modules.
... out of add_pragma_type_spec.m.
compiler/add_pragma_type_spec.m:
compiler/add_pragma_type_spec_constr.m:
As above.
compiler/add_pragma.m:
Import the new module.
compiler/make_hlds.m:
Include the new module.
compiler/notes/compiler_design.html:
Document the new module.
I seem to have been broken it on Aug 18 with the move to associate
a option with every severity_informational spec. The code added then
treated all these options as bool options, but one is not.
compiler/error_util.m:
Allow a severity_informational spec to depend on an accumulating
option, which --show-pred-movability is.
As far as I can see, it is the only non-bool option used
in such messages, but since we don't have a database of
options named in severity_informational specs, I can't be sure.
compiler/hlds_call_tree.m:
Avoid printing a sentence when its subject is moot.
tests/valid/show_movability.m:
New test case to test the --show-pred-movability option.
tests/valid/Mercury.options:
Specify the option for the new test case.
compiler/unused_args.m:
Make the new version of a test succeeds, where the old version
*looked like* it failed, but did not.
compiler/lambda.m:
Fix misleading module comment.
compiler/build_eqv_maps.m:
compiler/equiv_type.m:
As above.
compiler/parse_tree.m:
compiler/notes/compiler_design.html:
Include and document the new module.
compiler/decide_type_repn.m:
compiler/equiv_type_hlds.m:
compiler/make_hlds_passes.m:
compiler/mercury_compile_make_hlds.m:
compiler/qual_info.m:
Conform to the changes above.