Commit Graph

2483 Commits

Author SHA1 Message Date
Julien Fischer
259edd0b3f Document how Cygwin treats argv[0].
runtime/mercury_runtime_util.c:
    As above, in particular there's no need to strip the .exe
    extension from it because Cygwin does that for us.
2023-10-22 23:45:22 +11:00
Julien Fischer
572630c1e7 Fix an XXX with trace count files on Windows.
runtime/mercury_trace_base.c:
    Handle the case where the trace count file name contains non-ASCII
    characters on Windows.
2023-10-22 20:59:24 +11:00
Julien Fischer
ab87605a35 Avoid an abort when writing trace count files on Windows.
Writing trace counts the default trace count file aborts on Windows due to the
program basename not being stripped of drive and directory qualifications.
Use the machinery introduced in commit 54de823 to avoid this.

Add XXX WINDOWS comments about other potential problems with the trace counts
mechanism on Windows.

runtime/mercury_trace_base.c:
    When constructing the default name for trace counts files, use the recently
    add MR_get_program-basename() function to extract the program basename.

    Add XXX WINDOWS comments about some other things. Resolving these will
    be the subject of future changes.

runtime/mercury_runtime_util.c:
    Adjust an error message.
2023-10-22 17:29:43 +11:00
Julien Fischer
54de823611 Fix runtime program basename on Windows.
Several places in the runtime make use of the program basename. This is
computed by stripping any directory qualification from the value of argv[0].
Currently, this is done by searching for uses of '/' as a directory separator.
This does not work on Windows where '\' is the directory separator and paths
may also be drive qualified. This diff adds a function that will handle
Windows-style paths.

Also, none of the uses of the program basename in the runtime currently account
for the presence of the .exe executable extension on Windows.  After this diff,
users won't have to, and in fact will not be allowed to, include the .exe
extension in the program name in these contexts.

runtime/mercury_runtime_util.[ch]:
    Add a function, MR_get_program_basename(), whose job is
    to strip any drive or directory qualification, and the executable
    extension from a given path.  On Windows, we use the OS's splitpath()
    function to do this.

    Add an XXX about the .exe extension on Cygwin.

runtime/mercury_wrapper.c:
    Use the new function when computing:
    - the name of the program-specific MERCURY_OPTIONS environment variable;
    - the value of the --trace-count-if-exec runtime option;
    - the value of the --coverage-test-if-exec runtime option.

doc/user_guide.texi:
    Document that the .exe extension is not expected in the three spots above.
2023-10-22 14:34:42 +11:00
Julien Fischer
bec35c03ff Fix compilation on Windows.
runtime/mercury_string.h:
     Fix a cut-and-paste error.
2023-10-18 14:58:44 +11:00
Julien Fischer
0975c8d329 Move some utility functions into the runtime.
Move the functions that convert between the UTF-8 and wide encodings of a
string on Windows from the library into the runtime. Upcoming changes will
require their presence in the runtime.

library/io.m:
    Move ML_utf8_to_wide() and ML_wide_to_utf8() from here ...

runtime/mercury_string.[ch]:
    ... to here and s/ML_/MR_/.

library/dir.m:
library/io.call_system.m:
library/io.environment.m:
library/io.file.m:
library/io.stream_ops.m:
    Conform to the above change.
2023-10-16 09:57:33 +11:00
Julien Fischer
2bc49683d5 Add an XXX about another portability problem.
runtime/mercury_trace_base.c
    As above.
2023-10-15 13:52:10 +11:00
Julien Fischer
f3fed35808 Add an XXX.
runtime/mercury_wrapper.c:
    Add an XXX about how the name of the program-specific options
    is constructed on Windows.
2023-10-15 13:32:38 +11:00
Julien Fischer
9cc8515a56 Update target for building runtime .c files.
runtime/Mmakefile:
    s/cs/all_cs/ for consistency with elsewhere.
2023-10-05 23:09:36 +11:00
Julien Fischer
57acffa039 Support optional package version information.
Add a new configure option, ---with-pkgversion, that allows those packaging
Mercury to include additional version information specific to their package in
the output of mmc --version etc.

Omit version and copyright information from the short usage messages for mmc, mprof
and mcov. The result is less cluttered and more direct.

Omit version information from the long usage (i.e. --help) message for the
above programs. This is to save space on the first line of the output and also
brings the man pages for mmc, mprof and mcov into line with the other man
pages, which do *not* have version information in their NAME section.

configure.ac:
    Add the new --with-pkgversion option.

runtime/mercury_conf.h.in:
runtime/mercury_dotnet.cs.in:
java/runtime/Constants.java.in:
    Define a constant for the package version.

library/library.m:
    Add the function package_version/0, which returns the package
    version string.

