This allows to perform those checks for *all* foreign_procs,
not just the ones that get added to the HLDS.
compiler/add_foreign_proc.m:
Move the code that checks the bodies of foreign_procs for the
presence of type_info variables for existentially quantified
type variables here from typecheck.m and typecheck_errors.m.
Change the diagnostic's wording to match our new phraseology.
Record identifiers in a set, not a list, for faster membership tests,
since we now do even more of them.
compiler/foreign.m:
Provide a mechanism to return the identifiers not just in the
non-comment parts of foreign_procs, but the comment parts as well,
since add_foreign_proc.m now needs this functionality.
compiler/make_hlds_warn.m:
Conform to the change in foreign.m.
compiler/typecheck.m:
compiler/typecheck_errors.m:
Delete the code that was moved (in a modified form)
to add_foreign_proc.m.
compiler/ml_foreign_proc_gen.m:
Update a reference in a comment.
tests/invalid/exist_foreign_error.err_exp:
Expect the updated wording of the affected diagnostics,
and expect diagnostics for *all* the foreign_procs in the test,
regardless of which language they are for.
tests/invalid/exist_foreign_error.err_exp2:
tests/invalid/exist_foreign_error.err_exp3:
Delete these files, since the output they expect is now
in the .err_exp file.
tests/invalid/fp_dup_bug.err_exp2:
tests/invalid/fp_dup_bug.err_exp3:
tests/invalid/gh72_errors.err_exp2:
tests/invalid/gh72_errors.err_exp3:
Expect the updated wording of diagnostics affected by previous
changes (which updated the .err_exp files for C, not these for
Java and C#).
compiler/add_foreign_proc.m:
Create a single predicate, check_foreign_proc to invoke all the
other predicates that each generate one kind of diagnostic
about foreign_procs. Inline in it all the other predicates
that previously did part of its job.
Do not let the lack of a proc_id stop the invocation of any
of those predicates, except the single one that needs the proc_id
for its work.
Also, make this the only place that decides how the foreign_proc
being for an imported predicate affects what we do.
Simplify predicate argument lists as allowed by the changes above.
compiler/add_foreign_proc.m:
Use the agreed wording *consistently* in the diagnostics
generated by this module.
Also, delete a call to the test for builtins that I recently
accidentally duplicated instead of just moving.
tests/invalid/foreign_proc_dup_var.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp:
tests/invalid/fp_dup_bug.err_exp:
tests/invalid/pragma_qual_error.err_exp:
tests/warnings/foreign_singleton.err_exp:
tests/warnings/singleton_test.err_exp:
tests/warnings/warn_return.err_exp:
tests/warnings/warn_succ_ind.err_exp:
Expect the updated wording for all those diagnostics.
compiler/make_hlds_warn.m:
We have long invoked the predicate that warns about singletons
(and a few other kinds of errors) in foreign_procs
- both when we add the foreign_proc to the HLDS,
- and when we add Mercury a clause to the HLDS, and the clause
contains a call_foreign_proc goal.
However, until the inlining pass, Mercury clauses can *never* contain
a call_foreign_proc goal, so the latter code never does anything.
Delete it.
compiler/add_foreign_proc.m:
Perform several more kinds of checks on all foreign_procs,
not just on the foreign_procs that we end up adding to the HLDS.
These are
- the checks for whether the foreign_proc is for a builtin operation;
- the checks for repeated variables in the foreign_proc's argument list;
and
- the checks for purity mismatches between the foreign_proc
and the predicate/function it is for.
An unrelated change: simplify, and make much more direct, the logic
of the is_foreign_proc_for_this_backend predicate.
tests/invalid/foreign_proc_dup_var.err_exp:
tests/invalid/foreign_purity_mismatch.err_exp:
Expect error messages not just for C foreign_procs, but Java and C#
foreign_procs as well.
tests/invalid/foreign_proc_dup_var.err_exp2:
tests/invalid/foreign_proc_dup_var.err_exp3:
tests/invalid/foreign_purity_mismatch.err_exp2:
tests/invalid/foreign_purity_mismatch.err_exp3:
Delete these files, which used to hold the diagnostics for
Java and C# foreign_procs respectively.
compiler/add_foreign_proc.m:
The existing code for adding foreign_procs
- tests whether the foreign_proc is for an imported predicate,
and if so, stops with an error message,
- then tests whether the foreign_proc is for the current backend,
and if it is not, ignores the foreign_proc,
- and then both adds the foreign proc to the HLDS, and checks it
for singletons.
Reverse the order of the last two tests, so that we now test
foreign_procs for singletons *even if* they are not for the current
backend. (Though of course we do not add such foreign_procs to the HLDS.)
library/io.environment.m:
library/private_builtin.m:
library/rtti_implementation.m:
Fix the warnings for now result for non-C foreign_procs even during
bootchecks in C grades.
tests/warnings/foreign_singleton.err_exp:
Expect warnings for Java and C# foreign_procs as well as C foreign_procs.
tests/warnings/singleton_test.{m,err_exp}:
tests/warnings/warn_return.{m,err_exp}:
tests/warnings/warn_succ_ind.{m,err_exp}:
Make these test cases more readable. Delete any obsolete parts,
as well as the causes of warnings that these test cases are
not intended to test for. (The latter makes the tests' *outputs*
more readable.)
Expect warnings for Java and C# foreign_procs as well as C foreign_procs,
and expect them with the new line numbers.
tests/warnings/foreign_singleton.err_exp2:
tests/warnings/foreign_singleton.err_exp3:
tests/warnings/singleton_test.err_exp2:
tests/warnings/singleton_test.err_exp3:
tests/warnings/warn_return.err_exp2:
tests/warnings/warn_return.err_exp3:
tests/warnings/warn_succ_ind.err_exp2:
tests/warnings/warn_succ_ind.err_exp3:
Delete these Java- and C#-specific expected outputs, since the warnings
they test for are now in the corresponding .err_exp files.
compiler/add_foreign_proc.m:
Replace the ~220 line add_foreign_proc predicate with
eight smaller predicates here (and one in sym_name.m),
none of which exceed 55 lines.
mdbcomp/sym_name.m:
Add that one predicate, which will probably be useful
elsewhere as well.
Fix bad existing documentation.
compiler/make_hlds_warn.m:
When generating "did you mean" messages to add to warnings about
singleton variables, consider state variables in two separate ways.
- When figuring out what you could have meant with a singleton reference
that is a variable such as PredInfo, consider that the intended reference
*could* have been to a state variable (such as !.PredInfo).
- When figuring out what you could have meant with a singleton reference
that is a state variable reference as !.PredIfno or !:PredIfno, consider
that the intended reference *could* have been to another state variable
(such as !.PredInfo or !:PredInfo).
Stop passing around a parameter that, for some predicates, was *always*
set to the same value.
tests/invalid/undef_symbol.{m,err_exp}:
Extend this test case with code that (except for the types)
duplicates the motivating example for this change.
tests/invalid/bug278.err_exp:
tests/invalid/field_syntax_error.err_exp:
Expect the extra dym messages that we now generate.
compiler/foreign.m:
When returning the list of identifiers inside a foreign_proc's code,
ignore the contents of comments. This means that warnings about
variable names that occur in the foreign_proc's argument list
but do not occur in the foreign_proc's code cannot be shut up anymore
by mention the variable name in comments.
The "mostly" part is that typecheck.m still looks at the bodies
of foreign_procs without knowing about comments. Fixing that
will be part a future change.
NEWS.md:
Announce this breaking change.
compiler/fact_table_gen.m:
When we try to generate a foreign_proc's body for a fact table
but cannot do so due to the fact table file not being readable,
add a marker to the predicate that the fact table is for.
compiler/hlds_markers.m:
Update the documentation of the existing predicate marker
we use for this.
compiler/make_hlds_warn.m:
Do not warn about singleton variables in foreign_proc bodies
that are empty due to missing fact table files.
library/array.m:
library/io.file.m:
library/profiling_builtin.m:
library/stm_builtin.m:
library/table_builtin.m:
library/term_size_prof_builtin.m:
tests/invalid/erroneous_throw_promise.m:
tests/invalid/foreign_procs_exist_type.m:
tests/invalid/foreign_purity_mismatch.m:
tests/invalid/gh72_errors.m:
tests/invalid_purity/purity.m:
tests/valid/solv.m:
Shut up warnings about singletons in foreign_procs by adding a _ prefix
to the names of the relevant arguments, and delete the comments
that can no longer do that job.
tests/invalid/foreign_purity_mismatch.err_exp:
tests/invalid/gh72_errors.err_exp:
tests/invalid/gh72_errors.err_exp2:
tests/invalid/gh72_errors.err_exp3:
tests/invalid_purity/purity.err_exp:
Expect updated line numbers.
tests/warnings/warn_return.{m,err_exp}:
Extend this test case to test that
- we DO warn about return statements outside comments, but
- we DO NOT warn about return statements inside comments.
compiler/foreign.m:
Rename c_code_to_name_list to foreign_code_to_identifiers,
which describes its job much better. Make it take the language
of the foreign code as input, though we ignore it for now.
Also rename the predicates in its call tree accordingly.
Restructure foreign_code_to_identifiers's call tree to ensure
tail recursion in loops that may be long enough for that to matter.
compiler/make_hlds_warn.m:
Conform to the changes above.
List the top modules of the make.m package first,
and the utility and data structure modules last.
Mention the deleted backends.
Improve wording in several places.
Fix some cut-and-paste errors.
compiler/switch_detection.m:
Add conditionally-enabled code to gather statistics about
what happens when a switch candidate has disjuncts left over,
and we test whether these leftovers form a switch on another variable.
(The results show that after 99.91% of switch candidates,
there are *no* disjuncts left over.)
compiler/mercury_compile_main.m:
Invoke the predicate that writes out any statistics we gathered.
tools/switch_depth:
This new summarizes the results.
compiler/switch_candidates.m:
Some ways of transforming disjunctions into switches call for
duplicating code. Any variables local to duplicated code must be
renamed apart by quantification. We used to set a flag calling for
the requantification of the procedure body when finding a switch
candidate that calls for such code duplication. However, this is wrong:
we only need to requantify the procedure body if such a switch candidate
is *actually selected*. Fix this, mostly to clarify the code, though
the avoiding unneeded requantification is also a (minor) performance win.
compiler/switch_detection.m:
Record *with each switch candidate* whether it calls for requantifying
the procedure body if it is selected.
The compiler has had no code to set it from its default value of "yes"
to "no" since the Erlang backend was deleted in October 2020.
compiler/options.m:
Delete the option.
compiler/handle_options.m:
Delete an (incorrect) reference to the option.
compiler/switch_detection.m:
Stop paying attention to the option.
tests/warnings/help_text.err_exp:
Stop expecting documentation of the option.
If the compiler decides that a du type should use the direct-arg
representation for some of its constructors, it must include information
about that into the .opt file of the module defining the type, in the
form of `where direct_arg is' clauses, which will be used by modules
opt-importing that module and that type. That information was not being
included for du types defined in the *interface* section of a module.
Also fix a related issue that was uncovered: a word_aligned_pointer
assertion on a foreign_type definition would have no effect if there is
a no-tag du type definition for the same type constructor.
compiler/intermod.m:
compler/intermod_decide.m:
Make should_opt_export_type_defn and some_type_needs_to_be_written
succeed for `status_exported' du type definitions with direct-arg
constructors. While `status_exported' suggests those type
definitions would be redundant in .opt files, the information about
the direct-arg constructors is not redundant.
compiler/du_type_layout.m:
Add a is_word_aligned_ptr() value to the ComponentTypeMap if a
no-tag du type also has a foreign_type definition for the current
target language with a word_aligned_pointer assertion. Previously,
this was only being done for single ctor NON no-tag du types.
Add a XXX mentioning that we silently ignore word_aligned_pointer
assertions in other cases.
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/direct_arg_opt.m:
tests/hard_coded/direct_arg_opt_helper_1.m:
tests/hard_coded/direct_arg_opt_helper_1.direct_arg_opt_helper_2.m:
tests/hard_coded/direct_arg_opt.exp:
Add a test case.
compiler/hlds_goal.m:
Document that all goals inside from_ground_term_deconstruct scopes
are not just unifications, but unifications whose right hand sides
are rhs_functors.
compiler/constraint.m:
Fix a potential problem, which is that pushing a constraint into
from_ground_term_{deconstruct,other) scopes can invalidate
their invariants.
compiler/goal_refs.m:
Fix a comment.
compiler/lco.m:
Qualify a call.
compiler/modecheck_goal.m:
Fix a misleading predicate name, and typos.
compiler/try_expand.m:
Exploit the newly-documented invariant about from_ground_term_deconstruct
scopes.
Simplify the interfaces between the new modules and switch_detection.m.
compiler/scout_disjunctions.m:
New module containing the part of the old switch_detection.m
that scouts disjunctions ahead of the main pass in bulk.
compiler/find_bind_var.m:
New module containing the part of the old switch_detection.m
that scouts disjunctions as *part* of the main pass, piecemeal.
compiler/switch_candidates.m:
New module containing the part of the old switch_detection.m
that recognizes candidate switches, and chooses the best switch
if there is more than one candidate.
compiler/switch_detection.m:
Delete the moved code. Conform to the interface simplifications.
compiler/check_hlds.m:
compiler/notes/compiler_design.html:
Add and document the new modules.
compiler/cse_detection.m:
Conform to the changes above.
compiler/hlds_out_goal.m:
Add the capability to format a case as a string.
The changes to file copying in the compiler in early 2024 mean that we no
longer encounter the same performance problems these workarounds were put
in place to avoid.
compiler/Mmakefile:
library/Mmakefile:
As above.
In Unix expansion of wildcard arguments is done by the shell. On Windows,
this is not the case and programs are responsible for expanding wildcard
argument themselves. When using source file mapping, we typically used
wildcards to specify the source files to map. When native Windows Mercury
compilers are used in the Windows command prompt or PowerShell, this does
not work, which is inconvenient to say the least. (In environments like
Cygwin or MSYS2, the shell does do wildcard expansion.)
Microsoft's C runtime has an optional component that programs can
link against which will do wildcard expansion on the argument vector
before main is called. Set up builds with MSVC to link against this
component when building the Mercury compiler.
scripts/parse_ml_options.sh-subr.in:
scripts/ml.in:
Add a new option --use-msvc-setargv-extension, which causes the the
wsetargv.obj file that enables the extension to be passed the linker.
(MSVC seems rather picky about where this is positioned. A a result
we do it within the ml script where have we more control over the matter.)
compiler/Mmakefile:
Pass --use-msvc-setargv-extension to the ml script if we are using MSVC.
Unrelated: Fix the identity of a compiler in a comment.
Unrelated: Add an XXX about something that looks suspicious.
util/mkinit.c:
Add a pointer to scripts/ml.in, saying that if the Windows entry
point (currently wmain) is updated, then the script may need to
be updated.
The source file name that is used as the second argument of a .module_dep file
may be directory qualified (e.g. if we are using source file mapping to
include source files from multiple directories). On Windows, such directory
qualified source file names may use '\' as a path separator. We use the term
parser to read the contents of .module dep files and that requires '\' to be
escaped. However, the code that writes module_dep files does not currently
do the required escaping. Fix that.
compiler/make.module_dep_file.m:
Escape the source file name before writing it to a .module_dep file.