Commit Graph

21195 Commits

Author SHA1 Message Date
Zoltan Somogyi
dadf30718d Add io.write_line_cc/4.
library/io.m:
    Add a version of io.write_line_cc that takes an explicit stream argument.

NEWS:
    Announce the addition.

browser/interactive_query.m:
    Use the new predicate.
2021-03-06 22:09:49 +11:00
Zoltan Somogyi
5d1b995302 Replace an O(n^2) algorithm with O(n).
Replace useless info in proc_label printouts with useful info.
2021-03-06 21:55:13 +11:00
Zoltan Somogyi
474035d884 Use test instead of [] in sh code. 2021-03-06 21:52:19 +11:00
Zoltan Somogyi
198b307289 Use related names for related variables.
Add an XXX about a missing file close operation.
2021-03-06 21:50:46 +11:00
Zoltan Somogyi
01f8599e90 --warn-implicit-stream-calls for all of mdbcomp. 2021-03-06 21:49:33 +11:00
Zoltan Somogyi
7c9c341e01 Use explicit streams in profiler/*.m.
profiler/call_graph.m:
profiler/generate_output.m:
profiler/mercury_profile.m:
profiler/options.m:
profiler/output.m:
profiler/process_file.m:
profiler/read.m:
profiler/snapshots.m:
    Replace implicit streams with explicit streams.

profiler/PROF_FLAGS.in:
    Specify --warn-implicit-stream-calls for all modules in this directory.
2021-03-06 21:46:37 +11:00
Zoltan Somogyi
3c07fc2121 Use explicit streams in deep_profiler/*.m.
deep_profiler/analysis_utils.m:
deep_profiler/autopar_find_best_par.m:
deep_profiler/autopar_reports.m:
deep_profiler/autopar_search_callgraph.m:
deep_profiler/autopar_search_goals.m:
deep_profiler/callgraph.m:
deep_profiler/canonical.m:
deep_profiler/cliques.m:
deep_profiler/coverage.m:
deep_profiler/dump.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:
deep_profiler/profile.m:
deep_profiler/read_profile.m:
deep_profiler/recursion_patterns.m:
deep_profiler/startup.m:
deep_profiler/var_use_analysis.m:
    Replace implicit streams with explicit streams.

    In some places, simplify some code, often using constructs such as
    string.format that either did not exist or were too expensive to use
    when the original code was written.

    Consistenly use the spelling StdErr over Stderr.

    In mdbprof_dump.m, put filename and reason-for-failing-to-open-that-file
    in the right order in an error message.

deep_profiler/DEEP_FLAGS.in:
    Turn on --warn-implicit-stream-calls for the entire deep_profiler
    directory.

mdbcomp/program_representation.m:
mdbcomp/trace_counts.m:
    Replace implicit streams with explicit streams. These are the two mdbcomp
    modules that (a) used to use implicit streams, and (2) are used by the
    deep profiler.

mdbcomp/Mercury.options:
    Turn on --warn-implicit-stream-calls for these two modules.

slice/mcov.m:
slice/mtc_union.m:
    Conform to the changes in mdbcomp.
2021-03-06 18:30:50 +11:00
Zoltan Somogyi
eeb69f14ba Use explicit streams in browser/*.m.
browser/browse.m:
browser/browser_info.m:
browser/collect_lib.m:
browser/declarative_debugger.m:
browser/declarative_oracle.m:
browser/declarative_user.m:
browser/diff.m:
browser/help.m:
browser/interactive_query.m:
browser/parse.m:
browser/util.m:
    Replace implicit streams with explicit streams.

    Shorten lines longer than 79 chars.

    In some places, simplify some code, often using constructs such as
    string.format that either did not exist or were too expensive to use
    when the original code was written.

    In some places, change predicate names that were not meaningful
    without module qualification by *including* the module qualification
    in the name (e.g. init -> browser_info_init).

    In some places, add XXXs.

    In browser_info.m, make the output stream *part* of the debugger type,
    because without this, having the debugger type belong to the stream
    typeclass does NOT make sense. (The typeclass instance for debugger
    used to always write to the current output stream, which this diff
    is replacing with the use of explicitly specified streams.)

    In browse.m, consistently put stream arguments before other arguments.

    In browse.m, when exporting Mercury predicates to C, export them
    under names with the standard ML_BROWSE_ prefix, NOT under the name
    of a *different* predicate with that prefix.

    In diff.m, eliminate an unnecessary difference between what we print
    when the difference between two terms is at the root, vs what we print
    when the difference between two terms is lower down.

    In interactive_query.m, when trying to write a program out to a file,
    do NOT write the program to the current output stream if we cannot open
    the file, since that would accomplish nothing useful.

    Also in interactive_query.m, cleanup .dylib instead of .so on MacOS.

    In util.m, delete some unused predicates.

    In collect_lib.m, document why some code is not worth updating.

    In declarative_oracle.m, rename predicates with previously-ambiguous
    names.

browser/MDBFLAGS.in:
    Specify --warn-implicit-stream-calls for all Mercury modules
    in the browser directory from now.

trace/mercury_trace_browse.c:
trace/mercury_trace_cmd_browsing.c:
ssdb/ssdb.m:
    Conform to the changes in browser/*.m.

tests/debugger/queens.{exp,exp2}:
    Expect the extra output from browser/diff.m.
2021-03-05 22:54:28 +11:00
Zoltan Somogyi
0c77df1735 Print per proc code gen progress messages ...
... if a predicate has more than one procedure.
2021-03-05 14:17:56 +11:00
Zoltan Somogyi
f55f592983 Include more info in an abort message. 2021-03-05 14:17:07 +11:00
Peter Wang
181122d1f8 Fix writing .module_dep files.
compiler/make.module_dep_file.m:
    Write foreign included file names to the .module_dep stream
    instead of the implicit output stream. The bug was introduced in
    commit 5f50259d16.

tests/mmc_make/Mmakefile:
    mmc --make does not set a non-zero exit status even if there were
    problems reading a .module_dep file. Explicitly grep for "error" in
    the mmc --make output in the include_file test that should have
    caught the preceding bug (assuming the workspace is built with
    --use-subdirs).

    grep for "error" in another test case.
2021-03-01 12:28:43 +11:00
Zoltan Somogyi
ac1c1f0795 Remove unneeded imports. 2021-02-26 20:43:26 +11:00
Zoltan Somogyi
5ec405ac0a Add an XXX about tuple_cons cons_ids.
compiler/prog_data.m:
    As above.

compiler/mercury_to_mercury.m:
    When generating debugging output, generate different output
    for tuple_cons cons_ids than for the initial representation
    of the tuple constructor, cons(unqualified("{}"), ...).
    To make this possible, take an argument that specifies whether
    we are generating debugging output.

compiler/error_msg_inst.m:
compiler/hlds_out_mode.m:
compiler/hlds_out_module.m:
compiler/inst_check.m:
compiler/mode_errors.m:
compiler/parse_tree_out_inst.m:
compiler/prog_ctgc.m:
    Pass the language (debug or not) to mercury_to_mercury.m
    when printing cons_ids.
2021-02-26 20:40:23 +11:00
Zoltan Somogyi
f15859f70b Fix indentation. 2021-02-26 20:32:42 +11:00
Zoltan Somogyi
5cbb6d5f1b Fix bad mode specializations.
library/hash_table.m:
library/stream.string_writer.m:
    Fix code where a mode specialization (i.e. the specification of
    a particular input function symbol for an argument) was applied
    to the wrong argument.
2021-02-26 17:55:51 +11:00
Zoltan Somogyi
3a21e5e374 Move two predicates to better homes.
compiler/type_util.m:
compiler/inst_util.m:
    Move two predicates that operate on types but are used only by code
    that manipulates insts from type_util.m to inst_util.m. The reason
    is that both predicates lose higher order inst information, and fixing
    that will require them to operate on insts as well. Moving them now
    should make the diff with the fix easier to review.

compiler/inst_match.m:
compiler/inst_test.m:
    Conform to the moves above.
2021-02-25 19:49:27 +11:00
Zoltan Somogyi
d2b3fef5cc Visually mark debug output from unique_modes.m.
compiler/mode_info.m:
    Add a new field to the debug flags we set up when --debug-modes is enabled.
    This field specifies whether the debug output is from mode checking,
    or from *unique* mode checking. Without this, the two are far too easy
    to confuse, as I found out the hard way.

compiler/mode_debug.m:
    Use the new field to add visually distinguish mode checkpoints from
    the two passes. For example. where mode checking would output
    "Enter unify", unique mode checking will output "Enter unique unify".

compiler/unique_modes.m:
    Delete a marker on mode checkpoints for conjunctions that also baffled me.
2021-02-25 19:45:57 +11:00
Zoltan Somogyi
4996509e32 Dump each arg-mode on its own line. 2021-02-25 19:24:53 +11:00
Zoltan Somogyi
7bdca312ec Clean up more modechecking code.
compiler/inst_match.m:
    Change the predicates that compare two insts to make the nested switch
    (first on one inst, then the other), make the nesting explicit.

    Give a predicate a more meaningful name.

    Add XXXs on dodgy code.
2021-02-25 12:21:58 +11:00
Zoltan Somogyi
5129769aa2 Address review comment. 2021-02-25 11:47:21 +11:00
Peter Wang
a40f21a4ca Update a comment. 2021-02-25 11:14:49 +11:00
Zoltan Somogyi
cd081d83cb Clean up some modechecking code.
compiler/inst_match.m:
    Replace a bool and a maybe with bespoke types, so that during a debugging
    session, there is no need to waste time on trying to remember what e.g.
    a "no" stands for.

compiler/modes.m:
    Put the code that checks each arg's final inst into its own predicate,
    to make the result easier to observe in mdb.

    Don't thread a goal through the code that checks final insts,
    since the code never updated or even looked at the goals.
    Delete this pair of goals from the argument lists of the ancestors
    of this predicate whenever possible, including an exported predicate.

compiler/modecheck_unify.m:
    Put a piece of code making a tricky decision into its own predicate,
    to allow breakpoints on that predicate to show the result of the decision.

    Conform to the change in modes.m.
2021-02-25 10:14:35 +11:00
Zoltan Somogyi
cdad329d15 Apply default func mode only to functions.
compiler/modecheck_call.m:
    This fixes a bug in my fix for Mantis bug #529.

compiler/options.m:
    Allow configure to test whether the bug is fixed, so we can delete
    any now-redundant explicit higher order insts in mode declarations.
2021-02-25 03:44:42 +11:00
Zoltan Somogyi
03d6c5f436 Get higher insts from types as well as modes.
compiler/modecheck_call.m:
    As above. This fixes Mantis bug #529.

compiler/options.m:
    Allow configure to test whether the bug is fixed, so we can delete
    any now-redundant explicit higher order insts in mode declarations.

tests/hard_coded/exist_cons_ho_arg.{m,exp}:
    A test case for the bug. This is a strengthened version of the
    Mantis test case.

tests/hard_coded/Mmakefile:
    Enable the new test case.
2021-02-24 19:57:37 +11:00
Zoltan Somogyi
6f8154d242 Put mode_errors.m's contents into logical order.
compiler/mode_errors.m:
    As above.

    Delete predicates that (a) do not belong here, but (b) do belong
    in some other module.

compiler/mode_info.m:
    Move mode_context_init here from mode_errors.m, since the mode_context
    type is defined here.

compiler/modes.m:
    Move two predicates, maybe_report_error_no_modes and
    +report_mode_inference_messages_for_preds here from mode_errors.m,
    since their only callers are here.

compiler/post_typecheck.m:
    Move +report_indistinguishable_modes_error here from mode_errors.m,
    since its only caller is here.
2021-02-24 18:49:29 +11:00
Zoltan Somogyi
c3f39870a1 Clean up the representation of mode errors.
compiler/mode_errors.m:
    Give the function symbols representing the various kinds of mode errors
    more meaningful names. (Some fix misleading implications, such as when
    a function symbol name includes "pred", but the error applies to functions
    as well.) Do the same for other function symbols in this module.

    Where arguments are lists that should never be empty, change their type
    to one_or_more to encode this invariant.

    In one case (var_multimode_pred_error), the same data items were packaged
    in two different ways in two different places. Remove this unnecessary
    difference.

    In some cases, put arguments in a more logical order.

    Improve the comments on most of these function symbols, fixing errors,
    fixing omissions, documenting arguments. Add XXXs where warranted.

    Put the types used in the various kinds of mode errors below the
    mode_error type itself. Put them into meaningful groups.

    The current order of the mode_error function symbols is totally
    haphazard. Propose a new order for them, but do not implement it yet,
    in order to make this diff easier to review.

    Make the representation of the error that says "calling an implied mode
    for this predicate or function is not implemented" say *why* it is
    not implemented. Include this info in the error message we generate.
    This error message is not exercised by any existing test case, which is
    why there are no changes to test cases in this diff.

    Improve the explanation for why you cannot unify two functions or
    two predicates. Since this explanation occurs only in verbose output,
    no test case is affected by this change either.

    Improve variable names.

compiler/mode_info.m:
    Conform to the changes in mode_errors.m.

    If --debug-modes is specified, print each error message as it is added
    to the mode_info. This helped me track down a bug in this change.

compiler/instmap.m:
compiler/modecheck_call.m:
compiler/modecheck_conj.m:
compiler/modecheck_goal.m:
compiler/modecheck_unify.m:
compiler/modecheck_util.m:
compiler/modes.m:
    Conform to the changes in mode_errors.m and/or mode_info.m.

    Add XXXs in some places. One marks one possible cause of Mantis bug #529.
2021-02-24 15:34:18 +11:00
Julien Fischer
23e0c34afe Fix a typo.
library/random.system_rng.m:
     s/MR_/ML_/ in a spot.
2021-02-21 14:40:52 +11:00
Julien Fischer
2f99fbb1d3 Respond to review comments.
library/random.system_rng.m:
      Shift most of the #includes into a local foreign_decl pragma
      so that they do not get included in the .mh file.

      Position the C# and Java foreign code pragmas to the end of the file,
      with the C one.
2021-02-20 16:13:00 +11:00
Julien Fischer
c2df9af6a8 Document and announce the system RNG module.
library/random.system_rng.m:
    Document what sources of randomness are used by the C backends.

library/MODULES_DOC:
library/MODULES_UNDOC:
    Include random.system_rng module in the library documentation.

NEWS:
    Announce the random.system_rng module.
2021-02-20 10:44:31 +11:00
Julien Fischer
7f87e4a686 Fix system RNG handles for non-urandom C implementations.
Ensure it is not possible to use a system RNG handle after it has been closed
with the arc4random() and rand_s() based implementations.

library/random.system_rng.m:
    As above.
2021-02-20 01:12:25 +11:00
Julien Fischer
c206ff93fc Fix indentation in a spot.
library/io.m:
    As above.
2021-02-19 23:21:56 +11:00
Julien Fischer
b7d3cb7c32 Fix system RNG handles in the C# and Java grades.
Ensure it is not possible to use a system RNG handle after it has been closed
in the C# and Java grades. This brings the implementation for these backends
into line with the /dev/urandom implementation on C.  (The other C implementation
will be made to conform in a separate change.)

library/random.system_rng.m:
    Add wrapper classes around the C# and Java system RNGs that allow
    us to track if they have already been closed.
2021-02-19 23:20:06 +11:00
Peter Wang
8b4407e447 Fix type_to_ctor_and_args for higher order types.
compiler/prog_type.m:
    Fix swapped "pred" and "func" in type_to_ctor_and_args.
2021-02-15 12:52:07 +11:00
Julien Fischer
2ff14bd80b Implement the system RNG on Windows.
On Windows we implement the system RNG by calling the CRT's rand_s() function.

library/random.system_rng.m:
    Implement the system RNG on Windows using rand_s().

runtime/mercury_std.h:
    On Windows define the macro _CRT_RAND_S before the initial
    inclusion of stdlib.h -- we must do this otherwise the declaration
    of rand_s() will not be visible.
2021-02-14 20:30:08 +11:00
Julien Fischer
6cd07540fe Use the arc4random() based system RNG on Cygwin.
library/random.system_rng.m:
    Cygwin provides the arc4random() family of functions; use
    that to implement the system RNG on Cygwin.
2021-02-06 03:16:28 +11:00
Julien Fischer
7b4fe0bdc3 Address review comment.
library/random.system_rng.m:
    Escape a backslash in foreign_decl pragma.
2021-02-02 16:01:12 +11:00
Julien Fischer
1e262841c1 Add an arc4random() based system RNG implementation.
library/random.system_rng.m:
    As above.

    Use the arc4random() based implementation on FreeBSD >= 12.0
    and macOS >= 10.12, falling back to the urandom approach on earlier
    versions.

    Always use the arc4random() approach on NetBSD and OpenBSD,
    both of which have used ChaCha20 in their implementation
    of arc4random() since 2014.
2021-02-02 00:52:46 +11:00
Julien Fischer
4109cb8347 Add a system RNG implementation for the C backends.
Add a system RNG implementation for the C backends that works by
reading random bits from /dev/urandom. We use this on Linux,
AIX and Solaris.

library/random.system_rng.m:
    Add two implementations of the system RNG for the C backends, one that
    reads from /dev/urandom and one that just aborts.  The former is used
    on Linux and the latter is used everywhere else (for now).
2021-02-01 16:57:29 +11:00
Julien Fischer
8c236f10bf Fix library build failure with older versions of .NET.
library/random.system_rng.m:
    Avoid the use of the BitConverter class as older versions
    of .NET (Mono) do not provide some of the methods we use.
2021-01-31 20:14:44 +11:00
Zoltan Somogyi
4ebe95672d Don't crash on inst_name nested inside itself.
This fixes Mantis bug #528.

compiler/error_msg_inst.m:
    Since an inst_name IN may be used nested inside itself, as in
    IN(..., IN(...), ...), do not insist that both occurrences of IN
    in such cases lead to the insertion of a new entry in the inst name
    expansion map.

tests/invalid/html.{m,err_exp}:
    The Mantis test case.

tests/invalid/Mmakefile:
    Enable the Mantis test case.
2021-01-30 01:45:26 +11:00
Julien Fischer
65566350b5 Add the system random number generator interface.
This is work-in-progress, currently only the C# and Java backends
are supported. Support for the C backends will be added separately.

library/random.system_rng.m:
    A new submodule containing the system RNG.

library/random.m:
library/library.m:
    Include the new submodule.

library/MODULES_UNDOC:
    Do not generate documentation for the new submodule.
2021-01-29 16:30:18 +11:00
Zoltan Somogyi
91162b548d Fix #line directives emitted in LLDS grades.
compiler/c_util.m:
    Add missing stream argument.

compiler/Mercury.options:
    Fix misspelt filename that prevented the problem in c_util.m
    from being automatically diagnosed.
2021-01-27 16:53:08 +11:00
Zoltan Somogyi
7393a043f7 Make code more readable. 2021-01-27 16:50:13 +11:00
Zoltan Somogyi
5a5a35bd09 Don't crash for type errors in foreign_procs.
Normally, foreign_procs are assumed to be type correct, because they
have to be: a Mercury compiler cannot check foreign code. However,
in one case, we can get type errors for foreign_procs That case is when
a predicate has

- an existentially typed argument, and
- two or more modes implemented by foreign procs.

The compiler has never been able to correctly handle more than one clause
defining the type_info of an existentially typed argument. When those clauses
were Mercury clauses, it generated an error; when those "clauses" were
foreign_procs, it *tried* to generate an error, but the code that did that
crashed the compiler.

compiler/typecheck_errors.m:
    Fix the compiler abort, letting the error message be generated.

tests/invalid/foreign_procs_exist_type.{m,err_exp}:
    Add a test case for this fix.

tests/invalid/Mmakefile:
    Enable the new test case.
2021-01-27 14:40:49 +11:00
Zoltan Somogyi
1045c87be3 Improve HLDS dumps of call_foreign_proc goals.
Delete the `' quotes around predicate names, since these confuse vim's
syntax highlighting.

Put each argument of a foreign_proc on its own line, since putting
all the args on one line often causes vim to regard the line
as excessively long, highlighting all characters after column #80.
2021-01-26 23:23:19 +11:00
Zoltan Somogyi
040d6717a6 Fix comments. 2021-01-26 23:22:54 +11:00
Zoltan Somogyi
b5cad10f9a Update programming style. 2021-01-26 14:57:37 +11:00
Zoltan Somogyi
4910a8564d Update programming style. 2021-01-26 14:33:09 +11:00
Julien Fischer
c00b42ec3c Minor updates for benchmarks.
benchmarks/progs/tree234/tree234x.m:
benchmarks/progs/pic/mercury/utils.m:
     Replace uses of is a synonym for unification.

benchmarks/progs/training_cars/*.m:
     Delete implementation imports that shadow those in the interface.
2021-01-25 22:37:08 +11:00
Julien Fischer
71624374c4 Fix compilation of a posix sample.
extras/posix/samples/mdprof_cgid.m:
    Conform to changes in the getopt module.
2021-01-25 20:28:23 +11:00