compiler/handle_options.m:
profiler/mercury_profile.m:
slice/mcov.m:
    Include a non-empty package version in the output of --version.

    Make the above changes to the short and long usage messages.

    Add an XXX about mprof's short usage message.
2023-09-09 14:23:50 +10:00
Peter Wang
a1a344db6f Explicitly start parallel marker threads.
As of Boehm GC v8.2.2 (commit b8ee3ca626d6bd67c8c2c94d517f2f7da7cd5a8c)
parallel marker threads are not started during GC_INIT(). Instead, the
marker threads are only started when the client program creates the
first (user) thread, or if GC_start_mark_threads() is called explicitly.

runtime/mercury_wrapper.c:
    Call GC_allow_register_threads() as part of GC initialisation.
    This will enable parallel marking in par.gc C grades from the start
    of the Mercury program, even if the program has not created any
    threads (yet).
2023-08-07 12:59:15 +10:00
Julien Fischer
fc0e0efb28 Fix alignment in Windows exception record messages.
runtime/mercury_memory_handlers.c:
    As above.
2023-07-16 22:04:05 +10:00
Peter Wang
adb22a74a7 Delete MERCURY_OPTIONS -a -r -t options.
The MERCURY_OPTIONS environment variable supported these options

    -a  benchmark_all_solns
    -r  repeats
    -t  use_own_timer

to perform microbenchmarks very early on in the Mercury project,
but the time for that is past.

runtime/mercury_wrapper.c:
    Delete code supporting -a, -r and -t options.

scripts/mprof_merge_runs:
    Delete mention of -r option.

tests/benchmarks/Mmakefile:
    Delete/comment out rules that makes use of the -r option.
2023-07-14 11:03:03 +10:00
Peter Wang
9cfc90a6a4 Fix MERCURY_OPTIONS -x option (disable GC).
runtime/mercury_wrapper.c:
    Set a variable when MERCURY_OPTIONS contains -x.

    We always disable GC at the start of the program run.
    Enable GC after startup unless MERCURY_OPTIONS contained -x.
2023-07-13 12:37:41 +10:00
Peter Wang
3d454aa6d4 Delete obsolete MR_DI_* variables.
runtime/mercury_wrapper.c:
    Delete MR_DI_output_current_ptr, MR_DI_found_match, and
    MR_DI_read_request_from_socket variables.
    The last reference to any of them was in 1999.
2023-07-13 12:35:52 +10:00
Peter Wang
60172fa5e6 Fix compilation with GCC 13.
Fixes GitHub issue #123.

runtime/mercury_ml_expand_body.h:
    Convince GCC 13 that a sprintf() call will not overflow.
2023-07-12 10:40:05 +10:00
Julien Fischer
fcefbd8887 Fix a typo.
runtime/mercury_memory_handlers.c:
    As above.
2023-07-11 20:01:25 +10:00
Julien Fischer
19d818209f Ignore *.obj files.
*/.gitignore:
    As above.

    Fix a few other omissions.
2023-06-26 20:05:24 +10:00
Julien Fischer
1a40cd9dd5 Avoid warnings from 64-bit MSVC.
runtime/mercury_memory_handlers.c:
    Cast pointers to word-sized integers.  (unsigned long is
    a 32-bit type on Windows.)
2023-06-26 19:53:33 +10:00
Julien Fischer
2a366cf295 Deprecate --no-ansi and --no-ansi-c.
--no-ansi (mgnuc) and --no-ansi-c (mmc) have not actually done anything for
many years now. Deprecate these options and remove their "use" throughout most
of the Mercury system. (The remaining uses are in the Makefiles for the Boehm
GC, which need to be updated separately.)

Also deprecate the internal compiler option --cflags-for-ansi.

compiler/options.m:
    Document that --no-ansi-c is now deprecated.

    Document that the internal option --cflags-for-ansi is now
    deprecated.

compiler/compile_target_code.m:
    Do not pass the ANSI options to the C compiler.

scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
    Deprecate the --no-ansi option; delete code that no longer does
    anything useful.

configure.ac:
    Delete the configuration variable CFLAGS_FOR_ANSI; it is only ever
    set to be empty. (The comment talks about --no-ansi doing other things
    in the mgnuc script. It used to also cause some preprocessor macros
    to be defined for compatibility with the system headers on some
    platforms -- that has not been the case since 2013.)

doc/user_guide.texi:
    Document that --no-ansi-c is deprecated.

bytecode/Mmakefile:
compiler/Mercury.options:
library/Mercury.options:
extras/odbc/odbc.m:
runtime/Mmakefile:
scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
tests/hard_coded/Mercury.options:
tests/valid/Mercury.options:
trace/Mmakefile:
util/Mmakefile:
    Conform to the above change.

NEWS.md:
    Announce the above.
2023-05-31 17:44:26 +10:00
Zoltan Somogyi
12985941ad Make old/new MercuryFile structs easily comparable ...
... by putting the macros that operate on both of them into the same order,
and documenting which macros are specific to just one version.
2023-04-24 14:00:13 +10:00
Zoltan Somogyi
2a12732260 Improve well-formedness checks on UTF strings.
library/io.m:
    Add the predicates

        read_named_file_as_string_wf
        read_named_file_as_lines_wf
        read_file_as_string_wf
        read_file_as_string_and_num_code_units_wf

    which extend their base predicates (without the _wf suffix) by checking
    whether the string read from the file is well formed, and returning
    an error if it is not.

library/io.stream_op.m:
    Fix and expand a comment.

library/io.text_read.m:
    Add a comment.

library/string.m:
    Add check_well_formedness, a predicate that checks whether a string
    is well formed, and (if relevant) specifies the offset of the first
    non-well-formed character.

    Make the documentation of index_next and index_next_repl more detailed.

runtime/mercury_string.[ch]:
    Define MR_utf8_find_ill_formed_char, a version of MR_utf8_verify
    that returns the offset of the first ill-formed UTF-8 char in the
    given string, if there is one. This is used in the implementation of
    check_well_formedness for C.

NEWS.md:
    Announce the new library predicates.

    Sort some lists of pred names.
2023-04-21 15:55:23 +10:00
Zoltan Somogyi
169e8a22d1 Fix documentation rot. 2023-04-20 19:52:46 +10:00
Zoltan Somogyi
4f9eb3e450 Update programming style. 2023-04-16 15:27:22 +10:00
Julien Fischer
c27f120d54 Update link to x86_64 ABI documentation.
runtime/machdeps/x86_64_regs.h:
    As above.
2023-01-23 02:29:13 +11:00
Zoltan Somogyi
05ef8e01fb Rename the .ll_debug grade component to .c_debug.
Rename mmc and mgnuc options that set this grade component to --c-debug-grade.
Let the options named --c-debug of both mmc and mgnuc enable C level debugging
of only the module being compiled.

runtime/mercury_grade.h:
    Rename the .ll_debug grade component to .c_debug. Also rename the C macro
    that controls the presence or absence of this grade component
    from MR_LL_DEBUG to MR_C_DEBUG_GRADE.

runtime/mercury_conf_param.h:
runtime/mercury_debug.c:
runtime/mercury_debug.h:
runtime/mercury_engine.c:
runtime/mercury_label.c:
runtime/mercury_memory_zones.c:
runtime/mercury_memory_zones.h:
runtime/mercury_overflow.c:
runtime/mercury_std.h:
runtime/mercury_wrapper.c:
    Rename the MR_LOWLEVEL_DEBUG macro to MR_DEBUG_THE_RUNTIME.
    Previously, the name of this macro wrongly implied that it had
    something to do with the old .ll_debug grade component, even though

    - the MR_LOWLEVEL_DEBUG macro was designed to debug LLDS grades,
      since only these existed when it was created, while

    - the .ll_debug grade component (now .c_debug) is useful only for
      MLDS grades targeting C.

compiler/options.m:
    Rename the old confusingly named low_level_debug option to c_debug_grade.
    Move it to the list of grade options, and fix its documentation, which
    was completely wrong:

    - code in compile_target_code.m treated it as being a synonym of
      the .ll_debug (now .c_debug) grade component, while
    - its (commented out) documentation here in options.m said it called for
      the enabling of what is now MR_DEBUG_THE_RUNTIME.

compiler/compile_target_code.m:
    Conform to the rename just above.

    Define MR_C_DEBUG_GRADE instead of MR_LL_DEBUG if c_debug_grade is enabled.

    Pass -g to the C compiler if either c_debug_grade or target_debug
    is enabled.

    Add an XXX about a missing safety check for an obsolete experimental
    feature.

compiler/compute_grade.m:
    When given a grade with a .c_debug grade component, set only the
    c_debug_grade option; don't set the target_debug option, which is NOT
    a grade option. The change to compile_target_code.m above handles the
    only situation in which this implication was formerly required.

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
    Look for and process the .c_debug grade component instead of .ll_debug.
    Use a sh variable named c_debug_grade to record its absence/presence.

    Look for and process the --c-debug-grade grade-component option,
    setting the same sh variable, c_debug_grade. (All grade components
    can be set piecemeal using sh options to the scripts using these
    subroutines.) This replaces the old, confusingly named option
    --low-level-debug.

scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
    Consistently use the sh variable c_debug to record the presence of
    the (non-grade) --c-debug option to mgnuc, and the sh variable
    c_debug_grade to record the presence of the .c_debug grade component.

    Stop looking for and handling the --low-level-debug option, which
    mgnuc used to document, even though this duplicated the same documentation
    in init_grade_options.sh-subr, which mgnuc includes. The difference was
    that init_grade_options.sh-subr meant it to represent the old .ll_debug
    MLDS grade component, while mgnuc treated it as specifying what is now
    MR_DEBUG_THE_RUNTIME for LLDS grades. It didn't help that two sh variables
    with quite different semantics had names that differed only in an
    underscore: LLDEBUG_OPTS vs LL_DEBUG_OPTS.

scripts/Mmakefile:
    Add a missing dependency to force the rebuild of mgnuc after each update
    of its sh subroutine mgnuc_file_ops.sh-subr.

doc/user_guide.texi:
    Document the --c-debug-grade option of mmc. This option was not publicly
    documented under its original misleading name (--low-level-debug), but
    its documentation is now possible without contorted dancing around the
    name.

    Clarify the documentation of mgnuc's --c-debug option.

README.sanitizers:
configure.ac:
    Conform to the rename of the grade component.

grade_lib/grade_spec.m:
grade_lib/grade_string.m:
grade_lib/grade_structure.m:
grade_lib/try_all_grade_structs.m:
    Conform to the rename of the grade component .ll_debug to .c_debug.

    Don't allow the .c_debug grade component in LLDS grades.

    In grade_string.m, add some obvious implications of some grade components.

grade_lib/choose_grade.m:
grade_lib/grade_lib.m:
grade_lib/test_grades.m:
grade_lib/var_value_names.m:
    Fix white space.

scripts/ml.in:
tools/lmc.in:
tools/test_mercury:
    Conform to the change in compile_target_code.m to the naming of
    Boehm gc library variants.
2022-12-29 20:33:08 +11:00
Peter Wang
fc1cd53f83 Reduce size of MR_win32_error_name.
All the strings returned by MR_win32_error_name include a common prefix
"ERROR_". Since there are many (1749) such strings, we can reduce the
size of the data by about 10 KB by returning only the part following the
prefix.

tools/generate_windows_error_name:
runtime/mercury_windows_error_name.c:
    Make MR_win32_error_name return strings without the "ERROR_" prefix.

library/io.m:
    Update caller system_error_win32_error_name to add the "ERROR_"
    prefix.
2022-08-29 10:57:39 +10:00
Peter Wang
fbcaaf805a Reduce list of Windows ERROR_ constants.
Fix compilation with older versions of MinGW(-w64) and any other
compilers which don't have as many ERROR_ constants defined.

tools/generate_windows_error_name:
    Reduce the list of ERROR_ constants.

runtime/mercury_windows_error_name.c:
    Regenerate.
2022-08-26 11:12:25 +10:00
Peter Wang
aaa6ac5fe1 Introduce io.system_error to io.m public interface.
Implement the error handling proposals from February 2022 on the
mercury-users list, and August 2022 on the mercury-reviews list.

We add io.system_error to the public interface of io.m
and document what its foreign representation is for each backend.

We allow io.error to optionally contain an io.system_error value,
and provide predicates to retrieve the io.system_error from an io.error.
The user may then inspect the system error via foreign code.

We also provide a predicate that takes an io.error and returns a name
for the system error it contains (if any). This makes it relatively easy
for Mercury programs to check for specific error conditions.

By returning platform-specific (actually, implementation-dependent)
error names, we are pushing the responsibility of mapping strings to
error conditions onto the application programmer. On the other hand, it
is not practical for us to map all possible system-specific error codes
to some common set of values. We could do it for a small set of common
error codes/exceptions, perhaps.

The standard library will construct io.error values containing
io.system_errors. However, we do not yet provide a facility for user
code to do the same.

library/io.m:
    Move io.system_error to the public interface.

    Change the internal representation of io.error to support containing
    a io.system_error. An io.system_error may originate from an errno
    value or a Windows system error code; the constructor distinguishes
    those cases.

    Add predicates to retrieve a system_error from io.error.

    Add predicate to return the name of the system error in an io.error.

    Replace make_err_msg with make_io_error_from_system_error.

    Replace make_maybe_win32_err_msg with
    make_io_error_from_maybe_win32_error.

    Delete ML_make_err_msg and ML_make_win32_err_msg macros.

browser/listing.m:
library/bitmap.m:
library/dir.m:
library/io.call_system.m:
library/io.environment.m:
library/io.file.m:
library/io.text_read.m:
mdbcomp/program_representation.m:
    Conform to changes.

    Leave comments for followup work.

tools/generate_errno_name:
tools/generate_windows_error_name:
    Add scripts to generate mercury_errno_name.c and
    mercury_windows_error_name.c.

runtime/Mmakefile:
runtime/mercury_errno_name.c:
runtime/mercury_errno_name.h:
runtime/mercury_windows_error_name.c:
runtime/mercury_windows_error_name.h:
    Add MR_errno_name() and MR_win32_error_name() functions,
    used by io.m to convert error codes to string names.

tests/hard_coded/null_char.exp:
    Update expected output.
2022-08-23 16:39:48 +10:00
Zoltan Somogyi
e35a09542e Print two kinds of ambiguities only if asked for.
trace/mercury_trace_cmd_developer.c:
trace/mercury_trace_tables.[ch]:
    Add two options to the mdb command "ambiguity".

    Print ambiguities between function and predicate forms of the same
    operation, such as list.length, only if the new option -b, or
    --both-pred-and-func, is given.

    Print ambiguities involving procedures that were created by type
    specialization only if the new option -s, or --typespec is given.
    (The -t option name was already taken.)

    These changes remove from the ambiguity command's output
    (some of) the parts that are not useful when one wants to eliminate
    ambiguities by renaming.

    Clarify a heading.

doc/user_guide.texi:
    Document the above changes.

runtime/mercury_proc_id.h:
    Fix a field name that has become misleading.

    MR_UserProcId_Structs have a field named MR_user_arity.
    In this name, the "MR_user_" part is a prefix shared by the other
    fields in that structure, to indicate that they are part of the id
    of a user-defined procedure, as opposed to a compiler-created
    unify, compare or index procedure. However, the arity it contains
    is what the compiler now calls a pred_form_arity: it does not count
    type_info and typeclass_info arguments added by polymorphism, but
    it *does* count function return values for functions. This is now
    misleading, because in the compiler, a user_arity does *not* count
    function return values for functions.

    Replace this field name with MR_user_pred_form_arity, which tells
    readers that this arity is a pred_form_arity. The presence of the
    "user" part of the name may still cause some confusion, but at least
    that confusion should motivate readers to look up the field name,
    whose comment should clarify things.

mdbcomp/rtti_access.m:
runtime/mercury_debug.c:
runtime/mercury_deep_profiling.c:
runtime/mercury_ho_call.c:
runtime/mercury_layout_util.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_stack_layout.h:
runtime/mercury_trace_base.c:
trace/mercury_trace.c:
trace/mercury_trace_external.c:
trace/mercury_trace_util.c:
    Conform to the change in mercury_proc_id.h.

tests/debugger/ambiguity.{m,inp,exp}:
tests/debugger/ambiguity_helper.m:
    Expand this test case to test the new functionality.
    The type specialized predicates are in a new helper module,
    because this is the simplest way to avoid dead procedure elimination
    deleting any of the predicates whose names we want to test for ambiguities.
2022-07-05 08:00:12 +10:00
Peter Wang
1b7e5adecf Don't use __builtin_setjmp, __builtin_longjmp on AArch64 with older GCCs.
There is an issue on Linux/aarch64 with older versions of gcc where a
commit performed on a thread using the gcc __builtin_longjmp function
causes an assertion failure in pthread_create() if the Mercury runtime
is dynamically linked:

    pthread_create.c:430: start_thread: Assertion `freesize < pd->stackblock_size' failed.

or a crash if the Mercury runtime is statically linked:

    *** Mercury runtime: caught segmentation violation ***
    cause: address not mapped to object

The gcc versions tested are:

    BAD - gcc version 6.3.0 20170516 (Debian 6.3.0-18) from Debian 9
    BAD - gcc version 8.3.0 (Debian 8.3.0-2) from Debian 10
    OK  - gcc version 10.2.1 20210110 (Debian 10.2.1-6) from Debian 11

on Debian with glibc.

runtime/mercury.h:
    Define MR_USE_GCC_BUILTIN_SETJMP_LONGJMP if we decide to use gcc's
    __builtin_setjmp and __builtin_longjmp functions instead of the
    standard functions.

    Use standard setjmp/longjmp on aarch64 if gcc version is < 10.

    Update the comment for MR_builtin_jmp_buf to refer to the GCC manual
    instead of the GCC source code. Use an array of 'intptr_t's instead
    of 'void *'s, to match the manual.

tests/hard_coded/Mmakefile
tests/hard_coded/thread_commit.m:
tests/hard_coded/thread_commit.exp:
tests/hard_coded/thread_commit.exp2:
    Add test case.
2022-05-26 12:47:21 +10:00
Zoltan Somogyi
d667194642 Introduce a new type for effective trace levels.
We have two main notions of trace levels. The first is the global trace level,
which is set by compiler options, and the second is the effective trace level
for a given procedure. The two are different not just in that the effective
trace level for a procedure may differ from the global trace level, but also
in that there exist effective trace levels that cannot be specified using
compiler options.

compiler/trace_params.m:
    Add the new type eff_trace_level for representing effective trace levels.
    (Old code has long used "Eff" as an abbreviation for "effective".)
    Use it where relevant.

    Delete functions that (a) first compute the effective trace level
    for a procedure, and (b) then test that effective trace level,
    and replace each of them with a function that does only (b).
    There was already a function that did only (a); rename it to avoid
    an ambiguity.

compiler/code_info.m:
    Store the effective trace level of the procedure being translated
    in the code_info, to save it from having to be recomputed many times.

compiler/code_loc_dep.m:
    Get the effective trace level for the procedure being compiled
    from code_info.

compiler/hlds_out_pred.m:
    Write out each procedure's effective trace level.

compiler/llds.m:
    Include the effective trace level in generated c_procs, for use by
    continuation_info.m.

compiler/continuation_info.m:
    Rename a predicate to avoid a name clash.

    Conform to the changes above.

compiler/handle_options.m:
    Note a non-problem.

compiler/globals.m:
compiler/layout.m:
compiler/layout_out.m:
compiler/liveness.m:
compiler/optimize.m:
compiler/proc_gen.m:
compiler/simplify_goal_conj.m:
compiler/simplify_goal_scope.m:
compiler/simplify_info.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/store_alloc.m:
compiler/trace_gen.m:
compiler/transform_llds.m:
    Conform to the changes above.

compiler/mercury_compile_front_end.m:
    Fix a misleading predicate name.

compiler/hlds_out_module.m:
    Simplify some code.

runtime/mercury_goto.h:
    Fix misplaced/wrong casts and stray backslashes in macros that are usually
    only used when debugging the debugger.
2022-05-01 05:34:10 +10:00
Peter Wang
594b09c547 Handle argv[0] == NULL.
On some operating systems, e.g. Linux, it is possible to enter main()
with argv[0] == NULL if the parent process calls execve() with
argv[0] == NULL, or equivalently, passing NULL for the argv parameter.

runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
    Do not assume argc > 0 and argv[0] != NULL in MR_process_args.
    If argv[0] is NULL then set MR_progname to the empty string
    so users of MR_progname can assume it points to a valid string.

    Add a new global variable MR_progname_is_known to indicate if
    argv[0] was NULL or not.

library/io.m:
    Make io.progname return the default program name if argv[0] was
    NULL.

util/mkinit.c:
    Set MR_progname to a valid string if argv[0] is NULL.
    This is not actually necessary, since, in that case, the subsequent
    call to parse_options() would immediately exit the program
    as no file names will be found in argv.
2022-01-31 14:11:08 +11:00
Zoltan Somogyi
adf6c55847 Shut up mmake actions for check_namespace.
This reduces the size of the output of tools/bootcheck by 3700+ lines,
or about 25%.

Mmake.common.in:
    Don't print the actions implementing namespace cleanliness checks.
    To allow the attribution of any violations of the namespace rules,
    print the name of the C module before any list of detected
    nonallowed symbols.

    To avoid mmake printing the actions for creating the .o files
    that some of the check_namespace actions later check, rename
    the affected object files .pseudo_o files, so that we can specify
    a rule for them that is a copy of the rule for .o files, differing
    only in not printing the compilation command.

    Mark the files involved in check_namespace actions as dependencies
    of .SECONDARY, which means that mmake does not automatically delete them
    after building them as intermediate files. The reason for this is that
    there is no way to tell make to delete intermediate files *silently*,
    i.e. without writing out the rm command that deletes them.
    To make up for this, tools/bootcheck now cleans up each directory
    immediately after "mmake check_namespace" with "mmake clean_check",
    which invokes mmake rules that do not print the rm commands.

    This change does have the effect that these intermediate files *will*
    hang around if the check_namespace target is every invoked manually.
    However,

    - we just about never run check_namespace in a directory manually, and
    - when we do, a simple "mmake clean_check" will do the required cleanup.

scripts/Mmake.rules:
    Move the vim tag line to its usual place at the top.

    Replace old-school rules such as .m.err with their modern equivalents
    (such as %.err: %.m).

scripts/Mmakefile:
    Instead of printing the rules that make test_mdbrc, print only a
    "making test_mdbrc" message.

runtime/Mmakefile:
    Conform to the change of the name of a make variable in Mmake.common.in.

ssdb/Mmakefile:
    Fix an old bug that something else in this diff tickled: make the
    .depend target of each main module depend on SSDB_FLAGS, *not* just
    the phony general "depend" target. This was a bug because tools/bootcheck

    - copied across to stage 2 ONLY SSDB_FLAGS.in, and NOT SSDB_FLAGS,

    - did NOT explicitly make SSDB_FLAGS from SSDB_FLAGS.in, even though
      pretty much invocations of the Mercury compiler in this directory
      have "--flags SSDB_FLAGS" as an implicit argument, and then

    - built dependencies in the ssdb directory by invoking the top
      Mmakefile's dep_ssdb target, which (indirectly) invokes
      $(SSDB_LIB_NAME).depend.

    Due to all the above, I don't actually know how tools/bootcheck
    could ever build stage2/ssdb until now :-(

tools/bootcheck:
    Invoke "mmake clean_check" after each "mmake check_namespace".

    Change the code that explicitly builds the directory-specific
    X_FLAGS file in each directory (which is invoked only when using
    mmc --make) to actually build all such files, when previously
    it built only a subset.

tests/invalid/Mmakefile:
tests/invalid_nodepend/Mmakefile:
tests/invalid_onlydepend/Mmakefile:
tests/invalid_options_file/Mmakefile:
tests/invalid_purity/Mmakefile:
tests/invalid_submodules/Mmakefile:
tests/stm/Mmakefile:
    Fix an unintended consequence of replacing the .m.err rule in
    scripts/Mmake.rules with %.err: %.m, which is that the %.err: %.m
    rules in these mmakefiles became ineffective, because they appear
    in the makefile we construct *after* the rule in scripts/Mmake.rules,
    which specify a different action (the rules here return a nonzero
    status in the *absence* of failure, which would be ridiculous
    for the rule in scripts/Mmake.rules). Apparently, the %.err: %.m rules
    overrode the rule in scripts/Mmake.rules while it had the old form,
    but do not do so now it has the new form.

    The fix is to make replace all the "%.err: %.m" rules in these Mmakefiles
    with "$(PROGS:%=%.err): %.err: %.m" rules, which specify that they
    override the generic rule for the .err files of the test cases
    in each directory.

    In invalid_purity/Mmakefile, fix a bug: -nodepend suffixes make sense
    in only in the name of a *test*, not the name of a *program*, so
    move such a suffix from a program name to a test name. Without this,
    the program's .err file would be included in the list of .err files
    to which the ".err: .m" rule applies under the wrong name.

    In invalid_submodules/Mmakefile, fix the misleading names of some
    make variables, and fix a misspelt directory name.

    Standardize on "$(PROGS:%=%.err)" notation, replacing earlier instances
    of "$(addsuffix .err,$(PROGS))". The reason for this is that when I tried
    using "$addsuffix .int_err,$(PROGS))" in tests/invalid/invalid_make_int,
    it did not work. (A google search on "gnu make addsuffix" did not yield
    any clues as to why. Maybe you can only add suffixes that do not contain
    underscores?)
2022-01-24 17:38:35 +11:00
Julien Fischer
093018109c Update references to LIMITATIONS file.
BUGS:
README.md:
bindist/Mmakefile:
compiler/notes/release_checklist.html:
compiler/prog_data.m:
doc/reference_manual.texi:
library/list.m:
runtime/mercury_type_desc.h:
    As above.
2022-01-01 15:53:34 +11:00
Peter Wang
f47a0cdba9 Update to Boehm GC v8.0.6 and libatomic_ops v7.6.12
.gitmodules:
boehm_gc:
    Update boehm_gc submodule to release-8.0-mercury-20201129.

runtime/mercury_report_stats.c:
runtime/mercury_wrapper.c:
    Use total full-collection time API added in Boehm GC v8.0.0.

NEWS:
    Announce change.
2021-11-30 11:15:06 +11:00
Julien Fischer
bc53a82404 Adjust formatting.
runtime/mercury_ml_expand_body.h:
    Add a space after a cast.
2021-11-04 01:29:41 +11:00
Adrian Wong
5e827201f3 Fix a bug where valid code points were treated like invalid surrogates.
runtime/mercury_string.h:
    As above. Valid code points in the ranges [1D800, 1DFFF] and
    [10D800, 10DFFF] were treated like invalid surrogates because the
    high bits were masked away.

tests/hard_coded/Mmakefile:
tests/hard_coded/char_not_surrogate.exp:
tests/hard_coded/char_not_surrogate.m:
tests/hard_coded/string_not_surrogate.exp:
tests/hard_coded/string_not_surrogate.m:
    Add test cases.
2021-11-04 00:46:05 +11:00
Julien Fischer
46e3fdddda Fix some comments.
runtime/mercury_conf.h.in:
    Fix incorrect marco names in a comment.
2021-09-28 01:12:03 +10:00
Zoltan Somogyi
14a76907fc Clarify a comment. 2021-06-14 16:50:37 +10:00
Zoltan Somogyi
1434b1df2f Delete a redundant test. 2021-06-14 14:10:54 +10:00
Zoltan Somogyi
f66a7d6642 Generate diagnostics for .par.mm grades.
compiler/handle_options.m:
runtime/mercury_grade.h:
scripts/final_grade_options.sh-subr:
    Generate an error message for grades that mix parallel execution
    and minimal model tabling.

compiler/compute_grade.m:
    Improve two comments.
2021-06-13 21:41:56 +10:00
Julien Fischer
90387ddc8c Delete an unused function.
runtime/mercury_bitmap.c:
     Delete the function MR_hex_char_to_int().  It has been unused since 2011.
     (Actually, it was unused before then since its only caller was also
     unused.)
2021-06-06 19:07:20 +10:00
Peter Wang
6a18491e03 Further prevent use of non-local gotos with PIC on x86 with GCC 5+.
configure.ac:
    Run the C compiler to check if it actually targets x86-64.
    Previously we assumed if $host is x86_64 then the C compiler will be
    targeting x86-64, but that is not true if gcc -m32 or gcc -mx32 is
    used.

    Then, as before, if the C compiler targets x86 and dynamic linking
    is enabled (except on Windows) and GCC is version 5+ then disable
    selection of any grades that use gcc labels.

runtime/mercury_goto.h:
    Report an error if the user tries to use non-local gotos with PIC
    on x86 with GCC 5+.

README.x86:
    Document the issue.

README.md:
    Add reference to README.x86.
2021-05-10 15:21:04 +10:00
Julien Fischer
26e542a6d4 Use __sync_synchronize() as a fallback memory barrier with clang.
runtime/mercury_atomic_ops.h:
    clang provides the GCC builtin function __sync_synchronize(); use that
    as a fallback memory barrier.

    Avoid unreadable #error directive output from clang.

    Add an XXX about C11 atomic ops.
2021-04-13 11:28:18 +10:00
Julien Fischer
2c0b268c1f Replace erroneous pragma with #error directive.
runtime/mercury_atomic_ops.h:
    As above; on aarch64-apple-darwin we were *not* getting the error about
    memory fence operations not being defined when using clang as the C
    compiler; compilation was instead aborting later due to MR_SFENCE
    not being defined.
2021-04-12 12:45:03 +10:00
Peter Wang
50270b130a Update term size code for RTTI changes introduced with subtypes.
runtime/mercury_term_size.c:
    Use MR_index_or_search_ptag_layout to search du type layouts by
    primary tag and MR_index_or_search_sectag_functor to search
    sectag_alternatives by secondary tag, as required for subtypes.

    Delete cases for MR_TYPECTOR_REP_RESERVED_ADDR*
    which have since been deleted.

    MR_SECTAG_REMOTE_WORD was previously renamed to
    MR_SECTAG_REMOTE_FULL_WORD.

    (Note that even with these changes, MR_RECORD_TERM_SIZES
    is not in a working state.)
2021-04-09 17:41:23 +10:00
Peter Wang
2b93c74d2b Update mercury_unify_compare_body.h for changes introduced with subtypes.
runtime/mercury_ho_call.c:
    Include mercury_deconstruct_macros.h for macros used in the
    following.

runtime/mercury_unify_compare_body.h:
    Use MR_index_or_search_ptag_layout to search du type layouts by
    primary tag and MR_index_or_search_sectag_functor to search
    sectag_alternatives by secondary tag, as required for subtypes.
2021-04-09 17:41:23 +10:00
Peter Wang
49ffafaa3e Fix MR_named_arg_num for RTTI changes introduced with subtypes.
runtime/mercury_deconstruct.c:
    Use MR_index_or_search_ptag_layout to search du type layouts by
    primary tag and MR_index_or_search_sectag_functor to search
    sectag_alternatives by secondary tag, as required for subtypes.

    (MR_named_arg_num is used by the debugger.)
2021-04-09 17:41:23 +10:00
Peter Wang
e60d6cb44a Fix deep copying of subtype terms.
runtime/mercury_deep_copy.c:
    Include mercury_deconstruct_macros.h for
    MR_index_or_search_ptag_layout and
    MR_index_or_search_sectag_functor.

runtime/mercury_deep_copy_body.h:
    Use the macros to search a du type layout by primary tag or a
    sectag_alternatives array by secondary tag, which is necessary
    for subtypes.

runtime/mercury_deconstruct.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_term_size.c:
runtime/mercury_unify_compare_body.h:
    Add comments where we can and can't directly index a du type layout
    or sectag alternatives array.

tests/hard_coded/subtype_rtti.m:
tests/hard_coded/subtype_rtti.exp:
tests/hard_coded/subtype_rtti.exp2:
    Test deep copying of subtype terms.
2021-04-09 17:41:23 +10:00